1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "TestCommon.h"
7 #include "nsIServiceManager.h"
8 #include "nsServiceManagerUtils.h"
9 #include "nsIEventTarget.h"
14 #if defined(PR_LOGGING)
16 // set NSPR_LOG_MODULES=Test:5
18 static PRLogModuleInfo
*gTestLog
= nullptr;
20 #define LOG(args) PR_LOG(gTestLog, PR_LOG_DEBUG, args)
22 class nsIOEvent
: public nsIRunnable
{
24 NS_DECL_THREADSAFE_ISUPPORTS
26 nsIOEvent(int i
) : mIndex(i
) {}
29 LOG(("Run [%d]\n", mIndex
));
36 NS_IMPL_ISUPPORTS(nsIOEvent
, nsIRunnable
)
38 static nsresult
RunTest()
41 nsCOMPtr
<nsIEventTarget
> target
=
42 do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID
, &rv
);
46 for (int i
=0; i
<10; ++i
) {
47 nsCOMPtr
<nsIRunnable
> event
= new nsIOEvent(i
);
48 LOG(("Dispatch %d\n", i
));
49 target
->Dispatch(event
, NS_DISPATCH_NORMAL
);
55 int main(int argc
, char **argv
)
57 if (test_common_init(&argc
, &argv
) != 0)
62 #if defined(PR_LOGGING)
63 gTestLog
= PR_NewLogModule("Test");
66 rv
= NS_InitXPCOM2(nullptr, nullptr, nullptr);
72 LOG(("RunTest failed [rv=%x]\n", rv
));
74 LOG(("sleeping main thread for 2 seconds...\n"));
75 PR_Sleep(PR_SecondsToInterval(2));
77 NS_ShutdownXPCOM(nullptr);