Bug 601299: Find RegExpStatics in cx->globalObject if necessary. (r=mrbkap)
[mozilla-central.git] / netwerk / test / TestMakeAbs.cpp
blob71e40b0322d4f99de05a165bdd1007ec27290cf4
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nspr.h"
39 #include "nscore.h"
40 #include "nsCOMPtr.h"
41 #include "nsIIOService.h"
42 #include "nsIServiceManager.h"
43 #include "nsIComponentRegistrar.h"
44 #include "nsIURI.h"
46 static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
48 nsresult ServiceMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) {
49 nsresult rv;
50 nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv));
51 if (NS_FAILED(rv)) return rv;
53 return serv->MakeAbsolute(relativeInfo, baseURI, _retval);
56 nsresult URLMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) {
57 return baseURI->MakeAbsolute(relativeInfo, _retval);
60 int
61 main(int argc, char* argv[])
63 nsresult rv = NS_OK;
64 if (argc < 4) {
65 printf("usage: %s int (loop count) baseURL relativeSpec\n", argv[0]);
66 return -1;
69 PRUint32 cycles = atoi(argv[1]);
70 char *base = argv[2];
71 char *rel = argv[3];
73 nsCOMPtr<nsIServiceManager> servMan;
74 NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
75 nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
76 NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
77 if (registrar)
78 registrar->AutoRegister(nsnull);
80 nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv));
81 if (NS_FAILED(rv)) return rv;
83 nsCOMPtr<nsIURI> uri;
84 rv = serv->NewURI(base, nsnull, getter_AddRefs(uri));
85 if (NS_FAILED(rv)) return rv;
87 char *absURLString;
88 PRUint32 i = 0;
89 while (i++ < cycles) {
90 rv = ServiceMakeAbsolute(uri, rel, &absURLString);
91 if (NS_FAILED(rv)) return rv;
92 nsMemory::Free(absURLString);
94 rv = URLMakeAbsolute(uri, rel, &absURLString);
95 nsMemory::Free(absURLString);
97 } // this scopes the nsCOMPtrs
98 // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
99 NS_ShutdownXPCOM(nsnull);
100 return rv;