Skip to content

Commit

Permalink
#41: Add usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
theHolgi committed Apr 4, 2024
1 parent 15176cd commit 1c75c07
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
7 changes: 7 additions & 0 deletions tests/data/mini_c_test/b.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ void b_step(void){

local_extern(2);
}

int x1 = 1;

int get_x1(void)
{
return x1;
}
36 changes: 24 additions & 12 deletions tests/data/mini_c_test/b_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,40 @@ TEST(b_test, TestSignalChain_3)
b_step();
}

TEST(b_test, TestSignalChain_4)
/* Introducing a test fixture */

class B : public Test {
void SetUp() override {
mock = CREATE_MOCK(); // Create the mock handle in the fixture
// Now some generic reactions can be set up
ON_CALL(*mock, a_get_y5).WillByDefault(Return(13));
}
void TearDown() override {
DESTROY_MOCK(); // Tear down the mock handle to finalize its expecations
}

protected:
mock_ptr_t mock;
};

TEST_F(B, TestSignalChain_4)
{
LOCAL_MOCK(mymock);
a_y4 = 13;
EXPECT_CALL(mymock, c_set_u3_and_u4(_, 13));
EXPECT_CALL(*mock, c_set_u3_and_u4(_, 13));
b_step();
}

TEST(b_test, TestSignalChain_5)
TEST_F(B, TestSignalChain_5)
{
LOCAL_MOCK(mymock);
EXPECT_CALL(mymock, a_get_y5())
.WillOnce(Return(13));
EXPECT_CALL(mymock, c_get_y3_and_set_u5(13));
// Makes use of a_get_y5 behavior from the fixture's setup
EXPECT_CALL(*mock, c_get_y3_and_set_u5(13));
b_step();
}

TEST(b_test, TestSignalChain_6)
TEST_F(B, TestSignalChain_6)
{
LOCAL_MOCK(mymock);
EXPECT_CALL(mymock, a_get_y6(_))
EXPECT_CALL(*mock, a_get_y6(_))
.WillOnce(SetArgPointee<0>(13));
EXPECT_CALL(mymock, c_set_u6(13));
EXPECT_CALL(*mock, c_set_u6(13));
b_step();
}

0 comments on commit 1c75c07

Please sign in to comment.