jgonzalezdr / cppumockgen Goto Github PK
View Code? Open in Web Editor NEWMock generator for CppUTest/CppUMock
License: BSD 3-Clause "New" or "Revised" License
Mock generator for CppUTest/CppUMock
License: BSD 3-Clause "New" or "Revised" License
In the follow code, the auto generated .cpp code doesn't include the ellipses from the function prototype, causing the code to not compile with a "no matching function defined" error
h/Log.h:
class CLog
{
static void Error (int32_t Module, const char_t *pMessage, ...)
};
mock/Log.CPP:
void Log::Error(int32_t Module, const char_t * pMessage) // missing **, ...**
{
mock().actualCall("Log::Error").withIntParameter("Module", Module).withConstPointerParameter("pMessage", pMessage);
}
libclang.dll is missing from the zipped / install packages, thus making those unusable if no libclang is already installed in the host.
Could the executable file be statically linked or libclang.dll distributed with the executable file?
Is there any way to support volatile variables with the expectations, g++ complains about it. I'm testing embedded code and have several functions like the following:
void word_write(volatile unsigned short *port_ptr, unsigned short value);
Thanks
Daniel
Could you change the expect generated from:
namespace expect {
namespace namespace1$ {
namespace class6$ {
MockExpectedCall& method1(CppUMockGen::Parameter<const namespace1::class6*> __object__, CppUMockGen::Parameter<const char*> p1, CppUMockGen::Parameter<int> p2)
{
bool __ignoreOtherParams__ = false;
MockExpectedCall& __expectedCall__ = mock().expectOneCall("namespace1::class6::method1");
mock().setData("namespace1::class6::method1__object___isIgnored", __object__.isIgnored());
if (!__object__.isIgnored()) { __expectedCall__.onObject(const_cast<namespace1::class6*>(__object__.getValue())); }
if (p1.isIgnored()) { __ignoreOtherParams__ = true; }
else { __expectedCall__.withStringParameter("p1", p1.getValue()); }
if (p2.isIgnored()) { __ignoreOtherParams__ = true; }
else { __expectedCall__.withIntParameter("p2", p2.getValue()); }
if (__ignoreOtherParams__) { __expectedCall__.ignoreOtherParameters(); }
return __expectedCall__;
}
}
}
}
To the following:
namespace expect {
namespace namespace1$ {
namespace class6$ {
MockExpectedCall& method1(CppUMockGen::Parameter<const namespace1::class6*> __object__, CppUMockGen::Parameter<const char*> p1, CppUMockGen::Parameter<int> p2)
{
return method1(1, __object, p1, p2);
}
}
}
}
To take advantage of the code already generated for the "numCalls".
First off, thank you for this wonderful tool. It is excellent and will save us a lot of time creating and maintaining mocks!
Sometimes the TESTs we write have no control over the mock's object instance. Only the unit under test does. So there is a need to ignore the class's object instance check. However, I am seeing a problem attempting to skip the object check. For example:
`
// class6.h
namespace namespace1
{
class class6
{
public:
void method1(const char* p1, int p2);
};
}
// class6.cpp
/*
#include
#include "class6.h"
namespace namespace1
{
void class6::method1(const char* p1, int p2)
{
if ((strcmp(p1, "hello") == 0) && (p2 == 42))
{
// do something
}
}
}*/
// class6_mock.cpp
/*
// class6_expect.hpp
/*
// class6_expect.cpp
/*
void unit_under_test(const char* p1, int p2)
{
namespace1::class6 class6_object_instance;
class6_object_instance.method1(p1, p2);
}
TEST_GROUP(class6)
{
void setup() {}
void teardown() { mock().clear(); }
};
TEST(class6, method1_check_object)
{
namespace1::class6 class6_mock;
expect::namespace1$::class6$::method1(&class6_mock, "hello", 42);
class6_mock.method1("hello", 42);
mock().checkExpectations();
}
TEST(class6, method1_ignore_object)
{
// The unit under test controls the lifecycle of the mock object so ignore the object parameter!
expect::namespace1$::class6$::method1(CppUMockGen::IgnoreParameter::YES, "hello", 42);
unit_under_test("hello", 42); // <-- EXCEPTION here!
mock().checkExpectations();
}
/*
Failure in TEST(class6, method1_ignore_object)
MockFailure: Function called on an unexpected object: namespace1::class6::method1
Actual object for call has address: <007FE96B>
EXPECTED calls that DID NOT happen related to function: namespace1::class6::method1
namespace1::class6::method1 -> const char* p1: , int p2: <42>
ACTUAL calls that DID happen related to function: namespace1::class6::method1
..
Errors (1 failures, 2 tests, 2 ran, 2 checks, 0 ignored, 0 filtered out, 24 ms)
*/
`
I used your example in the documentation page, "namespace1::class6::method", to generate the class6 mock.
Hello
I cannot build it in ArchLinux with clang 12.0.0
Some ideas?
Hi,
could you create a conan recipe for CppUMockgGen?
http://conan.io/
See also
https://github.com/cpputest/cpputest
and
https://github.com/cpputest/conan-cpputest
Hi
First of all, thank you for your effort.
I noted that the application is not able to manage a function definition in another included header file.
//file1.h
#include file2.h
//file2.h
void foo(int bar);
Run-> CppUMockGen.exe -i file1.h -m
it return an error.
Regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.