-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add support for gtest if testing is enabled. #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c35b27d
2befa51
48f6bc8
405426a
cd1255a
12f9519
4198148
0d56bb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Add unit tests for TQObject as an example for further reference.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1078,6 +1078,22 @@ function(ROOT_ADD_TEST test) | |
|
|
||
| endfunction() | ||
|
|
||
| #---------------------------------------------------------------------------- | ||
| # function ROOT_ADD_GTEST(<testsuite> <name> LIBRARIES) | ||
| # | ||
| function(ROOT_ADD_GTEST test_suite test_name) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In roottest, I found the following parameters useful: Also, I just glob the test sources: Just drop a source file into test/ and it's part of the unit test.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that could be done when we start adding tests and need it. I don't like globbing because it causes quite a few issues if the source folder is unclean, etc. In general, it would be much more often editing tests rather than adding new ones.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would request that we do this from day 0. Else it'll be a mess, with people adding their files by hand, until you find the time to do it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. I don't see it that dramatic, I will clean up all eventual mess if there is any.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The team converged on globbing. |
||
| CMAKE_PARSE_ARGUMENTS(ARG "" "" "LIBRARIES" ${ARGN}) | ||
|
|
||
| include_directories(${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add the source directory to the include dirs, or does that happen by default? (I want to be able to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ping?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
|
||
| # Note we cannot use ROOT_EXECUTABLE because it requires to pass LIBRARIES to link with. | ||
| # The test suites should chose this in their specific CMakeLists.txt file. | ||
| ROOT_EXECUTABLE(${test_suite} ${test_name} LIBRARIES ${ARG_LIBRARIES}) | ||
|
||
| target_link_libraries(${test_suite} gtest gtest_main gmock gmock_main) | ||
| ROOT_ADD_TEST(gtest-${test_suite} COMMAND ${test_suite}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is missing some environment: is what I pass to ROOT_ADD_TEST in roottest/cmake/modules/RootCTestMacros.cmake's
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I am missing context but it seems this is out of the scope of this PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed for runing the tests without setting thisroot.sh before. I.e. no, AFAIK this is a prerequisite.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ping?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, this was resolved internally. There was something to check, outside of this PR. |
||
| endfunction() | ||
|
|
||
|
|
||
| #---------------------------------------------------------------------------- | ||
| # ROOT_ADD_TEST_SUBDIRECTORY( <name> ) | ||
| #---------------------------------------------------------------------------- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,10 @@ add_subdirectory(thread) | |
| add_subdirectory(zip) | ||
| add_subdirectory(lzma) | ||
|
|
||
| if(testing) | ||
| ROOT_ADD_TEST_SUBDIRECTORY(test) | ||
|
||
| endif() | ||
|
|
||
| if(NOT WIN32) | ||
| add_subdirectory(newdelete) | ||
| endif() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ############################################################################ | ||
| # CMakeLists.txt file for testing ROOT (global) core package | ||
| ############################################################################ | ||
|
|
||
| add_subdirectory(base) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| set (link_libs Core) | ||
|
|
||
| ROOT_ADD_GTEST(CoreBaseTests | ||
|
||
| TQObjectTests.cxx | ||
| LIBRARIES ${link_libs} | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #include "gtest/gtest.h" | ||
| #include "gmock/gmock.h" | ||
|
|
||
| #include "Rtypes.h" | ||
| #include "TQObject.h" | ||
| #include "TQConnection.h" | ||
|
|
||
| #include "RQ_OBJECT.h" | ||
|
|
||
| // FIXME: We should think of a common place to put the mock objects. | ||
| class TQConnectionMock : public TQConnection { | ||
|
||
| public: | ||
| virtual ~TQConnectionMock() {} // gmock requires it for cleanup on shutdown. | ||
| MOCK_METHOD1(SetArg, void(Long_t param)); | ||
| MOCK_METHOD1(SetArg, void(ULong_t param)); | ||
| MOCK_METHOD1(SetArg, void(Float_t param)); | ||
| MOCK_METHOD1(SetArg, void(Double_t param)); | ||
| MOCK_METHOD1(SetArg, void(Long64_t param)); | ||
| MOCK_METHOD1(SetArg, void(ULong64_t param)); | ||
| MOCK_METHOD1(SetArg, void(const char *param)); | ||
| MOCK_METHOD2(SetArg, void(const Long_t *params, Int_t nparam /* = -1*/)); | ||
|
|
||
| MOCK_METHOD0(SendSignal, void()); | ||
|
|
||
| // MOCK_METHOD1(SendSignal, void()); | ||
| }; | ||
|
|
||
| #define Stringify(s) Stringifyx(s) | ||
| #define Stringifyx(s) #s | ||
|
|
||
| #define DICT_CLASS \ | ||
| class RQ_OBJECTTester : public TQObject { \ | ||
| /* This will expand, adding signal/slot support to this class */ \ | ||
| RQ_OBJECT("RQ_OBJECTTester"); \ | ||
| Int_t fValue = 0; \ | ||
| \ | ||
| public: \ | ||
| void SetValue(Int_t value) \ | ||
| { \ | ||
| /* to prevent infinite looping in the case of cyclic connections */ \ | ||
| if (value != fValue) { \ | ||
| fValue = value; \ | ||
| Emit("SetValue(Int_t)", fValue); \ | ||
| } \ | ||
| } \ | ||
| void PrintValue() const { printf("value=%d\n", fValue); } \ | ||
| Int_t GetValue() const { return fValue; } \ | ||
| }; | ||
|
|
||
| DICT_CLASS; | ||
|
|
||
| TEST(TQObject, Emit) | ||
| { | ||
| gInterpreter->ProcessLine(Stringify(DICT_CLASS)); | ||
| RQ_OBJECTTester a; | ||
| RQ_OBJECTTester b; | ||
| a.Connect("SetValue(Int_t)", "RQ_OBJECTTester", &b, "SetValue(Int_t)"); | ||
|
|
||
| EXPECT_EQ(0, b.GetValue()); | ||
|
|
||
| a.SetValue(1); | ||
| EXPECT_EQ(1, b.GetValue()); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
test_nameTQObjectTests.cxxin the example below? If so, can you rename this tosourcethen? And can we have multiple sources?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the name of the Binary (i.e. test suite). Yeah we can have multiple files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I specify multiple sources? Can you add this to the doc of the CMake function? (I don't see how binary name and source files map to
<testsuite>and<name>).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.