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 Aug 19, 2023
1 parent e9fb874 commit c8d1b22
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion hammocking/hammocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from jinja2 import Environment, FileSystemLoader
import logging

Config.set_library_file('libclang-14.so.1')
# Config.set_library_file('libclang-14.so.1')

class Variable:
def __init__(self, type: str, name: str, size: int = 0) -> None:
Expand Down
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 c8d1b22

Please sign in to comment.