Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reqTest bug #172

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/ayab/com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void Com::onPacketReceived(const uint8_t *buffer, size_t size) {
break;

case static_cast<uint8_t>(AYAB_API::reqTest):
h_reqTest(buffer, size);
h_reqTest();
break;

case static_cast<uint8_t>(AYAB_API::helpCmd):
Expand Down Expand Up @@ -316,14 +316,8 @@ void Com::h_reqInfo() const {
* \param buffer A pointer to a data buffer.
* \param size The number of bytes in the data buffer.
*/
void Com::h_reqTest(const uint8_t *buffer, size_t size) const {
if (size < 2U) {
// message is too short
send_cnfTest(ErrorCode::expected_longer_message);
return;
}

auto machineType = static_cast<Machine_t>(buffer[1]);
void Com::h_reqTest() const {
auto machineType = static_cast<Machine_t>(GlobalKnitter::getMachineType());

// Note (August 2020): the return value of this function has changed.
// Previously, it returned `true` for success and `false` for failure.
Expand Down
2 changes: 1 addition & 1 deletion src/ayab/com.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Com : public ComInterface {
void h_reqStart(const uint8_t *buffer, size_t size);
void h_cnfLine(const uint8_t *buffer, size_t size);
void h_reqInfo() const;
void h_reqTest(const uint8_t *buffer, size_t size) const;
void h_reqTest() const;
void h_unrecognized() const;

void send_cnfInfo() const;
Expand Down
14 changes: 2 additions & 12 deletions test/test_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,10 @@ TEST_F(ComTest, test_reqInit_checksum_error) {
ASSERT_TRUE(Mock::VerifyAndClear(fsmMock));
}

TEST_F(ComTest, test_reqtest_fail) {
// no machineType
TEST_F(ComTest, test_reqtest) {
uint8_t buffer[] = {static_cast<uint8_t>(AYAB_API::reqTest)};
EXPECT_CALL(*fsmMock, setState(OpState::test)).Times(0);
expected_write_onPacketReceived(buffer, sizeof(buffer), true);

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

TEST_F(ComTest, test_reqtest_success_KH270) {
uint8_t buffer[] = {static_cast<uint8_t>(AYAB_API::reqTest), static_cast<uint8_t>(Machine_t::Kh270)};
EXPECT_CALL(*fsmMock, setState(OpState::test));
EXPECT_CALL(*knitterMock, setMachineType(Machine_t::Kh270));
EXPECT_CALL(*knitterMock, setMachineType(Machine_t::Kh910));
EXPECT_CALL(*arduinoMock, millis);
expected_write_onPacketReceived(buffer, sizeof(buffer), false);

Expand Down