dimanche 22 mars 2020

GMOCK : need to mock async behaviour

bool Test::someFun() {
    if (libFunction([](bool b) {
            if (b) {
                doThisWork();
            } else {
                doThatWork();
            }
        })) {
        return true;
    } else return false;
}

signature of libFunction is:

typedef void (*FUN)(bool);
bool libFunction(FUN f);

Hi Guys, I need to test someFun function using Gtest/GMOCK. i need to mock libFunction which is written in C. this libFunction takes a callback(lambda) argument.

Could you please help me with below 2 queries.

  1. how to mock a C function (libFunction) ?
  2. how to test callback which is passed as argument to libFunction as my actual implementation is in lambda which is need to be tested. is there a way to replace libFunction definition with dummy definition so that at run time of test case my dummy implementation will call instead of actual one and i can simulate the libFunction behaviour in dummy function. Could to please suggest better way to test this.

Aucun commentaire:

Enregistrer un commentaire