nsresult init() { nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); if (NS_FAILED(rv)) return rv; return CallGetService(kCharsetConverterManagerCID, &ccMan); }
int main(int argc, char* argv[]) { nsresult rv; { nsCOMPtr<nsIFile> topDir; nsCOMPtr<nsIServiceManager> servMan; rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); if (NS_FAILED(rv)) return -1; if (argc > 1 && argv[1] != nsnull) { char* pathStr = argv[1]; NS_NewNativeLocalFile(nsDependentCString(pathStr), 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; }
int main(int argc, char* argv[]) { nsresult rv; { nsCOMPtr<nsIServiceManager> servMan; NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); if (registrar) registrar->AutoRegister(nullptr); NS_ASSERTION(NS_SUCCEEDED(rv), "AutoregisterComponents failed"); if (argc < 2) { printf("usage: %s resource://foo/<path-to-resolve>\n", argv[0]); return -1; } 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"); } // this scopes the nsCOMPtrs // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM rv = NS_ShutdownXPCOM(nullptr); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return rv; }
int main(int argc, char** argv) { NS_InitXPCOM2(nsnull, nsnull, nsnull); // -------------------------------------------- printf("Test Line Break\n"); PRBool lbok ; PRBool wbok ; lbok =TestWordBreaker(); if(lbok) printf("Line Break Test\nOK\n"); else printf("Line Break Test\nFailed\n"); wbok = TestLineBreaker(); if(wbok) printf("Word Break Test\nOK\n"); else printf("Word Break Test\nFailed\n"); SampleWordBreakUsage(); // -------------------------------------------- printf("Finish All The Test Cases\n"); if(lbok && wbok) printf("Line/Word Break Test\nOK\n"); else printf("Line/Word Break Test\nFailed\n"); return 0; }
int main(int argc, char **argv) { if (PR_GetEnv("MOZ_BREAK_ON_MAIN")) NS_BREAK(); if (argc < 5) { fprintf(stderr, "USAGE: TestIncrementalDownload <url> <file> <chunksize> <interval-in-seconds>\n"); return -1; } nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); if (NS_FAILED(rv)) return -1; int32_t chunkSize = atoi(argv[3]); int32_t interval = atoi(argv[4]); rv = DoIncrementalFetch(argv[1], argv[2], chunkSize, interval); if (NS_FAILED(rv)) fprintf(stderr, "ERROR: DoIncrementalFetch failed [%x]\n", static_cast<uint32_t>(rv)); NS_ShutdownXPCOM(nullptr); return 0; }
int main(int argc, char** argv) { if (argc <= 1) { puts("nrun <contractid>"); return EXIT_FAILURE; } const char* contract_id = argv[1]; // initialize XPCOM nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); if (NS_FAILED(rv)) { printf("XPCOM initialization failed: [%x]\n", rv); return EXIT_FAILURE; } // check for new components nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, nsnull); // run the application run(contract_id); // shut down and go home NS_ShutdownXPCOM(nsnull); return EXIT_SUCCESS; }
//---------------------------------------------------------------------- int main(int argc, char **argv) { /* I need this to free shared memory in case of a crash */ signal(SIGTERM, abnormal_exit_handler); signal(SIGQUIT, abnormal_exit_handler); signal(SIGINT, abnormal_exit_handler); signal(SIGHUP, abnormal_exit_handler); signal(SIGSEGV, abnormal_exit_handler); signal(SIGILL, abnormal_exit_handler); signal(SIGABRT, abnormal_exit_handler); // Initialize XPCOM nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed"); if (NS_SUCCEEDED(rv)) { // The toolkit service in mozilla will look in the environment // to determine which toolkit to use. Yes, it is a dumb hack to // force it here, but we have no choice because of toolkit specific // code linked into the viewer. putenv("MOZ_TOOLKIT=photon"); gTheApp = new nsNativeViewerApp(); gTheApp->Initialize(argc, argv); gTheApp->Run(); delete gTheApp; // Shutdown XPCOM rv = NS_ShutdownXPCOM(nsnull); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); } return 0; }
int main(int argc, char* argv[]) { { NS_InitXPCOM2(nullptr, nullptr, nullptr); nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (!prefs) { return -1; } // When NSS initializes, it attempts to get some localized strings. // As a result, OS X and Windows flip out if this isn't set. // (This isn't done automatically since this test doesn't have a // lot of the other boilerplate components that would otherwise // keep the certificate db alive longer than we want it to.) nsresult rv = prefs->SetBoolPref("intl.locale.matchOS", true); if (NS_FAILED(rv)) { return -1; } nsCOMPtr<nsIX509CertDB> certdb(do_GetService(NS_X509CERTDB_CONTRACTID)); if (!certdb) { return -1; } } // this scopes the nsCOMPtrs // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM NS_ShutdownXPCOM(nullptr); return 0; }
int main(int argc, char** argv) { if (argc < 2) { fprintf(stderr, "%s [FILE]...\n", argv[0]); } nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); if (NS_FAILED(rv)) return (int)rv; int res = 0; for (int i = 1; i < argc; ++i) { const char *filename = argv[i]; printf("\nParsing %s.\n", filename); nsCOMPtr<nsIURI> uri = FileToURI(filename, &rv); if (rv == NS_ERROR_OUT_OF_MEMORY) { fprintf(stderr, "Out of memory.\n"); return 1; } if (uri) res = ParseCSSFile(uri); } NS_ShutdownXPCOM(nullptr); return res; }
int main(int argc, char** argv) { nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); if (NS_FAILED(rv)) { printf("NS_InitXPCOM2 failed\n"); return 1; } // -------------------------------------------- TestCaseConversion(); // -------------------------------------------- FuzzCaseConversion(); // -------------------------------------------- TestEntityConversion(nsIEntityConverter::html40); // -------------------------------------------- TestSaveAsCharset(); // -------------------------------------------- TestNormalization(); // -------------------------------------------- printf("Finish All The Test Cases\n"); return 0; }
int main(int argc, char* argv[]) { nsresult rv = NS_OK; // Start up XPCOM rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); if (NS_FAILED(rv)) return rv; /** * Create event queue for this thread */ nsCOMPtr<nsIEventQueueService> eventQService = do_GetService(kEventQueueServiceCID, &rv); if (NS_FAILED(rv)) goto error_exit; eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(gEventQ)); /** * Test Cache */ TestMemoryObjectCache(); error_exit: gEventQ = nsnull; eventQService = nsnull; NS_ShutdownXPCOM(nsnull); printf("XPCOM shut down.\n\n"); return rv; }
int main(int argc, char *argv[]) { int ret = 0; nsresult rv; { nsCOMPtr<nsIServiceManager> servMan; rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); if (NS_FAILED(rv)) return -1; nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); /* With no arguments, RegFactory will autoregister */ if (argc <= 1) { rv = registrar->AutoRegister(nsnull); ret = (NS_FAILED(rv)) ? -1 : 0; } else ret = ProcessArgs(registrar, argc, argv); } // 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; }
int main(int argc, char **argv) { if (test_common_init(&argc, &argv) != 0) return -1; nsresult rv; #if defined(PR_LOGGING) gTestLog = PR_NewLogModule("Test"); #endif rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); if (NS_FAILED(rv)) return rv; rv = RunTest(); if (NS_FAILED(rv)) LOG(("RunTest failed [rv=%x]\n", rv)); LOG(("sleeping main thread for 2 seconds...\n")); PR_Sleep(PR_SecondsToInterval(2)); NS_ShutdownXPCOM(nullptr); return 0; }
void main(int argc, char* argv[]) { nsresult rv; nsIServiceManager* servMgr; rv = NS_InitXPCOM2(&servMgr, NULL, NULL); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed"); // try loading a component and releasing it to see if it leaks if (argc > 1 && argv[1] != nsnull) { char* cidStr = argv[1]; nsISupports* obj = nsnull; if (cidStr[0] == '{') { nsCID cid; cid.Parse(cidStr); rv = CallCreateInstance(cid, &obj); } else { // contractID case: rv = CallCreateInstance(cidStr, &obj); } if (NS_SUCCEEDED(rv)) { printf("Successfully created %s\n", cidStr); NS_RELEASE(obj); } else { printf("Failed to create %s (%x)\n", cidStr, rv); } } rv = NS_ShutdownXPCOM(servMgr); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); }
int main(int argc, char** argv) { nsresult rv; if (argc < 2) { fprintf(stderr, "usage: %s <url> [<poll-interval>]\n", argv[0]); return 1; } rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); if (NS_FAILED(rv)) { fprintf(stderr, "NS_InitXPCOM2 failed\n"); return 1; } // Create a stream data source and initialize it on argv[1], which // is hopefully a "file:" URL. (Actually, we can do _any_ kind of // URL, but only a "file:" URL will be written back to disk.) nsCOMPtr<nsIRDFDataSource> ds = do_CreateInstance(kRDFXMLDataSourceCID, &rv); if (NS_FAILED(rv)) { NS_ERROR("unable to create RDF/XML data source"); return rv; } nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(ds); if (! remote) return NS_ERROR_UNEXPECTED; rv = remote->Init(argv[1]); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to initialize data source"); if (NS_FAILED(rv)) return rv; // The do_QI() on the pointer is a hack to make sure that the new // object gets AddRef()-ed. nsCOMPtr<nsIRDFObserver> observer = do_QueryInterface(new Observer); if (! observer) return NS_ERROR_OUT_OF_MEMORY; rv = ds->AddObserver(observer); if (NS_FAILED(rv)) return rv; while (1) { // Okay, this should load the XML file... rv = remote->Refresh(PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to open datasource"); if (NS_FAILED(rv)) return rv; if (argc <= 2) break; PRInt32 pollinterval = atol(argv[2]); if (! pollinterval) break; PR_Sleep(PR_SecondsToInterval(pollinterval)); } return NS_OK; }
nsresult InitXPCOM_Impl(JNIEnv* env, jobject aMozBinDirectory, jobject aAppFileLocProvider, jobject* aResult) { nsresult rv; // create an nsILocalFile from given java.io.File nsCOMPtr<nsIFile> directory; if (aMozBinDirectory) { rv = File_to_nsILocalFile(env, aMozBinDirectory, getter_AddRefs(directory)); NS_ENSURE_SUCCESS(rv, rv); } // create nsAppFileLocProviderProxy from given Java object nsCOMPtr<nsIDirectoryServiceProvider> provider; if (aAppFileLocProvider) { rv = NS_NewAppFileLocProviderProxy(aAppFileLocProvider, getter_AddRefs(provider)); NS_ENSURE_SUCCESS(rv, rv); } // init XPCOM nsCOMPtr<nsIServiceManager> servMan; rv = NS_InitXPCOM2(getter_AddRefs(servMan), directory, provider); NS_ENSURE_SUCCESS(rv, rv); // create Java proxy for service manager returned by NS_InitXPCOM2 return NativeInterfaceToJavaObject(env, servMan, NS_GET_IID(nsIServiceManager), nullptr, aResult); }
int main(int argc, char **argv) { if (test_common_init(&argc, &argv) != 0) return -1; if (argc < 2) { printf("usage: %s <url>\n", argv[0]); return -1; } gTestLog = PR_NewLogModule("Test"); nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); if (NS_FAILED(rv)) return -1; { nsCOMPtr<nsIURI> uri; rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(argv[1])); if (NS_FAILED(rv)) return -1; nsCOMPtr<nsIScriptSecurityManager> secman = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, -1); nsCOMPtr<nsIPrincipal> systemPrincipal; rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal)); NS_ENSURE_SUCCESS(rv, -1); nsCOMPtr<nsIChannel> chan; rv = NS_NewChannel(getter_AddRefs(chan), uri, systemPrincipal, nsILoadInfo::SEC_NORMAL, nsIContentPolicy::TYPE_OTHER); if (NS_FAILED(rv)) return -1; nsCOMPtr<nsIStreamLoaderObserver> observer = new MyStreamLoaderObserver(); if (!observer) return -1; nsCOMPtr<nsIStreamLoader> loader; rv = NS_NewStreamLoader(getter_AddRefs(loader), observer); if (NS_FAILED(rv)) return -1; rv = chan->AsyncOpen(loader, nullptr); if (NS_FAILED(rv)) return -1; PumpEvents(); } // this scopes the nsCOMPtrs // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM NS_ShutdownXPCOM(nullptr); return 0; }
int main(int argc, char **argv) { if (NS_FAILED(NS_InitXPCOM2(nullptr, nullptr, nullptr))) return -1; RunTests(); NS_ShutdownXPCOM(nullptr); return 0; }
int main(int argc, char **argv) { if (test_common_init(&argc, &argv) != 0) return -1; int sleepLen = 10; // default: 10 seconds if (argc == 1) { printf("usage: TestDNS [-N] hostname1 [hostname2 ...]\n"); return -1; } { nsCOMPtr<nsIServiceManager> servMan; NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); nsCOMPtr<nsPIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID); if (!dns) return -1; if (argv[1][0] == '-') { sleepLen = atoi(argv[1]+1); argv++; argc--; } for (int j=0; j<2; ++j) { for (int i=1; i<argc; ++i) { // assume non-ASCII input is given in the native charset nsAutoCString hostBuf; if (IsAscii(argv[i])) hostBuf.Assign(argv[i]); else hostBuf = NS_ConvertUTF16toUTF8(NS_ConvertASCIItoUTF16(argv[i])); nsCOMPtr<nsIDNSListener> listener = new myDNSListener(argv[i], i); nsCOMPtr<nsICancelable> req; nsresult rv = dns->AsyncResolve(hostBuf, nsIDNSService::RESOLVE_CANONICAL_NAME, listener, nullptr, getter_AddRefs(req)); if (NS_FAILED(rv)) printf("### AsyncResolve failed [rv=%x]\n", static_cast<uint32_t>(rv)); } printf("main thread sleeping for %d seconds...\n", sleepLen); PR_Sleep(PR_SecondsToInterval(sleepLen)); } printf("shutting down main thread...\n"); dns->Shutdown(); } NS_ShutdownXPCOM(nullptr); return 0; }
int main(int argc, char **argv) { nsresult rv; if (argc == 1) { printf("usage: TestHttp <url>\n"); return -1; } { nsCOMPtr<nsIServiceManager> servMan; NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); if (registrar) registrar->AutoRegister(nullptr); // Create the Event Queue for this thread... nsCOMPtr<nsIEventQueueService> eqs = do_GetService(kEventQueueServiceCID, &rv); RETURN_IF_FAILED(rv, "do_GetService(EventQueueService)"); rv = eqs->CreateMonitoredThreadEventQueue(); RETURN_IF_FAILED(rv, "CreateMonitoredThreadEventQueue"); rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); RETURN_IF_FAILED(rv, "GetThreadEventQueue"); nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIChannel> chan; nsCOMPtr<nsIStreamListener> listener = new MyListener(); nsCOMPtr<nsIInterfaceRequestor> callbacks = new MyNotifications(); rv = NS_NewURI(getter_AddRefs(uri), argv[1]); RETURN_IF_FAILED(rv, "NS_NewURI"); rv = NS_NewChannel(getter_AddRefs(chan), uri, nsContentUtils::GetSystemPrincipal(), nsILoadInfo::SEC_NORMAL, nsIContentPolicy::TYPE_OTHER); RETURN_IF_FAILED(rv, "NS_OpenURI"); rv = chan->AsyncOpen(listener, nullptr); RETURN_IF_FAILED(rv, "AsyncOpen"); while (gKeepRunning) gEventQ->ProcessPendingEvents(); printf(">>> done\n"); } // this scopes the nsCOMPtrs // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM rv = NS_ShutdownXPCOM(nullptr); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; }
extern "C" int StartXPCOM(nsIServiceManager** srvmgr) { nsresult res = NS_InitXPCOM2(srvmgr, 0, 0); if (NS_SUCCEEDED(res)) { extern nsIInterfaceInfoManager *infomgr; infomgr = XPTI_GetInterfaceInfoManager(); } return res; }
int main(int argc, char **argv) { if (test_common_init(&argc, &argv) != 0) return -1; if (argc < 2) { printf("usage: %s <url>\n", argv[0]); return -1; } #if defined(PR_LOGGING) gTestLog = PR_NewLogModule("Test"); #endif nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); if (NS_FAILED(rv)) return -1; { // Create the Event Queue for this thread... rv = NS_GetMainEventQ(&gEventQ); if (NS_FAILED(rv)) return -1; nsCOMPtr<nsIURI> uri; rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(argv[1])); if (NS_FAILED(rv)) return -1; nsCOMPtr<nsIChannel> chan; rv = NS_NewChannel(getter_AddRefs(chan), uri); if (NS_FAILED(rv)) return -1; nsCOMPtr<nsIStreamLoaderObserver> observer = new MyStreamLoaderObserver(); if (!observer) return -1; nsCOMPtr<nsIStreamLoader> loader; rv = NS_NewStreamLoader(getter_AddRefs(loader), chan, observer, nsnull); if (NS_FAILED(rv)) return -1; // Enter the message pump to allow the URL load to proceed. while (gKeepRunning) { PLEvent *e; gEventQ->WaitForEvent(&e); gEventQ->HandleEvent(e); } } // this scopes the nsCOMPtrs // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM NS_ShutdownXPCOM(nsnull); return rv; }
int main(int argc, char* argv[]) { if (test_common_init(&argc, &argv) != 0) return -1; nsresult rv; if (argc < 4) { printf("usage: %s <file-to-read> <start-offset> <read-length>\n", argv[0]); return -1; } char* fileName = argv[1]; int64_t offset, length; int err = PR_sscanf(argv[2], "%lld", &offset); if (err == -1) { printf("Start offset must be an integer!\n"); return 1; } err = PR_sscanf(argv[3], "%lld", &length); if (err == -1) { printf("Length must be an integer!\n"); return 1; } { nsCOMPtr<nsIServiceManager> servMan; NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); if (registrar) registrar->AutoRegister(nullptr); #if defined(PR_LOGGING) gTestLog = PR_NewLogModule("Test"); #endif nsCOMPtr<nsIFile> file; rv = NS_NewNativeLocalFile(nsDependentCString(fileName), false, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; rv = RunTest(file, offset, length); NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed"); // give background threads a chance to finish whatever work they may // be doing. PR_Sleep(PR_SecondsToInterval(1)); } // this scopes the nsCOMPtrs // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM rv = NS_ShutdownXPCOM(nullptr); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return NS_OK; }
int main(int argc, char** argv) { nsresult rv; if (argc < 2) { fprintf(stderr, "usage: %s <url>\n", argv[0]); return 1; } NS_InitXPCOM2(nullptr, nullptr, nullptr); // Create a stream data source and initialize it on argv[1], which // is hopefully a "file:" URL. nsCOMPtr<nsIRDFDataSource> ds = do_CreateInstance(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "xml-datasource", &rv); RETURN_IF_FAILED(rv, "RDF/XML datasource creation"); nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(ds, &rv); RETURN_IF_FAILED(rv, "QI to nsIRDFRemoteDataSource"); rv = remote->Init(argv[1]); RETURN_IF_FAILED(rv, "datasource initialization"); // Okay, this should load the XML file... rv = remote->Refresh(false); RETURN_IF_FAILED(rv, "datasource refresh"); // Pump events until the load is finished nsCOMPtr<nsIThread> thread = do_GetCurrentThread(); bool done = false; while (!done) { NS_ENSURE_TRUE(NS_ProcessNextEvent(thread), 1); remote->GetLoaded(&done); } nsCOMPtr<rdfIDataSource> rdfds = do_QueryInterface(ds, &rv); RETURN_IF_FAILED(rv, "QI to rdIDataSource"); { nsCOMPtr<nsIOutputStream> out = new ConsoleOutputStreamImpl(); nsCOMPtr<rdfISerializer> ser = do_CreateInstance(NS_RDF_SERIALIZER "ntriples", &rv); RETURN_IF_FAILED(rv, "Creation of NTriples Serializer"); rv = ser->Serialize(rdfds, out); RETURN_IF_FAILED(rv, "Serialization to NTriples"); out->Close(); } return 0; }
bool VirtualBoxBridge::initXPCOM() { nsresult rc; /* * This is the standard XPCOM init procedure. * What we do is just follow the required steps to get an instance * of our main interface, which is IVirtualBox. * * Note that we scope all nsCOMPtr variables in order to have all XPCOM * objects automatically released before we call NS_ShutdownXPCOM at the * end. This is an XPCOM requirement. */ rc = NS_InitXPCOM2(getter_AddRefs(nsCOM_serviceManager), nsnull, nsnull); if (NS_FAILED(rc)) { std::cerr << "Error: XPCOM could not be initialized! rc=0x" << std::hex << rc << std::dec << std::endl; return false; } /* * Make sure the main event queue is created. This event queue is * responsible for dispatching incoming XPCOM IPC messages. The main * thread should run this event queue's loop during lengthy non-XPCOM * operations to ensure messages from the VirtualBox server and other * XPCOM IPC clients are processed. This use case doesn't perform such * operations so it doesn't run the event loop. */ rc = NS_GetMainEventQ(getter_AddRefs(nsCOM_eventQ)); if (NS_FAILED(rc)) { std::cerr << "Error: could not get main event queue! rc=0x" << std::hex << rc << std::dec << std::endl; return false; } /* * Now XPCOM is ready and we can start to do real work. * All interfaces will be retrieved from the XPCOM component manager. * We use the XPCOM provided smart pointer nsCOMPtr for all objects * because that's very convenient and removes the need deal with * reference counting and freeing. */ rc = NS_GetComponentManager(getter_AddRefs(nsCOM_manager)); if (NS_FAILED(rc)) { std::cerr << "Error: could not get component manager! rc=0x" << std::hex << rc << std::dec << std::endl; return false; } return true; }
int main(int argc, char **argv) { LOG("entering main\n"); int numProcs = 10; // if this is a child process, then just run the test if (argc > 1) { if (strcmp(argv[1], "-child") == 0) { RandomSleep(1000, 1000); LOG("running child test\n"); NS_InitXPCOM2(nsnull, nsnull, nsnull); DoTest(); NS_ShutdownXPCOM(nsnull); return 0; } else if (argv[1][0] == '-') { // argument is a number numProcs = atoi(argv[1] + 1); if (numProcs == 0) { printf("### usage: TestIPCLocks [-N]\n" "where, N is the number of test processes to spawn.\n"); return -1; } } } LOG("sleeping for 1 second\n"); PR_Sleep(PR_SecondsToInterval(1)); PRProcess **procs = (PRProcess **) malloc(sizeof(PRProcess*) * numProcs); int i; // else, spawn the child processes for (i=0; i<numProcs; ++i) { char *const argv[] = {"./TestIPCLocks", "-child", nsnull}; LOG("spawning child test\n"); procs[i] = PR_CreateProcess("./TestIPCLocks", argv, nsnull, nsnull); } PRInt32 exitCode; for (i=0; i<numProcs; ++i) PR_WaitProcess(procs[i], &exitCode); return 0; }
int main(int argc, char** argv) { if (sizeof(wchar_t) != 2) { printf("This test can only be run where sizeof(wchar_t) == 2\n"); return 1; } if (strlen(versionText) == 0) { printf("No testcases: to run the tests generate the header file using\n"); printf(" perl genNormalizationData.pl\n"); printf("in intl/unichar/tools and rebuild\n"); return 1; } printf("NormalizationTest: test nsIUnicodeNormalizer. UCD version: %s\n", versionText); if (argc <= 1) verboseMode = false; else if ((argc == 2) && (!strcmp(argv[1], "-v"))) verboseMode = true; else { printf(" Usage: NormalizationTest [OPTION]..\n"); printf("Options:\n"); printf(" -v Verbose mode\n"); return 1; } nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); if (NS_FAILED(rv)) { printf("NS_InitXPCOM2 failed\n"); return 1; } normalizer = nullptr; nsresult res; res = CallGetService(kUnicodeNormalizerCID, &normalizer); if(NS_FAILED(res) || !normalizer) { printf("GetService failed\n"); return 1; } TestPart0(); TestPart1(); TestPart2(); TestPart3(); NS_RELEASE(normalizer); printf("Test finished \n"); return 0; }
int main (int argc, char ** argv) { txDriverProcessor driver; #ifdef MOZ_JPROF setupProfilingStuff(); #endif NS_InitXPCOM2(nsnull, nsnull, nsnull); if (!txDriverProcessor::init()) return 1; driver.main (argc, argv); txDriverProcessor::shutdown(); NS_ShutdownXPCOM(nsnull); return 0; }
int main(int argc, char** argv) { nsresult rv; if (argc < 2) { fprintf(stderr, "usage: %s <url>\n", argv[0]); return 1; } NS_InitXPCOM2(nsnull, nsnull, nsnull); // Create a stream data source and initialize it on argv[1], which // is hopefully a "file:" URL. nsCOMPtr<nsIRDFDataSource> ds = do_CreateInstance(kRDFXMLDataSourceCID, &rv); RETURN_IF_FAILED(rv, "RDF/XML datasource creation"); nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(ds, &rv); RETURN_IF_FAILED(rv, "QI to nsIRDFRemoteDataSource"); rv = remote->Init(argv[1]); RETURN_IF_FAILED(rv, "datasource initialization"); // Okay, this should load the XML file... rv = remote->Refresh(false); RETURN_IF_FAILED(rv, "datasource refresh"); // Pump events until the load is finished nsCOMPtr<nsIThread> thread = do_GetCurrentThread(); bool done = false; while (!done) { NS_ENSURE_STATE(NS_ProcessNextEvent(thread)); remote->GetLoaded(&done); } // And this should write it back out. The do_QI() on the pointer // is a hack to make sure that the new object gets AddRef()-ed. nsCOMPtr<nsIOutputStream> out = do_QueryInterface(new ConsoleOutputStreamImpl, &rv); RETURN_IF_FAILED(rv, "creation of console output stream"); nsCOMPtr<nsIRDFXMLSource> source = do_QueryInterface(ds); RETURN_IF_FAILED(rv, "QI to nsIRDFXMLSource"); rv = source->Serialize(out); RETURN_IF_FAILED(rv, "datasoure serialization"); return NS_OK; }
int main(int argc, char **argv) { #ifdef NS_TRACE_MALLOC argc = NS_TraceMallocStartupArgs(argc, argv); #endif #ifdef CRAWL_STACK_ON_SIGSEGV strcpy(_progname,argv[0]); signal(SIGSEGV, ah_crap_handler); signal(SIGILL, ah_crap_handler); signal(SIGABRT, ah_crap_handler); #endif // CRAWL_STACK_ON_SIGSEGV #ifdef MOZ_WIDGET_GTK gtk_set_locale(); #endif gtk_init(&argc, &argv); // Initialize XPCOM nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed"); if (NS_SUCCEEDED(rv)) { // The toolkit service in mozilla will look in the environment // to determine which toolkit to use. Yes, it is a dumb hack to // force it here, but we have no choice because of toolkit specific // code linked into the viewer. putenv("MOZ_TOOLKIT=gtk"); gTheApp = new nsNativeViewerApp(); gTheApp->Initialize(argc, argv); gTheApp->Run(); delete gTheApp; // Shutdown XPCOM rv = NS_ShutdownXPCOM(nsnull); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); // XXX This is disabled because sometimes it hangs waiting for a // netlib thread to exit, which isn't exiting :-(. Need more // shutdown logic in necko first. #if 0 // Shutdown NSPR PR_LogFlush(); PR_Cleanup(); #endif } return 0; }