From 585baa080335d561a8a9b8d4c958b0c3b5f385a9 Mon Sep 17 00:00:00 2001 From: "timeless%mac.com" Date: Thu, 4 Jul 2002 14:29:25 +0000 Subject: [PATCH] Bug 155466 clean up test consumers to correctly use NS_ShutdownXPCOM r=dmose, sr=scc, moa: dougt, dbradley, gagan, harish, akk git-svn-id: svn://10.0.0.236/trunk@124683 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/htmlparser/tests/outsinks/Convert.cpp | 37 +- mozilla/js/src/xpconnect/shell/xpcshell.cpp | 186 +-- mozilla/js/src/xpconnect/tests/TestXPC.cpp | 111 +- mozilla/netwerk/base/tests/makefile.win | 3 + mozilla/netwerk/base/tests/urltest.cpp | 50 +- .../streamconv/test/TestStreamConv.cpp | 297 ++-- mozilla/netwerk/test/TestCacheBlockFiles.cpp | 1251 +++++++++-------- mozilla/netwerk/test/TestCacheMgr.cpp | 67 +- mozilla/netwerk/test/TestCacheService.cpp | 12 +- mozilla/netwerk/test/TestCallbacks.cpp | 6 +- mozilla/netwerk/test/TestDBMAccess.cpp | 38 +- mozilla/netwerk/test/TestDNSDaemon.cpp | 2 +- mozilla/netwerk/test/TestFileInput.cpp | 44 +- mozilla/netwerk/test/TestFileInput2.cpp | 106 +- mozilla/netwerk/test/TestFileTransport.cpp | 45 +- mozilla/netwerk/test/TestHttp.cpp | 59 +- mozilla/netwerk/test/TestMakeAbs.cpp | 47 +- mozilla/netwerk/test/TestPageLoad.cpp | 106 +- mozilla/netwerk/test/TestPerf.cpp | 2 +- mozilla/netwerk/test/TestProtocols.cpp | 100 +- mozilla/netwerk/test/TestRawCache.cpp | 171 +-- mozilla/netwerk/test/TestRes.cpp | 50 +- mozilla/netwerk/test/TestSocketInput.cpp | 94 +- mozilla/netwerk/test/TestSocketTransport.cpp | 82 +- mozilla/netwerk/test/TestThreadedIO.cpp | 35 +- mozilla/netwerk/test/TestUpload.cpp | 116 +- mozilla/netwerk/test/TestWriteStream.cpp | 39 +- mozilla/netwerk/test/urltest.cpp | 111 +- .../htmlparser/tests/outsinks/Convert.cpp | 37 +- mozilla/xpcom/tests/RegFactory.cpp | 14 +- mozilla/xpcom/tests/TestFactory.cpp | 74 +- mozilla/xpcom/tests/TestPipes.cpp | 3 + mozilla/xpcom/tests/nsIFileEnumerator.cpp | 57 +- mozilla/xpcom/tools/registry/regExport.cpp | 1 + mozilla/xpcom/tools/registry/regxpcom.cpp | 19 +- 35 files changed, 1781 insertions(+), 1691 deletions(-) diff --git a/mozilla/htmlparser/tests/outsinks/Convert.cpp b/mozilla/htmlparser/tests/outsinks/Convert.cpp index 74781150a60..8c3a8788e5a 100644 --- a/mozilla/htmlparser/tests/outsinks/Convert.cpp +++ b/mozilla/htmlparser/tests/outsinks/Convert.cpp @@ -287,23 +287,30 @@ Usage: %s [-i intype] [-o outtype] [-f flags] [-w wrapcol] [-c comparison_file] exit(1); } } - else file = stdin; + else + file = stdin; + nsresult ret; + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + // Read in the string: very inefficient, but who cares? + nsString inString; + int c; + while ((c = getc(file)) != EOF) + inString.Append(PRUnichar(c)); - // Read in the string: very inefficient, but who cares? - nsString inString; - int c; - while ((c = getc(file)) != EOF) - inString.Append(PRUnichar(c)); + if (file != stdin) + fclose(file); - if (file != stdin) - fclose(file); - - return HTML2text(inString, inType, outType, flags, wrapCol, compareAgainst); + ret = HTML2text(inString, inType, outType, flags, wrapCol, compareAgainst); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + nsresult rv = NS_ShutdownXPCOM( NULL ); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); + return ret; } diff --git a/mozilla/js/src/xpconnect/shell/xpcshell.cpp b/mozilla/js/src/xpconnect/shell/xpcshell.cpp index 17bbed06753..a675ac5914f 100644 --- a/mozilla/js/src/xpconnect/shell/xpcshell.cpp +++ b/mozilla/js/src/xpconnect/shell/xpcshell.cpp @@ -827,125 +827,125 @@ main(int argc, char **argv) gErrFile = stderr; gOutFile = stdout; + { + nsCOMPtr servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + if (NS_FAILED(rv)) { + printf("NS_InitXPCOM failed!\n"); + return 1; + } + { + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); + } - nsCOMPtr servMan; - rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - if (NS_FAILED(rv)) { - printf("NS_InitXPCOM failed!\n"); - return 1; - } - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + nsCOMPtr rtsvc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1"); + // get the JSRuntime from the runtime svc + if (!rtsvc) { + printf("failed to get nsJSRuntimeService!\n"); + return 1; + } + if (NS_FAILED(rtsvc->GetRuntime(&rt)) || !rt) { + printf("failed to get JSRuntime from nsJSRuntimeService!\n"); + return 1; + } - nsCOMPtr rtsvc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1"); - // get the JSRuntime from the runtime svc - if (!rtsvc) { - printf("failed to get nsJSRuntimeService!\n"); - return 1; - } - - if (NS_FAILED(rtsvc->GetRuntime(&rt)) || !rt) { - printf("failed to get JSRuntime from nsJSRuntimeService!\n"); - return 1; - } + jscontext = JS_NewContext(rt, 8192); + if (!jscontext) { + printf("JS_NewContext failed!\n"); + return 1; + } - jscontext = JS_NewContext(rt, 8192); - if (!jscontext) { - printf("JS_NewContext failed!\n"); - return 1; - } + JS_SetErrorReporter(jscontext, my_ErrorReporter); - JS_SetErrorReporter(jscontext, my_ErrorReporter); + nsCOMPtr xpc = do_GetService(nsIXPConnect::GetCID()); + if (!xpc) { + printf("failed to get nsXPConnect service!\n"); + return 1; + } - nsCOMPtr xpc = do_GetService(nsIXPConnect::GetCID()); - if (!xpc) { - printf("failed to get nsXPConnect service!\n"); - return 1; - } + // Since the caps security system might set a default security manager + // we will be sure that the secman on this context gives full trust. + // That way we can avoid getting principals from the caps security manager + // just to shut it up. Also, note that even though our secman will allow + // anything, we set the flags to '0' so it ought never get called anyway. + nsCOMPtr secman = + NS_STATIC_CAST(nsIXPCSecurityManager*, new FullTrustSecMan()); + xpc->SetSecurityManagerForJSContext(jscontext, secman, 0); - // Since the caps security system might set a default security manager - // we will be sure that the secman on this context gives full trust. - // That way we can avoid getting principals from the caps security manager - // just to shut it up. Also, note that even though our secman will allow - // anything, we set the flags to '0' so it ought never get called anyway. - nsCOMPtr secman = - NS_STATIC_CAST(nsIXPCSecurityManager*, new FullTrustSecMan()); - xpc->SetSecurityManagerForJSContext(jscontext, secman, 0); - -// xpc->SetCollectGarbageOnMainThreadOnly(PR_TRUE); -// xpc->SetDeferReleasesUntilAfterGarbageCollection(PR_TRUE); + // xpc->SetCollectGarbageOnMainThreadOnly(PR_TRUE); + // xpc->SetDeferReleasesUntilAfterGarbageCollection(PR_TRUE); #ifdef TEST_TranslateThis - nsCOMPtr - translator(new nsXPCFunctionThisTranslator); - xpc->SetFunctionThisTranslator(NS_GET_IID(nsITestXPCFunctionCallback), translator, nsnull); + nsCOMPtr + translator(new nsXPCFunctionThisTranslator); + xpc->SetFunctionThisTranslator(NS_GET_IID(nsITestXPCFunctionCallback), translator, nsnull); #endif - nsCOMPtr cxstack = do_GetService("@mozilla.org/js/xpc/ContextStack;1"); - if (!cxstack) { - printf("failed to get the nsThreadJSContextStack service!\n"); - return 1; - } + nsCOMPtr cxstack = do_GetService("@mozilla.org/js/xpc/ContextStack;1"); + if (!cxstack) { + printf("failed to get the nsThreadJSContextStack service!\n"); + return 1; + } - if(NS_FAILED(cxstack->Push(jscontext))) { - printf("failed to push the current JSContext on the nsThreadJSContextStack!\n"); - return 1; - } + if(NS_FAILED(cxstack->Push(jscontext))) { + printf("failed to push the current JSContext on the nsThreadJSContextStack!\n"); + return 1; + } - glob = JS_NewObject(jscontext, &global_class, NULL, NULL); - if (!glob) - return 1; - if (!JS_InitStandardClasses(jscontext, glob)) - return 1; - if (!JS_DefineFunctions(jscontext, glob, glob_functions)) - return 1; - if (NS_FAILED(xpc->InitClasses(jscontext, glob))) - return 1; + glob = JS_NewObject(jscontext, &global_class, NULL, NULL); + if (!glob) + return 1; + if (!JS_InitStandardClasses(jscontext, glob)) + return 1; + if (!JS_DefineFunctions(jscontext, glob, glob_functions)) + return 1; + if (NS_FAILED(xpc->InitClasses(jscontext, glob))) + return 1; - argc--; - argv++; + argc--; + argv++; - result = ProcessArgs(jscontext, glob, argv, argc); + result = ProcessArgs(jscontext, glob, argv, argc); #ifdef TEST_InitClassesWithNewWrappedGlobal - // quick hacky test... + // quick hacky test... - JSContext* foo = JS_NewContext(rt, 8192); - nsCOMPtr bar(new TestGlobal()); - nsCOMPtr baz; - xpc->InitClassesWithNewWrappedGlobal(foo, bar, NS_GET_IID(nsIXPCTestNoisy), - PR_TRUE, getter_AddRefs(baz)); - bar = nsnull; - baz = nsnull; - JS_GC(foo); - JS_DestroyContext(foo); + JSContext* foo = JS_NewContext(rt, 8192); + nsCOMPtr bar(new TestGlobal()); + nsCOMPtr baz; + xpc->InitClassesWithNewWrappedGlobal(foo, bar, NS_GET_IID(nsIXPCTestNoisy), + PR_TRUE, getter_AddRefs(baz)); + bar = nsnull; + baz = nsnull; + JS_GC(foo); + JS_DestroyContext(foo); #endif //#define TEST_CALL_ON_WRAPPED_JS_AFTER_SHUTDOWN 1 #ifdef TEST_CALL_ON_WRAPPED_JS_AFTER_SHUTDOWN - // test of late call and release (see below) - nsCOMPtr bogus; - xpc->WrapJS(jscontext, glob, NS_GET_IID(nsIJSContextStack), - (void**) getter_AddRefs(bogus)); + // test of late call and release (see below) + nsCOMPtr bogus; + xpc->WrapJS(jscontext, glob, NS_GET_IID(nsIJSContextStack), + (void**) getter_AddRefs(bogus)); #endif - JS_ClearScope(jscontext, glob); - JS_GC(jscontext); - JSContext *oldcx; - cxstack->Pop(&oldcx); - NS_ASSERTION(oldcx == jscontext, "JS thread context push/pop mismatch"); - cxstack = nsnull; - JS_GC(jscontext); - JS_DestroyContext(jscontext); - xpc->SyncJSContexts(); - xpc = nsnull; // force nsCOMPtr to Release the service - secman = nsnull; - rtsvc = nsnull; - + JS_ClearScope(jscontext, glob); + JS_GC(jscontext); + JSContext *oldcx; + cxstack->Pop(&oldcx); + NS_ASSERTION(oldcx == jscontext, "JS thread context push/pop mismatch"); + cxstack = nsnull; + JS_GC(jscontext); + JS_DestroyContext(jscontext); + xpc->SyncJSContexts(); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM rv = NS_ShutdownXPCOM( NULL ); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); diff --git a/mozilla/js/src/xpconnect/tests/TestXPC.cpp b/mozilla/js/src/xpconnect/tests/TestXPC.cpp index b920acde7d5..47610b8a5b3 100644 --- a/mozilla/js/src/xpconnect/tests/TestXPC.cpp +++ b/mozilla/js/src/xpconnect/tests/TestXPC.cpp @@ -704,75 +704,76 @@ int main() gErrFile = stderr; gOutFile = stdout; - - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if(registrar) + registrar->AutoRegister(nsnull); - // get the JSRuntime from the runtime svc, if possible - nsCOMPtr rtsvc = - do_GetService("@mozilla.org/js/xpc/RuntimeService;1", &rv); - if(NS_FAILED(rv) || NS_FAILED(rtsvc->GetRuntime(&rt)) || !rt) - DIE("FAILED to get a JSRuntime"); + // get the JSRuntime from the runtime svc, if possible + nsCOMPtr rtsvc = + do_GetService("@mozilla.org/js/xpc/RuntimeService;1", &rv); + if(NS_FAILED(rv) || NS_FAILED(rtsvc->GetRuntime(&rt)) || !rt) + DIE("FAILED to get a JSRuntime"); - jscontext = JS_NewContext(rt, 8192); - if(!jscontext) - DIE("FAILED to create a JSContext"); + jscontext = JS_NewContext(rt, 8192); + if(!jscontext) + DIE("FAILED to create a JSContext"); - JS_SetErrorReporter(jscontext, my_ErrorReporter); + JS_SetErrorReporter(jscontext, my_ErrorReporter); - nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); - if(!xpc) - DIE("FAILED to get xpconnect service\n"); + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); + if(!xpc) + DIE("FAILED to get xpconnect service\n"); - nsCOMPtr cxstack = - do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv); - if(NS_FAILED(rv)) - DIE("FAILED to get the nsThreadJSContextStack service!\n"); + nsCOMPtr cxstack = + do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv); + if(NS_FAILED(rv)) + DIE("FAILED to get the nsThreadJSContextStack service!\n"); - if(NS_FAILED(cxstack->Push(jscontext))) - DIE("FAILED to push the current jscontext on the nsThreadJSContextStack service!\n"); + if(NS_FAILED(cxstack->Push(jscontext))) + DIE("FAILED to push the current jscontext on the nsThreadJSContextStack service!\n"); - // XXX I'd like to replace this with code that uses a wrapped xpcom object - // as the global object. The old TextXPC did this. The support for this - // is not working now in the new xpconnect code. + // XXX I'd like to replace this with code that uses a wrapped xpcom object + // as the global object. The old TextXPC did this. The support for this + // is not working now in the new xpconnect code. - glob = JS_NewObject(jscontext, &global_class, NULL, NULL); - if (!glob) - DIE("FAILED to create global object"); - if (!JS_InitStandardClasses(jscontext, glob)) - DIE("FAILED to init standard classes"); - if (!JS_DefineFunctions(jscontext, glob, glob_functions)) - DIE("FAILED to define global functions"); - if (NS_FAILED(xpc->InitClasses(jscontext, glob))) - DIE("FAILED to init xpconnect classes"); + glob = JS_NewObject(jscontext, &global_class, NULL, NULL); + if (!glob) + DIE("FAILED to create global object"); + if (!JS_InitStandardClasses(jscontext, glob)) + DIE("FAILED to init standard classes"); + if (!JS_DefineFunctions(jscontext, glob, glob_functions)) + DIE("FAILED to define global functions"); + if (NS_FAILED(xpc->InitClasses(jscontext, glob))) + DIE("FAILED to init xpconnect classes"); - /**********************************************/ - // run the tests... + /**********************************************/ + // run the tests... - TestCategoryManmager(); - TestSecurityManager(jscontext, glob, xpc); - TestArgFormatter(jscontext, glob, xpc); - TestThreadJSContextStack(jscontext); + TestCategoryManmager(); + TestSecurityManager(jscontext, glob, xpc); + TestArgFormatter(jscontext, glob, xpc); + TestThreadJSContextStack(jscontext); - /**********************************************/ + /**********************************************/ - if(NS_FAILED(cxstack->Pop(nsnull))) - DIE("FAILED to pop the current jscontext from the nsThreadJSContextStack service!\n"); + if(NS_FAILED(cxstack->Pop(nsnull))) + DIE("FAILED to pop the current jscontext from the nsThreadJSContextStack service!\n"); - JS_ClearScope(jscontext, glob); - JS_GC(jscontext); - JS_GC(jscontext); - JS_DestroyContext(jscontext); - xpc->SyncJSContexts(); - xpc->DebugDump(4); - - cxstack = nsnull; // release service held by nsCOMPtr - xpc = nsnull; // release service held by nsCOMPtr - rtsvc = nsnull; // release service held by nsCOMPtr + JS_ClearScope(jscontext, glob); + JS_GC(jscontext); + JS_GC(jscontext); + JS_DestroyContext(jscontext); + xpc->SyncJSContexts(); + xpc->DebugDump(4); + cxstack = nsnull; // release service held by nsCOMPtr + xpc = nsnull; // release service held by nsCOMPtr + rtsvc = nsnull; // release service held by nsCOMPtr + } rv = NS_ShutdownXPCOM( NULL ); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM FAILED"); diff --git a/mozilla/netwerk/base/tests/makefile.win b/mozilla/netwerk/base/tests/makefile.win index eba0bfc4d23..f4a2a5315cd 100644 --- a/mozilla/netwerk/base/tests/makefile.win +++ b/mozilla/netwerk/base/tests/makefile.win @@ -23,6 +23,9 @@ IGNORE_MANIFEST = 1 MODULE = urltest DEPTH= ..\..\.. +REQUIRES = xpcom \ + necko \ + string MAKE_OBJ_TYPE=EXE diff --git a/mozilla/netwerk/base/tests/urltest.cpp b/mozilla/netwerk/base/tests/urltest.cpp index 3068a57154b..bfc29e017a9 100644 --- a/mozilla/netwerk/base/tests/urltest.cpp +++ b/mozilla/netwerk/base/tests/urltest.cpp @@ -52,14 +52,12 @@ #include "nsIComponentRegistrar.h" #include "nsIStreamListener.h" #include "nsIInputStream.h" -#include "nsINetService.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsString.h" #include "nsReadableUtils.h" - +#include "nsNetCID.h" #include "nsIURL.h" -#include "nsINetService.h" #ifdef XP_PC #define NETLIB_DLL "netlib.dll" @@ -74,9 +72,7 @@ #endif #endif -// Define CIDs... -static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID); -//NS_DEFINE_IID(kIPostToServerIID, NS_IPOSTTOSERVER_IID); +static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); #ifdef XP_UNIX extern "C" char *fe_GetConfigDir(void) { @@ -238,33 +234,36 @@ int main(int argc, char **argv) // char buf[256]; // nsIStreamListener *pConsumer; // nsIURL *pURL; - nsresult result; - int i; + nsresult rv; if (argc < 2) { printf("urltest: \n"); return 0; } - - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - testURL(argv[1]); - return 0; + testURL(argv[1]); #if 0 - for (i=1; i < argc; i++) { - if (PL_strcasecmp(argv[i], "-all") == 0) { - testURL(0); - continue; - } + for (int i=1; i < argc; i++) { + if (PL_strcasecmp(argv[i], "-all") == 0) { + testURL(0); + continue; + } - testURL(argv[i]); - } - return 0; + testURL(argv[i]); + } #endif + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM FAILED"); + return 0; } @@ -302,7 +301,8 @@ int testURL(const char* i_pURL) for (int i = 0; i< tests; ++i) { - nsIURL* pURL = CreateURL(url[i]); + nsCOMPtr pURL = do_CreateInstance(kStandardUrlCID); +pURL CreateURL(url[i]); pURL->DebugString(&temp); cout << temp << endl; pURL->Release(); diff --git a/mozilla/netwerk/streamconv/test/TestStreamConv.cpp b/mozilla/netwerk/streamconv/test/TestStreamConv.cpp index 7f45e522fde..3b617c0514e 100644 --- a/mozilla/netwerk/streamconv/test/TestStreamConv.cpp +++ b/mozilla/netwerk/streamconv/test/TestStreamConv.cpp @@ -140,180 +140,177 @@ int main(int argc, char* argv[]) { nsresult rv; - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - // Create the Event Queue for this thread... - nsCOMPtr eventQService = - do_GetService(kEventQueueServiceCID, &rv); - if (NS_FAILED(rv)) return rv; - - eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); - - nsCOMPtr catman = - do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - nsXPIDLCString previous; - - /////////////////////////////////////////// - // BEGIN - Stream converter registration - // All stream converters must register with the ComponentManager - /////////////////////////////////////////// - - // these stream converters are just for testing. running this harness - // from the dist/bin dir will also pickup converters registered - // in other modules (necko converters for example). - - PRUint32 converterListSize = 7; - const char *const converterList[] = { - "?from=a/foo&to=b/foo", - "?from=b/foo&to=c/foo", - "?from=b/foo&to=d/foo", - "?from=c/foo&to=d/foo", - "?from=d/foo&to=e/foo", - "?from=d/foo&to=f/foo", - "?from=t/foo&to=k/foo", - }; - - TestConverterFactory *convFactory = new TestConverterFactory(kTestConverterCID, "TestConverter", NS_ISTREAMCONVERTER_KEY); - nsCOMPtr convFactSup(do_QueryInterface(convFactory, &rv)); - if (NS_FAILED(rv)) return rv; - - PRUint32 count = 0; - while (count < converterListSize) { - // register the TestConverter with the component manager. One contractid registration - // per conversion pair (from - to pair). - nsCString contractID(NS_ISTREAMCONVERTER_KEY); - contractID.Append(converterList[count]); - rv = nsComponentManager::RegisterFactory(kTestConverterCID, - "TestConverter", - contractID.get(), - convFactSup, - PR_TRUE); + // Create the Event Queue for this thread... + nsCOMPtr eventQService = + do_GetService(kEventQueueServiceCID, &rv); if (NS_FAILED(rv)) return rv; - rv = catman->AddCategoryEntry(NS_ISTREAMCONVERTER_KEY, converterList[count], "x", - PR_TRUE, PR_TRUE, getter_Copies(previous)); + + eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); + + nsCOMPtr catman = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; - count++; - } + nsXPIDLCString previous; - nsCOMPtr StreamConvService = - do_GetService(kStreamConverterServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + /////////////////////////////////////////// + // BEGIN - Stream converter registration + // All stream converters must register with the ComponentManager + /////////////////////////////////////////// - // Define the *from* content type and *to* content-type for conversion. - nsString fromStr; - fromStr.Assign(NS_LITERAL_STRING("a/foo")); - nsString toStr; - toStr.Assign(NS_LITERAL_STRING("c/foo")); + // these stream converters are just for testing. running this harness + // from the dist/bin dir will also pickup converters registered + // in other modules (necko converters for example). + + PRUint32 converterListSize = 7; + const char *const converterList[] = { + "?from=a/foo&to=b/foo", + "?from=b/foo&to=c/foo", + "?from=b/foo&to=d/foo", + "?from=c/foo&to=d/foo", + "?from=d/foo&to=e/foo", + "?from=d/foo&to=f/foo", + "?from=t/foo&to=k/foo", + }; + + TestConverterFactory *convFactory = new TestConverterFactory(kTestConverterCID, "TestConverter", NS_ISTREAMCONVERTER_KEY); + nsCOMPtr convFactSup(do_QueryInterface(convFactory, &rv)); + if (NS_FAILED(rv)) return rv; + + for (PRUint32 count = 0; count < converterListSize; ++count) { + // register the TestConverter with the component manager. One contractid registration + // per conversion pair (from - to pair). + nsCString contractID(NS_ISTREAMCONVERTER_KEY); + contractID.Append(converterList[count]); + rv = nsComponentManager::RegisterFactory(kTestConverterCID, + "TestConverter", + contractID.get(), + convFactSup, + PR_TRUE); + if (NS_FAILED(rv)) return rv; + rv = catman->AddCategoryEntry(NS_ISTREAMCONVERTER_KEY, converterList[count], "x", + PR_TRUE, PR_TRUE, getter_Copies(previous)); + if (NS_FAILED(rv)) return rv; + } + + nsCOMPtr StreamConvService = + do_GetService(kStreamConverterServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + + // Define the *from* content type and *to* content-type for conversion. + nsString fromStr(NS_LITERAL_STRING("a/foo")); + nsString toStr(NS_LITERAL_STRING("c/foo")); #ifdef ASYNC_TEST - // ASYNCRONOUS conversion + // ASYNCRONOUS conversion + // Build up a channel that represents the content we're + // starting the transaction with. + // + // sample multipart mixed content-type string: + // "multipart/x-mixed-replacE;boundary=thisrandomstring" +#if 0 + nsCOMPtr channel; + nsCOMPtr dummyURI; + rv = NS_NewURI(getter_AddRefs(dummyURI), "http://meaningless"); + if (NS_FAILED(rv)) return rv; - // Build up a channel that represents the content we're - // starting the transaction with. - // - // sample multipart mixed content-type string: - // "multipart/x-mixed-replacE;boundary=thisrandomstring" - /*nsCOMPtr channel; - nsCOMPtr dummyURI; - rv = NS_NewURI(getter_AddRefs(dummyURI), "http://meaningless"); - if (NS_FAILED(rv)) return rv; + rv = NS_NewInputStreamChannel(getter_AddRefs(channel), + dummyURI, + nsnull, // inStr + "text/plain", // content-type + -1); // XXX fix contentLength + if (NS_FAILED(rv)) return rv; - rv = NS_NewInputStreamChannel(getter_AddRefs(channel), - dummyURI, - nsnull, // inStr - "text/plain", // content-type - -1); // XXX fix contentLength - if (NS_FAILED(rv)) return rv; - - nsCOMPtr request(do_QueryInterface(channel));*/ - - nsCOMPtr 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. - // An example of this listener in mozilla would be the DocLoader. - nsIStreamListener *dataReceiver = new EndListener(); - 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 = nsnull; - rv = StreamConvService->AsyncConvertData(fromStr.get(), toStr.get(), - dataReceiver, nsnull, &converterListener); - if (NS_FAILED(rv)) return rv; - 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, nsnull); - if (NS_FAILED(rv)) return rv; - - - rv = SEND_DATA("aaa"); - if (NS_FAILED(rv)) return rv; - - rv = SEND_DATA("aaa"); - if (NS_FAILED(rv)) return rv; - - // Finish the request. - rv = converterListener->OnStopRequest(request, nsnull, rv); - if (NS_FAILED(rv)) return rv; - - NS_RELEASE(converterListener); - - -#else - // SYNCRONOUS conversion - nsCOMPtr convertedData; - rv = StreamConvService->Convert(inputData, fromStr.get(), toStr.get(), - nsnull, getter_AddRefs(convertedData)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr request(do_QueryInterface(channel)); #endif - // Enter the message pump to allow the URL load to proceed. - while ( gKeepRunning ) { -#ifdef XP_WIN - MSG msg; + nsCOMPtr request; - if (GetMessage(&msg, NULL, 0, 0)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } else - gKeepRunning = PR_FALSE; + // setup a listener to receive the converted data. This guy is the end + // listener in the chain, he wants the fully converted (toType) data. + // An example of this listener in mozilla would be the DocLoader. + nsIStreamListener *dataReceiver = new EndListener(); + 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 = nsnull; + rv = StreamConvService->AsyncConvertData(fromStr.get(), toStr.get(), + dataReceiver, nsnull, &converterListener); + if (NS_FAILED(rv)) return rv; + 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, nsnull); + if (NS_FAILED(rv)) return rv; + + rv = SEND_DATA("aaa"); + if (NS_FAILED(rv)) return rv; + + rv = SEND_DATA("aaa"); + if (NS_FAILED(rv)) return rv; + + // Finish the request. + rv = converterListener->OnStopRequest(request, nsnull, rv); + if (NS_FAILED(rv)) return rv; + + NS_RELEASE(converterListener); +#else + // SYNCRONOUS conversion + nsCOMPtr convertedData; + rv = StreamConvService->Convert(inputData, fromStr.get(), toStr.get(), + nsnull, getter_AddRefs(convertedData)); + if (NS_FAILED(rv)) return rv; +#endif + + // Enter the message pump to allow the URL load to proceed. + while ( gKeepRunning ) { +#ifdef XP_WIN + MSG msg; + + if (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } else + gKeepRunning = PR_FALSE; #else #ifdef XP_MAC - /* Mac stuff is missing here! */ + /* Mac stuff is missing here! */ #else #ifdef XP_OS2 - QMSG qmsg; + QMSG qmsg; - if (WinGetMsg(0, &qmsg, 0, 0, 0)) - WinDispatchMsg(0, &qmsg); - else - gKeepRunning = PR_FALSE; + if (WinGetMsg(0, &qmsg, 0, 0, 0)) + WinDispatchMsg(0, &qmsg); + else + gKeepRunning = PR_FALSE; #else #ifdef XP_UNIX - PLEvent *gEvent; - rv = gEventQ->GetEvent(&gEvent); - rv = gEventQ->HandleEvent(gEvent); - /* gKeepRunning = PR_FALSE; */ + PLEvent *gEvent; + rv = gEventQ->GetEvent(&gEvent); + rv = gEventQ->HandleEvent(gEvent); + /* gKeepRunning = PR_FALSE; */ #else - /* Other stuff is missing here! */ + /* Other stuff is missing here! */ #endif /* XP_UNIX */ #endif /* XP_OS2 */ #endif /* XP_MAC */ #endif /* XP_WIN */ - } - - //return NS_ShutdownXPCOM(NULL); + } + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + NS_ShutdownXPCOM(nsnull); return rv; } diff --git a/mozilla/netwerk/test/TestCacheBlockFiles.cpp b/mozilla/netwerk/test/TestCacheBlockFiles.cpp index 09698b63608..34f5f263259 100644 --- a/mozilla/netwerk/test/TestCacheBlockFiles.cpp +++ b/mozilla/netwerk/test/TestCacheBlockFiles.cpp @@ -45,7 +45,7 @@ static struct MacInitializer { MacInitializer() /** * StressTest() */ - + typedef struct Allocation { PRInt32 start; PRInt32 count; @@ -65,8 +65,8 @@ StressTest(nsILocalFile * localFile, PRInt32 testNumber, PRBool readWrite) char * writeBuf[4]; char readBuf[256 * 4]; - - + + if (readWrite) { for (i = 0; i < 4; i++) { writeBuf[i] = new char[256 * i]; @@ -75,7 +75,7 @@ StressTest(nsILocalFile * localFile, PRInt32 testNumber, PRBool readWrite) rv = NS_ERROR_OUT_OF_MEMORY; goto exit; } - + memset(writeBuf[i], i, 256 * i); } } @@ -99,7 +99,7 @@ StressTest(nsILocalFile * localFile, PRInt32 testNumber, PRBool readWrite) ((currentAllocations > 0) && (rand() % 4 == 0))) { // deallocate if we've reached the limit, or 25% of the time we have allocations a = rand() % currentAllocations; - + if (readWrite) { // read verify deallocation rv = blockFile->ReadBlocks(readBuf, block[a].start, block[a].count); @@ -117,17 +117,17 @@ StressTest(nsILocalFile * localFile, PRInt32 testNumber, PRBool readWrite) } } } - + rv = blockFile->DeallocateBlocks(block[a].start, block[a].count); if (NS_FAILED(rv)) { printf("Test %d: failed (DeallocateBlocks() returned %d)\n", testNumber, rv); goto exit; } - + --currentAllocations; if (currentAllocations > 0) block[a] = block[currentAllocations]; - + } else { // allocate blocks --i; @@ -138,7 +138,7 @@ StressTest(nsILocalFile * localFile, PRInt32 testNumber, PRBool readWrite) printf("Test %d: failed (AllocateBlocks() failed.)\n", testNumber); goto exit; } - + if (readWrite) { // write buffer rv = blockFile->WriteBlocks(writeBuf[block[a].count], block[a].start, block[a].count); @@ -149,11 +149,11 @@ StressTest(nsILocalFile * localFile, PRInt32 testNumber, PRBool readWrite) } } } - + // now deallocate remaining allocations i = currentAllocations; while (i--) { - + if (readWrite) { // read verify deallocation rv = blockFile->ReadBlocks(readBuf, block[a].start, block[a].count); @@ -193,7 +193,7 @@ exit: /** * main() */ - + int main(void) { @@ -204,686 +204,689 @@ main(void) SIOUXSettings.autocloseonquit = false; SIOUXSettings.asktosaveonclose = false; #endif - + unsigned long now = time(0); srand(now); - + nsCOMPtr file; nsCOMPtr localFile; nsresult rv = NS_OK; - - // Start up XPCOM - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + { + // Start up XPCOM + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - // Get default directory - rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, - getter_AddRefs(file)); - if (NS_FAILED(rv)) { - printf("NS_GetSpecialDirectory() failed : 0x%.8x\n", rv); - goto exit; - } - char * currentDirPath; - rv = file->GetPath(¤tDirPath); - if (NS_FAILED(rv)) { - printf("currentProcessDir->GetPath() failed : 0x%.8x\n", rv); - goto exit; - } + // Get default directory + rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, + getter_AddRefs(file)); + if (NS_FAILED(rv)) { + printf("NS_GetSpecialDirectory() failed : 0x%.8x\n", rv); + goto exit; + } + char * currentDirPath; + rv = file->GetPath(¤tDirPath); + if (NS_FAILED(rv)) { + printf("currentProcessDir->GetPath() failed : 0x%.8x\n", rv); + goto exit; + } - printf("Current Process Directory: %s\n", currentDirPath); - - - // Generate name for cache block file + printf("Current Process Directory: %s\n", currentDirPath); + + + // Generate name for cache block file rv = file->Append("_CACHE_001_"); - if (NS_FAILED(rv)) goto exit; - - // Delete existing file - rv = file->Delete(PR_FALSE); - if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) goto exit; + if (NS_FAILED(rv)) goto exit; - // Need nsILocalFile to open + // Delete existing file + rv = file->Delete(PR_FALSE); + if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) goto exit; + + // Need nsILocalFile to open localFile = do_QueryInterface(file, &rv); - if (NS_FAILED(rv)) { - printf("do_QueryInterface(file) failed : 0x%.8x\n", rv); - goto exit; - } - - nsDiskCacheBlockFile * blockFile = new nsDiskCacheBlockFile; - if (!blockFile) { - rv = NS_ERROR_OUT_OF_MEMORY; - goto exit; - } - - //---------------------------------------------------------------- - // local variables used in tests - //---------------------------------------------------------------- - PRUint32 bytesWritten = 0; - PRInt32 startBlock; - PRInt32 i = 0; + if (NS_FAILED(rv)) { + printf("do_QueryInterface(file) failed : 0x%.8x\n", rv); + goto exit; + } + + nsDiskCacheBlockFile * blockFile = new nsDiskCacheBlockFile; + if (!blockFile) { + rv = NS_ERROR_OUT_OF_MEMORY; + goto exit; + } + + //---------------------------------------------------------------- + // local variables used in tests + //---------------------------------------------------------------- + PRUint32 bytesWritten = 0; + PRInt32 startBlock; + PRInt32 i = 0; - //---------------------------------------------------------------- - // Test 1: Open non-existing file - //---------------------------------------------------------------- - rv = blockFile->Open(localFile, 256); - if (NS_FAILED(rv)) { - printf("Test 1: failed (Open returned: 0x%.8x)\n", rv); - goto exit; - } + //---------------------------------------------------------------- + // Test 1: Open non-existing file + //---------------------------------------------------------------- + rv = blockFile->Open(localFile, 256); + if (NS_FAILED(rv)) { + printf("Test 1: failed (Open returned: 0x%.8x)\n", rv); + goto exit; + } - rv = blockFile->Close(); - if (NS_FAILED(rv)) { - printf("Test 1: failed (Close returned: 0x%.8x)\n", rv); - goto exit; - } - - printf("Test 1: passed\n"); + rv = blockFile->Close(); + if (NS_FAILED(rv)) { + printf("Test 1: failed (Close returned: 0x%.8x)\n", rv); + goto exit; + } + + printf("Test 1: passed\n"); - //---------------------------------------------------------------- - // Test 2: Open existing file (with no allocation) - //---------------------------------------------------------------- - rv = blockFile->Open(localFile, 256); - if (NS_FAILED(rv)) { - printf("Test 2: failed (Open returned: 0x%.8x)\n", rv); - goto exit; - } - - rv = blockFile->Close(); - if (NS_FAILED(rv)) { - printf("Test 2: failed (Close returned: 0x%.8x)\n", rv); - goto exit; - } + //---------------------------------------------------------------- + // Test 2: Open existing file (with no allocation) + //---------------------------------------------------------------- + rv = blockFile->Open(localFile, 256); + if (NS_FAILED(rv)) { + printf("Test 2: failed (Open returned: 0x%.8x)\n", rv); + goto exit; + } - printf("Test 2: passed\n"); + rv = blockFile->Close(); + if (NS_FAILED(rv)) { + printf("Test 2: failed (Close returned: 0x%.8x)\n", rv); + goto exit; + } + + printf("Test 2: passed\n"); - //---------------------------------------------------------------- - // Test 3: Open existing file (bad format) size < kBitMapBytes - //---------------------------------------------------------------- - - // Delete existing file - rv = localFile->Delete(PR_FALSE); - if (NS_FAILED(rv)) { - printf("Test 3 failed (Delete returned: 0x%.8x)\n", rv); - goto exit; - } - - // write < kBitMapBytes to file - nsANSIFileStream * stream = new nsANSIFileStream; - if (!stream) { - printf("Test 3 failed (unable to allocate stream\n", rv); - goto exit; - } - NS_ADDREF(stream); - rv = stream->Open(localFile); - if (NS_FAILED(rv)) { + //---------------------------------------------------------------- + // Test 3: Open existing file (bad format) size < kBitMapBytes + //---------------------------------------------------------------- + + // Delete existing file + rv = localFile->Delete(PR_FALSE); + if (NS_FAILED(rv)) { + printf("Test 3 failed (Delete returned: 0x%.8x)\n", rv); + goto exit; + } + + // write < kBitMapBytes to file + nsANSIFileStream * stream = new nsANSIFileStream; + if (!stream) { + printf("Test 3 failed (unable to allocate stream\n", rv); + goto exit; + } + NS_ADDREF(stream); + rv = stream->Open(localFile); + if (NS_FAILED(rv)) { + NS_RELEASE(stream); + printf("Test 3 failed (stream->Open returned: 0x%.8x)\n", rv); + goto exit; + } + + bytesWritten = 0; + rv = stream->Write("Tell me something good.\n", 24, &bytesWritten); + if (NS_FAILED(rv)) { + NS_RELEASE(stream); + printf("Test 3 failed (stream->Write returned: 0x%.8x)\n", rv); + goto exit; + } + + rv = stream->Close(); + if (NS_FAILED(rv)) { + NS_RELEASE(stream); + printf("Test 3 failed (stream->Close returned: 0x%.8x)\n", rv); + goto exit; + } NS_RELEASE(stream); - printf("Test 3 failed (stream->Open returned: 0x%.8x)\n", rv); - goto exit; - } - - bytesWritten = 0; - rv = stream->Write("Tell me something good.\n", 24, &bytesWritten); - if (NS_FAILED(rv)) { - NS_RELEASE(stream); - printf("Test 3 failed (stream->Write returned: 0x%.8x)\n", rv); - goto exit; - } - rv = stream->Close(); - if (NS_FAILED(rv)) { - NS_RELEASE(stream); - printf("Test 3 failed (stream->Close returned: 0x%.8x)\n", rv); - goto exit; - } - NS_RELEASE(stream); + rv = blockFile->Open(localFile, 256); + if (NS_SUCCEEDED(rv)) { + printf("Test 3: failed (Open erroneously succeeded)\n", rv); - rv = blockFile->Open(localFile, 256); - if (NS_SUCCEEDED(rv)) { - printf("Test 3: failed (Open erroneously succeeded)\n", rv); - - (void) blockFile->Close(); - goto exit; - } - - printf("Test 3: passed\n"); + (void) blockFile->Close(); + goto exit; + } + + printf("Test 3: passed\n"); - //---------------------------------------------------------------- - // Test 4: Open non-existing file (again) - //---------------------------------------------------------------- + //---------------------------------------------------------------- + // Test 4: Open non-existing file (again) + //---------------------------------------------------------------- - // Delete existing file - rv = localFile->Delete(PR_FALSE); - if (NS_FAILED(rv)) { - printf("Test 4 failed (Delete returned: 0x%.8x)\n", rv); - goto exit; - } + // Delete existing file + rv = localFile->Delete(PR_FALSE); + if (NS_FAILED(rv)) { + printf("Test 4 failed (Delete returned: 0x%.8x)\n", rv); + goto exit; + } - rv = blockFile->Open(localFile, 256); - if (NS_FAILED(rv)) { - printf("Test 4: failed (Open returned: 0x%.8x)\n", rv); - goto exit; - } + rv = blockFile->Open(localFile, 256); + if (NS_FAILED(rv)) { + printf("Test 4: failed (Open returned: 0x%.8x)\n", rv); + goto exit; + } - printf("Test 4: passed\n"); + printf("Test 4: passed\n"); - //---------------------------------------------------------------- - // Test 5: AllocateBlocks: invalid block count (0, 5) - //---------------------------------------------------------------- + //---------------------------------------------------------------- + // Test 5: AllocateBlocks: invalid block count (0, 5) + //---------------------------------------------------------------- - startBlock = blockFile->AllocateBlocks(0); - if (startBlock > -1) { - printf("Test 5: failed (AllocateBlocks(0) erroneously succeeded)\n"); - goto exit; - } + startBlock = blockFile->AllocateBlocks(0); + if (startBlock > -1) { + printf("Test 5: failed (AllocateBlocks(0) erroneously succeeded)\n"); + goto exit; + } - startBlock = blockFile->AllocateBlocks(5); - if (startBlock > -1) { - printf("Test 5: failed (AllocateBlocks(5) erroneously succeeded)\n"); - goto exit; - } - printf("Test 5: passed\n"); - - - //---------------------------------------------------------------- - // Test 6: AllocateBlocks: valid block count (1, 2, 3, 4) - //---------------------------------------------------------------- - startBlock = blockFile->AllocateBlocks(1); - if (startBlock != 0) { - printf("Test 6: failed (AllocateBlocks(1) failed)\n"); - goto exit; - } - - startBlock = blockFile->AllocateBlocks(2); - if (startBlock != 1) { - printf("Test 6: failed (AllocateBlocks(2) failed)\n"); - goto exit; - } - - startBlock = blockFile->AllocateBlocks(3); - if (startBlock != 4) { - printf("Test 6: failed (AllocateBlocks(3) failed)\n"); - goto exit; - } - - startBlock = blockFile->AllocateBlocks(4); - if (startBlock != 8) { - printf("Test 6: failed (AllocateBlocks(4) failed)\n"); - goto exit; - } - - // blocks allocated should be 1220 3330 4444 - printf("Test 6: passed\n"); // but bits could be mis-allocated - - - - //---------------------------------------------------------------- - // Test 7: VerifyAllocation - //---------------------------------------------------------------- - rv = blockFile->VerifyAllocation(0,1); - if (NS_FAILED(rv)) { - printf("Test 7: failed (VerifyAllocation(0,1) returned: 0x%.8x)\n", rv); - goto exit; - } - - rv = blockFile->VerifyAllocation(1,2); - if (NS_FAILED(rv)) { - printf("Test 7: failed (VerifyAllocation(1,2) returned: 0x%.8x)\n", rv); - goto exit; - } - - rv = blockFile->VerifyAllocation(4,3); - if (NS_FAILED(rv)) { - printf("Test 7: failed (VerifyAllocation(4,3) returned: 0x%.8x)\n", rv); - goto exit; - } - - rv = blockFile->VerifyAllocation(8,4); - if (NS_FAILED(rv)) { - printf("Test 7: failed (VerifyAllocation(8,4) returned: 0x%.8x)\n", rv); - goto exit; - } - printf("Test 7: passed\n"); - - - //---------------------------------------------------------------- - // Test 8: LastBlock - //---------------------------------------------------------------- - PRInt32 lastBlock = blockFile->LastBlock(); - if (lastBlock != 11) { - printf("Test 8: failed (LastBlock() returned: %d)\n", lastBlock); - goto exit; - } - printf("Test 8: passed\n"); + startBlock = blockFile->AllocateBlocks(5); + if (startBlock > -1) { + printf("Test 5: failed (AllocateBlocks(5) erroneously succeeded)\n"); + goto exit; + } + printf("Test 5: passed\n"); - //---------------------------------------------------------------- - // Test 9: DeallocateBlocks: bad startBlock ( < 0) - //---------------------------------------------------------------- - rv = blockFile->DeallocateBlocks(-1, 4); - if (NS_SUCCEEDED(rv)) { - printf("Test 9: failed (DeallocateBlocks(-1, 4) erroneously succeeded)\n"); - goto exit; - } - printf("Test 9: passed\n"); - - - //---------------------------------------------------------------- - // Test 10: DeallocateBlocks: bad numBlocks (0, 5) - //---------------------------------------------------------------- - rv = blockFile->DeallocateBlocks(0, 0); - if (NS_SUCCEEDED(rv)) { - printf("Test 10: failed (DeallocateBlocks(0, 0) erroneously succeeded)\n"); - goto exit; - } - - rv = blockFile->DeallocateBlocks(0, 5); - if (NS_SUCCEEDED(rv)) { - printf("Test 10: failed (DeallocateBlocks(0, 5) erroneously succeeded)\n"); - goto exit; - } - - printf("Test 10: passed\n"); - - - //---------------------------------------------------------------- - // Test 11: DeallocateBlocks: unallocated blocks - //---------------------------------------------------------------- - rv = blockFile->DeallocateBlocks(12, 1); - if (NS_SUCCEEDED(rv)) { - printf("Test 11: failed (DeallocateBlocks(12, 1) erroneously succeeded)\n"); - goto exit; - } - - printf("Test 11: passed\n"); - - - //---------------------------------------------------------------- - // Test 12: DeallocateBlocks: 1, 2, 3, 4 (allocated in Test 6) - //---------------------------------------------------------------- - rv = blockFile->DeallocateBlocks(0, 1); - if (NS_FAILED(rv)) { - printf("Test 12: failed (DeallocateBlocks(12, 1) returned: 0x%.8x)\n", rv); - goto exit; - } - - rv = blockFile->DeallocateBlocks(1, 2); - if (NS_FAILED(rv)) { - printf("Test 12: failed (DeallocateBlocks(1, 2) returned: 0x%.8x)\n", rv); - goto exit; - } - - rv = blockFile->DeallocateBlocks(4, 3); - if (NS_FAILED(rv)) { - printf("Test 12: failed (DeallocateBlocks(4, 3) returned: 0x%.8x)\n", rv); - goto exit; - } - - rv = blockFile->DeallocateBlocks(8, 4); - if (NS_FAILED(rv)) { - printf("Test 12: failed (DeallocateBlocks(8, 4) returned: 0x%.8x)\n", rv); - goto exit; - } - - // zero blocks should be allocated - rv = blockFile->Close(); - if (NS_FAILED(rv)) { - printf("Test 12: failed (Close returned: 0x%.8x)\n", rv); - goto exit; - } - - printf("Test 12: passed\n"); - - - //---------------------------------------------------------------- - // Test 13: Allocate/Deallocate boundary test - //---------------------------------------------------------------- - - rv = blockFile->Open(localFile, 256); - if (NS_FAILED(rv)) { - printf("Test 13: failed (Open returned: 0x%.8x)\n", rv); - goto exit; - } - - // fully allocate, 1 block at a time - for (i=0; i< kBitMapBytes * 8; ++i) { + //---------------------------------------------------------------- + // Test 6: AllocateBlocks: valid block count (1, 2, 3, 4) + //---------------------------------------------------------------- startBlock = blockFile->AllocateBlocks(1); - if (startBlock < 0) { - printf("Test 13: failed (AllocateBlocks(1) failed on i=%d)\n", i); + if (startBlock != 0) { + printf("Test 6: failed (AllocateBlocks(1) failed)\n"); goto exit; } - } - - // attempt allocation with full bit map - startBlock = blockFile->AllocateBlocks(1); - if (startBlock >= 0) { - printf("Test 13: failed (AllocateBlocks(1) erroneously succeeded i=%d)\n", i); - goto exit; - } - - // deallocate all the bits - for (i=0; i< kBitMapBytes * 8; ++i) { - rv = blockFile->DeallocateBlocks(i,1); - if (NS_FAILED(rv)) { - printf("Test 13: failed (DeallocateBlocks(%d,1) returned: 0x%.8x)\n", i,rv); - goto exit; - } - } - - // attempt deallocation beyond end of bit map - rv = blockFile->DeallocateBlocks(i,1); - if (NS_SUCCEEDED(rv)) { - printf("Test 13: failed (DeallocateBlocks(%d,1) erroneously succeeded)\n", i); - goto exit; - } - - // bit map should be empty - - // fully allocate, 2 block at a time - for (i=0; i< kBitMapBytes * 8; i+=2) { + startBlock = blockFile->AllocateBlocks(2); - if (startBlock < 0) { - printf("Test 13: failed (AllocateBlocks(2) failed on i=%d)\n", i); + if (startBlock != 1) { + printf("Test 6: failed (AllocateBlocks(2) failed)\n"); goto exit; } - } - - // attempt allocation with full bit map - startBlock = blockFile->AllocateBlocks(2); - if (startBlock >= 0) { - printf("Test 13: failed (AllocateBlocks(2) erroneously succeeded i=%d)\n", i); - goto exit; - } - - // deallocate all the bits - for (i=0; i< kBitMapBytes * 8; i+=2) { - rv = blockFile->DeallocateBlocks(i,2); - if (NS_FAILED(rv)) { - printf("Test 13: failed (DeallocateBlocks(%d,2) returned: 0x%.8x)\n", i,rv); - goto exit; - } - } - // bit map should be empty - - // fully allocate, 4 block at a time - for (i=0; i< kBitMapBytes * 8; i+=4) { - startBlock = blockFile->AllocateBlocks(4); - if (startBlock < 0) { - printf("Test 13: failed (AllocateBlocks(4) failed on i=%d)\n", i); - goto exit; - } - } - - // attempt allocation with full bit map - startBlock = blockFile->AllocateBlocks(4); - if (startBlock >= 0) { - printf("Test 13: failed (AllocateBlocks(4) erroneously succeeded i=%d)\n", i); - goto exit; - } - - // deallocate all the bits - for (i=0; i< kBitMapBytes * 8; i+=4) { - rv = blockFile->DeallocateBlocks(i,4); - if (NS_FAILED(rv)) { - printf("Test 13: failed (DeallocateBlocks(%d,4) returned: 0x%.8x)\n", i,rv); - goto exit; - } - } - - // bit map should be empty - - // allocate as many triple-blocks as possible - for (i=0; i< kBitMapBytes * 8; i+=4) { startBlock = blockFile->AllocateBlocks(3); - if (startBlock < 0) { - printf("Test 13: failed (AllocateBlocks(3) failed on i=%d)\n", i); + if (startBlock != 4) { + printf("Test 6: failed (AllocateBlocks(3) failed)\n"); goto exit; } - } - - // attempt allocation with "full" bit map - startBlock = blockFile->AllocateBlocks(3); - if (startBlock >= 0) { - printf("Test 13: failed (AllocateBlocks(3) erroneously succeeded i=%d)\n", i); - goto exit; - } - - // leave some blocks allocated - rv = blockFile->Close(); - if (NS_FAILED(rv)) { - printf("Test 13: failed (Close returned: 0x%.8x)\n", rv); - goto exit; - } - - printf("Test 13: passed\n"); - - - //---------------------------------------------------------------- - // Test 14: ValidateFile (open existing file w/size < allocated blocks - //---------------------------------------------------------------- - rv = blockFile->Open(localFile, 256); - if (NS_SUCCEEDED(rv)) { - printf("Test 14: failed (Open erroneously succeeded)\n"); - goto exit; - } - - // Delete existing file - rv = localFile->Delete(PR_FALSE); - if (NS_FAILED(rv)) { - printf("Test 14 failed (Delete returned: 0x%.8x)\n", rv); - goto exit; - } - printf("Test 14: passed\n"); - - - //---------------------------------------------------------------- - // Test 15: Allocate/Deallocate stress test - //---------------------------------------------------------------- - - rv = StressTest(localFile, 15, PR_FALSE); - if (NS_FAILED(rv)) - goto exit; - - printf("Test 15: passed\n"); - - - //---------------------------------------------------------------- - // Test 16: WriteBlocks - //---------------------------------------------------------------- - - rv = blockFile->Open(localFile, 256); - if (NS_FAILED(rv)) { - printf("Test 16: failed (Open returned: 0x%.8x)\n", rv); - goto exit; - } - - char * one = new char[256 * 1]; - char * two = new char[256 * 2]; - char * three = new char[256 * 3]; - char * four = new char[256 * 4]; - if (!one || !two || !three || !four) { - printf("Test 16: failed - out of memory\n"); - rv = NS_ERROR_OUT_OF_MEMORY; - goto exit; - } - - memset(one, 1, 256); - memset(two, 2, 256 * 2); - memset(three, 3, 256 * 3); - memset(four, 4, 256 * 4); - - startBlock = blockFile->AllocateBlocks(1); - if (startBlock != 0) { - printf("Test 16: failed (AllocateBlocks(1) failed)\n"); - goto exit; - } - - rv = blockFile->WriteBlocks(one, startBlock, 1); - if (NS_FAILED(rv)) { - printf("Test 16: failed (WriteBlocks(1) returned 0x%.8x)\n", rv); - goto exit; - } - - startBlock = blockFile->AllocateBlocks(2); - if (startBlock != 1) { // starting with empy map, this allocation should begin at block 1 - printf("Test 16: failed (AllocateBlocks(2) failed)\n"); - goto exit; - } - - rv = blockFile->WriteBlocks(two, startBlock, 2); - if (NS_FAILED(rv)) { - printf("Test 16: failed (WriteBlocks(2) returned 0x%.8x)\n", rv); - goto exit; - } - - startBlock = blockFile->AllocateBlocks(3); - if (startBlock != 4) { // starting with empy map, this allocation should begin at block 4 - printf("Test 16: failed (AllocateBlocks(3) failed)\n"); - goto exit; - } - - rv = blockFile->WriteBlocks(three, startBlock, 3); - if (NS_FAILED(rv)) { - printf("Test 16: failed (WriteBlocks(3) returned 0x%.8x)\n", rv); - goto exit; - } - - startBlock = blockFile->AllocateBlocks(4); - if (startBlock != 8) { // starting with empy map, this allocation should begin at block 8 - printf("Test 16: failed (AllocateBlocks(4) failed)\n"); - goto exit; - } - - rv = blockFile->WriteBlocks(four, startBlock, 4); - if (NS_FAILED(rv)) { - printf("Test 16: failed (WriteBlocks(4) returned 0x%.8x)\n", rv); - goto exit; - } - - printf("Test 16: passed\n"); - - - //---------------------------------------------------------------- - // Test 17: ReadBlocks - //---------------------------------------------------------------- - - rv = blockFile->ReadBlocks(one, 0, 1); - if (NS_FAILED(rv)) { - printf("Test 17: failed (ReadBlocks(1) returned 0x%.8x)\n", rv); - goto exit; - } - - // Verify buffer - for (i = 0; i < 256; i++) { - if (one[i] != 1) { - printf("Test 17: failed (verifying buffer 1)\n"); - rv = NS_ERROR_FAILURE; + startBlock = blockFile->AllocateBlocks(4); + if (startBlock != 8) { + printf("Test 6: failed (AllocateBlocks(4) failed)\n"); goto exit; } - } - rv = blockFile->ReadBlocks(two, 1, 2); - if (NS_FAILED(rv)) { - printf("Test 17: failed (ReadBlocks(2) returned 0x%.8x)\n", rv); - goto exit; - } + // blocks allocated should be 1220 3330 4444 + printf("Test 6: passed\n"); // but bits could be mis-allocated - // Verify buffer - for (i = 0; i < 256 * 2; i++) { - if (two[i] != 2) { - printf("Test 17: failed (verifying buffer 2)\n"); - rv = NS_ERROR_FAILURE; + + + //---------------------------------------------------------------- + // Test 7: VerifyAllocation + //---------------------------------------------------------------- + rv = blockFile->VerifyAllocation(0,1); + if (NS_FAILED(rv)) { + printf("Test 7: failed (VerifyAllocation(0,1) returned: 0x%.8x)\n", rv); goto exit; } - } - rv = blockFile->ReadBlocks(three, 4, 3); - if (NS_FAILED(rv)) { - printf("Test 17: failed (ReadBlocks(3) returned 0x%.8x)\n", rv); - goto exit; - } - - // Verify buffer - for (i = 0; i < 256 * 3; i++) { - if (three[i] != 3) { - printf("Test 17: failed (verifying buffer 3)\n"); - rv = NS_ERROR_FAILURE; + rv = blockFile->VerifyAllocation(1,2); + if (NS_FAILED(rv)) { + printf("Test 7: failed (VerifyAllocation(1,2) returned: 0x%.8x)\n", rv); goto exit; } - } - rv = blockFile->ReadBlocks(four, 8, 4); - if (NS_FAILED(rv)) { - printf("Test 17: failed (ReadBlocks(4) returned 0x%.8x)\n", rv); - goto exit; - } - - // Verify buffer - for (i = 0; i < 256 * 4; i++) { - if (four[i] != 4) { - printf("Test 17: failed (verifying buffer 4)\n"); - rv = NS_ERROR_FAILURE; + rv = blockFile->VerifyAllocation(4,3); + if (NS_FAILED(rv)) { + printf("Test 7: failed (VerifyAllocation(4,3) returned: 0x%.8x)\n", rv); goto exit; } - } - rv = blockFile->Close(); - if (NS_FAILED(rv)) { - printf("Test 17: failed (Close returned: 0x%.8x)\n", rv); - goto exit; - } - - printf("Test 17: passed\n"); - + rv = blockFile->VerifyAllocation(8,4); + if (NS_FAILED(rv)) { + printf("Test 7: failed (VerifyAllocation(8,4) returned: 0x%.8x)\n", rv); + goto exit; + } + printf("Test 7: passed\n"); - //---------------------------------------------------------------- - // Test 18: ValidateFile (open existing file with blocks allocated) - //---------------------------------------------------------------- - rv = blockFile->Open(localFile, 256); - if (NS_FAILED(rv)) { - printf("Test 18: failed (Open returned: 0x%.8x)\n", rv); - goto exit; - } - rv = blockFile->Close(); - if (NS_FAILED(rv)) { - printf("Test 18: failed (Close returned: 0x%.8x)\n", rv); - goto exit; - } - - printf("Test 18: passed\n"); + //---------------------------------------------------------------- + // Test 8: LastBlock + //---------------------------------------------------------------- + PRInt32 lastBlock = blockFile->LastBlock(); + if (lastBlock != 11) { + printf("Test 8: failed (LastBlock() returned: %d)\n", lastBlock); + goto exit; + } + printf("Test 8: passed\n"); - //---------------------------------------------------------------- - // Test 19: WriteBlocks/ReadBlocks stress - //---------------------------------------------------------------- - rv = StressTest(localFile, 19, PR_FALSE); - if (NS_FAILED(rv)) - goto exit; + //---------------------------------------------------------------- + // Test 9: DeallocateBlocks: bad startBlock ( < 0) + //---------------------------------------------------------------- + rv = blockFile->DeallocateBlocks(-1, 4); + if (NS_SUCCEEDED(rv)) { + printf("Test 9: failed (DeallocateBlocks(-1, 4) erroneously succeeded)\n"); + goto exit; + } + printf("Test 9: passed\n"); - printf("Test 19: passed\n"); + + //---------------------------------------------------------------- + // Test 10: DeallocateBlocks: bad numBlocks (0, 5) + //---------------------------------------------------------------- + rv = blockFile->DeallocateBlocks(0, 0); + if (NS_SUCCEEDED(rv)) { + printf("Test 10: failed (DeallocateBlocks(0, 0) erroneously succeeded)\n"); + goto exit; + } + + rv = blockFile->DeallocateBlocks(0, 5); + if (NS_SUCCEEDED(rv)) { + printf("Test 10: failed (DeallocateBlocks(0, 5) erroneously succeeded)\n"); + goto exit; + } + + printf("Test 10: passed\n"); + + + //---------------------------------------------------------------- + // Test 11: DeallocateBlocks: unallocated blocks + //---------------------------------------------------------------- + rv = blockFile->DeallocateBlocks(12, 1); + if (NS_SUCCEEDED(rv)) { + printf("Test 11: failed (DeallocateBlocks(12, 1) erroneously succeeded)\n"); + goto exit; + } + + printf("Test 11: passed\n"); + + + //---------------------------------------------------------------- + // Test 12: DeallocateBlocks: 1, 2, 3, 4 (allocated in Test 6) + //---------------------------------------------------------------- + rv = blockFile->DeallocateBlocks(0, 1); + if (NS_FAILED(rv)) { + printf("Test 12: failed (DeallocateBlocks(12, 1) returned: 0x%.8x)\n", rv); + goto exit; + } + + rv = blockFile->DeallocateBlocks(1, 2); + if (NS_FAILED(rv)) { + printf("Test 12: failed (DeallocateBlocks(1, 2) returned: 0x%.8x)\n", rv); + goto exit; + } + + rv = blockFile->DeallocateBlocks(4, 3); + if (NS_FAILED(rv)) { + printf("Test 12: failed (DeallocateBlocks(4, 3) returned: 0x%.8x)\n", rv); + goto exit; + } + + rv = blockFile->DeallocateBlocks(8, 4); + if (NS_FAILED(rv)) { + printf("Test 12: failed (DeallocateBlocks(8, 4) returned: 0x%.8x)\n", rv); + goto exit; + } + + // zero blocks should be allocated + rv = blockFile->Close(); + if (NS_FAILED(rv)) { + printf("Test 12: failed (Close returned: 0x%.8x)\n", rv); + goto exit; + } + + printf("Test 12: passed\n"); + + + //---------------------------------------------------------------- + // Test 13: Allocate/Deallocate boundary test + //---------------------------------------------------------------- + + rv = blockFile->Open(localFile, 256); + if (NS_FAILED(rv)) { + printf("Test 13: failed (Open returned: 0x%.8x)\n", rv); + goto exit; + } + + // fully allocate, 1 block at a time + for (i=0; i< kBitMapBytes * 8; ++i) { + startBlock = blockFile->AllocateBlocks(1); + if (startBlock < 0) { + printf("Test 13: failed (AllocateBlocks(1) failed on i=%d)\n", i); + goto exit; + } + } + + // attempt allocation with full bit map + startBlock = blockFile->AllocateBlocks(1); + if (startBlock >= 0) { + printf("Test 13: failed (AllocateBlocks(1) erroneously succeeded i=%d)\n", i); + goto exit; + } + + // deallocate all the bits + for (i=0; i< kBitMapBytes * 8; ++i) { + rv = blockFile->DeallocateBlocks(i,1); + if (NS_FAILED(rv)) { + printf("Test 13: failed (DeallocateBlocks(%d,1) returned: 0x%.8x)\n", i,rv); + goto exit; + } + } + + // attempt deallocation beyond end of bit map + rv = blockFile->DeallocateBlocks(i,1); + if (NS_SUCCEEDED(rv)) { + printf("Test 13: failed (DeallocateBlocks(%d,1) erroneously succeeded)\n", i); + goto exit; + } + + // bit map should be empty + + // fully allocate, 2 block at a time + for (i=0; i< kBitMapBytes * 8; i+=2) { + startBlock = blockFile->AllocateBlocks(2); + if (startBlock < 0) { + printf("Test 13: failed (AllocateBlocks(2) failed on i=%d)\n", i); + goto exit; + } + } + + // attempt allocation with full bit map + startBlock = blockFile->AllocateBlocks(2); + if (startBlock >= 0) { + printf("Test 13: failed (AllocateBlocks(2) erroneously succeeded i=%d)\n", i); + goto exit; + } + + // deallocate all the bits + for (i=0; i< kBitMapBytes * 8; i+=2) { + rv = blockFile->DeallocateBlocks(i,2); + if (NS_FAILED(rv)) { + printf("Test 13: failed (DeallocateBlocks(%d,2) returned: 0x%.8x)\n", i,rv); + goto exit; + } + } + + // bit map should be empty + + // fully allocate, 4 block at a time + for (i=0; i< kBitMapBytes * 8; i+=4) { + startBlock = blockFile->AllocateBlocks(4); + if (startBlock < 0) { + printf("Test 13: failed (AllocateBlocks(4) failed on i=%d)\n", i); + goto exit; + } + } + + // attempt allocation with full bit map + startBlock = blockFile->AllocateBlocks(4); + if (startBlock >= 0) { + printf("Test 13: failed (AllocateBlocks(4) erroneously succeeded i=%d)\n", i); + goto exit; + } + + // deallocate all the bits + for (i=0; i< kBitMapBytes * 8; i+=4) { + rv = blockFile->DeallocateBlocks(i,4); + if (NS_FAILED(rv)) { + printf("Test 13: failed (DeallocateBlocks(%d,4) returned: 0x%.8x)\n", i,rv); + goto exit; + } + } + + // bit map should be empty + + // allocate as many triple-blocks as possible + for (i=0; i< kBitMapBytes * 8; i+=4) { + startBlock = blockFile->AllocateBlocks(3); + if (startBlock < 0) { + printf("Test 13: failed (AllocateBlocks(3) failed on i=%d)\n", i); + goto exit; + } + } + + // attempt allocation with "full" bit map + startBlock = blockFile->AllocateBlocks(3); + if (startBlock >= 0) { + printf("Test 13: failed (AllocateBlocks(3) erroneously succeeded i=%d)\n", i); + goto exit; + } + + // leave some blocks allocated + + rv = blockFile->Close(); + if (NS_FAILED(rv)) { + printf("Test 13: failed (Close returned: 0x%.8x)\n", rv); + goto exit; + } + + printf("Test 13: passed\n"); + + + //---------------------------------------------------------------- + // Test 14: ValidateFile (open existing file w/size < allocated blocks + //---------------------------------------------------------------- + rv = blockFile->Open(localFile, 256); + if (NS_SUCCEEDED(rv)) { + printf("Test 14: failed (Open erroneously succeeded)\n"); + goto exit; + } + + // Delete existing file + rv = localFile->Delete(PR_FALSE); + if (NS_FAILED(rv)) { + printf("Test 14 failed (Delete returned: 0x%.8x)\n", rv); + goto exit; + } + printf("Test 14: passed\n"); + + + //---------------------------------------------------------------- + // Test 15: Allocate/Deallocate stress test + //---------------------------------------------------------------- + + rv = StressTest(localFile, 15, PR_FALSE); + if (NS_FAILED(rv)) + goto exit; + + printf("Test 15: passed\n"); + + + //---------------------------------------------------------------- + // Test 16: WriteBlocks + //---------------------------------------------------------------- + + rv = blockFile->Open(localFile, 256); + if (NS_FAILED(rv)) { + printf("Test 16: failed (Open returned: 0x%.8x)\n", rv); + goto exit; + } + + char * one = new char[256 * 1]; + char * two = new char[256 * 2]; + char * three = new char[256 * 3]; + char * four = new char[256 * 4]; + if (!one || !two || !three || !four) { + printf("Test 16: failed - out of memory\n"); + rv = NS_ERROR_OUT_OF_MEMORY; + goto exit; + } + + memset(one, 1, 256); + memset(two, 2, 256 * 2); + memset(three, 3, 256 * 3); + memset(four, 4, 256 * 4); + + startBlock = blockFile->AllocateBlocks(1); + if (startBlock != 0) { + printf("Test 16: failed (AllocateBlocks(1) failed)\n"); + goto exit; + } + + rv = blockFile->WriteBlocks(one, startBlock, 1); + if (NS_FAILED(rv)) { + printf("Test 16: failed (WriteBlocks(1) returned 0x%.8x)\n", rv); + goto exit; + } + + startBlock = blockFile->AllocateBlocks(2); + if (startBlock != 1) { // starting with empy map, this allocation should begin at block 1 + printf("Test 16: failed (AllocateBlocks(2) failed)\n"); + goto exit; + } + + rv = blockFile->WriteBlocks(two, startBlock, 2); + if (NS_FAILED(rv)) { + printf("Test 16: failed (WriteBlocks(2) returned 0x%.8x)\n", rv); + goto exit; + } + + startBlock = blockFile->AllocateBlocks(3); + if (startBlock != 4) { // starting with empy map, this allocation should begin at block 4 + printf("Test 16: failed (AllocateBlocks(3) failed)\n"); + goto exit; + } + + rv = blockFile->WriteBlocks(three, startBlock, 3); + if (NS_FAILED(rv)) { + printf("Test 16: failed (WriteBlocks(3) returned 0x%.8x)\n", rv); + goto exit; + } + + startBlock = blockFile->AllocateBlocks(4); + if (startBlock != 8) { // starting with empy map, this allocation should begin at block 8 + printf("Test 16: failed (AllocateBlocks(4) failed)\n"); + goto exit; + } + + rv = blockFile->WriteBlocks(four, startBlock, 4); + if (NS_FAILED(rv)) { + printf("Test 16: failed (WriteBlocks(4) returned 0x%.8x)\n", rv); + goto exit; + } + + printf("Test 16: passed\n"); + + + //---------------------------------------------------------------- + // Test 17: ReadBlocks + //---------------------------------------------------------------- + + rv = blockFile->ReadBlocks(one, 0, 1); + if (NS_FAILED(rv)) { + printf("Test 17: failed (ReadBlocks(1) returned 0x%.8x)\n", rv); + goto exit; + } + + // Verify buffer + for (i = 0; i < 256; i++) { + if (one[i] != 1) { + printf("Test 17: failed (verifying buffer 1)\n"); + rv = NS_ERROR_FAILURE; + goto exit; + } + } + + rv = blockFile->ReadBlocks(two, 1, 2); + if (NS_FAILED(rv)) { + printf("Test 17: failed (ReadBlocks(2) returned 0x%.8x)\n", rv); + goto exit; + } + + // Verify buffer + for (i = 0; i < 256 * 2; i++) { + if (two[i] != 2) { + printf("Test 17: failed (verifying buffer 2)\n"); + rv = NS_ERROR_FAILURE; + goto exit; + } + } + + rv = blockFile->ReadBlocks(three, 4, 3); + if (NS_FAILED(rv)) { + printf("Test 17: failed (ReadBlocks(3) returned 0x%.8x)\n", rv); + goto exit; + } + + // Verify buffer + for (i = 0; i < 256 * 3; i++) { + if (three[i] != 3) { + printf("Test 17: failed (verifying buffer 3)\n"); + rv = NS_ERROR_FAILURE; + goto exit; + } + } + + rv = blockFile->ReadBlocks(four, 8, 4); + if (NS_FAILED(rv)) { + printf("Test 17: failed (ReadBlocks(4) returned 0x%.8x)\n", rv); + goto exit; + } + + // Verify buffer + for (i = 0; i < 256 * 4; i++) { + if (four[i] != 4) { + printf("Test 17: failed (verifying buffer 4)\n"); + rv = NS_ERROR_FAILURE; + goto exit; + } + } + + rv = blockFile->Close(); + if (NS_FAILED(rv)) { + printf("Test 17: failed (Close returned: 0x%.8x)\n", rv); + goto exit; + } + + printf("Test 17: passed\n"); + + + //---------------------------------------------------------------- + // Test 18: ValidateFile (open existing file with blocks allocated) + //---------------------------------------------------------------- + rv = blockFile->Open(localFile, 256); + if (NS_FAILED(rv)) { + printf("Test 18: failed (Open returned: 0x%.8x)\n", rv); + goto exit; + } + + rv = blockFile->Close(); + if (NS_FAILED(rv)) { + printf("Test 18: failed (Close returned: 0x%.8x)\n", rv); + goto exit; + } + + printf("Test 18: passed\n"); + + //---------------------------------------------------------------- + // Test 19: WriteBlocks/ReadBlocks stress + //---------------------------------------------------------------- + + rv = StressTest(localFile, 19, PR_FALSE); + if (NS_FAILED(rv)) + goto exit; + + printf("Test 19: passed\n"); exit: - if (currentDirPath) - nsMemory::Free(currentDirPath); - - NS_ShutdownXPCOM(nsnull); - - printf("XPCOM shut down.\n\n"); + if (currentDirPath) + nsMemory::Free(currentDirPath); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM if (NS_FAILED(rv)) printf("Test failed: 0x%.8x\n", rv); - return 0; + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); + + printf("XPCOM shut down.\n\n"); + return 0; } diff --git a/mozilla/netwerk/test/TestCacheMgr.cpp b/mozilla/netwerk/test/TestCacheMgr.cpp index 613d161c8a3..0df52d9b8ee 100644 --- a/mozilla/netwerk/test/TestCacheMgr.cpp +++ b/mozilla/netwerk/test/TestCacheMgr.cpp @@ -88,11 +88,11 @@ public: RandomStream(PRUint32 aSeed) { mStartSeed = mState = aSeed; } - + PRUint32 GetStartSeed() { return mStartSeed; } - + PRUint32 Next() { mState = 1103515245 * mState + 12345 ^ (mState >> 16); return mState; @@ -140,7 +140,7 @@ public: if (*aBuf++ != (char)(NextChar() & 0xff)) return PR_FALSE; } - + // Check for terminating NUL character if (*aBuf) return PR_FALSE; @@ -160,7 +160,7 @@ public: } protected: - + PRUint32 mState; PRUint32 mStartSeed; }; @@ -223,7 +223,7 @@ public: nsresult aStatus) { PRIntervalTime endTime; PRIntervalTime duration; - + endTime = PR_IntervalNow(); duration = (endTime - mStartTime); @@ -291,12 +291,12 @@ TestReadStream(nsICachedNetData *cacheEntry, nsITestDataStream *testDataStream, NS_ASSERTION(NS_SUCCEEDED(rv), " "); // FIXME NS_ASSERTION(actualContentLength == expectedStreamLength, // "nsICachedNetData::GetContentLength() busted ?"); - + nsReader *reader = new nsReader; reader->AddRef(); rv = reader->Init(testDataStream, expectedStreamLength); NS_ASSERTION(NS_SUCCEEDED(rv), " "); - + rv = channel->AsyncOpen(0, reader); NS_ASSERTION(NS_SUCCEEDED(rv), " "); reader->Release(); @@ -350,7 +350,7 @@ TestRead(nsINetDataCacheManager *aCache, PRUint32 aFlags) aFlags, &inCache); NS_ASSERTION(NS_SUCCEEDED(rv), " "); NS_ASSERTION(inCache, "nsINetDataCacheManager::Contains error"); - + rv = aCache->GetCachedNetData(uriCacheKey, secondaryCacheKey, sizeof secondaryCacheKey, aFlags, @@ -436,7 +436,7 @@ FillCache(nsINetDataCacheManager *aCache, PRUint32 aFlags, PRUint32 aCacheCapaci gTotalBytesWritten = 0; PRIntervalTime startTime = PR_IntervalNow(); - + for (testNum = 0; testNum < NUM_CACHE_ENTRIES; testNum++) { randomStream = new RandomStream(testNum); randomStream->ReadString(cacheKey, sizeof cacheKey - 1); @@ -448,7 +448,7 @@ FillCache(nsINetDataCacheManager *aCache, PRUint32 aFlags, PRUint32 aCacheCapaci aFlags, &inCache); NS_ASSERTION(NS_SUCCEEDED(rv), " "); NS_ASSERTION(!inCache, "nsINetDataCacheManager::Contains error"); - + rv = aCache->GetCachedNetData(cacheKey, secondaryCacheKey, sizeof secondaryCacheKey, aFlags, @@ -496,7 +496,7 @@ FillCache(nsINetDataCacheManager *aCache, PRUint32 aFlags, PRUint32 aCacheCapaci nsCOMPtr trans(do_QueryInterface(channel)); rv = trans->OpenOutputStream(0, -1, 0,getter_AddRefs(outStream)); NS_ASSERTION(NS_SUCCEEDED(rv), " "); - + int streamLength = randomStream->Next() % MAX_CONTENT_LENGTH; int remaining = streamLength; while (remaining) { @@ -507,7 +507,7 @@ FillCache(nsINetDataCacheManager *aCache, PRUint32 aFlags, PRUint32 aCacheCapaci rv = outStream->Write(buf, amount, &numWritten); NS_ASSERTION(NS_SUCCEEDED(rv), " "); NS_ASSERTION(numWritten == (PRUint32)amount, "Write() bug?"); - + remaining -= amount; PRUint32 storageInUse; @@ -572,29 +572,34 @@ int main(int argc, char* argv[]) { nsresult rv; - nsCOMPtr cache; + { + nsCOMPtr cache; - - // Start up XPCOM - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + // Start up XPCOM + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - rv = nsComponentManager::CreateInstance(NS_NETWORK_CACHE_MANAGER_CONTRACTID, - nsnull, - NS_GET_IID(nsINetDataCacheManager), - getter_AddRefs(cache)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create cache manager factory") ; + rv = nsComponentManager::CreateInstance(NS_NETWORK_CACHE_MANAGER_CONTRACTID, + nsnull, + NS_GET_IID(nsINetDataCacheManager), + getter_AddRefs(cache)); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create cache manager factory") ; - cache->SetDiskCacheCapacity(DISK_CACHE_CAPACITY); - cache->SetMemCacheCapacity(MEM_CACHE_CAPACITY); + cache->SetDiskCacheCapacity(DISK_CACHE_CAPACITY); + cache->SetMemCacheCapacity(MEM_CACHE_CAPACITY); - InitQueue(); - - Test(cache, nsINetDataCacheManager::BYPASS_PERSISTENT_CACHE, MEM_CACHE_CAPACITY); - Test(cache, nsINetDataCacheManager::BYPASS_MEMORY_CACHE, DISK_CACHE_CAPACITY); + InitQueue(); + + Test(cache, nsINetDataCacheManager::BYPASS_PERSISTENT_CACHE, MEM_CACHE_CAPACITY); + Test(cache, nsINetDataCacheManager::BYPASS_MEMORY_CACHE, DISK_CACHE_CAPACITY); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/netwerk/test/TestCacheService.cpp b/mozilla/netwerk/test/TestCacheService.cpp index 294bcfa034c..1ccb47ac289 100644 --- a/mozilla/netwerk/test/TestCacheService.cpp +++ b/mozilla/netwerk/test/TestCacheService.cpp @@ -112,7 +112,7 @@ TestMemoryObjectCache() printf("OpenCacheEntry(ACCESS_READ_WRITE) failed: %x\n", rv); goto error_exit; } - + nsCOMPtr foo = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv); @@ -124,7 +124,7 @@ TestMemoryObjectCache() descriptor = nsnull; // Test refetching entry - + rv = session->OpenCacheEntry("http://www.mozilla.org/somekey", nsICache::ACCESS_READ_WRITE, nsICache::BLOCKING, @@ -141,7 +141,7 @@ TestMemoryObjectCache() } else { printf("data matches...\n"); } - + char * metaData; rv = descriptor->GetMetaDataElement("itemOne", &metaData); if (NS_SUCCEEDED(rv)) printf("metaData = %s\n", metaData); @@ -194,7 +194,7 @@ main(int argc, char* argv[]) if (NS_FAILED(rv)) goto error_exit; eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(gEventQ)); - + /** * Test Cache */ @@ -208,7 +208,7 @@ main(int argc, char* argv[]) printf("nsCacheService::Shutdown() : rv = %x\n", rv); gCacheService = nsnull; } - + gEventQ = nsnull; eventQService = nsnull; @@ -218,5 +218,5 @@ main(int argc, char* argv[]) return rv; } - + diff --git a/mozilla/netwerk/test/TestCallbacks.cpp b/mozilla/netwerk/test/TestCallbacks.cpp index c7f5d0bdd7f..9693ffbea8f 100644 --- a/mozilla/netwerk/test/TestCallbacks.cpp +++ b/mozilla/netwerk/test/TestCallbacks.cpp @@ -80,7 +80,7 @@ public: NS_DECL_ISUPPORTS ConsumerContext() { NS_INIT_REFCNT();} - + NS_IMETHOD Equals(void *aPtr, PRBool *_retval) { *_retval = PR_TRUE; if (aPtr != this) *_retval = PR_FALSE; @@ -298,7 +298,7 @@ int main(int argc, char *argv[]) { nsresult StartLoad(const char *aURISpec) { nsresult rv = NS_OK; - + // create a context ConsumerContext *context = new ConsumerContext; nsCOMPtr contextSup = do_QueryInterface(context, &rv); @@ -309,7 +309,7 @@ nsresult StartLoad(const char *aURISpec) { rv = nsServiceManager::GetService(kIOServiceCID, NS_GET_IID(nsIIOService), getter_AddRefs(serv)); if (NS_FAILED(rv)) return rv; - + // create a uri nsCOMPtr uri; rv = NS_NewURI(getter_AddRefs(uri), aURISpec); diff --git a/mozilla/netwerk/test/TestDBMAccess.cpp b/mozilla/netwerk/test/TestDBMAccess.cpp index e052f3ec76d..6d58288933c 100644 --- a/mozilla/netwerk/test/TestDBMAccess.cpp +++ b/mozilla/netwerk/test/TestDBMAccess.cpp @@ -67,12 +67,12 @@ int writeDBM(int cycles) 0600 , DB_HASH , &hash_info) ; - + if (!myDB) { printf("no db!\n"); return -1; } - + // initalize data to write int x; char * data = (char*) malloc(DATASIZE); @@ -81,13 +81,13 @@ int writeDBM(int cycles) for (x=1; x<=ENTRYCOUNT; x++) { nsCAutoString keyName("foo"); keyName.AppendInt( x ); - + db_key.data = NS_CONST_CAST(char*, keyName.get()); db_key.size = keyName.Length(); - + db_data.data = data; db_data.size = DATASIZE ; - + if(0 != (*myDB->put)(myDB, &db_key, &db_data, 0)) { printf("--> Error putting\n"); return -1; @@ -97,14 +97,14 @@ int writeDBM(int cycles) db_key.size = sizeof(x); db_data.data = NS_CONST_CAST(char*, keyName.get()); db_data.size = keyName.Length(); - + if(0 != (*myDB->put)(myDB, &db_key, &db_data, 0)) { printf("--> Error putting\n"); return -1; } #endif } - + (*myDB->sync)(myDB, 0); free(data); } @@ -120,7 +120,7 @@ readDBM(int cycles) int status = 0 ; DBT db_key, db_data ; PRIntervalTime time = PR_IntervalNow(); - + while (cycles--) { for (int x=1; x<=ENTRYCOUNT; x++) { #if USE_ENTRY_ID @@ -128,7 +128,7 @@ readDBM(int cycles) db_key.data = (void*)&x; db_key.size = sizeof(x) ; - + status = (*myDB->get)(myDB, &db_key, &entry_data, 0); if(status != 0) { printf("Bad Status %d\n", status); @@ -162,7 +162,7 @@ readDBM(int cycles) } (*myDB->sync)(myDB, 0); (*myDB->close)(myDB); - + return PR_IntervalToMilliseconds( PR_IntervalNow() - time); } @@ -184,13 +184,13 @@ writeFile(int cycles) // create "cache" directories PR_MakeDir(TMPDIR "foo", 0755); - + for (x=0; x<32; x++) { nsCAutoString filename; filename.Assign(TMPDIR "foo" DIRSEP); filename.AppendInt(x); PR_MakeDir(filename.get(), 0755); } - + // create "cache" files for (x=1; x<=ENTRYCOUNT; x++) { nsCAutoString filename; filename.Assign(TMPDIR "foo" DIRSEP); @@ -236,7 +236,7 @@ readFile(int cycles) printf("readFile\n"); PRFileDesc* fd; PRInt32 fStatus; - + // begin timing "lookups" PRIntervalTime time = PR_IntervalNow(); while (cycles--) { @@ -245,31 +245,31 @@ readFile(int cycles) filename.AppendInt( x % 32 ); filename.Append(DIRSEP); filename.AppendInt( x ); - + fd = PR_OpenFile(filename.get(), PR_RDONLY, 0); if (!fd) { printf("bad filename? %s\n", filename.get()); continue; } - + PRInt32 size = PR_Available(fd); - + char* fdBuffer = (char*) malloc (size); - + PRIntervalTime i1, i2, i3; i1 = PR_IntervalNow(); fStatus = PR_Read(fd, fdBuffer, size); i2 = PR_IntervalNow(); - + if (fStatus == -1) { printf("Bad fStatus %d\n", PR_GetError()); exit(1); } i3 = PR_IntervalNow(); - + PR_Close(fd); free(fdBuffer); diff --git a/mozilla/netwerk/test/TestDNSDaemon.cpp b/mozilla/netwerk/test/TestDNSDaemon.cpp index 2a284acab35..2742cada0cc 100644 --- a/mozilla/netwerk/test/TestDNSDaemon.cpp +++ b/mozilla/netwerk/test/TestDNSDaemon.cpp @@ -213,7 +213,7 @@ main(int argc, char* argv[]) while(notDone) { int status = 0; fd_set fdset; - + FD_ZERO(&fdset); FD_SET(fileno(stdin), &fdset); if (socket_fd > 0) diff --git a/mozilla/netwerk/test/TestFileInput.cpp b/mozilla/netwerk/test/TestFileInput.cpp index e5e15794b3c..25d31ae11f1 100644 --- a/mozilla/netwerk/test/TestFileInput.cpp +++ b/mozilla/netwerk/test/TestFileInput.cpp @@ -109,7 +109,7 @@ public: PRThread* prthread; thread->GetPRThread(&prthread); PR_EnterMonitor(mMonitor); - nsCOMPtr eventQService = + nsCOMPtr eventQService = do_GetService(kEventQueueServiceCID, &rv); if (NS_SUCCEEDED(rv)) { rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &mEventQueue); @@ -120,7 +120,7 @@ public: // wake up event loop PR_Notify(mMonitor); PR_ExitMonitor(mMonitor); - + return NS_OK; } @@ -360,7 +360,7 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts) nsIStreamListener* listener; reader->QueryInterface(NS_GET_IID(nsIStreamListener), (void**)&listener); NS_ASSERTION(listener, "QI failed"); - + nsITransport* trans; rv = fts->CreateTransport(localFile, PR_RDONLY, 0, PR_TRUE, &trans); NS_ASSERTION(NS_SUCCEEDED(rv), "create failed"); @@ -402,28 +402,32 @@ main(int argc, char* argv[]) } char* dirName = argv[1]; + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + nsCOMPtr fts = + do_GetService(kFileTransportServiceCID, &rv); + if (NS_FAILED(rv)) return rv; - nsCOMPtr fts = - do_GetService(kFileTransportServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + SerialReadTest(dirName); - SerialReadTest(dirName); + //ParallelReadTest(dirName, fts); - //ParallelReadTest(dirName, fts); - - fts->ProcessPendingRequests(); - - printf("duration %d ms, volume %d\n", - PR_IntervalToMilliseconds(gDuration), - gVolume); - gVolume = 0; + fts->ProcessPendingRequests(); + printf("duration %d ms, volume %d\n", + PR_IntervalToMilliseconds(gDuration), + gVolume); + gVolume = 0; + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/netwerk/test/TestFileInput2.cpp b/mozilla/netwerk/test/TestFileInput2.cpp index beae69682af..c4f65424f81 100644 --- a/mozilla/netwerk/test/TestFileInput2.cpp +++ b/mozilla/netwerk/test/TestFileInput2.cpp @@ -146,7 +146,7 @@ Copy(nsIInputStream* inStr, nsIOutputStream* outStr, rv = inStr->Read(buf, bufSize, &count); if (NS_FAILED(rv)) return rv; if (count == 0) break; - + PRUint32 writeCount; rv = outStr->Write(buf, count, &writeCount); if (NS_FAILED(rv)) return rv; @@ -175,10 +175,10 @@ public: nsCOMPtr fileIn; rv = NS_NewLocalFileInputStream(getter_AddRefs(fileIn), mInPath); if (NS_FAILED(rv)) return rv; - + rv = NS_NewBufferedInputStream(getter_AddRefs(inStr), fileIn, 65535); if (NS_FAILED(rv)) return rv; - + // Open the output stream: nsCOMPtr fileOut; rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOut), @@ -286,7 +286,7 @@ public: // Copy from one to the other rv = Copy(inStr, outStr, mBuffer, mBufferSize, ©Count); if (NS_FAILED(rv)) return rv; - + endTime = PR_IntervalNow(); gTimeSampler.AddTime(endTime - startTime); @@ -353,7 +353,7 @@ Test(CreateFun create, PRUint32 count, { nsresult rv; PRUint32 i; - + nsCAutoString inDir; nsCAutoString outDir; (void)inDirSpec->GetNativePath(inDir); @@ -363,7 +363,7 @@ Test(CreateFun create, PRUint32 count, gTimeSampler.Reset(); nsTimeSampler testTime; testTime.StartTime(); - + nsISupportsArray* threads; rv = NS_NewISupportsArray(&threads); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewISupportsArray failed"); @@ -453,60 +453,64 @@ main(int argc, char* argv[]) char* inDir = argv[1]; char* outDir = argv[2]; + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + nsCOMPtr inDirFile; + rv = NS_NewNativeLocalFile(nsDependentCString(inDir), PR_FALSE, getter_AddRefs(inDirFile)); + if (NS_FAILED(rv)) return rv; - nsCOMPtr inDirFile; - rv = NS_NewNativeLocalFile(nsDependentCString(inDir), PR_FALSE, getter_AddRefs(inDirFile)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr outDirFile; + rv = NS_NewNativeLocalFile(nsDependentCString(outDir), PR_FALSE, getter_AddRefs(outDirFile)); + if (NS_FAILED(rv)) return rv; - nsCOMPtr outDirFile; - rv = NS_NewNativeLocalFile(nsDependentCString(outDir), PR_FALSE, getter_AddRefs(outDirFile)); - if (NS_FAILED(rv)) return rv; - - CreateFun create = FileChannelWorker::Create; - Test(create, 1, inDirFile, outDirFile, 16 * 1024); + CreateFun create = FileChannelWorker::Create; + Test(create, 1, inDirFile, outDirFile, 16 * 1024); #if 1 - printf("FileChannelWorker *****************************\n"); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); + printf("FileChannelWorker *****************************\n"); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); #endif - create = FileSpecWorker::Create; - printf("FileSpecWorker ********************************\n"); + create = FileSpecWorker::Create; + printf("FileSpecWorker ********************************\n"); #if 1 - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); - Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); + Test(create, 20, inDirFile, outDirFile, 16 * 1024); #endif #if 1 - Test(create, 20, inDirFile, outDirFile, 4 * 1024); - Test(create, 20, inDirFile, outDirFile, 4 * 1024); - Test(create, 20, inDirFile, outDirFile, 4 * 1024); - Test(create, 20, inDirFile, outDirFile, 4 * 1024); - Test(create, 20, inDirFile, outDirFile, 4 * 1024); - Test(create, 20, inDirFile, outDirFile, 4 * 1024); - Test(create, 20, inDirFile, outDirFile, 4 * 1024); - Test(create, 20, inDirFile, outDirFile, 4 * 1024); - Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); + Test(create, 20, inDirFile, outDirFile, 4 * 1024); #endif - + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/netwerk/test/TestFileTransport.cpp b/mozilla/netwerk/test/TestFileTransport.cpp index 0b1dfc6ca36..5771f0e2c49 100644 --- a/mozilla/netwerk/test/TestFileTransport.cpp +++ b/mozilla/netwerk/test/TestFileTransport.cpp @@ -150,11 +150,11 @@ public: //PR_Sleep(100); return NS_OK; } - + MyListener(PRUint32 stopCount = 1) : mTotal(0), mStopCount(stopCount) { NS_INIT_REFCNT(); } - + nsresult Init(const char* origFile) { nsresult rv; nsCOMPtr file; @@ -354,29 +354,34 @@ main(int argc, char* argv[]) return -1; } char* fileName = argv[1]; + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + nsCOMPtr eventQService = + do_GetService(kEventQueueServiceCID, &rv); + if (NS_FAILED(rv)) return rv; - nsCOMPtr eventQService = - do_GetService(kEventQueueServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); + if (NS_FAILED(rv)) return rv; - rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); - if (NS_FAILED(rv)) return rv; + rv = TestAsyncRead(fileName, 0, -1); + NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed"); - rv = TestAsyncRead(fileName, 0, -1); - NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed"); + rv = TestAsyncWrite(fileName, 0, -1); + NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncWrite failed"); - rv = TestAsyncWrite(fileName, 0, -1); - NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncWrite failed"); + rv = TestAsyncRead(fileName, 10, 100); + NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed"); - rv = TestAsyncRead(fileName, 10, 100); - NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed"); - - NS_RELEASE(gEventQ); + NS_RELEASE(gEventQ); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return NS_OK; } diff --git a/mozilla/netwerk/test/TestHttp.cpp b/mozilla/netwerk/test/TestHttp.cpp index 6ff016976fe..70f870ae929 100644 --- a/mozilla/netwerk/test/TestHttp.cpp +++ b/mozilla/netwerk/test/TestHttp.cpp @@ -134,41 +134,46 @@ int main(int argc, char **argv) printf("usage: TestHttp \n"); return -1; } + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + // Create the Event Queue for this thread... + nsCOMPtr eqs = + do_GetService(kEventQueueServiceCID, &rv); + RETURN_IF_FAILED(rv, "do_GetService(EventQueueService)"); - // Create the Event Queue for this thread... - nsCOMPtr eqs = - do_GetService(kEventQueueServiceCID, &rv); - RETURN_IF_FAILED(rv, "do_GetService(EventQueueService)"); + rv = eqs->CreateMonitoredThreadEventQueue(); + RETURN_IF_FAILED(rv, "CreateMonitoredThreadEventQueue"); - rv = eqs->CreateMonitoredThreadEventQueue(); - RETURN_IF_FAILED(rv, "CreateMonitoredThreadEventQueue"); + rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); + RETURN_IF_FAILED(rv, "GetThreadEventQueue"); - rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); - RETURN_IF_FAILED(rv, "GetThreadEventQueue"); + nsCOMPtr uri; + nsCOMPtr chan; + nsCOMPtr listener = new MyListener(); + nsCOMPtr callbacks = new MyNotifications(); - nsCOMPtr uri; - nsCOMPtr chan; - nsCOMPtr listener = new MyListener(); - nsCOMPtr callbacks = new MyNotifications(); + rv = NS_NewURI(getter_AddRefs(uri), argv[1]); + RETURN_IF_FAILED(rv, "NS_NewURI"); - rv = NS_NewURI(getter_AddRefs(uri), argv[1]); - RETURN_IF_FAILED(rv, "NS_NewURI"); + rv = NS_NewChannel(getter_AddRefs(chan), uri, nsnull, nsnull, callbacks); + RETURN_IF_FAILED(rv, "NS_OpenURI"); - rv = NS_NewChannel(getter_AddRefs(chan), uri, nsnull, nsnull, callbacks); - RETURN_IF_FAILED(rv, "NS_OpenURI"); + rv = chan->AsyncOpen(listener, nsnull); + RETURN_IF_FAILED(rv, "AsyncOpen"); - rv = chan->AsyncOpen(listener, nsnull); - RETURN_IF_FAILED(rv, "AsyncOpen"); + while (gKeepRunning) + gEventQ->ProcessPendingEvents(); - while (gKeepRunning) - gEventQ->ProcessPendingEvents(); - - printf(">>> done\n"); + printf(">>> done\n"); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/netwerk/test/TestMakeAbs.cpp b/mozilla/netwerk/test/TestMakeAbs.cpp index e6ec0f7d6b6..301934095ee 100644 --- a/mozilla/netwerk/test/TestMakeAbs.cpp +++ b/mozilla/netwerk/test/TestMakeAbs.cpp @@ -49,7 +49,7 @@ nsresult ServiceMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval nsresult rv; nsCOMPtr serv(do_GetService(kIOServiceCID, &rv)); if (NS_FAILED(rv)) return rv; - + return serv->MakeAbsolute(relativeInfo, baseURI, _retval); } @@ -69,30 +69,33 @@ main(int argc, char* argv[]) PRUint32 cycles = atoi(argv[1]); char *base = argv[2]; char *rel = argv[3]; + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); - - nsCOMPtr serv(do_GetService(kIOServiceCID, &rv)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr uri; - rv = serv->NewURI(base, nsnull, getter_AddRefs(uri)); - if (NS_FAILED(rv)) return rv; - - char *absURLString; - PRUint32 i = 0; - while (i++ < cycles) { - rv = ServiceMakeAbsolute(uri, rel, &absURLString); + nsCOMPtr serv(do_GetService(kIOServiceCID, &rv)); if (NS_FAILED(rv)) return rv; - nsMemory::Free(absURLString); - rv = URLMakeAbsolute(uri, rel, &absURLString); - nsMemory::Free(absURLString); - } + nsCOMPtr uri; + rv = serv->NewURI(base, nsnull, getter_AddRefs(uri)); + if (NS_FAILED(rv)) return rv; + char *absURLString; + PRUint32 i = 0; + while (i++ < cycles) { + rv = ServiceMakeAbsolute(uri, rel, &absURLString); + if (NS_FAILED(rv)) return rv; + nsMemory::Free(absURLString); + + rv = URLMakeAbsolute(uri, rel, &absURLString); + nsMemory::Free(absURLString); + } + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + NS_ShutdownXPCOM(nsnull); return rv; } diff --git a/mozilla/netwerk/test/TestPageLoad.cpp b/mozilla/netwerk/test/TestPageLoad.cpp index 4a66c008294..409960b7f61 100644 --- a/mozilla/netwerk/test/TestPageLoad.cpp +++ b/mozilla/netwerk/test/TestPageLoad.cpp @@ -98,7 +98,7 @@ static NS_METHOD streamParse (nsIInputStream* in, } else { tmp = (char *)fromRawSegment; } - + while(i < (int)count) { i = getStrLine(tmp, lineBuf, i, count); if(i < 0) { @@ -148,7 +148,7 @@ static NS_METHOD streamParse (nsIInputStream* in, } } i++; - + } *writeCount = count; return NS_OK; @@ -199,7 +199,7 @@ MyListener::OnDataAvailable(nsIRequest *req, nsISupports *ctxt, PRUint32 bytesRead=0; int i=0; char buf[1024]; - + if(ctxt == nsnull) { bytesRead=0; rv = stream->ReadSegments(streamParse, &offset, count, &bytesRead); @@ -293,7 +293,7 @@ int getStrLine(const char *src, char *str, int ind, int max) { nsresult auxLoad(char *uriBuf) { nsresult rv; - + nsCOMPtr myBool = do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID); nsCOMPtr uri; @@ -313,7 +313,7 @@ nsresult auxLoad(char *uriBuf) rv = NS_NewURI(getter_AddRefs(uri), uriBuf); if (NS_FAILED(rv)) return(rv); } - + //Compare to see if exists PRUint32 num; uriList->Count(&num); @@ -331,13 +331,13 @@ nsresult auxLoad(char *uriBuf) uriList->AppendElement(uri); rv = NS_NewChannel(getter_AddRefs(chan), uri, nsnull, nsnull, callbacks); RETURN_IF_FAILED(rv, "NS_NewChannel"); - + gKeepRunning++; rv = chan->AsyncOpen(listener, myBool); RETURN_IF_FAILED(rv, "AsyncOpen"); return NS_OK; - + } //---------Buffer writer fun--------- @@ -348,65 +348,69 @@ nsresult auxLoad(char *uriBuf) int main(int argc, char **argv) { nsresult rv; - + if (argc == 1) { printf("usage: TestPageLoad \n"); return -1; } + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + PRTime start, finish; - PRTime start, finish; + rv = NS_NewISupportsArray(getter_AddRefs(uriList)); + RETURN_IF_FAILED(rv, "NS_NewISupportsArray"); - rv = NS_NewISupportsArray(getter_AddRefs(uriList)); - RETURN_IF_FAILED(rv, "NS_NewISupportsArray"); + // Create the Event Queue for this thread... + nsCOMPtr eqs = + do_GetService(kEventQueueServiceCID, &rv); + RETURN_IF_FAILED(rv, "do_GetService(EventQueueService)"); - // Create the Event Queue for this thread... - nsCOMPtr eqs = - do_GetService(kEventQueueServiceCID, &rv); - RETURN_IF_FAILED(rv, "do_GetService(EventQueueService)"); + rv = eqs->CreateMonitoredThreadEventQueue(); + RETURN_IF_FAILED(rv, "CreateMonitoredThreadEventQueue"); - rv = eqs->CreateMonitoredThreadEventQueue(); - RETURN_IF_FAILED(rv, "CreateMonitoredThreadEventQueue"); + rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); + RETURN_IF_FAILED(rv, "GetThreadEventQueue"); - rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); - RETURN_IF_FAILED(rv, "GetThreadEventQueue"); + printf("Loading necko ... \n"); + nsCOMPtr chan; + nsCOMPtr listener = new MyListener(); + nsCOMPtr callbacks = new MyNotifications(); - printf("Loading necko ... \n"); - nsCOMPtr chan; - nsCOMPtr listener = new MyListener(); - nsCOMPtr callbacks = new MyNotifications(); + rv = NS_NewURI(getter_AddRefs(baseURI), argv[1]); + RETURN_IF_FAILED(rv, "NS_NewURI"); - rv = NS_NewURI(getter_AddRefs(baseURI), argv[1]); - RETURN_IF_FAILED(rv, "NS_NewURI"); + rv = NS_NewChannel(getter_AddRefs(chan), baseURI, nsnull, nsnull, callbacks); + RETURN_IF_FAILED(rv, "NS_OpenURI"); + gKeepRunning++; - rv = NS_NewChannel(getter_AddRefs(chan), baseURI, nsnull, nsnull, callbacks); - RETURN_IF_FAILED(rv, "NS_OpenURI"); - gKeepRunning++; + //TIMER STARTED----------------------- + printf("Starting clock ... \n"); + start = PR_Now(); + rv = chan->AsyncOpen(listener, nsnull); + RETURN_IF_FAILED(rv, "AsyncOpen"); - //TIMER STARTED----------------------- - printf("Starting clock ... \n"); - start = PR_Now(); - rv = chan->AsyncOpen(listener, nsnull); - RETURN_IF_FAILED(rv, "AsyncOpen"); + while (gKeepRunning) { + gEventQ->ProcessPendingEvents(); + } - while (gKeepRunning) { - gEventQ->ProcessPendingEvents(); - } + finish = PR_Now(); + PRUint32 totalTime32; + PRUint64 totalTime64; + LL_SUB(totalTime64, finish, start); + LL_L2UI(totalTime32, totalTime64); - finish = PR_Now(); - PRUint32 totalTime32; - PRUint64 totalTime64; - LL_SUB(totalTime64, finish, start); - LL_L2UI(totalTime32, totalTime64); - - printf("\n\n--------------------\nAll done:\nnum found:%d\nnum start:%d\n", numFound, numStart); - - printf("\n\n>>PageLoadTime>>%u>>\n\n", totalTime32); - + printf("\n\n--------------------\nAll done:\nnum found:%d\nnum start:%d\n", numFound, numStart); + + printf("\n\n>>PageLoadTime>>%u>>\n\n", totalTime32); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/netwerk/test/TestPerf.cpp b/mozilla/netwerk/test/TestPerf.cpp index 67b2e63f770..6f6280de5a2 100644 --- a/mozilla/netwerk/test/TestPerf.cpp +++ b/mozilla/netwerk/test/TestPerf.cpp @@ -33,7 +33,7 @@ load_sync_1(nsISupports *element, void *data) if (NS_FAILED(rv) || bytesRead == 0) break; } - + return PR_TRUE; } diff --git a/mozilla/netwerk/test/TestProtocols.cpp b/mozilla/netwerk/test/TestProtocols.cpp index 3d8dd5e5226..877eccc60ac 100644 --- a/mozilla/netwerk/test/TestProtocols.cpp +++ b/mozilla/netwerk/test/TestProtocols.cpp @@ -39,7 +39,7 @@ The TestProtocols tests the basic protocols architecture and can be used to test individual protocols as well. If this grows too big then we should split it to individual protocols. - + -Gagan Saksena 04/29/99 */ @@ -258,7 +258,7 @@ InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context) NS_RELEASE(visitor); } - + nsCOMPtr resChannel = do_QueryInterface(request); if (resChannel) { printf("Resumable entity identification:\n"); @@ -555,7 +555,7 @@ nsresult LoadURLsFromFile(char *aFileName) printf("\t%s\n", fileBuffer.get()); StartLoadingURL(fileBuffer.get()); } - + PR_Close(fd); return NS_OK; } @@ -590,64 +590,66 @@ main(int argc, char* argv[]) rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); if (NS_FAILED(rv)) return rv; - - // Create the Event Queue for this thread... - nsCOMPtr eventQService = - do_GetService(kEventQueueServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + { + // Create the Event Queue for this thread... + nsCOMPtr eventQService = + do_GetService(kEventQueueServiceCID, &rv); + if (NS_FAILED(rv)) return rv; - eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); + eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); - int i; - printf("\nTrying to load:\n"); - for (i=1; iWaitForEvent(&gEvent); - rv = gEventQ->HandleEvent(gEvent); + PLEvent *gEvent; + rv = gEventQ->WaitForEvent(&gEvent); + rv = gEventQ->HandleEvent(gEvent); #endif /* XP_UNIX */ #endif /* !WIN32 */ - } + } + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM NS_ShutdownXPCOM(nsnull); return rv; } diff --git a/mozilla/netwerk/test/TestRawCache.cpp b/mozilla/netwerk/test/TestRawCache.cpp index 6034f2e744b..dd37d009992 100644 --- a/mozilla/netwerk/test/TestRawCache.cpp +++ b/mozilla/netwerk/test/TestRawCache.cpp @@ -91,11 +91,11 @@ public: RandomStream(PRUint32 aSeed) { mStartSeed = mState = aSeed; } - + PRUint32 GetStartSeed() { return mStartSeed; } - + PRUint32 Next() { mState = 1103515245 * mState + 12345; return mState; @@ -125,7 +125,7 @@ public: } protected: - + PRUint32 mState; PRUint32 mStartSeed; }; @@ -136,11 +136,11 @@ public: CounterStream(PRUint32 aSeed) { mStartSeed = mState = aSeed; } - + PRUint32 GetStartSeed() { return mStartSeed; } - + PRUint32 Next() { mState += 1; mState &= 0xff; @@ -171,7 +171,7 @@ public: } protected: - + PRUint32 mState; PRUint32 mStartSeed; }; @@ -233,7 +233,7 @@ public: nsresult aStatus) { PRIntervalTime endTime; PRIntervalTime duration; - + endTime = PR_IntervalNow(); duration = (endTime - mStartTime); @@ -299,11 +299,11 @@ TestReadStream(nsINetDataCacheRecord *record, nsITestDataStream *testDataStream, NS_ASSERTION(NS_SUCCEEDED(rv), " "); NS_ASSERTION(actualContentLength == expectedStreamLength, "nsINetDataCacheRecord::GetContentLength() busted ?"); - + nsReader *reader = new nsReader; rv = reader->Init(testDataStream, expectedStreamLength); NS_ASSERTION(NS_SUCCEEDED(rv), " "); - + rv = channel->AsyncOpen(0, reader); NS_ASSERTION(NS_SUCCEEDED(rv), " "); reader->Release(); @@ -434,7 +434,7 @@ TestRead(nsINetDataCache *cache) rv = cache->Contains(cacheKey, sizeof cacheKey, &inCache); NS_ASSERTION(NS_SUCCEEDED(rv), " "); NS_ASSERTION(inCache, "nsINetDataCache::Contains error"); - + rv = cache->GetCachedNetData(cacheKey, sizeof cacheKey, getter_AddRefs(record)); NS_ASSERTION(NS_SUCCEEDED(rv), " "); @@ -549,7 +549,7 @@ TestOffsetWrites(nsINetDataCache *cache) nsCOMPtr trans(do_QueryInterface(channel)); rv = trans->OpenOutputStream(startingOffset, -1, 0, getter_AddRefs(outStream)); NS_ASSERTION(NS_SUCCEEDED(rv), "OpenOutputStream failed"); - + counterStream = new CounterStream(startingOffset); counterStream->Read(buf, sizeof buf); @@ -563,7 +563,7 @@ TestOffsetWrites(nsINetDataCache *cache) NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't close channel"); delete counterStream; } - + delete randomStream; counterStream = new CounterStream(0); @@ -593,7 +593,7 @@ FillCache(nsINetDataCache *cache) PRUint32 totalBytesWritten = 0; PRIntervalTime startTime = PR_IntervalNow(); - + for (testNum = 0; testNum < NUM_CACHE_ENTRIES; testNum++) { randomStream = new RandomStream(testNum); randomStream->Read(cacheKey, sizeof cacheKey); @@ -602,7 +602,7 @@ FillCache(nsINetDataCache *cache) rv = cache->Contains(cacheKey, sizeof cacheKey, &inCache); NS_ASSERTION(NS_SUCCEEDED(rv), " "); NS_ASSERTION(!inCache, "nsINetDataCache::Contains error"); - + rv = cache->GetCachedNetData(cacheKey, sizeof cacheKey, getter_AddRefs(record)); NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't access record via opaque cache key"); @@ -632,7 +632,7 @@ FillCache(nsINetDataCache *cache) nsCOMPtr trans(do_QueryInterface(channel)); rv = trans->OpenOutputStream(0, -1, 0, getter_AddRefs(outStream)); NS_ASSERTION(NS_SUCCEEDED(rv), " "); - + PRUint32 beforeOccupancy; rv = cache->GetStorageInUse(&beforeOccupancy); NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get cache occupancy"); @@ -647,7 +647,7 @@ FillCache(nsINetDataCache *cache) rv = outStream->Write(buf, amount, &numWritten); NS_ASSERTION(NS_SUCCEEDED(rv), " "); NS_ASSERTION(numWritten == (PRUint32)amount, "Write() bug?"); - + remaining -= amount; } outStream->Close(); @@ -659,7 +659,7 @@ FillCache(nsINetDataCache *cache) PRUint32 streamLengthInKB = streamLength >> 10; NS_ASSERTION((afterOccupancy - beforeOccupancy) >= streamLengthInKB, "nsINetDataCache::GetStorageInUse() is busted"); - + // *Now* there should be an entry in the cache rv = cache->Contains(cacheKey, sizeof cacheKey, &inCache); @@ -687,21 +687,21 @@ PRBool initPref () nsCOMPtr prefPtr(do_GetService(kPrefCID, &rv)); if (NS_FAILED(rv)) return false; - + nsCOMPtr fileSpec; rv = NS_NewFileSpec (getter_AddRefs(fileSpec)); if (NS_FAILED(rv)) return false; - + nsCString defaultPrefFile(PR_GetEnv ("MOZILLA_FIVE_HOME")); if (defaultPrefFile.Length()) defaultPrefFile += "/"; else defaultPrefFile = "./"; defaultPrefFile += "default_prefs.js"; - + fileSpec->SetUnixStyleFilePath (defaultPrefFile.get()); - + PRBool exists = false; fileSpec->Exists(&exists); if (exists) @@ -721,87 +721,88 @@ main(int argc, char* argv[]) printf(" %s -m to test memcache\n", argv[0]) ; return -1 ; } + { + nsCOMPtr cache; + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr cache; + if (PL_strcasecmp(argv[1], "-m") == 0) { + rv = nsComponentManager::CreateInstance(kMemCacheCID, nsnull, + NS_GET_IID(nsINetDataCache), + getter_AddRefs(cache)); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create memory cache factory"); + } else if (PL_strcasecmp(argv[1], "-f") == 0) { + // initialize pref + initPref() ; + rv = nsComponentManager::CreateInstance(kDiskCacheCID, nsnull, + NS_GET_IID(nsINetDataCache), + getter_AddRefs(cache)); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create disk cache factory") ; + } else { + printf(" %s -f to test filecache\n", argv[0]) ; + printf(" %s -m to test memcache\n", argv[0]) ; + return -1 ; + } - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + InitQueue(); - if (PL_strcasecmp(argv[1], "-m") == 0) { - rv = nsComponentManager::CreateInstance(kMemCacheCID, nsnull, - NS_GET_IID(nsINetDataCache), - getter_AddRefs(cache)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create memory cache factory"); - } else if (PL_strcasecmp(argv[1], "-f") == 0) { - // initialize pref - initPref() ; + PRUnichar* description; + rv = cache->GetDescription(&description); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get cache description"); + nsCAutoString descStr; descStr.AssignWithConversion(description); + printf("Testing: %s\n", descStr.get()); - rv = nsComponentManager::CreateInstance(kDiskCacheCID, nsnull, - NS_GET_IID(nsINetDataCache), - getter_AddRefs(cache)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create disk cache factory") ; + rv = cache->RemoveAll(); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't clear cache"); - } else { - printf(" %s -f to test filecache\n", argv[0]) ; - printf(" %s -m to test memcache\n", argv[0]) ; - return -1 ; - } + PRUint32 startOccupancy; + rv = cache->GetStorageInUse(&startOccupancy); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get cache occupancy"); - InitQueue(); + PRUint32 numEntries = (PRUint32)-1; + rv = cache->GetNumEntries(&numEntries); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get number of cache entries"); + NS_ASSERTION(numEntries == 0, "Couldn't clear cache"); - PRUnichar* description; - rv = cache->GetDescription(&description); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get cache description"); - nsCAutoString descStr; descStr.AssignWithConversion(description); - printf("Testing: %s\n", descStr.get()); + rv = FillCache(cache); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't fill cache with random test data"); - rv = cache->RemoveAll(); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't clear cache"); + rv = TestRead(cache); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't read random test data from cache"); - PRUint32 startOccupancy; - rv = cache->GetStorageInUse(&startOccupancy); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get cache occupancy"); + rv = TestRecordID(cache); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't index records using record ID"); - PRUint32 numEntries = (PRUint32)-1; - rv = cache->GetNumEntries(&numEntries); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get number of cache entries"); - NS_ASSERTION(numEntries == 0, "Couldn't clear cache"); + rv = TestEnumeration(cache); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't successfully enumerate records"); - rv = FillCache(cache); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't fill cache with random test data"); + rv = TestTruncation(cache); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't successfully truncate records"); - rv = TestRead(cache); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't read random test data from cache"); + rv = TestOffsetWrites(cache); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't successfully write to records using non-zero offsets"); - rv = TestRecordID(cache); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't index records using record ID"); + rv = cache->RemoveAll(); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't clear cache"); + rv = cache->GetNumEntries(&numEntries); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get number of cache entries"); + NS_ASSERTION(numEntries == 0, "Couldn't clear cache"); - rv = TestEnumeration(cache); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't successfully enumerate records"); + PRUint32 endOccupancy; + rv = cache->GetStorageInUse(&endOccupancy); - rv = TestTruncation(cache); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't successfully truncate records"); - - rv = TestOffsetWrites(cache); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't successfully write to records using non-zero offsets"); - - rv = cache->RemoveAll(); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't clear cache"); - rv = cache->GetNumEntries(&numEntries); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get number of cache entries"); - NS_ASSERTION(numEntries == 0, "Couldn't clear cache"); - - PRUint32 endOccupancy; - rv = cache->GetStorageInUse(&endOccupancy); - - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get cache occupancy"); - - NS_ASSERTION(startOccupancy == endOccupancy, "Cache occupancy not correctly computed ?"); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't get cache occupancy"); + NS_ASSERTION(startOccupancy == endOccupancy, "Cache occupancy not correctly computed ?"); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/netwerk/test/TestRes.cpp b/mozilla/netwerk/test/TestRes.cpp index 85642f22066..646f54698e2 100644 --- a/mozilla/netwerk/test/TestRes.cpp +++ b/mozilla/netwerk/test/TestRes.cpp @@ -105,7 +105,7 @@ TestOpenInputStream(const char* url) rv = in->Read(buf, sizeof(buf), &amt); if (NS_FAILED(rv)) return rv; if (amt == 0) break; // eof - + char* str = buf; while (amt-- > 0) { fputc(*str++, stdout); @@ -148,7 +148,7 @@ public: nsresult rv; nsCOMPtr uri; nsCOMPtr channel = do_QueryInterface(request); - + rv = channel->GetURI(getter_AddRefs(uri)); if (NS_SUCCEEDED(rv)) { char* str; @@ -160,13 +160,13 @@ public: } return NS_OK; } - + NS_IMETHOD OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult aStatus) { nsresult rv; nsCOMPtr uri; nsCOMPtr channel = do_QueryInterface(request); - + rv = channel->GetURI(getter_AddRefs(uri)); if (NS_SUCCEEDED(rv)) { char* str; @@ -242,30 +242,34 @@ int main(int argc, char* argv[]) { nsresult rv; + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "AutoregisterComponents failed"); - NS_ASSERTION(NS_SUCCEEDED(rv), "AutoregisterComponents failed"); + if (argc < 2) { + printf("usage: %s resource://foo/\n", argv[0]); + return -1; + } - if (argc < 2) { - printf("usage: %s resource://foo/\n", argv[0]); - return -1; - } + rv = SetupMapping(); + NS_ASSERTION(NS_SUCCEEDED(rv), "SetupMapping failed"); + if (NS_FAILED(rv)) return rv; - rv = SetupMapping(); - NS_ASSERTION(NS_SUCCEEDED(rv), "SetupMapping failed"); - if (NS_FAILED(rv)) return rv; - - rv = TestOpenInputStream(argv[1]); - NS_ASSERTION(NS_SUCCEEDED(rv), "TestOpenInputStream failed"); - - rv = TestAsyncRead(argv[1]); - NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed"); + rv = TestOpenInputStream(argv[1]); + NS_ASSERTION(NS_SUCCEEDED(rv), "TestOpenInputStream failed"); + rv = TestAsyncRead(argv[1]); + NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed"); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return rv; } diff --git a/mozilla/netwerk/test/TestSocketInput.cpp b/mozilla/netwerk/test/TestSocketInput.cpp index 0ff78b202d5..1119125afbe 100644 --- a/mozilla/netwerk/test/TestSocketInput.cpp +++ b/mozilla/netwerk/test/TestSocketInput.cpp @@ -151,69 +151,71 @@ main(int argc, char* argv[]) //port = portString.ToInteger(&rv); port = 13; + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + // Create the Event Queue for this thread... + nsCOMPtr eventQService = + do_GetService(kEventQueueServiceCID, &rv); + if (NS_FAILED(rv)) return rv; - // Create the Event Queue for this thread... - nsCOMPtr eventQService = - do_GetService(kEventQueueServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + nsCOMPtr eventQ; + rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ)); + if (NS_FAILED(rv)) return rv; - nsCOMPtr eventQ; - rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr sts = + do_GetService(kSocketTransportServiceCID, &rv); + if (NS_FAILED(rv)) return rv; - nsCOMPtr sts = - do_GetService(kSocketTransportServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + nsITransport* transport; - nsITransport* transport; + rv = sts->CreateTransport(hostName, port, nsnull, 0, 0, &transport); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr request; + transport->AsyncRead(nsnull, new InputTestConsumer, 0, -1, 0, getter_AddRefs(request)); - rv = sts->CreateTransport(hostName, port, nsnull, 0, 0, &transport); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr request; - transport->AsyncRead(nsnull, new InputTestConsumer, 0, -1, 0, getter_AddRefs(request)); - - NS_RELEASE(transport); - } - - // Enter the message pump to allow the URL load to proceed. - while ( gKeepRunning ) { - -#ifdef WIN32 - MSG msg; - - if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); + NS_RELEASE(transport); } + + // Enter the message pump to allow the URL load to proceed. + while ( gKeepRunning ) { +#ifdef WIN32 + MSG msg; + + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } #else #ifdef XP_MAC - /* Mac stuff is missing here! */ - + /* Mac stuff is missing here! */ #else #ifdef XP_OS2 - QMSG qmsg; + QMSG qmsg; - if (WinGetMsg(0, &qmsg, 0, 0, 0)) - WinDispatchMsg(0, &qmsg); - else - gKeepRunning = FALSE; + if (WinGetMsg(0, &qmsg, 0, 0, 0)) + WinDispatchMsg(0, &qmsg); + else + gKeepRunning = FALSE; #else - PLEvent *gEvent; - rv = eventQ->GetEvent(&gEvent); - rv = eventQ->HandleEvent(gEvent); + PLEvent *gEvent; + rv = eventQ->GetEvent(&gEvent); + rv = eventQ->HandleEvent(gEvent); #endif #endif #endif - } - - sts->Shutdown(); + } + sts->Shutdown(); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/netwerk/test/TestSocketTransport.cpp b/mozilla/netwerk/test/TestSocketTransport.cpp index 9ece985f0c7..61b0eb07c7b 100644 --- a/mozilla/netwerk/test/TestSocketTransport.cpp +++ b/mozilla/netwerk/test/TestSocketTransport.cpp @@ -371,7 +371,7 @@ TestConnection::Run(void) nsresult rv = NS_OK; // Create the Event Queue for this thread... - nsCOMPtr eventQService = + nsCOMPtr eventQService = do_GetService(kEventQueueServiceCID, &rv); if (NS_FAILED(rv)) return rv; @@ -384,7 +384,7 @@ TestConnection::Run(void) if (NS_SUCCEEDED(rv)) { if (mIsAsync) { - + // // Initiate an async read... // @@ -587,11 +587,12 @@ main(int argc, char* argv[]) // Parse the command line args... // // ----- -/// if (argc < 3) { -/// printf("usage: %s [-sync|-silent] \n", argv[0]); -/// return -1; -/// } - +#if 0 + if (argc < 3) { + printf("usage: %s [-sync|-silent] \n", argv[0]); + return -1; + } +#endif PRBool bIsAsync = PR_TRUE; const char* hostName = nsnull; int i; @@ -626,46 +627,47 @@ main(int argc, char* argv[]) // Initialize XPCom... // // ----- + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); - - // Create the Event Queue for this thread... - nsCOMPtr eventQService = - do_GetService(kEventQueueServiceCID, &rv); - if (NS_FAILED(rv)) return rv; - - // - // Create the connections and threads... - // - for (i=0; i eventQService = + do_GetService(kEventQueueServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + // + // Create the connections and threads... + // + for (i=0; iInit(TimerCallback, nsnull, 1000); - } + // + // Start up the timer to test Suspend/Resume APIs on the transport... + // + gPeriodicTimer = do_CreateInstance("@mozilla.org/timer;1", &rv); + if (NS_SUCCEEDED(rv)) { + gPeriodicTimer->Init(TimerCallback, nsnull, 1000); + } #endif /* USE_TIMERS */ - - // Enter the message pump to allow the URL load to proceed. - Pump_PLEvents(eventQService); + // Enter the message pump to allow the URL load to proceed. + Pump_PLEvents(eventQService); - PRTime endTime; - endTime = PR_Now(); - -// printf("Elapsed time: %d\n", (PRInt32)(endTime/1000UL - gElapsedTime/1000UL)); + PRTime endTime; + endTime = PR_Now(); + // printf("Elapsed time: %d\n", (PRInt32)(endTime/1000UL - gElapsedTime/1000UL)); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/netwerk/test/TestThreadedIO.cpp b/mozilla/netwerk/test/TestThreadedIO.cpp index e286cbc9c5c..fdacb4b66b3 100644 --- a/mozilla/netwerk/test/TestThreadedIO.cpp +++ b/mozilla/netwerk/test/TestThreadedIO.cpp @@ -70,7 +70,7 @@ createEventQueue() { // Create channel for requested URL. static nsCOMPtr createChannel( const char *url ) { - nsCOMPtr result; + nsCOMPtr result; nsCOMPtr uri; printf( "Calling NS_NewURI for %s...\n", url ); @@ -261,12 +261,16 @@ main( int argc, char* argv[] ) { // Initialize XPCOM. printf( "Initializing XPCOM...\n" ); rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); - if ( NS_SUCCEEDED( rv ) ) { - printf( "...XPCOM initialized OK\n" ); - - // Create the Event Queue for this thread... - printf( "Creating event queue for main thread (0x%08X)...\n", - (int)(void*)PR_GetCurrentThread() ); + if ( NS_FAILED( rv ) ) { + printf( "%s %d: NS_InitXPCOM failed, rv=0x%08X\n", + (char*)__FILE__, (int)__LINE__, (int)rv ); + return rv; + } + printf( "...XPCOM initialized OK\n" ); + // Create the Event Queue for this thread... + printf( "Creating event queue for main thread (0x%08X)...\n", + (int)(void*)PR_GetCurrentThread() ); + { nsCOMPtr mainThreadQ = createEventQueue(); if ( mainThreadQ ) { @@ -300,16 +304,13 @@ main( int argc, char* argv[] ) { PR_JoinThread( thread[ joinThread ] ); } } - // Shut down XPCOM. - printf( "Shutting down XPCOM...\n" ); - NS_ShutdownXPCOM( 0 ); - printf( "...XPCOM shutdown complete\n" ); - } else { - printf( "%s %d: NS_InitXPCOM failed, rv=0x%08X\n", - (char*)__FILE__, (int)__LINE__, (int)rv ); - return rv; - } - + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + // Shut down XPCOM. + printf( "Shutting down XPCOM...\n" ); + NS_ShutdownXPCOM( 0 ); + printf( "...XPCOM shutdown complete\n" ); + // Exit. printf( "...test complete, rv=0x%08X\n", (int)rv ); return rv; diff --git a/mozilla/netwerk/test/TestUpload.cpp b/mozilla/netwerk/test/TestUpload.cpp index fa868a2fd4f..eda1f25a7c8 100644 --- a/mozilla/netwerk/test/TestUpload.cpp +++ b/mozilla/netwerk/test/TestUpload.cpp @@ -133,78 +133,80 @@ main(int argc, char* argv[]) char* uriSpec = argv[1]; char* fileName = argv[2]; + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + // Create the Event Queue for this thread... + nsCOMPtr eventQService = + do_GetService(kEventQueueServiceCID, &rv); + if (NS_FAILED(rv)) return rv; - // Create the Event Queue for this thread... - nsCOMPtr eventQService = - do_GetService(kEventQueueServiceCID, &rv); - if (NS_FAILED(rv)) return rv; + eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); - eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); + nsCOMPtr ioService(do_GetService(kIOServiceCID, &rv)); + // first thing to do is create ourselves a stream that + // is to be uploaded. + nsCOMPtr uploadStream; + rv = NS_NewPostDataStream(getter_AddRefs(uploadStream), + PR_TRUE, + nsDependentCString(fileName), // XXX UTF-8 + 0, ioService); + if (NS_FAILED(rv)) return rv; + // create our url. + nsCOMPtr uri; + rv = NS_NewURI(getter_AddRefs(uri), uriSpec); + if (NS_FAILED(rv)) return rv; - - nsCOMPtr ioService(do_GetService(kIOServiceCID, &rv)); - // first thing to do is create ourselves a stream that - // is to be uploaded. - nsCOMPtr uploadStream; - rv = NS_NewPostDataStream(getter_AddRefs(uploadStream), - PR_TRUE, - nsDependentCString(fileName), // XXX UTF-8 - 0, ioService); - if (NS_FAILED(rv)) return rv; - - // create our url. - nsCOMPtr uri; - rv = NS_NewURI(getter_AddRefs(uri), uriSpec); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr channel; - rv = ioService->NewChannelFromURI(uri, getter_AddRefs(channel)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr channel; + rv = ioService->NewChannelFromURI(uri, getter_AddRefs(channel)); + if (NS_FAILED(rv)) return rv; - // QI and set the upload stream - nsCOMPtr uploadChannel(do_QueryInterface(channel)); - uploadChannel->SetUploadStream(uploadStream, nsnull, -1); + // QI and set the upload stream + nsCOMPtr uploadChannel(do_QueryInterface(channel)); + uploadChannel->SetUploadStream(uploadStream, nsnull, -1); - // create a dummy listener - InputTestConsumer* listener; - - listener = new InputTestConsumer; - NS_IF_ADDREF(listener); - if (!listener) { - NS_ERROR("Failed to create a new stream listener!"); - return -1;; - } + // create a dummy listener + InputTestConsumer* listener; - channel->AsyncOpen(listener, nsnull); + listener = new InputTestConsumer; + if (!listener) { + NS_ERROR("Failed to create a new stream listener!"); + return -1;; + } + NS_ADDREF(listener); - while ( gKeepRunning ) { + channel->AsyncOpen(listener, nsnull); + + while ( gKeepRunning ) { #ifdef WIN32 - MSG msg; - - if (GetMessage(&msg, NULL, 0, 0)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } else { - gKeepRunning = 0; - } + MSG msg; + + if (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } else { + gKeepRunning = 0; + } #else #ifdef XP_MAC - /* Mac stuff is missing here! */ + /* Mac stuff is missing here! */ #else - PLEvent *gEvent; - rv = gEventQ->WaitForEvent(&gEvent); - rv = gEventQ->HandleEvent(gEvent); + PLEvent *gEvent; + rv = gEventQ->WaitForEvent(&gEvent); + rv = gEventQ->HandleEvent(gEvent); #endif /* XP_UNIX */ #endif /* !WIN32 */ - } - NS_ShutdownXPCOM(nsnull); + } + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/netwerk/test/TestWriteStream.cpp b/mozilla/netwerk/test/TestWriteStream.cpp index 6494e3fea42..77cbc279d5d 100644 --- a/mozilla/netwerk/test/TestWriteStream.cpp +++ b/mozilla/netwerk/test/TestWriteStream.cpp @@ -73,11 +73,11 @@ public: RandomStream(PRUint32 aSeed) { mStartSeed = mState = aSeed; } - + PRUint32 GetStartSeed() { return mStartSeed; } - + PRUint32 Next() { mState = 1103515245 * mState + 12345; return mState; @@ -107,7 +107,7 @@ public: } protected: - + PRUint32 mState; PRUint32 mStartSeed; }; @@ -124,11 +124,11 @@ TestSyncWrite(char* filename, PRUint32 startPosition, PRInt32 length) nsCOMPtr outStream ; RandomStream *randomStream; char buf[500]; - + nsCOMPtr fts = do_GetService(kFileTransportServiceCID, &rv) ; if (NS_FAILED(rv)) return rv ; - + nsCOMPtr fs; rv = NS_NewNativeLocalFile(nsDependentCString(filename), PR_FALSE, getter_AddRefs(fs)); if (NS_FAILED(rv)) return rv ; @@ -137,10 +137,10 @@ TestSyncWrite(char* filename, PRUint32 startPosition, PRInt32 length) rv = fts->CreateTransport(fs, PR_RDWR | PR_CREATE_FILE, 0664, PR_TRUE, getter_AddRefs(transport)) ; if (NS_FAILED(rv)) return rv ; - + rv = transport->OpenOutputStream(startPosition, -1, 0, getter_AddRefs(outStream)) ; if (NS_FAILED(rv)) return rv; - + PRIntervalTime startTime = PR_IntervalNow(); randomStream = new RandomStream(PL_HashString(filename)); @@ -154,7 +154,7 @@ TestSyncWrite(char* filename, PRUint32 startPosition, PRInt32 length) rv = outStream->Write(buf, amount, &numWritten); NS_ASSERTION(NS_SUCCEEDED(rv), " "); NS_ASSERTION(numWritten == (PRUint32)amount, "Write() bug?"); - + remaining -= amount; } outStream->Close(); @@ -192,7 +192,7 @@ TestSyncWrites(char* filenamePrefix, PRUint32 startPosition, PRInt32 length) return NS_OK; } - + //////////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) @@ -205,15 +205,20 @@ main(int argc, char* argv[]) } char* fileName = argv[1]; int length = atoi(argv[2]); + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); - - rv = TestSyncWrites(fileName, 0, length); - NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed"); + rv = TestSyncWrites(fileName, 0, length); + NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed"); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return NS_OK; } diff --git a/mozilla/netwerk/test/urltest.cpp b/mozilla/netwerk/test/urltest.cpp index 1a73a54cf87..33c3ea79a1e 100644 --- a/mozilla/netwerk/test/urltest.cpp +++ b/mozilla/netwerk/test/urltest.cpp @@ -244,7 +244,7 @@ nsresult makeAbsTest(const char* i_BaseURI, const char* relativePortion, { if (!i_BaseURI) return NS_ERROR_FAILURE; - + // build up the base URL nsCOMPtr baseURL; nsresult status = nsComponentManager::CreateInstance(kStdURLCID, nsnull, @@ -268,7 +268,7 @@ nsresult makeAbsTest(const char* i_BaseURI, const char* relativePortion, cout << "Analyzing " << temp.get() << endl; cout << "With " << relativePortion << endl; - + cout << "Got " << newURL.get() << endl; if (expectedResult) { cout << "Expect " << expectedResult << endl; @@ -420,69 +420,74 @@ int main(int argc, char **argv) printusage(); return NS_OK; } + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + // end of all messages from register components... + cout << "------------------" << endl << endl; - // end of all messages from register components... - cout << "------------------" << endl << endl; - - PRInt32 urlFactory = URL_FACTORY_DEFAULT; - PRBool bMakeAbs= PR_FALSE; - char* relativePath = 0; - char* url = 0; - for (int i=1; i= argc) + PRInt32 urlFactory = URL_FACTORY_DEFAULT; + PRBool bMakeAbs= PR_FALSE; + char* relativePath = 0; + char* url = 0; + for (int i=1; i= argc) + { + printusage(); + return NS_OK; + } } - } - else if (PL_strcasecmp(argv[i], "-abs") == 0) - { - if (!gFileIO) + else if (PL_strcasecmp(argv[i], "-abs") == 0) { - relativePath = argv[i+1]; + if (!gFileIO) + { + relativePath = argv[i+1]; + i++; + } + bMakeAbs = PR_TRUE; + } + else if (PL_strcasecmp(argv[i], "-file") == 0) + { + if (i+1 >= argc) + { + printusage(); + return NS_OK; + } + gFileIO = argv[i+1]; i++; } - bMakeAbs = PR_TRUE; - } - else if (PL_strcasecmp(argv[i], "-file") == 0) - { - if (i+1 >= argc) + else { - printusage(); - return NS_OK; + url = argv[i]; } - gFileIO = argv[i+1]; - i++; + } + PRTime startTime = PR_Now(); + if (bMakeAbs) + { + rv = (url && relativePath) + ? doMakeAbsTest(url, relativePath) + : doMakeAbsTest(); } else { - url = argv[i]; + rv = gFileIO ? testURL(0, urlFactory) : testURL(url, urlFactory); } - } - PRTime startTime = PR_Now(); - if (bMakeAbs) - { - rv = (url && relativePath) ? doMakeAbsTest(url, relativePath) : - doMakeAbsTest(); - } - else - { - rv = gFileIO ? testURL(0, urlFactory) : testURL(url, urlFactory); - } - if (gFileIO) - { - PRTime endTime = PR_Now(); - printf("Elapsed time: %d micros.\n", (PRInt32) - (endTime - startTime)); - } + if (gFileIO) + { + PRTime endTime = PR_Now(); + printf("Elapsed time: %d micros.\n", (PRInt32) + (endTime - startTime)); + } + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); return rv; } diff --git a/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp b/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp index 74781150a60..8c3a8788e5a 100644 --- a/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp +++ b/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp @@ -287,23 +287,30 @@ Usage: %s [-i intype] [-o outtype] [-f flags] [-w wrapcol] [-c comparison_file] exit(1); } } - else file = stdin; + else + file = stdin; + nsresult ret; + { + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); + // Read in the string: very inefficient, but who cares? + nsString inString; + int c; + while ((c = getc(file)) != EOF) + inString.Append(PRUnichar(c)); - // Read in the string: very inefficient, but who cares? - nsString inString; - int c; - while ((c = getc(file)) != EOF) - inString.Append(PRUnichar(c)); + if (file != stdin) + fclose(file); - if (file != stdin) - fclose(file); - - return HTML2text(inString, inType, outType, flags, wrapCol, compareAgainst); + ret = HTML2text(inString, inType, outType, flags, wrapCol, compareAgainst); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + nsresult rv = NS_ShutdownXPCOM( NULL ); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); + return ret; } diff --git a/mozilla/xpcom/tests/RegFactory.cpp b/mozilla/xpcom/tests/RegFactory.cpp index c2f6d9126a8..56a5623188e 100644 --- a/mozilla/xpcom/tests/RegFactory.cpp +++ b/mozilla/xpcom/tests/RegFactory.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -133,8 +133,9 @@ int ProcessArgs(nsIComponentRegistrar* register, int argc, char *argv[]) int main(int argc, char *argv[]) { - int ret = 0; - + int ret = 0; + nsresult rv; + { nsCOMPtr servMan; rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); if (NS_FAILED(rv)) return -1; @@ -149,6 +150,9 @@ int main(int argc, char *argv[]) } else ret = ProcessArgs(registrar, argc, argv); - - return ret; + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM( NULL ); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); + return ret; } diff --git a/mozilla/xpcom/tests/TestFactory.cpp b/mozilla/xpcom/tests/TestFactory.cpp index 5df2a449b0f..b64fa351c77 100644 --- a/mozilla/xpcom/tests/TestFactory.cpp +++ b/mozilla/xpcom/tests/TestFactory.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -115,46 +115,48 @@ nsresult TestFactory::CreateInstance(nsISupports *aDelegate, int main(int argc, char **argv) { nsresult rv; + { + nsCOMPtr servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + if (NS_FAILED(rv)) return -1; + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->RegisterFactory(kTestFactoryCID, + nsnull, + nsnull, + new TestFactory()); - nsCOMPtr servMan; - rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - if (NS_FAILED(rv)) return -1; - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + ITestClass *t = NULL; + nsComponentManager::CreateInstance(kTestFactoryCID, + NULL, + NS_GET_IID(ITestClass), + (void **) &t); - registrar->RegisterFactory(kTestFactoryCID, - nsnull, - nsnull, - new TestFactory()); + if (t != NULL) { + t->Test(); + t->Release(); + } else { + cout << "CreateInstance failed\n"; + } + t = NULL; - ITestClass *t = NULL; - nsComponentManager::CreateInstance(kTestFactoryCID, - NULL, - NS_GET_IID(ITestClass), - (void **) &t); - - if (t != NULL) { - t->Test(); - t->Release(); - } else { - cout << "CreateInstance failed\n"; - } - - t = NULL; - - nsComponentManager::CreateInstance(kTestLoadedFactoryCID, - NULL, - NS_GET_IID(ITestClass), - (void **) &t); - - if (t != NULL) { - t->Test(); - t->Release(); - } else { - cout << "Dynamic CreateInstance failed\n"; - } + nsComponentManager::CreateInstance(kTestLoadedFactoryCID, + NULL, + NS_GET_IID(ITestClass), + (void **) &t); + if (t != NULL) { + t->Test(); + t->Release(); + } else { + cout << "Dynamic CreateInstance failed\n"; + } + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/xpcom/tests/TestPipes.cpp b/mozilla/xpcom/tests/TestPipes.cpp index 83452ee674e..6834f48d9f2 100644 --- a/mozilla/xpcom/tests/TestPipes.cpp +++ b/mozilla/xpcom/tests/TestPipes.cpp @@ -654,6 +654,9 @@ main(int argc, char* argv[]) NS_ASSERTION(NS_SUCCEEDED(rv), "TestChainedPipes failed"); RunTests(16, 1); RunTests(4096, 16); + NS_RELEASE(servMgr); + rv = NS_ShutdownXPCOM( NULL ); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/xpcom/tests/nsIFileEnumerator.cpp b/mozilla/xpcom/tests/nsIFileEnumerator.cpp index afc2d32f094..88e9e446d61 100644 --- a/mozilla/xpcom/tests/nsIFileEnumerator.cpp +++ b/mozilla/xpcom/tests/nsIFileEnumerator.cpp @@ -59,33 +59,38 @@ int main(int argc, char* argv[]) { nsresult rv; - nsCOMPtr topDir; - - nsCOMPtr servMan; - rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); - if (NS_FAILED(rv)) return -1; - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nsnull); - - if (argc > 1 && argv[1] != nsnull) { - char* pathStr = argv[1]; - NS_NewNativeLocalFile(nsDependentCString(pathStr), PR_FALSE, getter_AddRefs(topDir)); - } - - if (!topDir) - { - printf("No Top Dir\n"); - return -1; - } - PRInt32 startTime = PR_IntervalNow(); - - LoopInDir(topDir); - - PRInt32 endTime = PR_IntervalNow(); - - printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime - startTime)); + nsCOMPtr topDir; + nsCOMPtr servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + if (NS_FAILED(rv)) return -1; + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); + + if (argc > 1 && argv[1] != nsnull) + { + char* pathStr = argv[1]; + NS_NewNativeLocalFile(nsDependentCString(pathStr), PR_FALSE, getter_AddRefs(topDir)); + } + + if (!topDir) + { + printf("No Top Dir\n"); + return -1; + } + PRInt32 startTime = PR_IntervalNow(); + + LoopInDir(topDir); + + PRInt32 endTime = PR_IntervalNow(); + + printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime - startTime)); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; } diff --git a/mozilla/xpcom/tools/registry/regExport.cpp b/mozilla/xpcom/tools/registry/regExport.cpp index 27465cdf831..2b32cae63d7 100644 --- a/mozilla/xpcom/tools/registry/regExport.cpp +++ b/mozilla/xpcom/tools/registry/regExport.cpp @@ -148,6 +148,7 @@ int main( int argc, char *argv[] ) { } NS_RELEASE(reg); } + NS_ShutdownXPCOM( servMgr ); return rv; } diff --git a/mozilla/xpcom/tools/registry/regxpcom.cpp b/mozilla/xpcom/tools/registry/regxpcom.cpp index 636ca84795e..288040e7f9c 100644 --- a/mozilla/xpcom/tools/registry/regxpcom.cpp +++ b/mozilla/xpcom/tools/registry/regxpcom.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -169,16 +169,17 @@ int ProcessArgs(nsIComponentRegistrar *registrar, int argc, char *argv[]) int main(int argc, char *argv[]) { - int ret; + int ret; + nsresult rv; #ifdef XP_MAC #if DEBUG - InitializeSIOUX(1); + InitializeSIOUX(1); #endif #endif - + { nsCOMPtr servMan; - nsresult rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); if (NS_FAILED(rv)) { printf("Can not initialize XPCOM\n"); @@ -198,7 +199,9 @@ int main(int argc, char *argv[]) { ret = ProcessArgs(registrar, argc, argv); } - - NS_ShutdownXPCOM(NULL); - return ret; + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); + return ret; }