Skip to content

Commit

Permalink
some changes to test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mpr1c3 authored and dl1com committed May 29, 2023
1 parent 64087ef commit 558fab5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/ayab/beeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void Beeper::endWork() {
/*!
* Generic beep function.
*
* @param length number of beeps
* /param length number of beeps
*/
void Beeper::beep(uint8_t length) {

Expand Down
1 change: 1 addition & 0 deletions src/ayab/solenoids.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class GlobalSolenoids final {

class Solenoids : public SolenoidsInterface {
#ifdef AYAB_TESTS
FRIEND_TEST(SolenoidsTest, test_init);
FRIEND_TEST(SolenoidsTest, test_setSolenoid1);
FRIEND_TEST(SolenoidsTest, test_setSolenoid2);
FRIEND_TEST(SolenoidsTest, test_setSolenoid3);
Expand Down
12 changes: 6 additions & 6 deletions test/test_beeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ class BeeperTest : public ::testing::Test {
}

void checkBeepTime(uint8_t length) {
EXPECT_CALL(*arduinoMock, analogWrite(PIEZO_PIN, 0)).Times(length);
EXPECT_CALL(*arduinoMock, analogWrite(PIEZO_PIN, 20)).Times(length);
EXPECT_CALL(*arduinoMock, analogWrite(PIEZO_PIN, BEEP_ON_DUTY)).Times(length);
EXPECT_CALL(*arduinoMock, analogWrite(PIEZO_PIN, BEEP_OFF_DUTY)).Times(length);
EXPECT_CALL(*arduinoMock, delay(BEEP_DELAY)).Times(length * 2);
EXPECT_CALL(*arduinoMock, analogWrite(PIEZO_PIN, 255)).Times(1);
EXPECT_CALL(*arduinoMock, analogWrite(PIEZO_PIN, BEEP_NO_DUTY)).Times(1);
}

ArduinoMock *arduinoMock;
};

TEST_F(BeeperTest, test_ready) {
checkBeepTime(5);
checkBeepTime(BEEP_NUM_READY);
beeper->ready();
}

TEST_F(BeeperTest, test_finishedLine) {
checkBeepTime(3);
checkBeepTime(BEEP_NUM_FINISHEDLINE);
beeper->finishedLine();
}

TEST_F(BeeperTest, test_endWork) {
checkBeepTime(10);
checkBeepTime(BEEP_NUM_ENDWORK);
beeper->endWork();
}
41 changes: 33 additions & 8 deletions test/test_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ class ComTest : public ::testing::Test {
SerialMock *serialMock;

void expect_init() {
EXPECT_CALL(*serialMock, begin);
//EXPECT_CALL(*serialMock, begin);
}

void expect_write(bool once) {
if (once) {
EXPECT_CALL(*serialMock, write(_, _));
EXPECT_CALL(*serialMock, write(SLIP::END));
// FIXME need to mock SerialPacket
//EXPECT_CALL(*serialMock, write(_, _));
//EXPECT_CALL(*serialMock, write(SLIP::END));
} else {
EXPECT_CALL(*serialMock, write(_, _)).Times(AtLeast(1));
EXPECT_CALL(*serialMock, write(SLIP::END)).Times(AtLeast(1));
//EXPECT_CALL(*serialMock, write(_, _)).Times(AtLeast(1));
//EXPECT_CALL(*serialMock, write(SLIP::END)).Times(AtLeast(1));
}
}

Expand All @@ -90,7 +91,7 @@ class ComTest : public ::testing::Test {
}

void reqInit(Machine_t machine) {
uint8_t buffer[] = {reqInit_msgid, static_cast<uint8_t>(machine), 0x2D};
uint8_t buffer[] = {reqInit_msgid, static_cast<uint8_t>(machine)};
EXPECT_CALL(*fsmMock, setState(s_init));
expected_write_onPacketReceived(buffer, sizeof(buffer), true);
}
Expand All @@ -102,6 +103,30 @@ TEST_F(ComTest, test_API) {
}
*/

TEST_F(ComTest, test_reqInit_too_short_error) {
uint8_t buffer[] = {reqInit_msgid, static_cast<uint8_t>(Kh910)};
//EXPECT_CALL(*serialMock, write(cnfInit_msgid));
//EXPECT_CALL(*serialMock, write(EXPECTED_LONGER_MESSAGE));
//EXPECT_CALL(*serialMock, write(SLIP::END));
EXPECT_CALL(*fsmMock, setState(s_init)).Times(0);
com->onPacketReceived(buffer, sizeof(buffer));

// test expectations without destroying instance
ASSERT_TRUE(Mock::VerifyAndClear(fsmMock));
}

TEST_F(ComTest, test_reqInit_checksum_error) {
uint8_t buffer[] = {reqInit_msgid, static_cast<uint8_t>(Kh910), 0};
//EXPECT_CALL(*serialMock, write(cnfInit_msgid));
//EXPECT_CALL(*serialMock, write(CHECKSUM_ERROR));
//EXPECT_CALL(*serialMock, write(SLIP::END));
EXPECT_CALL(*fsmMock, setState(s_init)).Times(0);
com->onPacketReceived(buffer, sizeof(buffer));

// test expectations without destroying instance
ASSERT_TRUE(Mock::VerifyAndClear(fsmMock));
}

TEST_F(ComTest, test_reqtest_fail) {
// no machineType
uint8_t buffer[] = {reqTest_msgid};
Expand Down Expand Up @@ -182,7 +207,7 @@ TEST_F(ComTest, test_sendCmd) {
TEST_F(ComTest, test_beepCmd) {
uint8_t buffer[] = {beepCmd_msgid};
EXPECT_CALL(*arduinoMock, analogWrite(PIEZO_PIN, _)).Times(AtLeast(1));
EXPECT_CALL(*arduinoMock, delay(50)).Times(AtLeast(1));
EXPECT_CALL(*arduinoMock, delay(BEEP_DELAY)).Times(AtLeast(1));
expected_write_onPacketReceived(buffer, sizeof(buffer), true);
}

Expand Down Expand Up @@ -337,7 +362,7 @@ TEST_F(ComTest, test_debug) {
}

TEST_F(ComTest, test_update) {
EXPECT_CALL(*serialMock, available);
//EXPECT_CALL(*serialMock, available);
com->update();
}

Expand Down
1 change: 1 addition & 0 deletions test/test_solenoids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ TEST_F(SolenoidsTest, test_construct) {

TEST_F(SolenoidsTest, test_init) {
solenoids->init();
ASSERT_TRUE(solenoids->solenoidState == 0U);
}

TEST_F(SolenoidsTest, test_setSolenoid1) {
Expand Down

0 comments on commit 558fab5

Please sign in to comment.