summaryrefslogtreecommitdiffstats
path: root/ipc/ipdl/test/gtest/IPDLUnitTest.h
diff options
context:
space:
mode:
Diffstat (limited to 'ipc/ipdl/test/gtest/IPDLUnitTest.h')
-rw-r--r--ipc/ipdl/test/gtest/IPDLUnitTest.h97
1 files changed, 60 insertions, 37 deletions
diff --git a/ipc/ipdl/test/gtest/IPDLUnitTest.h b/ipc/ipdl/test/gtest/IPDLUnitTest.h
index f4548b508c..e2c44630b7 100644
--- a/ipc/ipdl/test/gtest/IPDLUnitTest.h
+++ b/ipc/ipdl/test/gtest/IPDLUnitTest.h
@@ -27,52 +27,75 @@ class IPDLTestHelper {
virtual void TestBody() = 0;
};
-#define IPDL_TEST_CLASS_NAME_(actorname) IPDL_TEST_##actorname
+#define IPDL_TEST_CLASS_NAME_(actorname, ...) IPDL_TEST_##actorname##__VA_ARGS__
-#define IPDL_TEST_HEAD_(actorname) \
- class IPDL_TEST_CLASS_NAME_(actorname) \
- : public ::mozilla::_ipdltest::IPDLTestHelper { \
- public: \
- IPDL_TEST_CLASS_NAME_(actorname)() : mActor(new actorname##Parent) {} \
- \
- private: \
- void TestBody() override; \
- const char* GetName() override { return sName; }; \
- actorname##Parent* GetActor() override { return mActor; }; \
- \
- RefPtr<actorname##Parent> mActor; \
- static const char* sName; \
- }; \
- const char* IPDL_TEST_CLASS_NAME_(actorname)::sName = \
- ::mozilla::_ipdltest::RegisterAllocChildActor( \
- #actorname, []() -> ::mozilla::ipc::IToplevelProtocol* { \
- return new actorname##Child; \
+#define IPDL_TEST_HEAD_(actorname, ...) \
+ class IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__) \
+ : public ::mozilla::_ipdltest::IPDLTestHelper { \
+ public: \
+ IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__) \
+ () : mActor(new actorname##Parent) {} \
+ \
+ private: \
+ void TestBody() override; \
+ const char* GetName() override { return sName; }; \
+ actorname##Parent* GetActor() override { return mActor; }; \
+ \
+ RefPtr<actorname##Parent> mActor; \
+ static const char* sName; \
+ }; \
+ const char* IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__)::sName = \
+ ::mozilla::_ipdltest::RegisterAllocChildActor( \
+ #actorname, []() -> ::mozilla::ipc::IToplevelProtocol* { \
+ return new actorname##Child; \
});
-#define IPDL_TEST_DECL_(testgroup, actorname, crossprocess) \
- TEST(testgroup, actorname) \
- { \
- IPDL_TEST_CLASS_NAME_(actorname) test; \
- test.TestWrapper(crossprocess); \
+#define IPDL_TEST_DECL_CROSSPROCESS_(actorname, ...) \
+ TEST(IPDLTest_CrossProcess, actorname##__VA_ARGS__) \
+ { \
+ IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__) test; \
+ test.TestWrapper(true); \
}
-#define IPDL_TEST_BODY_SEGUE_(actorname) \
- void IPDL_TEST_CLASS_NAME_(actorname)::TestBody()
+#define IPDL_TEST_DECL_CROSSTHREAD_(actorname, ...) \
+ TEST(IPDLTest_CrossThread, actorname##__VA_ARGS__) \
+ { \
+ IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__) test; \
+ test.TestWrapper(false); \
+ }
+
+#define IPDL_TEST_DECL_ANY_(actorname, ...) \
+ IPDL_TEST_DECL_CROSSPROCESS_(actorname, ##__VA_ARGS__) \
+ IPDL_TEST_DECL_CROSSTHREAD_(actorname, ##__VA_ARGS__)
+
+#define IPDL_TEST_BODY_SEGUE_(actorname, ...) \
+ void IPDL_TEST_CLASS_NAME_(actorname, ##__VA_ARGS__)::TestBody()
-// Declare a basic IPDL unit test which will be run in both both cross-thread
-// and cross-process configurations. The actor `actorname` will be instantiated
-// by default-constructing the parent & child actors in the relevant processes,
-// and the test block will be executed, with `mActor` being a pointer to the
-// parent actor. The test is asynchronous, and will end when the IPDL connection
-// between the created actors is destroyed.
+// Declare an IPDL unit test. The `mode` should be set to either `CROSSTHREAD`,
+// `CROSSPROCESS`, or `ANY` to run in the selected configuration(s). The actor
+// `actorname` will be instantiated by default-constructing the parent & child
+// actors in the relevant processes, and the test block will be executed, with
+// `mActor` being a pointer to the parent actor. The test is asynchronous, and
+// will end when the IPDL connection between the created actors is destroyed.
+// `aCrossProcess` will indicate whether the test is running cross-process
+// (true) or cross-thread (false).
+//
+// You can optionally pass a single additional argument which provides a
+// `testname`, which will be appended to `actorname` as the full GTest test
+// name. It should be of the form usually passed to the `TEST` gtest macro (an
+// identifier).
//
// GTest assertions fired in the child process will be relayed to the parent
// process, and should generally function correctly.
-#define IPDL_TEST(actorname) \
- IPDL_TEST_HEAD_(actorname) \
- IPDL_TEST_DECL_(IPDLTest_CrossProcess, actorname, true) \
- IPDL_TEST_DECL_(IPDLTest_CrossThread, actorname, false) \
- IPDL_TEST_BODY_SEGUE_(actorname)
+#define IPDL_TEST_ON(mode, actorname, ...) \
+ IPDL_TEST_HEAD_(actorname, ##__VA_ARGS__) \
+ IPDL_TEST_DECL_##mode##_(actorname, ##__VA_ARGS__) \
+ IPDL_TEST_BODY_SEGUE_(actorname, ##__VA_ARGS__)
+
+// Declare an IPDL unit test that will run in both cross-thread and
+// cross-process configurations. See the documentation of IPDL_TEST_ON for more
+// info.
+#define IPDL_TEST(actorname, ...) IPDL_TEST_ON(ANY, actorname, ##__VA_ARGS__)
} // namespace mozilla::_ipdltest