From dc9f02682a15b16fcaf936c18f84620cb74bff58 Mon Sep 17 00:00:00 2001 From: Esteban Duran Date: Sun, 12 Sep 2021 11:37:05 -0500 Subject: [PATCH 1/2] docs: MathComponent References TestMain The existing MathComponent tutorial references a `main.cpp` test file that has been replaced by an autogenerated TestMain.cpp file. The docs have been updated to reference the TestMain file instead of the old manually created main.cpp file. --- .../test/ut/{main.cpp => TestMain.cpp} | 0 .../test/ut/{main.cpp => TestMain.cpp} | 0 docs/Tutorials/MathComponent/Tutorial.md | 19 +++++++++++++------ 3 files changed, 13 insertions(+), 6 deletions(-) rename docs/Tutorials/MathComponent/MathReceiver/test/ut/{main.cpp => TestMain.cpp} (100%) rename docs/Tutorials/MathComponent/MathSender/test/ut/{main.cpp => TestMain.cpp} (100%) diff --git a/docs/Tutorials/MathComponent/MathReceiver/test/ut/main.cpp b/docs/Tutorials/MathComponent/MathReceiver/test/ut/TestMain.cpp similarity index 100% rename from docs/Tutorials/MathComponent/MathReceiver/test/ut/main.cpp rename to docs/Tutorials/MathComponent/MathReceiver/test/ut/TestMain.cpp diff --git a/docs/Tutorials/MathComponent/MathSender/test/ut/main.cpp b/docs/Tutorials/MathComponent/MathSender/test/ut/TestMain.cpp similarity index 100% rename from docs/Tutorials/MathComponent/MathSender/test/ut/main.cpp rename to docs/Tutorials/MathComponent/MathSender/test/ut/TestMain.cpp diff --git a/docs/Tutorials/MathComponent/Tutorial.md b/docs/Tutorials/MathComponent/Tutorial.md index 9432be3203..6e9954cc52 100644 --- a/docs/Tutorials/MathComponent/Tutorial.md +++ b/docs/Tutorials/MathComponent/Tutorial.md @@ -1089,6 +1089,7 @@ TesterBase.hpp TesterBase.cpp GTestBase.hpp GTestBase.cpp +TestMain.cpp ``` The functions of the files are: @@ -1098,6 +1099,7 @@ The functions of the files are: |TesterBase.*|Base class for test class. Defines necessary handlers as well as helper functions |GTestBase.*|Helper class derived from TesterBase that has macros that use Google Test to test interfaces| |Tester.*|Derived tester class that inherits from GTestBase. Includes instance of the component and helpers to connect ports| +|TestMain.cpp|Main unit test implementation file| Unit tests are built in subdirectories of the module, so the unit test file must be copied there. The build system supports a standard subdirectory of `test/ut` below the module being tested. While in the MathSender directory, create the `test/ut` directory: @@ -1121,7 +1123,7 @@ set(SOURCE_FILES register_fprime_module() set(UT_SOURCE_FILES - "${CMAKE_CURRENT_LIST_DIR}/test/ut/main.cpp" + "${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp" "${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp" "${CMAKE_CURRENT_LIST_DIR}/test/ut/TesterBase.cpp" "${CMAKE_CURRENT_LIST_DIR}/test/ut/GTestBase.cpp" @@ -1135,7 +1137,8 @@ A `UT_MODS` variable may be set should the UT depend on modules not automaticall ##### 2.4.1.3.2 Test Code Implementation -The `main.cpp` file must be added. For this test, it appears like this: +The unit tests must be added to `TestMain.cpp`. Change the default code to appear +like this: ```c++ #include "Tester.hpp" @@ -1164,7 +1167,6 @@ int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } - ``` F' uses the Google Test framework to run unit tests. For more information about the Google Test Framework see here: @@ -1228,7 +1230,7 @@ The test component is instantiated here: NameSpace::Tester tester; ``` -This allows the component to start from an newly initialized state for each unit test. +This allows the component to start from a newly initialized state for each unit test. The unit test is executed by calling a member function of the `tester` class: @@ -1236,6 +1238,9 @@ The unit test is executed by calling a member function of the `tester` class: tester.someUnitTestFunc(); ``` +> NOTE: The autogenerated `Tester.*` files include a placeholder "toDo" function. Feel +free to leave that in or delete it. + The `Tester.hpp` stub can be updated to include the declarations of the unit test functions: ```c++ @@ -1245,6 +1250,9 @@ The `Tester.hpp` stub can be updated to include the declarations of the unit tes // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- + //! To do + //! + void toDo(void); //! Test operation command //! @@ -1275,7 +1283,7 @@ Add a member function to the implementation class in `Tester.cpp` to implement t this->sendCmd_MS_DO_MATH(0,10,1.0,2.0,MathSenderComponentBase::ADD); // retrieve the message from the message queue and dispatch the command to the handler this->component.doDispatch(); - // verify that that only one output port was called + // verify that only one output port was called ASSERT_FROM_PORT_HISTORY_SIZE(1); // verify that the math operation port was only called once ASSERT_from_mathOut_SIZE(1); @@ -1321,7 +1329,6 @@ Add a member function to the implementation class in `Tester.cpp` to implement t // verify the expected value of the event arguments ASSERT_EVENTS_MS_RESULT(0,10.0); } - ``` Some highlights are: From fdb2b25b4e7cacb0faaa5851b06a9e334e1cf872 Mon Sep 17 00:00:00 2001 From: M Starch Date: Thu, 16 Sep 2021 12:31:28 -0700 Subject: [PATCH 2/2] lestarch: updating docs to clarify *Base.* files being autocoded. --- docs/Tutorials/MathComponent/Tutorial.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/Tutorials/MathComponent/Tutorial.md b/docs/Tutorials/MathComponent/Tutorial.md index 6e9954cc52..94c0b176c2 100644 --- a/docs/Tutorials/MathComponent/Tutorial.md +++ b/docs/Tutorials/MathComponent/Tutorial.md @@ -1085,19 +1085,17 @@ The files that are generated are: ``` Tester.hpp Tester.cpp -TesterBase.hpp -TesterBase.cpp -GTestBase.hpp -GTestBase.cpp TestMain.cpp ``` +**Note:** TesterBase.* and GTestBase.* files can be removed. these will be regenerated when the unit test builds. + The functions of the files are: |File|Function| |---|---| -|TesterBase.*|Base class for test class. Defines necessary handlers as well as helper functions -|GTestBase.*|Helper class derived from TesterBase that has macros that use Google Test to test interfaces| +|TesterBase.*| Base class for test class. Defines necessary handlers as well as helper functions. **Autocoded** | +|GTestBase.*|Helper class derived from TesterBase that has macros that use Google Test to test interfaces. **Autocoded** | |Tester.*|Derived tester class that inherits from GTestBase. Includes instance of the component and helpers to connect ports| |TestMain.cpp|Main unit test implementation file| @@ -1125,8 +1123,6 @@ register_fprime_module() set(UT_SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp" "${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp" - "${CMAKE_CURRENT_LIST_DIR}/test/ut/TesterBase.cpp" - "${CMAKE_CURRENT_LIST_DIR}/test/ut/GTestBase.cpp" ) register_fprime_ut() ```