CMock is designed to mock C functions and C++ static member methods. It does not mock non-static (instance) members; for those, you should use a dedicated C++ mocking framework.
Handling Multiple Definitions
When mixing CMock with a C++ framework, you may encounter multiple definition errors because the C++ framework might link the real object. To resolve this, use the weak attribute in your real implementation for any functions that CMock mocks:
#if defined(TEST)
__attribute__((weak))
#endif
Generated Function Naming
To avoid collisions with namespaces or classes, CMock generates function names by including the namespace and class hierarchy.
Example Mapping:
If you have:
namespace MyNamespace {
class MyClass {
static int DoesSomething(int a, int b);
};
}
CMock will generate:
void MyNamespace_MyClass_DoesSomething_ExpectAndReturn(int a, int b, int toReturn);
namespace MyNamespace {
class MyClass {
static int DoesSomething(int a, int b);
};
}
// Generates:
// void MyNamespace_MyClass_DoesSomething_ExpectAndReturn(int a, int b, int toReturn);