Skip to content

Commit 567e2c5

Browse files
docs: Update MathComponent to Reference TestMain (#1030)
* 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 <[email protected]>
1 parent 97e49a9 commit 567e2c5

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

docs/Tutorials/MathComponent/Tutorial.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,19 +1085,19 @@ The files that are generated are:
10851085
```
10861086
Tester.hpp
10871087
Tester.cpp
1088-
TesterBase.hpp
1089-
TesterBase.cpp
1090-
GTestBase.hpp
1091-
GTestBase.cpp
1088+
TestMain.cpp
10921089
```
10931090

1091+
**Note:** TesterBase.* and GTestBase.* files can be removed. these will be regenerated when the unit test builds.
1092+
10941093
The functions of the files are:
10951094

10961095
|File|Function|
10971096
|---|---|
1098-
|TesterBase.*|Base class for test class. Defines necessary handlers as well as helper functions
1099-
|GTestBase.*|Helper class derived from TesterBase that has macros that use Google Test to test interfaces|
1097+
|TesterBase.*| Base class for test class. Defines necessary handlers as well as helper functions. **Autocoded** |
1098+
|GTestBase.*|Helper class derived from TesterBase that has macros that use Google Test to test interfaces. **Autocoded** |
11001099
|Tester.*|Derived tester class that inherits from GTestBase. Includes instance of the component and helpers to connect ports|
1100+
|TestMain.cpp|Main unit test implementation file|
11011101

11021102
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:
11031103

@@ -1121,10 +1121,8 @@ set(SOURCE_FILES
11211121
register_fprime_module()
11221122
11231123
set(UT_SOURCE_FILES
1124-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/main.cpp"
1124+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp"
11251125
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
1126-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TesterBase.cpp"
1127-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/GTestBase.cpp"
11281126
)
11291127
register_fprime_ut()
11301128
```
@@ -1135,7 +1133,8 @@ A `UT_MODS` variable may be set should the UT depend on modules not automaticall
11351133

11361134
##### 2.4.1.3.2 Test Code Implementation
11371135

1138-
The `main.cpp` file must be added. For this test, it appears like this:
1136+
The unit tests must be added to `TestMain.cpp`. Change the default code to appear
1137+
like this:
11391138

11401139
```c++
11411140
#include "Tester.hpp"
@@ -1164,7 +1163,6 @@ int main(int argc, char **argv) {
11641163
::testing::InitGoogleTest(&argc, argv);
11651164
return RUN_ALL_TESTS();
11661165
}
1167-
11681166
```
11691167
11701168
F' uses the Google Test framework to run unit tests. For more information about the Google Test Framework see here:
@@ -1228,14 +1226,17 @@ The test component is instantiated here:
12281226
NameSpace::Tester tester;
12291227
```
12301228

1231-
This allows the component to start from an newly initialized state for each unit test.
1229+
This allows the component to start from a newly initialized state for each unit test.
12321230

12331231
The unit test is executed by calling a member function of the `tester` class:
12341232

12351233
```c++
12361234
tester.someUnitTestFunc();
12371235
```
12381236

1237+
> NOTE: The autogenerated `Tester.*` files include a placeholder "toDo" function. Feel
1238+
free to leave that in or delete it.
1239+
12391240
The `Tester.hpp` stub can be updated to include the declarations of the unit test functions:
12401241

12411242
```c++
@@ -1245,6 +1246,9 @@ The `Tester.hpp` stub can be updated to include the declarations of the unit tes
12451246
// ----------------------------------------------------------------------
12461247
// Tests
12471248
// ----------------------------------------------------------------------
1249+
//! To do
1250+
//!
1251+
void toDo(void);
12481252

12491253
//! Test operation command
12501254
//!
@@ -1275,7 +1279,7 @@ Add a member function to the implementation class in `Tester.cpp` to implement t
12751279
this->sendCmd_MS_DO_MATH(0,10,1.0,2.0,MathSenderComponentBase::ADD);
12761280
// retrieve the message from the message queue and dispatch the command to the handler
12771281
this->component.doDispatch();
1278-
// verify that that only one output port was called
1282+
// verify that only one output port was called
12791283
ASSERT_FROM_PORT_HISTORY_SIZE(1);
12801284
// verify that the math operation port was only called once
12811285
ASSERT_from_mathOut_SIZE(1);
@@ -1321,7 +1325,6 @@ Add a member function to the implementation class in `Tester.cpp` to implement t
13211325
// verify the expected value of the event arguments
13221326
ASSERT_EVENTS_MS_RESULT(0,10.0);
13231327
}
1324-
13251328
```
13261329

13271330
Some highlights are:

0 commit comments

Comments
 (0)