Skip to content

Commit

Permalink
Fix other review issues pertaining to unit tests and argument checks …
Browse files Browse the repository at this point in the history
…in the SmSignalBuffer constructors
  • Loading branch information
watney committed Sep 19, 2024
1 parent fe98ac6 commit f5eef35
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 47 deletions.
15 changes: 8 additions & 7 deletions FppTest/state_machine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SmTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/SmTest.fpp"
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp"
"${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp"
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp"
"${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp"
)
set(MOD_DEPS Fw/Sm)

register_fprime_module()

set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SmTest.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TesterHelpers.cpp"
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp"
"${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SmTestTestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SmTestTester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp"
"${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp"
)

set(UT_MOD_DEPS STest)
set(UT_AUTO_HELPERS ON)
register_fprime_ut()
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// ----------------------------------------------------------------------
// TestMain.cpp
// SmTestTestMain.cpp
// ----------------------------------------------------------------------

#include "FppTest/state_machine/test/ut/Tester.hpp"
#include "FppTest/state_machine/test/ut/SmTestTester.hpp"
#include "Fw/Test/UnitTest.hpp"
#include "STest/Random/Random.hpp"

using namespace FppTest;

TEST(schedIn, OK) {
COMMENT("schedIn OK");
Tester tester;
SmTestTester tester;
tester.schedIn_OK();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// ======================================================================
// \title Tester.cpp
// \title SmTestTester.cpp
// \author watney
// \brief cpp file for SmTest test harness implementation class
// ======================================================================

#include <cstring>

#include "FppTest/state_machine/test/ut/Tester.hpp"
#include "FppTest/state_machine/test/ut/SmTestTester.hpp"
#include "Fw/Types/ExternalString.hpp"
#include "STest/Pick/Pick.hpp"

Expand All @@ -16,21 +16,21 @@ namespace FppTest {
// Construction and destruction
// ----------------------------------------------------------------------

Tester::Tester()
: SmTestGTestBase("Tester", Tester::MAX_HISTORY_SIZE),
SmTestTester::SmTestTester()
: SmTestGTestBase("SmTestTester", SmTestTester::MAX_HISTORY_SIZE),
component("SmTest") {
this->initComponents();
this->connectPorts();
this->component.setIdBase(ID_BASE);
}

Tester::~Tester() {}
SmTestTester::~SmTestTester() {}

// ----------------------------------------------------------------------
// Tests
// ----------------------------------------------------------------------

void Tester::schedIn_OK() {
void SmTestTester::schedIn_OK() {
ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device1.state);
ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device2.state);
ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device3.state);
Expand Down Expand Up @@ -65,7 +65,7 @@ void Tester::schedIn_OK() {
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
void Tester ::
void SmTestTester ::
dispatchAll()
{
while (this->component.m_queue.getNumMsgs() > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace FppTest {

class Tester : public SmTestGTestBase {
class SmTestTester : public SmTestGTestBase {
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
Expand All @@ -32,11 +32,11 @@ class Tester : public SmTestGTestBase {

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

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

public:
// ----------------------------------------------------------------------
Expand Down
27 changes: 0 additions & 27 deletions FppTest/state_machine/test/ut/TesterHelpers.cpp

This file was deleted.

8 changes: 8 additions & 0 deletions Fw/Sm/SmSignalBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace Fw {

SmSignalBuffer::SmSignalBuffer(const U8 *args, FwSizeType size) : m_bufferData{} {
FW_ASSERT(args != nullptr);
FW_ASSERT(size <= sizeof(this->m_bufferData));
SerializeStatus stat = SerializeBufferBase::setBuff(args,size);
FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast<NATIVE_INT_TYPE>(stat));
}
Expand All @@ -17,6 +19,9 @@ namespace Fw {
SmSignalBuffer::SmSignalBuffer(const SmSignalBuffer& other) : Fw::SerializeBufferBase(),
m_bufferData{}
{
FW_ASSERT(other.getBuffAddr() != nullptr);
FW_ASSERT(other.getBuffLength() <= sizeof(this->m_bufferData));

SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength());
FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast<NATIVE_INT_TYPE>(stat));
}
Expand All @@ -25,6 +30,9 @@ namespace Fw {
if(this == &other) {
return *this;
}

FW_ASSERT(other.getBuffAddr() != nullptr);
FW_ASSERT(other.getBuffLength() <= sizeof(this->m_bufferData));

SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength());
FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast<NATIVE_INT_TYPE>(stat));
Expand Down

0 comments on commit f5eef35

Please sign in to comment.