CPPUtest Error -Expected Call Was Not Fulfilled.

450 views
Skip to first unread message

Revati Dharmadhikari

unread,
Feb 21, 2023, 12:43:38 AM2/21/23
to cpputest
Hi All,

I have created one project in which I am passing pointer as parameter but is giving me error Mock Failure: Expected call WAS NOT fulfilled.
    EXPECTED calls that WERE NOT fulfilled:
        settingsDailyStepsGet -> void* current_daily_steps: <0x7ffc57389420> (expected 1 call, called 0 times)
        settingsDailyStepsSet -> void* daily_steps: <0x7ffc57389428> (expected 1 call, called 0 times)
    EXPECTED calls that WERE fulfilled:
        <none>

.
Errors (1 failures, 1 tests, 1 ran, 2 checks, 0 ignored, 0 filtered out, 0 ms)

can any one help me in this.
Thanks,
Revati.

Bas Vodde

unread,
Feb 21, 2023, 7:38:44 AM2/21/23
to cppu...@googlegroups.com

Was it called then (did you call actualCall somewhere)?

Bas

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/479806aa-f249-47a3-9895-bee4914c05bfn%40googlegroups.com.

Revati Dharmadhikari

unread,
Feb 21, 2023, 11:52:39 PM2/21/23
to cpputest
TEST(AppStepsset, simpleTest)
{
    // arrange
    uint8_t daily_steps = 56;
    uint8_t current_daily_steps = 55;

   
        uint8_t *ptr;
        ptr = &current_daily_steps;
        uint8_t *ptr1;
        ptr1 = &daily_steps;
    mock().expectOneCall("settingsDailyStepsGet")
          .withPointerParameter("ptr",&ptr)
          .andReturnValue(0);
         
    mock().expectOneCall("settingsDailyStepsSet")
          .withPointerParameter("daily_steps", &ptr1)
          .andReturnValue(0);      

    // act
    error_t appstepsset = appcSystemSettingDailyStepsSet(daily_steps);

    // assert
    mock().checkExpectations();
    CHECK_EQUAL(0, appstepsset);
}

when i am running settingsDailyStepsGet and settingsDailyStepsSet function individually it is working fine and if running appcSystemSettingDailyStepsSet() and settingsDailyStepsGet and settingsDailyStepsSet simultaneously it is not working fine

Bas Vodde

unread,
Feb 22, 2023, 4:46:40 AM2/22/23
to cpputest
Hi,

You do need to create mocks that call the mock().actualCall, otherwise the unit test framework cannot know you have called the method.

Bas

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.

Revati Dharmadhikari

unread,
Feb 22, 2023, 5:06:53 AM2/22/23
to cpputest

TEST(AppStepsset, simpleTest)
{
    // arrange
    uint8_t daily_steps = 56;
    uint8_t current_daily_steps = 55;

   
        uint8_t *ptr;
        ptr = &current_daily_steps;
        uint8_t *ptr1;
        ptr1 = &daily_steps;
    mock().actualCall("settingsDailyStepsGet")
          .withPointerParameter("ptr",&ptr)
          .andReturnValue(0);
         
    mock().actualCall("settingsDailyStepsSet")

          .withPointerParameter("daily_steps", &ptr1)
          .andReturnValue(0);      

    // act
    error_t appstepsset = appcSystemSettingDailyStepsSet(daily_steps);

    // assert
    mock().checkExpectations();
    CHECK_EQUAL(0, appstepsset);
}
is this correct way or need to change something?

Bas Vodde

unread,
Feb 22, 2023, 5:08:22 AM2/22/23
to cppu...@googlegroups.com

Revati Dharmadhikari

unread,
Feb 22, 2023, 5:10:59 AM2/22/23
to cpputest
I am not getting actually can you tell me where i should change the code please

Revati

Bas Vodde

unread,
Feb 22, 2023, 5:12:32 AM2/22/23
to cppu...@googlegroups.com

Hi,

You need to change the mock, not the test.

I suggest to look at the manual. Without the mock it won’t work.

Bas

Revati Dharmadhikari

unread,
Feb 22, 2023, 5:17:17 AM2/22/23
to cpputest


error_t settingsDailyStepsGet(uint8_t *buf)
{
    printf("\nsettingsDailyStepsGet gets called");

    return uint8_t(mock().actualCall(__func__)
        .withParameter("&current_daily_steps", *buf)
        .returnValue().getUnsignedIntValue());
}

uint8_t settingsDailyStepsSet(uint8_t *buf)
{
    printf("\nsettingsDailyStepsSet gets called");

    return uint8_t(mock().actualCall(__func__)
        .withParameter("daily_steps", *buf)
        .returnValue().getUnsignedIntValue());

Bas Vodde

unread,
Feb 22, 2023, 5:18:23 AM2/22/23
to cpputest

Yup, then make sure it gets linked in your program… and that the original ones don’t get linked.

Bas

Revati Dharmadhikari

unread,
Feb 22, 2023, 5:23:20 AM2/22/23
to cpputest
yes it linked but it is giving same error as before.

Bas Vodde

unread,
Feb 22, 2023, 5:25:41 AM2/22/23
to cppu...@googlegroups.com

Hi,

And you ensured you do not link the original? Do you get the printf statements ?

Bas


Revati Dharmadhikari

unread,
Feb 22, 2023, 5:26:43 AM2/22/23
to cpputest
No I am not getting

Bas Vodde

unread,
Feb 22, 2023, 5:29:07 AM2/22/23
to cpputest

Hi,

Then, my guess is that you are still linking the original versions of these methods with your test.

That means the original will be called and not the mock. Thus it won’t be able to know that.

Bas


Revati Dharmadhikari

unread,
Feb 22, 2023, 5:52:59 AM2/22/23
to cpputest
where to check i am linking original one or another one

Bas Vodde

unread,
Feb 22, 2023, 6:00:03 AM2/22/23
to cppu...@googlegroups.com

Hi,

That I cannot tell you as I cannot see how you are building your program.

You need to remove the file which has the original implementation from your build and link the file which has the mocks.

Bas


Revati Dharmadhikari

unread,
Feb 22, 2023, 6:02:38 AM2/22/23
to cpputest
I have linked that file only which has mocks

Bas Vodde

unread,
Feb 22, 2023, 11:46:36 AM2/22/23
to cppu...@googlegroups.com

Ok, but in order for it to work, you will need to make sure it doesn’t link the originals.

Bas

Revati Dharmadhikari

unread,
Feb 23, 2023, 12:30:30 AM2/23/23
to cpputest
Hi,

I have settings.c which have original functions written and appdailystepsget.cpp which have test cases and  dailystepsget.cpp and  dailystepsset.cpp which have mock().actual call .All four file should be included in cmakeList?
my cmakeList.txt:
# build the unit test executable.
#set(CURRENT_EXE_NAME )
set(CURRENT_EXE_NAME ${APP_NAME})


SET(CMAKE_CXX_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "-g -O0 -Wall -W -fprofile-arcs -ftest-coverage")
SET(CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
set(GCOV_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
set(GCOV_LINK_FLAGS "-lgcov")


set(SOURCE_FILES
    main.cpp
    dailystepsget.cpp
   appdailysteps_set.cpp
   dailystepsset.cpp
    /home/rdharmadhikari/Settings2/src/AppStepsSet/settings.c
 
    )
   
add_executable(${CURRENT_EXE_NAME} ${SOURCE_FILES})
#add_dependencies(${CURRENT_EXE_NAME} cpputest)
target_include_directories(${CURRENT_EXE_NAME} PUBLIC /home/rdharmadhikari/Settings2/src/StepsSet /home/rdharmadhikari/cpputest/include)
target_link_libraries(${CURRENT_EXE_NAME} /home/rdharmadhikari/cpputest/lib/libCppUTest.a /home/rdharmadhikari/cpputest/lib/libCppUTestExt.a gcov)



add_custom_target( cov
COMMAND [ -d Coverage ] && rm -rf Coverage/||echo "No folder"
COMMAND mkdir Coverage
COMMAND ${CURRENT_EXE_NAME}
COMMAND cp CMakeFiles/${APP_NAME}.dir/__/src/${APP_NAME}/*.gcno Coverage/
COMMAND mv CMakeFiles/${APP_NAME}.dir/__/src/${APP_NAME}/*.gcda Coverage/
COMMAND cd Coverage && lcov -t "result" -o ${APP_NAME}_coverage.info -c -d .
COMMAND cd Coverage && genhtml -o coverage ${APP_NAME}_coverage.info
COMMENT "Generated Coverage Report Successfully!"
)

Revati Dharmadhikari

unread,
Feb 23, 2023, 12:31:54 AM2/23/23
to cpputest
If i remove the file which has function defination in it.It will throw error as undefined reference to function name. so what to do?

Bas Vodde

unread,
Feb 23, 2023, 3:29:03 AM2/23/23
to cpputest

Two choices:

* Put the functions you want to mock in a separate file and exclude that one and the other functions not
* Also create mocks for the undefined reference errors

Thanks,

Bas

Revati Dharmadhikari

unread,
Feb 23, 2023, 5:07:13 AM2/23/23
to cpputest
Can you elobrate please. I didnt get it.

Bas Vodde

unread,
Feb 23, 2023, 7:04:43 AM2/23/23
to cppu...@googlegroups.com

You mocked 2 functions. I assume the file that you exclude contains more functions. Hence you get the error. Otherwise you wouldn’t.

Thus you need to put these two functions in a separate file so you can exclude only these two functions, or
you need to resolve the linker error by providing mocks for all the functions that it has linker errors of.

Thanks,

Bas


Revati Dharmadhikari

unread,
Feb 23, 2023, 7:09:47 AM2/23/23
to cpputest
Got it thank you.

Revati Dharmadhikari

unread,
Mar 1, 2023, 6:48:04 AM3/1/23
to cpputest
Hi,
When I am trying to run both positive testcase and negative testcase it is not working properly.Giving error why is it so?
TEST(AppCallsEnableset, simpleTest)
{

uint8_t on =1;
uint8_t current_on;
   mock().expectOneCall("flashRead")
          .withParameter("buf",current_on )
          .withParameter("CALLS_ENABLE_START_ADDRESS", 9961512)
          .withParameter("len", 4)
          .withParameter("CALLS_ENABLE_NVID", 16)
          .andReturnValue(0);
         
     mock().expectOneCall("flashWrite")
          .withParameter("buf", on)
          .withParameter("CALLS_ENABLE_START_ADDRESS", 9961512)
          .withParameter("len", 4)
          .withParameter("CALLS_ENABLE_NVID", 16)
          .andReturnValue(0);


         
            error_t appCallsEnableset = appcSystemSettingCallsEnableSet(on);

    // assert
    mock().checkExpectations();
    CHECK_EQUAL(0, appCallsEnableset);
   
}

/*TEST(AppCallsEnableset, simpleTest2)
{
uint8_t on =1;
uint8_t current_on;

mock().expectOneCall("flashRead")
          .withParameter("buf", current_on)
          .withParameter("CALLS_ENABLE_START_ADDRESS", 9961512)
          .withParameter("len", 4)
          .withParameter("CALLS_ENABLE_NVID", 16)
          .andReturnValue(0);
         
    mock().expectOneCall("flashWrite")
          .withParameter("buf", on)
          .withParameter("CALLS_ENABLE_START_ADDRESS", 9961512)
          .withParameter("len", 4)
          .withParameter("CALLS_ENABLE_NVID", 16)
          .andReturnValue(8);


            error_t appCallsEnableset = appcSystemSettingCallsEnableSet(on);

    // assert
    mock().checkExpectations();
    CHECK_EQUAL(255, appCallsEnableset);
   
}*/

Thanks,
Revati

Bas Vodde

unread,
Mar 1, 2023, 10:49:31 AM3/1/23
to cppu...@googlegroups.com

Hi,

It is not possible for anyone to answer that without showing the error or knowing the code.

Only thing I notice from the code you pasted is that the second test is commented out. So it is not likely to give an error :)

Bas


Revati Dharmadhikari

unread,
Mar 1, 2023, 11:35:40 PM3/1/23
to cpputest
Hi,
Yes It is same code with different return value That's why it is looking similar.
Reply all
Reply to author
Forward
0 new messages