Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Migrating MathSender unit tests to v3.4.0 standards

* Migrating MathReceiver unit tests to v3.4.0 standards

* Fixing UT writing

* Merged version of nasa/fprime#2293
  • Loading branch information
LeStarch authored Oct 5, 2023
1 parent efa91d7 commit d4f5c39
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 132 deletions.
4 changes: 2 additions & 2 deletions Components/MathReceiver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ register_fprime_module()

set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/MathReceiver.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/MathReceiverTester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/MathReceiverTestMain.cpp"
)
set(UT_AUTO_HELPERS ON)
set(UT_MOD_DEPS STest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
// TestMain.cpp
// ----------------------------------------------------------------------

#include "Tester.hpp"
#include "MathReceiverTester.hpp"
#include "STest/Random/Random.hpp"

/*
TEST(Nominal, ToDo) {
MathModule::Tester tester;
MathModule::MathReceiverTester tester;
tester.toDo();
}
*/

TEST(Nominal, AddCommand) {
MathModule::Tester tester;
MathModule::MathReceiverTester tester;
tester.testAdd();
}

TEST(Nominal, SubCommand) {
MathModule::Tester tester;
MathModule::MathReceiverTester tester;
tester.testSub();
}

TEST(Nominal, Throttle) {
MathModule::Tester tester;
MathModule::MathReceiverTester tester;
tester.testThrottle();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// \brief cpp file for MathReceiver test harness implementation class
// ======================================================================

#include "Tester.hpp"
#include "MathReceiverTester.hpp"
#include "STest/Pick/Pick.hpp"

namespace MathModule {
Expand All @@ -13,17 +13,17 @@ namespace MathModule {
// Construction and destruction
// ----------------------------------------------------------------------

Tester ::
Tester() :
MathReceiverGTestBase("Tester", Tester::MAX_HISTORY_SIZE),
MathReceiverTester ::
MathReceiverTester() :
MathReceiverGTestBase("Tester", MathReceiverTester::MAX_HISTORY_SIZE),
component("MathReceiver")
{
this->initComponents();
this->connectPorts();
}

Tester ::
~Tester()
MathReceiverTester ::
~MathReceiverTester()
{

}
Expand All @@ -32,20 +32,20 @@ namespace MathModule {
// Tests
// ----------------------------------------------------------------------

void Tester ::
void MathReceiverTester ::
toDo()
{
// TODO
}

F32 Tester ::
F32 MathReceiverTester ::
pickF32Value()
{
const F32 m = 10e6;
return m * (1.0 - 2 * STest::Pick::inUnitInterval());
}

void Tester ::
void MathReceiverTester ::
setFactor(
F32 factor,
ThrottleState throttleState
Expand All @@ -69,7 +69,7 @@ namespace MathModule {
}
}

F32 Tester ::
F32 MathReceiverTester ::
computeResult(
F32 val1,
MathOp op,
Expand Down Expand Up @@ -99,7 +99,7 @@ namespace MathModule {
return result;
}

void Tester ::
void MathReceiverTester ::
doMathOp(
MathOp op,
F32 factor
Expand Down Expand Up @@ -150,7 +150,7 @@ namespace MathModule {

}

void Tester ::
void MathReceiverTester ::
testAdd()
{
// Set the factor parameter by command
Expand All @@ -160,7 +160,7 @@ namespace MathModule {
this->doMathOp(MathOp::ADD, factor);
}

void Tester ::
void MathReceiverTester ::
testSub()
{
// Set the factor parameter by loading parameters
Expand All @@ -171,7 +171,7 @@ namespace MathModule {
this->doMathOp(MathOp::SUB, factor);
}

void Tester ::
void MathReceiverTester ::
testThrottle()
{

Expand Down Expand Up @@ -208,7 +208,7 @@ namespace MathModule {
// Handlers for typed from ports
// ----------------------------------------------------------------------

void Tester ::
void MathReceiverTester ::
from_mathResultOut_handler(
const NATIVE_INT_TYPE portNum,
F32 result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#ifndef TESTER_HPP
#define TESTER_HPP

#include "GTestBase.hpp"
#include "MathReceiverGTestBase.hpp"
#include "Components/MathReceiver/MathReceiver.hpp"

namespace MathModule {

class Tester :
class MathReceiverTester :
public MathReceiverGTestBase
{

Expand All @@ -28,13 +28,13 @@ namespace MathModule {
// Queue depth supplied to component instance under test
static const NATIVE_INT_TYPE TEST_INSTANCE_QUEUE_DEPTH = 10;

//! Construct object Tester
//! Construct object MathReceiverTester
//!
Tester();
MathReceiverTester();

//! Destroy object Tester
//! Destroy object MathReceiverTester
//!
~Tester();
~MathReceiverTester();

private:

Expand Down
4 changes: 2 additions & 2 deletions Components/MathSender/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ register_fprime_module()

set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/MathSender.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/MathSenderTester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/MathSenderTestMain.cpp"
)
set(UT_AUTO_HELPERS ON)
set(UT_MOD_DEPS STest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
// TestMain.cpp
// ----------------------------------------------------------------------

#include "Tester.hpp"
#include "MathSenderTester.hpp"
#include "STest/Random/Random.hpp"

/*
TEST(Nominal, ToDo) {
MathModule::Tester tester;
MathModule::MathSenderTester tester;
tester.toDo();
}
*/

TEST(Nominal, AddCommand) {
MathModule::Tester tester;
MathModule::MathSenderTester tester;
tester.testAddCommand();
}

TEST(Nominal, Result) {
MathModule::Tester tester; ///@TODO
MathModule::MathSenderTester tester; ///@TODO
tester.testResult();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// \brief cpp file for MathSender test harness implementation class
// ======================================================================

#include "Tester.hpp"
#include "MathSenderTester.hpp"
#include "STest/Pick/Pick.hpp"

namespace MathModule {
Expand All @@ -13,17 +13,17 @@ namespace MathModule {
// Construction and destruction
// ----------------------------------------------------------------------

Tester ::
Tester() :
MathSenderGTestBase("Tester", Tester::MAX_HISTORY_SIZE),
MathSenderTester ::
MathSenderTester() :
MathSenderGTestBase("Tester", MathSenderTester::MAX_HISTORY_SIZE),
component("MathSender")
{
this->initComponents();
this->connectPorts();
}

Tester ::
~Tester()
MathSenderTester ::
~MathSenderTester()
{

}
Expand All @@ -32,13 +32,13 @@ namespace MathModule {
// Tests
// ----------------------------------------------------------------------

void Tester ::
void MathSenderTester ::
toDo()
{
// TODO
}

void Tester ::
void MathSenderTester ::
testDoMath(MathOp op)
{
// Pick values
Expand Down Expand Up @@ -83,13 +83,13 @@ namespace MathModule {
ASSERT_EVENTS_COMMAND_RECV(0, val1, op, val2);
}

void Tester ::
void MathSenderTester ::
testAddCommand()
{
this->testDoMath(MathOp::ADD);
}

void Tester ::
void MathSenderTester ::
testResult()
{
// Generate an expected result
Expand Down Expand Up @@ -118,7 +118,7 @@ namespace MathModule {
// Handlers for typed from ports
// ----------------------------------------------------------------------

void Tester ::
void MathSenderTester ::
from_mathOpOut_handler(
const NATIVE_INT_TYPE portNum,
F32 val1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#ifndef TESTER_HPP
#define TESTER_HPP

#include "GTestBase.hpp"
#include "MathSenderGTestBase.hpp"
#include "Components/MathSender/MathSender.hpp"

namespace MathModule {

class Tester :
class MathSenderTester :
public MathSenderGTestBase
{

Expand All @@ -28,13 +28,13 @@ namespace MathModule {
// Queue depth supplied to component instance under test
static const NATIVE_INT_TYPE TEST_INSTANCE_QUEUE_DEPTH = 10;

//! Construct object Tester
//! Construct object MathSenderTester
//!
Tester();
MathSenderTester();

//! Destroy object Tester
//! Destroy object MathSenderTester
//!
~Tester();
~MathSenderTester();

public:

Expand Down
10 changes: 5 additions & 5 deletions docs/writing-unit-tests-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ This stub contains all the boilerplate necessary to write and run unit tests aga
fprime-util impl --ut
```

You haved just generate three new files ```Tester.cpp Tester.hpp TestMain.cpp```. Move these files to the `test/ut` in MathSender using:
You haved just generate three new files ```MathSenderTester.cpp MathSenderTester.hpp MathSenderTestMain.cpp```. Move these files to the `test/ut` in MathSender using:

```shell
# In: MathSender
mv Tester.* TestMain.cpp test/ut
mv MathSenderTester.* MathSenderTestMain.cpp test/ut
```

## Add the Tests to the Build

Add `Tester.cpp` and `TestMain.cpp` to the build. Do so by editing the CMakeLists.txt to add the 2 new source files. The UT section should now look like the following:
Add `MathSenderTester.cpp` and `MathSenderTestMain.cpp` to the build. Do so by editing the CMakeLists.txt to add the 2 new source files. The UT section should now look like the following:

```cmake
# In: MathSender/CMakeLists.txt
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/MathSender.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/MathSenderTester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/MathSenderTestMain.cpp"
)
set(UT_AUTO_HELPERS ON)
register_fprime_ut()
Expand Down
Loading

0 comments on commit d4f5c39

Please sign in to comment.