michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "TestCommon.h" michael@0: #include "nsXPCOM.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "nsIEventTarget.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsNetCID.h" michael@0: #include "prlog.h" michael@0: michael@0: #if defined(PR_LOGGING) michael@0: // michael@0: // set NSPR_LOG_MODULES=Test:5 michael@0: // michael@0: static PRLogModuleInfo *gTestLog = nullptr; michael@0: #endif michael@0: #define LOG(args) PR_LOG(gTestLog, PR_LOG_DEBUG, args) michael@0: michael@0: class nsIOEvent : public nsIRunnable { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: michael@0: nsIOEvent(int i) : mIndex(i) {} michael@0: michael@0: NS_IMETHOD Run() { michael@0: LOG(("Run [%d]\n", mIndex)); michael@0: return NS_OK; michael@0: } michael@0: michael@0: private: michael@0: int mIndex; michael@0: }; michael@0: NS_IMPL_ISUPPORTS(nsIOEvent, nsIRunnable) michael@0: michael@0: static nsresult RunTest() michael@0: { michael@0: nsresult rv; michael@0: nsCOMPtr target = michael@0: do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: for (int i=0; i<10; ++i) { michael@0: nsCOMPtr event = new nsIOEvent(i); michael@0: LOG(("Dispatch %d\n", i)); michael@0: target->Dispatch(event, NS_DISPATCH_NORMAL); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: if (test_common_init(&argc, &argv) != 0) michael@0: return -1; michael@0: michael@0: nsresult rv; michael@0: michael@0: #if defined(PR_LOGGING) michael@0: gTestLog = PR_NewLogModule("Test"); michael@0: #endif michael@0: michael@0: rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: rv = RunTest(); michael@0: if (NS_FAILED(rv)) michael@0: LOG(("RunTest failed [rv=%x]\n", rv)); michael@0: michael@0: LOG(("sleeping main thread for 2 seconds...\n")); michael@0: PR_Sleep(PR_SecondsToInterval(2)); michael@0: michael@0: NS_ShutdownXPCOM(nullptr); michael@0: return 0; michael@0: }