1 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef mozilla__ipdltest_IPDLUnitTests_h
7 #define mozilla__ipdltest_IPDLUnitTests_h 1
8
9 #include "base/message_loop.h"
10 #include "base/process.h"
11 #include "chrome/common/ipc_channel.h"
12
13 #include "nsCOMPtr.h"
14 #include "nsDebug.h"
15 #include "nsServiceManagerUtils.h" // do_GetService()
16 #include "nsWidgetsCID.h" // NS_APPSHELL_CID
17 #include "nsXULAppAPI.h"
18
19 #define MOZ_IPDL_TESTFAIL_LABEL "TEST-UNEXPECTED-FAIL"
20 #define MOZ_IPDL_TESTPASS_LABEL "TEST-PASS"
21 #define MOZ_IPDL_TESTINFO_LABEL "TEST-INFO"
22
23 namespace mozilla {
24 namespace _ipdltest {
25
26 //-----------------------------------------------------------------------------
27 // both processes
28 const char* IPDLUnitTestName();
29
30 // NB: these are named like the similar functions in
31 // xpcom/test/TestHarness.h. The names should nominally be kept in
32 // sync.
33
fail(const char * fmt,...)34 inline void fail(const char* fmt, ...) {
35 va_list ap;
36
37 fprintf(stderr, MOZ_IPDL_TESTFAIL_LABEL " | %s | ", IPDLUnitTestName());
38
39 va_start(ap, fmt);
40 vfprintf(stderr, fmt, ap);
41 va_end(ap);
42
43 fputc('\n', stderr);
44
45 MOZ_CRASH("failed test");
46 }
47
passed(const char * fmt,...)48 inline void passed(const char* fmt, ...) {
49 va_list ap;
50
51 printf(MOZ_IPDL_TESTPASS_LABEL " | %s | ", IPDLUnitTestName());
52
53 va_start(ap, fmt);
54 vprintf(fmt, ap);
55 va_end(ap);
56
57 fputc('\n', stdout);
58 }
59
60 //-----------------------------------------------------------------------------
61 // parent process only
62
63 class IPDLUnitTestSubprocess;
64
65 extern void* gParentActor;
66 extern IPDLUnitTestSubprocess* gSubprocess;
67
68 void IPDLUnitTestMain(void* aData);
69
70 void QuitParent();
71
72 //-----------------------------------------------------------------------------
73 // child process only
74
75 extern void* gChildActor;
76
77 void IPDLUnitTestChildInit(IPC::Channel* transport, base::ProcessId parentPid,
78 MessageLoop* worker);
79
80 void QuitChild();
81
82 } // namespace _ipdltest
83 } // namespace mozilla
84
85 #endif // ifndef mozilla__ipdltest_IPDLUnitTests_h
86