Skip to content

Commit

Permalink
docs: Update MathComponent to Reference TestMain (#1030)
Browse files Browse the repository at this point in the history
* 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.

* lestarch: updating docs to clarify *Base.* files being autocoded.

Co-authored-by: M Starch <LeStarch@googlemail.com>
  • Loading branch information
astroesteban and LeStarch authored Sep 16, 2021
1 parent 97e49a9 commit 567e2c5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions docs/Tutorials/MathComponent/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1085,19 +1085,19 @@ 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|

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:

Expand All @@ -1121,10 +1121,8 @@ 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"
)
register_fprime_ut()
```
Expand All @@ -1135,7 +1133,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"
Expand Down Expand Up @@ -1164,7 +1163,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:
Expand Down Expand Up @@ -1228,14 +1226,17 @@ 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:

```c++
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++
Expand All @@ -1245,6 +1246,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
//!
Expand Down Expand Up @@ -1275,7 +1279,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);
Expand Down Expand Up @@ -1321,7 +1325,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:
Expand Down

0 comments on commit 567e2c5

Please sign in to comment.