1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/TestMakeAbs.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nspr.h" 1.10 +#include "nscore.h" 1.11 +#include "nsCOMPtr.h" 1.12 +#include "nsIIOService.h" 1.13 +#include "nsIServiceManager.h" 1.14 +#include "nsIComponentRegistrar.h" 1.15 +#include "nsIURI.h" 1.16 + 1.17 +static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); 1.18 + 1.19 +nsresult ServiceMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) { 1.20 + nsresult rv; 1.21 + nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv)); 1.22 + if (NS_FAILED(rv)) return rv; 1.23 + 1.24 + return serv->MakeAbsolute(relativeInfo, baseURI, _retval); 1.25 +} 1.26 + 1.27 +nsresult URLMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) { 1.28 + return baseURI->MakeAbsolute(relativeInfo, _retval); 1.29 +} 1.30 + 1.31 +int 1.32 +main(int argc, char* argv[]) 1.33 +{ 1.34 + nsresult rv = NS_OK; 1.35 + if (argc < 4) { 1.36 + printf("usage: %s int (loop count) baseURL relativeSpec\n", argv[0]); 1.37 + return -1; 1.38 + } 1.39 + 1.40 + uint32_t cycles = atoi(argv[1]); 1.41 + char *base = argv[2]; 1.42 + char *rel = argv[3]; 1.43 + { 1.44 + nsCOMPtr<nsIServiceManager> servMan; 1.45 + NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); 1.46 + nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); 1.47 + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); 1.48 + if (registrar) 1.49 + registrar->AutoRegister(nullptr); 1.50 + 1.51 + nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv)); 1.52 + if (NS_FAILED(rv)) return rv; 1.53 + 1.54 + nsCOMPtr<nsIURI> uri; 1.55 + rv = serv->NewURI(base, nullptr, getter_AddRefs(uri)); 1.56 + if (NS_FAILED(rv)) return rv; 1.57 + 1.58 + char *absURLString; 1.59 + uint32_t i = 0; 1.60 + while (i++ < cycles) { 1.61 + rv = ServiceMakeAbsolute(uri, rel, &absURLString); 1.62 + if (NS_FAILED(rv)) return rv; 1.63 + nsMemory::Free(absURLString); 1.64 + 1.65 + rv = URLMakeAbsolute(uri, rel, &absURLString); 1.66 + nsMemory::Free(absURLString); 1.67 + } 1.68 + } // this scopes the nsCOMPtrs 1.69 + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM 1.70 + NS_ShutdownXPCOM(nullptr); 1.71 + return rv; 1.72 +}