1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is Mozilla.
16 * The Initial Developer of the Original Code is IBM Corporation.
17 * Portions created by IBM Corporation are Copyright (C) 2003
18 * IBM Corporation. All Rights Reserved.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #include "TestCommon.h"
39 #include "nsIServiceManager.h"
40 #include "nsServiceManagerUtils.h"
41 #include "nsIEventTarget.h"
46 #if defined(PR_LOGGING)
48 // set NSPR_LOG_MODULES=Test:5
50 static PRLogModuleInfo
*gTestLog
= nsnull
;
52 #define LOG(args) PR_LOG(gTestLog, PR_LOG_DEBUG, args)
54 class nsIOEvent
: public nsIRunnable
{
58 nsIOEvent(int i
) : mIndex(i
) {}
61 LOG(("Run [%d]\n", mIndex
));
68 NS_IMPL_THREADSAFE_ISUPPORTS1(nsIOEvent
, nsIRunnable
)
70 static nsresult
RunTest()
73 nsCOMPtr
<nsIEventTarget
> target
=
74 do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID
, &rv
);
78 for (int i
=0; i
<10; ++i
) {
79 nsCOMPtr
<nsIRunnable
> event
= new nsIOEvent(i
);
80 LOG(("Dispatch %d\n", i
));
81 target
->Dispatch(event
, NS_DISPATCH_NORMAL
);
87 int main(int argc
, char **argv
)
89 if (test_common_init(&argc
, &argv
) != 0)
94 #if defined(PR_LOGGING)
95 gTestLog
= PR_NewLogModule("Test");
98 rv
= NS_InitXPCOM2(nsnull
, nsnull
, nsnull
);
104 LOG(("RunTest failed [rv=%x]\n", rv
));
106 LOG(("sleeping main thread for 2 seconds...\n"));
107 PR_Sleep(PR_SecondsToInterval(2));
109 NS_ShutdownXPCOM(nsnull
);