In the Cookbook.md file, section for mocking free functions, in the example header, it needs the test framework header and the trompeloeil header. So it needs to change from this
// unit-test-C-API.h
#include "C-API.h"
class API
:
:
to this (catch2 example)
// unit-test-C-API.h
#include <catch2/catch_test_macros.hpp>
#include <catch2/trompeloeil.hpp> /* this should go last */
#include "C-API.h"
class API
:
:
Then in the c file there is a typo:
// unit-test_c_api.cpp
#include "unit-test-C-API.h"
API c_api_mock;
extern "C" {
c_api_cookie c_api_init()
{
return api_mock.c_api_init(); // <----- here it should be c_api_mock instead of api_mock
}
int c_api_func1(c_api_cookie* cookie, const char* str, size_t len)
{
return api_mock.c_api_func1(cookie, str, len); // <----- here it should be c_api_mock instead of api_mock
}
void c_api_end(c_api_cookie* cookie)
{
api_mock.c_api_end(cookie); // <----- here it should be c_api_mock instead of api_mock
}
}
In the Cookbook.md file, section for mocking free functions, in the example header, it needs the test framework header and the trompeloeil header. So it needs to change from this
to this (catch2 example)
Then in the c file there is a typo: