Bug 782594 - Don't return nsresult from main() (netwerk/); r=bz
authorAryeh Gregor <ayg@aryeh.name>
Tue, 07 Aug 2012 20:17:27 +0300
changeset 110415 6c0ffaa92c3cbdb430543b16d95be2ad4ac9d70a
parent 110414 20d9cf9332ce9a678393f40b7266f453b7090a34
child 110416 3bb941410b40c0f63de36e077633d289c8219f5c
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs782594
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 782594 - Don't return nsresult from main() (netwerk/); r=bz
netwerk/streamconv/test/TestStreamConv.cpp
netwerk/test/PropertiesTest.cpp
netwerk/test/TestBlockingSocket.cpp
netwerk/test/TestCallbacks.cpp
netwerk/test/TestOpen.cpp
netwerk/test/TestPageLoad.cpp
netwerk/test/TestProtocols.cpp
netwerk/test/TestSTSParser.cpp
netwerk/test/TestServ.cpp
netwerk/test/TestStreamLoader.cpp
netwerk/test/TestUpload.cpp
netwerk/test/urltest.cpp
--- a/netwerk/streamconv/test/TestStreamConv.cpp
+++ b/netwerk/streamconv/test/TestStreamConv.cpp
@@ -173,22 +173,22 @@ main(int argc, char* argv[])
 
         nsCOMPtr<nsIServiceManager> servMan;
         NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
     
         nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
 
         nsCOMPtr<nsICategoryManager> catman =
             do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
         nsCString previous;
 
         nsCOMPtr<nsIStreamConverterService> StreamConvService =
                  do_GetService(kStreamConverterServiceCID, &rv);
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 
         // Define the *from* content type and *to* content-type for conversion.
         static const char fromStr[] = "a/foo";
         static const char toStr[] = "c/foo";
     
 #ifdef ASYNC_TEST
         // ASYNCHRONOUS conversion
 
@@ -196,24 +196,24 @@ main(int argc, char* argv[])
         // starting the transaction with.
         //
         // sample multipart mixed content-type string:
         // "multipart/x-mixed-replacE;boundary=thisrandomstring"
 #if 0
         nsCOMPtr<nsIChannel> channel;
         nsCOMPtr<nsIURI> dummyURI;
         rv = NS_NewURI(getter_AddRefs(dummyURI), "http://meaningless");
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 
         rv = NS_NewInputStreamChannel(getter_AddRefs(channel),
                                       dummyURI,
                                       nullptr,   // inStr
                                       "text/plain", // content-type
                                       -1);      // XXX fix contentLength
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 
         nsCOMPtr<nsIRequest> request(do_QueryInterface(channel));
 #endif
 
         nsCOMPtr<nsIRequest> request;
 
         // setup a listener to receive the converted data. This guy is the end
         // listener in the chain, he wants the fully converted (toType) data.
@@ -222,47 +222,47 @@ main(int argc, char* argv[])
         NS_ADDREF(dataReceiver);
 
         // setup a listener to push the data into. This listener sits inbetween the
         // unconverted data of fromType, and the final listener in the chain (in this case
         // the dataReceiver.
         nsIStreamListener *converterListener = nullptr;
         rv = StreamConvService->AsyncConvertData(fromStr, toStr,
                                                  dataReceiver, nullptr, &converterListener);
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
         NS_RELEASE(dataReceiver);
 
         // at this point we have a stream listener to push data to, and the one
         // that will receive the converted data. Let's mimic On*() calls and get the conversion
         // going. Typically these On*() calls would be made inside their respective wrappers On*()
         // methods.
         rv = converterListener->OnStartRequest(request, nullptr);
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 
         rv = SEND_DATA("aaa");
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 
         rv = SEND_DATA("aaa");
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 
         // Finish the request.
         rv = converterListener->OnStopRequest(request, nullptr, rv);
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 
         NS_RELEASE(converterListener);
 #else
         // SYNCHRONOUS conversion
         nsCOMPtr<nsIInputStream> convertedData;
         rv = StreamConvService->Convert(inputData, fromStr, toStr,
                                         nullptr, getter_AddRefs(convertedData));
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 #endif
 
         // Enter the message pump to allow the URL load to proceed.
         while ( gKeepRunning ) {
             if (!NS_ProcessNextEvent(thread))
                 break;
         }
     } // this scopes the nsCOMPtrs
     // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
     NS_ShutdownXPCOM(nullptr);
-    return rv;
+    return 0;
 }
--- a/netwerk/test/PropertiesTest.cpp
+++ b/netwerk/test/PropertiesTest.cpp
@@ -35,24 +35,24 @@ main(int argc, char* argv[])
   nsresult ret;
 
   nsCOMPtr<nsIServiceManager> servMan;
   NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
 
   nsIInputStream* in = nullptr;
 
   nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &ret));
-  if (NS_FAILED(ret)) return ret;
+  if (NS_FAILED(ret)) return 1;
 
   nsIChannel *channel = nullptr;
   ret = service->NewChannel(NS_LITERAL_CSTRING(TEST_URL), nullptr, nullptr, &channel);
-  if (NS_FAILED(ret)) return ret;
+  if (NS_FAILED(ret)) return 1;
 
   ret = channel->Open(&in);
-  if (NS_FAILED(ret)) return ret;
+  if (NS_FAILED(ret)) return 1;
 
   nsIPersistentProperties* props;
   ret = CallCreateInstance(kPersistentPropertiesCID, &props);
   if (NS_FAILED(ret) || (!props)) {
     printf("create nsIPersistentProperties failed\n");
     return 1;
   }
   ret = props->Load(in);
--- a/netwerk/test/TestBlockingSocket.cpp
+++ b/netwerk/test/TestBlockingSocket.cpp
@@ -105,26 +105,26 @@ main(int argc, char* argv[])
         NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
 
 #if defined(PR_LOGGING)
         gTestLog = PR_NewLogModule("Test");
 #endif
 
         nsCOMPtr<nsIFile> file;
         rv = NS_NewNativeLocalFile(nsDependentCString(fileName), false, getter_AddRefs(file));
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 
         rv = RunBlockingTest(nsDependentCString(hostName), port, file);
 #if defined(PR_LOGGING)
         if (NS_FAILED(rv))
             LOG(("RunBlockingTest failed [rv=%x]\n", rv));
 #endif
 
         // give background threads a chance to finish whatever work they may
         // be doing.
         LOG(("sleeping for 5 seconds...\n"));
         PR_Sleep(PR_SecondsToInterval(5));
     } // this scopes the nsCOMPtrs
     // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
     rv = NS_ShutdownXPCOM(nullptr);
     NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
-    return NS_OK;
+    return 0;
 }
--- a/netwerk/test/TestCallbacks.cpp
+++ b/netwerk/test/TestCallbacks.cpp
@@ -216,33 +216,33 @@ int main(int argc, char *argv[]) {
     bool cmdLineURL = false;
 
     if (argc > 1) {
         // run in signle url mode
         cmdLineURL = true;
     }
 
     rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
-    if (NS_FAILED(rv)) return rv;
+    if (NS_FAILED(rv)) return -1;
 
     if (cmdLineURL) {
         rv = StartLoad(argv[1]);
     } else {
         rv = StartLoad("http://badhostnamexyz/test.txt");
     }
-    if (NS_FAILED(rv)) return rv;
+    if (NS_FAILED(rv)) return -1;
 
     // Enter the message pump to allow the URL load to proceed.
     PumpEvents();
 
     NS_ShutdownXPCOM(nullptr);
     if (gError) {
         fprintf(stderr, "\n\n-------ERROR-------\n\n");
     }
-    return rv;
+    return 0;
 }
 
 nsresult StartLoad(const char *aURISpec) {
     nsresult rv = NS_OK;
 
     // create a context
     ConsumerContext *context = new ConsumerContext;
     nsCOMPtr<nsISupports> contextSup = do_QueryInterface(context, &rv);
--- a/netwerk/test/TestOpen.cpp
+++ b/netwerk/test/TestOpen.cpp
@@ -28,17 +28,17 @@
 
 int
 main(int argc, char **argv)
 {
     if (test_common_init(&argc, &argv) != 0)
         return -1;
 
     nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
-    if (NS_FAILED(rv)) return rv;
+    if (NS_FAILED(rv)) return -1;
 
     char buf[256];
 
     if (argc != 3) {
         printf("Usage: TestOpen url filename\nLoads a URL using ::Open, writing it to a file\n");
         return -1;
     }
 
--- a/netwerk/test/TestPageLoad.cpp
+++ b/netwerk/test/TestPageLoad.cpp
@@ -20,21 +20,21 @@
 
 namespace TestPageLoad {
 
 int getStrLine(const char *src, char *str, int ind, int max);
 nsresult auxLoad(char *uriBuf);
 //----------------------------------------------------------------------
 
 
-#define RETURN_IF_FAILED(rv, step) \
+#define RETURN_IF_FAILED(rv, ret, step) \
     PR_BEGIN_MACRO \
     if (NS_FAILED(rv)) { \
         printf(">>> %s failed: rv=%x\n", step, rv); \
-        return rv;\
+        return ret;\
     } \
     PR_END_MACRO
 
 static nsCString globalStream;
 //static char urlBuf[256];
 static nsCOMPtr<nsIURI> baseURI;
 static nsCOMArray<nsIURI> uriList;
 
@@ -291,21 +291,21 @@ nsresult auxLoad(char *uriBuf)
       if(equal) {
         printf("(duplicate, canceling) %s\n",uriBuf); 
         return NS_OK;
       }
     }
     printf("\n");
     uriList.AppendObject(uri);
     rv = NS_NewChannel(getter_AddRefs(chan), uri, nullptr, nullptr, callbacks);
-    RETURN_IF_FAILED(rv, "NS_NewChannel");
+    RETURN_IF_FAILED(rv, rv, "NS_NewChannel");
 
     gKeepRunning++;
     rv = chan->AsyncOpen(listener, myBool);
-    RETURN_IF_FAILED(rv, "AsyncOpen");
+    RETURN_IF_FAILED(rv, rv, "AsyncOpen");
 
     return NS_OK;
 
 }
 
 //---------Buffer writer fun---------
 
 } // namespace
@@ -332,27 +332,27 @@ int main(int argc, char **argv)
         PRTime start, finish;
 
         printf("Loading necko ... \n");
         nsCOMPtr<nsIChannel> chan;
         nsCOMPtr<nsIStreamListener> listener = new MyListener();
         nsCOMPtr<nsIInterfaceRequestor> callbacks = new MyNotifications();
 
         rv = NS_NewURI(getter_AddRefs(baseURI), argv[1]);
-        RETURN_IF_FAILED(rv, "NS_NewURI");
+        RETURN_IF_FAILED(rv, -1, "NS_NewURI");
 
         rv = NS_NewChannel(getter_AddRefs(chan), baseURI, nullptr, nullptr, callbacks);
-        RETURN_IF_FAILED(rv, "NS_OpenURI");
+        RETURN_IF_FAILED(rv, -1, "NS_OpenURI");
         gKeepRunning++;
 
         //TIMER STARTED-----------------------
         printf("Starting clock ... \n");
         start = PR_Now();
         rv = chan->AsyncOpen(listener, nullptr);
-        RETURN_IF_FAILED(rv, "AsyncOpen");
+        RETURN_IF_FAILED(rv, -1, "AsyncOpen");
 
         PumpEvents();
 
         finish = PR_Now();
         uint32_t totalTime32;
         uint64_t totalTime64;
         LL_SUB(totalTime64, finish, start);
         LL_L2UI(totalTime32, totalTime64);
--- a/netwerk/test/TestProtocols.cpp
+++ b/netwerk/test/TestProtocols.cpp
@@ -830,17 +830,17 @@ main(int argc, char* argv[])
 #endif
 
     /* 
       The following code only deals with XPCOM registration stuff. and setting
       up the event queues. Copied from TestSocketIO.cpp
     */
 
     rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
-    if (NS_FAILED(rv)) return rv;
+    if (NS_FAILED(rv)) return -1;
 
     {
         int i;
         LOG(("Trying to load:\n"));
         for (i=1; i<argc; i++) {
             // Turn on verbose printing...
             if (PL_strcasecmp(argv[i], "-verbose") == 0) {
                 gVerbose = true;
@@ -882,10 +882,10 @@ main(int argc, char* argv[])
             LOG(("\t%s\n", argv[i]));
             rv = StartLoadingURL(argv[i]);
         }
         // Enter the message pump to allow the URL load to proceed.
         PumpEvents();
     } // this scopes the nsCOMPtrs
     // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
     NS_ShutdownXPCOM(nullptr);
-    return rv;
+    return NS_FAILED(rv) ? -1 : 0;
 }
--- a/netwerk/test/TestSTSParser.cpp
+++ b/netwerk/test/TestSTSParser.cpp
@@ -87,21 +87,21 @@ main(int32_t argc, char *argv[])
     if (!profile) {
       fail("Couldn't get the profile directory.");
       return -1;
     }
 
     // grab handle to the service
     nsCOMPtr<nsIStrictTransportSecurityService> stss;
     stss = do_GetService("@mozilla.org/stsservice;1", &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
+    NS_ENSURE_SUCCESS(rv, -1);
 
     nsCOMPtr<nsIPermissionManager> pm;
     pm = do_GetService("@mozilla.org/permissionmanager;1", &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
+    NS_ENSURE_SUCCESS(rv, -1);
 
     int rv0, rv1;
 
     nsTArray<bool> rvs(24);
 
     // *** parsing tests
     printf("*** Attempting to parse valid STS headers ...\n");
 
--- a/netwerk/test/TestServ.cpp
+++ b/netwerk/test/TestServ.cpp
@@ -122,24 +122,24 @@ main(int argc, char* argv[])
 #endif
 
     /* 
      * The following code only deals with XPCOM registration stuff. and setting
      * up the event queues. Copied from TestSocketIO.cpp
      */
 
     rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
-    if (NS_FAILED(rv)) return rv;
+    if (NS_FAILED(rv)) return -1;
 
     {
         rv = MakeServer(atoi(argv[1]));
         if (NS_FAILED(rv)) {
             LOG(("MakeServer failed [rv=%x]\n", rv));
             return -1;
         }
 
         // Enter the message pump to allow the URL load to proceed.
         PumpEvents();
     } // this scopes the nsCOMPtrs
     // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
     NS_ShutdownXPCOM(nullptr);
-    return rv;
+    return 0;
 }
--- a/netwerk/test/TestStreamLoader.cpp
+++ b/netwerk/test/TestStreamLoader.cpp
@@ -80,10 +80,10 @@ int main(int argc, char **argv)
     rv = chan->AsyncOpen(loader, nullptr);
     if (NS_FAILED(rv))
       return -1;
 
     PumpEvents();
   } // this scopes the nsCOMPtrs
   // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
   NS_ShutdownXPCOM(nullptr);
-  return rv;
+  return 0;
 }
--- a/netwerk/test/TestUpload.cpp
+++ b/netwerk/test/TestUpload.cpp
@@ -122,26 +122,26 @@ main(int argc, char* argv[])
         nsCOMPtr<nsIIOService> ioService(do_GetService(kIOServiceCID, &rv));
         // first thing to do is create ourselves a stream that
         // is to be uploaded.
         nsCOMPtr<nsIInputStream> uploadStream;
         rv = NS_NewPostDataStream(getter_AddRefs(uploadStream),
                                   true,
                                   nsDependentCString(fileName), // XXX UTF-8
                                   0, ioService);
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 
         // create our url.
         nsCOMPtr<nsIURI> uri;
         rv = NS_NewURI(getter_AddRefs(uri), uriSpec);
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 
         nsCOMPtr<nsIChannel> channel;
         rv = ioService->NewChannelFromURI(uri, getter_AddRefs(channel));
-        if (NS_FAILED(rv)) return rv;
+        if (NS_FAILED(rv)) return -1;
 	
         // QI and set the upload stream
         nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(channel));
         uploadChannel->SetUploadStream(uploadStream, EmptyCString(), -1);
 
         // create a dummy listener
         InputTestConsumer* listener;
 
--- a/netwerk/test/urltest.cpp
+++ b/netwerk/test/urltest.cpp
@@ -375,21 +375,19 @@ void printusage(void)
            "\t<URL> : The string representing the URL.\n");
 }
 
 int main(int argc, char **argv)
 {
     if (test_common_init(&argc, &argv) != 0)
         return -1;
 
-    int rv = -1;
-
     if (argc < 2) {
         printusage();
-        return NS_OK;
+        return 0;
     }
     {
         nsCOMPtr<nsIServiceManager> servMan;
         NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
 
         // end of all messages from register components...
         printf("------------------\n\n");
 
@@ -399,57 +397,62 @@ int main(int argc, char **argv)
         char* url = 0;
         for (int i=1; i<argc; i++) {
             if (PL_strcasecmp(argv[i], "-std") == 0)
             {
                 urlFactory = URL_FACTORY_STDURL;
                 if (i+1 >= argc)
                 {
                     printusage();
-                    return NS_OK;
+                    return 0;
                 }
             }
             else if (PL_strcasecmp(argv[i], "-abs") == 0)
             {
                 if (!gFileIO)
                 {
                     relativePath = argv[i+1];
                     i++;
                 }
                 bMakeAbs = true;
             }
             else if (PL_strcasecmp(argv[i], "-file") == 0)
             {
                 if (i+1 >= argc)
                 {
                     printusage();
-                    return NS_OK;
+                    return 0;
                 }
                 gFileIO = argv[i+1];
                 i++;
             }
             else
             {
                 url = argv[i];
             }
         }
         PRTime startTime = PR_Now();
         if (bMakeAbs)
         {
-            rv = (url && relativePath)
-               ? doMakeAbsTest(url, relativePath)
-               : doMakeAbsTest();
+            if (url && relativePath) {
+              doMakeAbsTest(url, relativePath);
+            } else {
+              doMakeAbsTest();
+            }
         }
         else
         {
-            rv = gFileIO ? testURL(0, urlFactory) : testURL(url, urlFactory);
+            if (gFileIO) {
+              testURL(0, urlFactory);
+            } else {
+              testURL(url, urlFactory);
+            }
         }
         if (gFileIO)
         {
             PRTime endTime = PR_Now();
             printf("Elapsed time: %d micros.\n", (int32_t)
                 (endTime - startTime));
         }
     } // this scopes the nsCOMPtrs
     // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
-    rv = NS_ShutdownXPCOM(nullptr);
-    return rv;
+    return NS_FAILED(NS_ShutdownXPCOM(nullptr)) ? 1 : 0;
 }