From e868009ade5b3332f5f05fa3335db17295f40dcf Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sat, 9 Mar 2024 06:38:49 -0500 Subject: [PATCH] Add KnitterMock::quit() --- test/mocks/knitter_mock.cpp | 7 ++++++- test/mocks/knitter_mock.h | 1 + test/test_com.cpp | 3 ++- test/test_knitter.cpp | 6 ++---- test/test_tester.cpp | 5 +++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/test/mocks/knitter_mock.cpp b/test/mocks/knitter_mock.cpp index bd57fc179..4b870472d 100644 --- a/test/mocks/knitter_mock.cpp +++ b/test/mocks/knitter_mock.cpp @@ -109,5 +109,10 @@ void Knitter::setLastLine() { void Knitter::setMachineType(Machine_t machineType) { assert(gKnitterMock != nullptr); - return gKnitterMock->setMachineType(machineType); + gKnitterMock->setMachineType(machineType); +} + +void Knitter::quit() const { + assert(gKnitterMock != nullptr); + gKnitterMock->quit(); } diff --git a/test/mocks/knitter_mock.h b/test/mocks/knitter_mock.h index 10469706b..5b56c488d 100644 --- a/test/mocks/knitter_mock.h +++ b/test/mocks/knitter_mock.h @@ -45,6 +45,7 @@ class KnitterMock : public KnitterInterface { MOCK_METHOD1(setNextLine, bool(uint8_t lineNumber)); MOCK_METHOD0(setLastLine, void()); MOCK_METHOD1(setMachineType, void(Machine_t)); + MOCK_CONST_METHOD0(quit, void()); }; KnitterMock *knitterMockInstance(); diff --git a/test/test_com.cpp b/test/test_com.cpp index f5021da42..7ba5d4e98 100644 --- a/test/test_com.cpp +++ b/test/test_com.cpp @@ -247,7 +247,8 @@ TEST_F(ComTest, test_stopCmd) { com->onPacketReceived(buffer, sizeof(buffer)); } -TEST_F(ComTest, test_quitCmd) { +TEST_F(ComTest, test_quitCmd_test) { + fsm->setState(OpState::test); uint8_t buffer[] = {static_cast(AYAB_API::quitCmd)}; EXPECT_CALL(*knitterMock, setUpInterrupt); EXPECT_CALL(*fsmMock, setState(OpState::init)); diff --git a/test/test_knitter.cpp b/test/test_knitter.cpp index 38a07d41a..29ca2aabc 100644 --- a/test/test_knitter.cpp +++ b/test/test_knitter.cpp @@ -737,9 +737,7 @@ TEST_F(KnitterTest, test_fsm_init_LR) { TEST_F(KnitterTest, test_quit) { get_to_knit(Machine_t::Kh910); - EXPECT_CALL(*fsmMock, setState(OpState::init)); + //ASSERT_EQ(fsm->getState(), OpState::knit); knitter->quit(); - - // test expectations without destroying instance - ASSERT_TRUE(Mock::VerifyAndClear(fsmMock)); + ASSERT_EQ(fsm->getState(), OpState::init); } diff --git a/test/test_tester.cpp b/test/test_tester.cpp index 70f78dc82..30ac77e63 100644 --- a/test/test_tester.cpp +++ b/test/test_tester.cpp @@ -194,12 +194,13 @@ TEST_F(TesterTest, test_autoTestCmd) { } TEST_F(TesterTest, test_quitCmd) { - EXPECT_CALL(*knitterMock, setUpInterrupt); + expect_startTest(0); + //EXPECT_CALL(*knitterMock, setUpInterrupt); EXPECT_CALL(*fsmMock, setState(OpState::init)); tester->quitCmd(); // test expectations without destroying instance - ASSERT_TRUE(Mock::VerifyAndClear(knitterMock)); + //ASSERT_TRUE(Mock::VerifyAndClear(knitterMock)); ASSERT_TRUE(Mock::VerifyAndClear(fsmMock)); }