Skip to content

Commit

Permalink
WIP test writing
Browse files Browse the repository at this point in the history
  • Loading branch information
stefi07 committed Aug 6, 2024
1 parent 6a737ab commit 3b875b5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 91 deletions.
96 changes: 17 additions & 79 deletions apps/fsmCtrl/tests/binaryUart_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ class MockIUart : public IUart
bool dataready() const override { return false; }
char getcqq() override { return '\0'; }
char putcqq(char c) override {
// Convert the byte to its hexadecimal representation
std::stringstream ss;
ss << std::setw(2) << std::setfill('0') << std::hex << static_cast<unsigned>(c);
std::string hexByte = ss.str();

// Append the hexadecimal representation to sentData
sentData += hexByte;
// // Convert the byte to its hexadecimal representation
// std::stringstream ss;
// ss << std::setw(2) << std::setfill('0') << std::hex << static_cast<unsigned>(c);
// std::string hexByte = ss.str();

// // Append the hexadecimal representation to sentData
// sentData += hexByte;
sentData += c;
return c;
}
void flushoutput() override { }
Expand Down Expand Up @@ -649,88 +650,25 @@ SCENARIO("Testing TxBinaryPacket", "[BinaryUart]")
WHEN("Called with given PayloadType, pointer to start of PayloadData and PayloadLen")
{
const uint16_t payloadType = 0x00000;
const uint64_t payloadData = 12345;
size_t payloadLen = sizeof(payloadData);

CAPTURE(pinout->sentData);
CAPTURE(payloadData);
CAPTURE(uart.TxBuffer[0]);
CAPTURE(uart.TxBuffer[1]);
CAPTURE(uart.TxBuffer[2]);
CAPTURE(uart.TxBuffer[3]);
CAPTURE(uart.TxBuffer[4]);
CAPTURE(uart.TxBuffer[5]);
CAPTURE(uart.TxBuffer[6]);
CAPTURE(uart.TxBuffer[7]);
CAPTURE(uart.TxBuffer[8]);
CAPTURE(uart.TxBuffer[9]);

uart.TxBinaryPacket(payloadType, &payloadData, payloadLen);

CAPTURE(pinout->sentData);
CAPTURE(payloadData);
CAPTURE(uart.TxBuffer[0]);
CAPTURE(uart.TxBuffer[1]);
CAPTURE(uart.TxBuffer[2]);
CAPTURE(uart.TxBuffer[3]);
CAPTURE(uart.TxBuffer[4]);
CAPTURE(uart.TxBuffer[5]);
CAPTURE(uart.TxBuffer[6]);
CAPTURE(uart.TxBuffer[7]);
CAPTURE(uart.TxBuffer[8]);
CAPTURE(uart.TxBuffer[9]);
const char testChar = 'a';
uint8_t payloadData[3] = {static_cast<uint8_t>(testChar), static_cast<uint8_t>(testChar), static_cast<uint8_t>(testChar)};
size_t payloadLen = 3 * sizeof(uint8_t);

uart.TxBinaryPacket(payloadType, reinterpret_cast<void *>(payloadData), payloadLen);

THEN("Builds and sends non-empty packet")
{
// Convert payloadData to a string representation for comparison
std::ostringstream oss;
oss << std::hex << std::setw(2) << std::setfill('0') << payloadData;
ostringstream oss("");
for (int temp = 0; temp < 3; temp++)
oss << static_cast<char>(payloadData[temp]);
std::string expectedData = oss.str();

// Convert sentData to a string representation in hexadecimal
std::ostringstream ossSent;
for (char c : pinout->sentData) {
ossSent << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(c);
}
std::string actualData = ossSent.str();

REQUIRE(actualData == expectedData);
REQUIRE(expectedData == pinout->sentData);

}
}
}
}


// SCENARIO("BinaryUart tests", "[BinaryUart]") {
// GIVEN("A BinaryUart instance") {
// MockIUart uart;
// MockIPacket packet;
// MockBinaryUartCallbacks callbacks;
// MagAOX::app::BinaryUart binaryUart(uart, packet, callbacks);

// WHEN("Initializing BinaryUart") {
// int rv = binaryUart.Init(123);
// THEN("Initialization should succeed") {
// REQUIRE(rv == 0);
// // ...
// }
// }

// WHEN("Processing data") {
// // Setup input data
// uint32_t serialNum = 123;
// binaryUart.Init(serialNum);
// uart.setDataReady(true); // Simulate data available on the UART
// bool processed = binaryUart.Process(nullptr);
// THEN("Processing should succeed") {
// REQUIRE(processed == true);
// // ...
// }
// }

// // ...
// }
// }

} //namespace binaryUart_test
24 changes: 12 additions & 12 deletions apps/fsmCtrl/tests/fsmCtrl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ SCENARIO( "INDI Callbacks", "[fsmCtrl]" )



SCENARIO("")
{
GIVEN("")
{
WHEN("")
{
REQUIRE();
REQUIRE();
REQUIRE();
}
}
}
// SCENARIO("")
// {
// GIVEN("")
// {
// WHEN("")
// {
// REQUIRE();
// REQUIRE();
// REQUIRE();
// }
// }
// }


} //namespace FSMTEST
1 change: 1 addition & 0 deletions tests/tests.list
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
../apps/zaberCtrl/tests/zaberCtrl_test

../apps/fsmCtrl/tests/fsmCtrl_test
../apps/fsmCtrl/tests/binaryUart_test

0 comments on commit 3b875b5

Please sign in to comment.