Comments (7)
Looks like the VAARG mock requires at least one arg. Have you tried letting the format string be the first arg -- i.e. something like this:
DECLARE_FAKE_VALUE_FUNC_VARARG(int, printf, ...);
int mock_printf(va_list arg)
{
int result = vfprintf(stdout, arg);
fprintf(stdout, "Goodbye\n");
return(result);
}
from fff.
@CanadianHoser, have you attempted @cormacc's suggestion?
from fff.
The suggestion by @cormacc won't work because it doesn't match the vfprintf prototype:
printf_test.cpp:12:38: error: too few arguments to function βint vfprintf(FILE*, const char*, __gnuc_va_list)β
int result = vfprintf(stdout, arg);
from fff.
I do think there's something to our system implementation. The code listed above does perform as expected (Tests 1 and 2 are suppressed, 3 & 4 are displayed) when compiled standalone, but the same code integrated into our much larger code base (which overrides printf elsewhere) behaves as indicated above. I did try putting put the mock_printf() implementation into a separate .c file to confirm it's not a compiler difference.
from fff.
@CanadianHoser, it looks like the generator for VARARG fakes, only generates N=2-20:
define FAKE_VALUE_FUNC2_VARARG(RETURN_TYPE, FUNCNAME, ARG0_TYPE, ...) \
DECLARE_FAKE_VALUE_FUNC2_VARARG(RETURN_TYPE, FUNCNAME, ARG0_TYPE, ...) \
DEFINE_FAKE_VALUE_FUNC2_VARARG(RETURN_TYPE, FUNCNAME, ARG0_TYPE, ...) \
We could probably manage N=1 for these kinds of situtations:
define FAKE_VALUE_FUNC1_VARARG(RETURN_TYPE, FUNCNAME, ARG0_TYPE) \
...
I'll see if I can put together a patch over the next couple of days.
from fff.
It seems you're just declaring the mock, but not defining it. You either have to use FAKE_VALUE_FUNC_VARARG
, which directly defines your mock function, or use the pair DEFINE_FAKE_VALUE_FUNC_VARARG
/DECLARE_FAKE_VALUE_FUNC_VARARG
if you want to split the declaration/definition.
from fff.
Hi @wulfgarpro, @rubiot:
I am having a similar issue with fprintf mocking, In the below code I tried to mock the fprintf from the standard library, unless I provided at least two parameters in the varArg list, the mocked fprintf is not being called, So the SampleTestPass will successfully call the mock fprintf function but the SampleTestFAIL will never call the mock function instead it calls the fprintf from the standard library as only one argument is provided in the varArgList.
can someone suggest what I am doing wrong:
#include "unity.h"
#include "unity_fixture.h"
#include "fff.h"
DEFINE_FFF_GLOBALS;
FAKE_VALUE_FUNC_VARARG(int, fprintf, FILE *, const char *, ...);
// This test will call the mocked fprintf
TEST(SampleTestGroup, SampleTestPass)
{
FILE * fd = fopen("/dev/stdout", "w");
fprintf(fd,"%s, %s", "first_var_arg", "second_var_arg");
printf("Datla-> (%s)", fprintf_fake.arg1_val); // This will print "Datla -> (%s, %s)"
TEST_FAIL(); // comment this line if needed
}
// This test will fail to call the mocked fprintf
TEST(SampleTestGroup, SampleTestFAIL)
{
FILE * fd = fopen("/dev/stdout", "w");
fprintf(fd,"%s", "first_var_arg");
printf("Datla-> (%s)", fprintf_fake.arg1_val); // This will print "Datla -> (null)" as mocked fprintf is not called
TEST_FAIL(); // comment this line if needed
}
TEST_GROUP_RUNNER(SampleTestGroup)
{
RUN_TEST_CASE(SampleTestGroup, SampleTestPass);
RUN_TEST_CASE(SampleTestGroup, SampleTestFAIL);
}
static void RunAllTests() {
RUN_TEST_GROUP(SampleTestGroup);
}
/**
* @brief Main entry point
*/
int main(int argc, char const *argv[])
{
return UnityMain(argc, argv, RunAllTests);
}
I am wondering why the SampleTestFAIL is not calling the mocked fprintf.
from fff.
Related Issues (20)
- fatal error: 'tr1/tuple' file not found HOT 1
- SET_RETURN_SEQ should reset return_val_seq_idx HOT 1
- Can FFF be used to generate the actual fake implementation?
- Argument history storing derefenced pointers HOT 1
- warning: ISO C99 requires at least one argument for the "..." in a variadic macro HOT 1
- Is it possible to mock static functions? HOT 1
- #pragma pack(1) breaks Function Return Value Sequences HOT 1
- How to install and to use? HOT 3
- Allow support for std::function as the `custom_fake` type HOT 1
- Linking issue in the example project HOT 1
- fake.callcount is always 0 when reuse a fake across multiple test-suites HOT 5
- FFF generated reset functions have mangled names HOT 2
- C++ Support for FFF Framework HOT 1
- Question: Releases and project maintenance
- Mocking static methods of the class HOT 3
- Is there a forum or fff community page for answering questions? HOT 2
- Unable to reuse fakes across multiple test modules HOT 1
- MVSC linking error multiple modules - How do I reuse a fake across multiple test-suites? HOT 2
- Alternating fff with real functions to access the hardware HOT 2
- Use of fff to mock c++ class member functions HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fff.