meekrosoft / fff

A testing micro framework for creating function test doubles
Other
768 stars 169 forks source link

Linking issue in the example project #117

Open ivankvolik opened 2 years ago

ivankvolik commented 2 years ago

Hello people,

I've tried expanding the example project to play a bit with it, but i am getting a linking error, which i am not able to solve.

What have i added?

In the hardware_abstraction.h I've added the function declaration with this signature: uint8_t IO_READ_CHARS(uint8_t* chars_array, uint8_t number_of_chars);

In driver.c I've added following function:

uint8_t testonia() {
    uint8_t buffer[100] = {0};
    uint8_t charNum = 0;
    uint8_t sumReturn  = HARDWARE_REV_A;

    sumReturn = IO_READ_CHARS(buffer, HARDWARE_REV_A);

    return buffer[3];
}

In driver.test.fff.cpp added the fake value func like so: FAKE_VALUE_FUNC(uint8_t, IO_READ_CHARS, uint8_t*, uint8_t);

declared a custom fake function:

uint8_t cust_fake(uint8_t* chars, uint8_t number) {
    chars[0] = 1u;
    chars[1] = 2u;
    chars[2] = 5u;
    chars[3] = 100u;

    return 3u;
}

And my test is in the following listing:

TEST_F(DriverTestFFF, Some_fake_test) {
    uint8_t ret = 0;
    IO_READ_CHARS_fake.custom_fake = cust_fake;

    IO_READ_CHARS_fake.return_val = 1;

    ret = testonia();

    ASSERT_EQ(ret, 100u);
}

The error I get on linking is that there is an undefined reference to IO_READ_CHARS.

FAILED: examples/driver_testing/driver_test 
: && /usr/bin/c++   examples/driver_testing/CMakeFiles/driver_test.dir/src/driver.c.o examples/driver_testing/CMakeFiles/driver_test.dir/src/driver.test.cpp.o -o examples/driver_testing/driver_test  gtest/libgtest.a  -lpthread  -static-libstdc++ && :
/usr/bin/ld: examples/driver_testing/CMakeFiles/driver_test.dir/src/driver.c.o: in function `testonia':
driver.c:(.text+0xcf): undefined reference to `IO_READ_CHARS'

Can somebody please tell me what did i do wrong?

ivankvolik commented 2 years ago

UPDATE: When I comment this line in testonia function, the linking passes and everything is executed. So I might have screwed something up in naming, or forgot to link the function somewhere.

sumReturn = IO_READ_CHARS(buffer, HARDWARE_REV_A);