{"id":13419375,"url":"https://github.com/meekrosoft/fff","last_synced_at":"2026-01-11T06:54:51.292Z","repository":{"id":40643715,"uuid":"1168299","full_name":"meekrosoft/fff","owner":"meekrosoft","description":"A testing micro framework for creating function test doubles","archived":false,"fork":false,"pushed_at":"2023-11-02T22:46:42.000Z","size":721,"stargazers_count":817,"open_issues_count":58,"forks_count":169,"subscribers_count":43,"default_branch":"master","last_synced_at":"2025-03-08T18:12:48.528Z","etag":null,"topics":["c","c-plus-plus","embedded","fake-functions","micro-framework","tdd"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meekrosoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2010-12-14T15:16:42.000Z","updated_at":"2025-03-08T07:36:05.000Z","dependencies_parsed_at":"2024-01-31T09:03:42.305Z","dependency_job_id":"185bee9a-382e-453d-bf0c-cff599af007d","html_url":"https://github.com/meekrosoft/fff","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meekrosoft%2Ffff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meekrosoft%2Ffff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meekrosoft%2Ffff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meekrosoft%2Ffff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meekrosoft","download_url":"https://codeload.github.com/meekrosoft/fff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243690113,"owners_count":20331726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-plus-plus","embedded","fake-functions","micro-framework","tdd"],"created_at":"2024-07-30T22:01:15.083Z","updated_at":"2026-01-11T06:54:51.243Z","avatar_url":"https://github.com/meekrosoft.png","language":"C","readme":"# Fake Function Framework  (fff)\n-----------------------------\n\n[![Build Status](https://travis-ci.org/meekrosoft/fff.svg?branch=master)](https://travis-ci.org/meekrosoft/fff)\n[![Build status](https://ci.appveyor.com/api/projects/status/md1gn8cxnjkrkq3b/branch/master?svg=true)](https://ci.appveyor.com/project/wulfgarpro/fff/branch/master)\n[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/wulfgarpro/fff?utm_source=share-link\u0026utm_medium=link\u0026utm_campaign=share-link)\n\n- [A Fake Function Framework for C](#a-fake-function-framework-for-c)\n- [Hello Fake World!](#hello-fake-world)\n- [Capturing Arguments](#capturing-arguments)\n- [Return Values](#return-values)\n- [Resetting a Fake](#resetting-a-fake)\n- [Call History](#call-history)\n- [Default Argument History](#default-argument-history)\n- [User Defined Argument History](#user-defined-argument-history)\n- [Function Return Value Sequences](#function-return-value-sequences)\n- [Custom Return Value Delegate](#custom-return-value-delegate)\n- [Return Value History](#return-value-history)\n- [Variadic Functions](#variadic-functions)\n- [Common Questions](#common-questions)\n- [Specifying GCC Function Attributes](#specifying-gcc-function-attributes)\n- [Find Out More](#find-out-more)\n- [Benefits](#benefits)\n- [Under the Hood](#under-the-hood)\n- [Cheat Sheet](#cheat-sheet)\n\n## A Fake Function Framework for C\nfff is a micro-framework for creating fake C functions for tests.  Because life\nis too short to spend time hand-writing fake functions for testing.\n\n## Running all tests\n\n### Linux / MacOS\nTo run all the tests and sample apps, simply call `$ buildandtest`. This script\nwill call down into CMake with the following:\n\n```shell\ncmake -B build -DFFF_GENERATE=ON -DFFF_UNIT_TESTING=ON\ncmake --build build\nctest --test-dir build --output-on-failure\n```\n\n## Hello Fake World!\n\nSay you are testing an embedded user interface and you have a function that\nyou want to create a fake for:\n\n```c\n// UI.c\n...\nvoid DISPLAY_init();\n...\n```\n\nHere's how you would define a fake function for this in your test suite:\n\n```c\n// test.c(pp)\n#include \"fff.h\"\nDEFINE_FFF_GLOBALS;\nFAKE_VOID_FUNC(DISPLAY_init);\n```\n\nAnd the unit test might look something like this:\n\n```c\nTEST_F(GreeterTests, init_initialises_display)\n{\n    UI_init();\n    ASSERT_EQ(DISPLAY_init_fake.call_count, 1);\n}\n```\n\nSo what has happened here?  The first thing to note is that the framework is\nheader only, all you need to do to use it is download `fff.h` and include\nit in your test suite.\n\nThe magic is in the `FAKE_VOID_FUNC`.  This\nexpands a macro that defines a function returning `void`\nwhich has zero arguments.  It also defines a struct\n`\"function_name\"_fake` which contains all the information about the fake.\nFor instance, `DISPLAY_init_fake.call_count`is incremented every time the faked\nfunction is called.\n\nUnder the hood it generates a struct that looks like this:\n\n```c\ntypedef struct DISPLAY_init_Fake {\n    unsigned int call_count;\n    unsigned int arg_history_len;\n    unsigned int arg_histories_dropped;\n    void(*custom_fake)();\n} DISPLAY_init_Fake;\nDISPLAY_init_Fake DISPLAY_init_fake;\n```\n\n## Capturing Arguments\n\nOk, enough with the toy examples.  What about faking functions with arguments?\n\n```c\n// UI.c\n...\nvoid DISPLAY_output(char * message);\n...\n```\n\nHere's how you would define a fake function for this in your test suite:\n\n```c\nFAKE_VOID_FUNC(DISPLAY_output, char *);\n```\n\nAnd the unit test might look something like this:\n\n```c\nTEST_F(UITests, write_line_outputs_lines_to_display)\n{\n    char msg[] = \"helloworld\";\n    UI_write_line(msg);\n    ASSERT_EQ(DISPLAY_output_fake.call_count, 1);\n    ASSERT_EQ(strncmp(DISPLAY_output_fake.arg0_val, msg, 26), 0);\n}\n```\n\n\nThere is no more magic here, the `FAKE_VOID_FUNC` works as in the\nprevious example.  The number of arguments that the function takes is calculated,\n and the macro arguments following the function name defines the argument\ntype (a char pointer in this example).\n\nA variable is created for every argument in the form\n`\"function_name\"fake.argN_val`\n\n## Return Values\n\nWhen you want to define a fake function that returns a value, you should use the\n`FAKE_VALUE_FUNC` macro.  For instance:\n\n```c\n// UI.c\n...\nunsigned int DISPLAY_get_line_capacity();\nunsigned int DISPLAY_get_line_insert_index();\n...\n```\n\nHere's how you would define fake functions for these in your test suite:\n\n```c\nFAKE_VALUE_FUNC(unsigned int, DISPLAY_get_line_capacity);\nFAKE_VALUE_FUNC(unsigned int, DISPLAY_get_line_insert_index);\n```\n\nAnd the unit test might look something like this:\n\n```c\nTEST_F(UITests, when_empty_lines_write_line_doesnt_clear_screen)\n{\n    // given\n    DISPLAY_get_line_insert_index_fake.return_val = 1;\n    char msg[] = \"helloworld\";\n    // when\n    UI_write_line(msg);\n    // then\n    ASSERT_EQ(DISPLAY_clear_fake.call_count, 0);\n}\n```\n\nOf course you can mix and match these macros to define a value function with\narguments, for instance to fake:\n\n```c\ndouble pow(double base, double exponent);\n```\n\nyou would use a syntax like this:\n\n```c\nFAKE_VALUE_FUNC(double, pow, double, double);\n```\n## Resetting a Fake\n\nGood tests are isolated tests, so it is important to reset the fakes for each\nunit test.  All the fakes have a reset function to reset their arguments and\ncall counts.  It is good practice is to call the reset function for all the\nfakes in the setup function of your test suite.\n\n```c\nvoid setup()\n{\n    // Register resets\n    RESET_FAKE(DISPLAY_init);\n    RESET_FAKE(DISPLAY_clear);\n    RESET_FAKE(DISPLAY_output_message);\n    RESET_FAKE(DISPLAY_get_line_capacity);\n    RESET_FAKE(DISPLAY_get_line_insert_index);\n}\n```\n\nYou might want to define a macro to do this:\n\n```c\n/* List of fakes used by this unit tester */\n#define FFF_FAKES_LIST(FAKE)            \\\n  FAKE(DISPLAY_init)                    \\\n  FAKE(DISPLAY_clear)                   \\\n  FAKE(DISPLAY_output_message)          \\\n  FAKE(DISPLAY_get_line_capacity)       \\\n  FAKE(DISPLAY_get_line_insert_index)\n\nvoid setup()\n{\n  /* Register resets */\n  FFF_FAKES_LIST(RESET_FAKE);\n\n  /* reset common FFF internal structures */\n  FFF_RESET_HISTORY();\n}\n```\n\n## Call History\nSay you want to test that a function calls functionA, then functionB, then\nfunctionA again, how would you do that?  Well fff maintains a call\nhistory so that it is easy to assert these expectations.\n\nHere's how it works:\n\n```c\nFAKE_VOID_FUNC(voidfunc2, char, char);\nFAKE_VALUE_FUNC(long, longfunc0);\n\nTEST_F(FFFTestSuite, calls_in_correct_order)\n{\n    longfunc0();\n    voidfunc2();\n    longfunc0();\n\n    ASSERT_EQ(fff.call_history[0], (void *)longfunc0);\n    ASSERT_EQ(fff.call_history[1], (void *)voidfunc2);\n    ASSERT_EQ(fff.call_history[2], (void *)longfunc0);\n}\n```\n\nThey are reset by calling `FFF_RESET_HISTORY();`\n\n## Default Argument History\n\nThe framework will by default store the arguments for the last ten calls made\nto a fake function.\n\n```c\nTEST_F(FFFTestSuite, when_fake_func_called_then_arguments_captured_in_history)\n{\n    voidfunc2('g', 'h');\n    voidfunc2('i', 'j');\n    ASSERT_EQ('g', voidfunc2_fake.arg0_history[0]);\n    ASSERT_EQ('h', voidfunc2_fake.arg1_history[0]);\n    ASSERT_EQ('i', voidfunc2_fake.arg0_history[1]);\n    ASSERT_EQ('j', voidfunc2_fake.arg1_history[1]);\n}\n```\n\nThere are two ways to find out if calls have been dropped.  The first is to\ncheck the dropped histories counter:\n\n```c\nTEST_F(FFFTestSuite, when_fake_func_called_max_times_plus_one_then_one_argument_history_dropped)\n{\n    int i;\n    for(i = 0; i \u003c 10; i++)\n    {\n        voidfunc2('1'+i, '2'+i);\n    }\n    voidfunc2('1', '2');\n    ASSERT_EQ(1u, voidfunc2_fake.arg_histories_dropped);\n}\n```\n\nThe other is to check if the call count is greater than the history size:\n\n```c\nASSERT(voidfunc2_fake.arg_history_len \u003c voidfunc2_fake.call_count);\n```\n\nThe argument histories for a fake function are reset when the `RESET_FAKE`\nfunction is called\n\n## User Defined Argument History\n\nIf you wish to control how many calls to capture for argument history you can\noverride the default by defining it before include the `fff.h` like this:\n\n```c\n// Want to keep the argument history for 13 calls\n#define FFF_ARG_HISTORY_LEN 13\n// Want to keep the call sequence history for 17 function calls\n#define FFF_CALL_HISTORY_LEN 17\n\n#include \"../fff.h\"\n```\n\n## Function Return Value Sequences\n\nOften in testing we would like to test the behaviour of sequence of function call\nevents.  One way to do this with fff is to specify a sequence of return values\nwith for the fake function.  It is probably easier to describe with an example:\n\n```c\n// faking \"long longfunc();\"\nFAKE_VALUE_FUNC(long, longfunc0);\n\nTEST_F(FFFTestSuite, return_value_sequences_exhausted)\n{\n    long myReturnVals[3] = { 3, 7, 9 };\n    SET_RETURN_SEQ(longfunc0, myReturnVals, 3);\n    ASSERT_EQ(myReturnVals[0], longfunc0());\n    ASSERT_EQ(myReturnVals[1], longfunc0());\n    ASSERT_EQ(myReturnVals[2], longfunc0());\n    ASSERT_EQ(myReturnVals[2], longfunc0());\n    ASSERT_EQ(myReturnVals[2], longfunc0());\n}\n```\n\nBy specifying a return value sequence using the `SET_RETURN_SEQ` macro,\nthe fake will return the values given in the parameter array in sequence.  When\nthe end of the sequence is reached the fake will continue to return the last\nvalue in the sequence indefinitely.\n\n## Custom Return Value Delegate\n\nYou can specify your own function to provide the return value for the fake. This\nis done by setting the `custom_fake` member of the fake.  Here's an example:\n\n```c\n#define MEANING_OF_LIFE 42\nlong my_custom_value_fake(void)\n{\n    return MEANING_OF_LIFE;\n}\nTEST_F(FFFTestSuite, when_value_custom_fake_called_THEN_it_returns_custom_return_value)\n{\n    longfunc0_fake.custom_fake = my_custom_value_fake;\n    long retval = longfunc0();\n    ASSERT_EQ(MEANING_OF_LIFE, retval);\n}\n```\n\n### Custom Return Value Delegate Sequences\n\nSay you have a function with an out parameter, and you want it to have a different behaviour\non the first three calls, for example: set the value 'x' to the out parameter on the first call,\nthe value 'y' to the out parameter on the second call, and the value 'z' to the out parameter\non the third call. You can specify a sequence of custom functions to a non-variadic function\nusing the `SET_CUSTOM_FAKE_SEQ` macro. Here's an example:\n\n```c\nvoid voidfunc1outparam_custom_fake1(char *a)\n{\n    *a = 'x';\n}\n\nvoid voidfunc1outparam_custom_fake2(char *a)\n{\n    *a = 'y';\n}\n\nvoid voidfunc1outparam_custom_fake3(char *a)\n{\n    *a = 'z';\n}\n\nTEST_F(FFFTestSuite, custom_fake_sequence_not_exausthed)\n{\n    void (*custom_fakes[])(char *) = {voidfunc1outparam_custom_fake1,\n                                      voidfunc1outparam_custom_fake2,\n                                      voidfunc1outparam_custom_fake3};\n    char a = 'a';\n\n    SET_CUSTOM_FAKE_SEQ(voidfunc1outparam, custom_fakes, 3);\n\n    voidfunc1outparam(\u0026a);\n    ASSERT_EQ('x', a);\n    voidfunc1outparam(\u0026a);\n    ASSERT_EQ('y', a);\n    voidfunc1outparam(\u0026a);\n    ASSERT_EQ('z', a);\n}\n```\n\nThe fake will call your custom functions in the order specified by the `SET_CUSTOM_FAKE_SEQ`\nmacro. When the last custom fake is reached the fake will keep calling the last custom\nfake in the sequence. This macro works much like the `SET_RETURN_SEQ` macro.\n\n## Return Value History\n\nSay you have two functions f1 and f2. f2 must be called to release some resource\nallocated by f1, but only in the cases where f1 returns zero. f1 could be\npthread_mutex_trylock and f2 could be pthread_mutex_unlock. fff will\nsave the history of returned values so this can be easily checked, even when\nyou use a sequence of custom fakes. Here's a simple example:\n\n    TEST_F(FFFTestSuite, return_value_sequence_saved_in_history)\n    {\n        long myReturnVals[3] = { 3, 7, 9 };\n        SET_RETURN_SEQ(longfunc0, myReturnVals, 3);\n        longfunc0();\n        longfunc0();\n        longfunc0();\n        ASSERT_EQ(myReturnVals[0], longfunc0_fake.return_val_history[0]);\n        ASSERT_EQ(myReturnVals[1], longfunc0_fake.return_val_history[1]);\n        ASSERT_EQ(myReturnVals[2], longfunc0_fake.return_val_history[2]);\n    }\n\nYou access the returned values in the `return_val_history` field.\n\n## Variadic Functions\n\nYou can fake variadic functions using the macros `FAKE_VALUE_FUNC_VARARG`\nand `FAKE_VOID_FUNC_VARARG`. For instance:\n\n    FAKE_VALUE_FUNC_VARARG(int, fprintf, FILE *, const char*, ...);\n\nIn order to access the variadic parameters from a custom fake function, declare a\n`va_list` parameter. For instance, a custom fake for `fprintf()`\ncould call the real `fprintf()` like this:\n\n    int fprintf_custom(FILE *stream, const char *format, va_list ap) {\n      if (fprintf0_fake.return_val \u003c 0) // should we fail?\n        return fprintf0_fake.return_val;\n      return vfprintf(stream, format, ap);\n    }\n\nJust like  [return value delegates](#custom-return-value-delegate-sequences), you can also specify sequences for variadic functions using `SET_CUSTOM_FAKE_SEQ`.\nSee the test files for examples.\n\n## Common Questions\n\n### How do I specify calling conventions for my fake functions?\n\nfff has a limited capability for enabling specification of Microsoft's Visual C/C++ calling conventions, but this support must be enabled when generating fff's header file `fff.h`.\n\n```bash\nruby fakegen.rb --with-calling-conventions \u003e fff.h\n```\n\nBy enabling this support, all of fff's fake function scaffolding will necessitate the specification of a calling convention, e.g. `__cdecl` for each VALUE or VOID fake.\n\nHere are some basic examples: take note that the placement of the calling convention being specified is different depending on whether the fake is a VOID or VALUE function.\n\n```c\nFAKE_VOID_FUNC(__cdecl, voidfunc1, int);\nFAKE_VALUE_FUNC(long, __cdecl, longfunc0);\n```\n\n### How do I fake a function that returns a value by reference?\n\nThe basic mechanism that fff provides you in this case is the custom_fake field described in the *Custom Return Value Delegate* example above.\n\nYou need to create a custom function (e.g. getTime_custom_fake) to produce the output optionally by use of a helper variable (e.g. getTime_custom_now) to retrieve that output from. Then some creativity to tie it all together. The most important part (IMHO) is to keep your test case readable and maintainable.\n\nIn case your project uses a C compiler that supports nested functions (e.g. GCC), or when using C++ lambdas, you can even combine all this in a single unit test function so you can easily oversee all details of the test.\n\n```c\n#include \u003cfunctional\u003e\n\n/* Configure FFF to use std::function, which enables capturing lambdas */\n#define CUSTOM_FFF_FUNCTION_TEMPLATE(RETURN, FUNCNAME, ...) \\\n    std::function\u003cRETURN (__VA_ARGS__)\u003e FUNCNAME\n\n#include \"fff.h\"\n\n/* The time structure */\ntypedef struct {\n   int hour, min;\n} Time;\n\n/* Our fake function */\nFAKE_VOID_FUNC(getTime, Time*);\n\n/* A test using the getTime fake function */\nTEST_F(FFFTestSuite, when_value_custom_fake_called_THEN_it_returns_custom_output)\n{\n    Time t;\n    Time getTime_custom_now = {\n        .hour = 13,\n        .min = 05,\n    };\n    getTime_fake.custom_fake = [getTime_custom_now](Time *now) {\n      *now = getTime_custom_now;\n    };\n\n    /* when getTime is called */\n    getTime(\u0026t);\n\n    /* then the specific time must be produced */\n    ASSERT_EQ(t.hour, 13);\n    ASSERT_EQ(t.min,  05);\n}\n```\n\n### How do I fake a function with a function pointer parameter?\n\nUsing fff to stub functions that have function pointer parameter can cause problems when trying to stub them. Presented here is an example how to deal with this situation.\n\nIf you need to stub a function that has a function pointer parameter, e.g. something like:\n\n```c\n/* timer.h */\ntypedef int timer_handle;\nextern int timer_start(timer_handle handle, long delay, void (*cb_function) (int arg), int arg);\n```\n\nThen creating a fake like below will horribly fail when trying to compile because the fff macro will internally expand into an illegal variable ```int (*)(int) arg2_val```.\n\n```c\n/* The fake, attempt one */\nFAKE_VALUE_FUNC(int,\n                timer_start,\n                timer_handle,\n                long,\n                void (*) (int argument),\n                int);\n```\n\nThe solution to this problem is to create a bridging type that needs only to be visible in the unit tester. The fake will use that intermediate type. This way the compiler will not complain because the types match.\n\n```c\n/* Additional type needed to be able to use callback in fff */\ntypedef void (*timer_cb) (int argument);\n\n/* The fake, attempt two */\nFAKE_VALUE_FUNC(int,\n                timer_start,\n                timer_handle,\n                long,\n                timer_cb,\n                int);\n```\n\nHere are some ideas how to create a test case with callbacks.\n\n```c\n/* Unit test */\nTEST_F(FFFTestSuite, test_fake_with_function_pointer)\n{\n    int cb_timeout_called = 0;\n    int result = 0;\n\n    void cb_timeout(int argument)\n    {\n      cb_timeout_called++;\n    }\n\n    int timer_start_custom_fake(timer_handle handle,\n                          long delay,\n                          void (*cb_function) (int arg),\n                          int arg)\n    {\n      if (cb_function) cb_function(arg);\n      return timer_start_fake.return_val;\n    }\n\n    /* given the custom fake for timer_start */\n    timer_start_fake.return_val = 33;\n    timer_start_fake.custom_fake = timer_start_custom_fake;\n\n    /* when timer_start is called\n     * (actually you would call your own function-under-test\n     *  that would then call the fake function)\n     */\n    result = timer_start(10, 100, cb_timeout, 55);\n\n    /* then the timer_start fake must have been called correctly */\n    ASSERT_EQ(result, 33);\n    ASSERT_EQ(timer_start_fake.call_count, 1);\n    ASSERT_EQ(timer_start_fake.arg0_val,   10);\n    ASSERT_EQ(timer_start_fake.arg1_val,   100);\n    ASSERT_EQ(timer_start_fake.arg2_val,   cb_timeout); /* callback provided by unit tester */\n    ASSERT_EQ(timer_start_fake.arg3_val,   55);\n\n    /* and ofcourse our custom fake correctly calls the registered callback */\n    ASSERT_EQ(cb_timeout_called, 1);\n}\n```\n\n### How do I reuse a fake across multiple test-suites?\n\nfff functions like `FAKE_VALUE_FUNC` will perform both the declaration AND the definition of the fake function and the corresponding data structs. This cannot be placed in a header, since it will lead to multiple definitions of the fake functions.\n\nThe solution is to separate declaration and definition of the fakes, and place the declaration into a public header file, and the definition into a private source file.\n\nHere is an example of how it could be done:\n\n```c\n/* Public header file */\n#include \"fff.h\"\n\nDECLARE_FAKE_VALUE_FUNC(int, value_function, int, int);\nDECLARE_FAKE_VOID_FUNC(void_function, int, int);\nDECLARE_FAKE_VALUE_FUNC_VARARG(int, value_function_vargs, const char *, int, ...);\nDECLARE_FAKE_VOID_FUNC_VARARG(void_function_vargs, const char *, int, ...);\n\n\n/* Private source file file */\n#include \"public_header.h\"\n\nDEFINE_FAKE_VALUE_FUNC(int, value_function, int, int);\nDEFINE_FAKE_VOID_FUNC(void_function, int, int);\nDEFINE_FAKE_VALUE_FUNC_VARARG(int, value_function_vargs, const char *, int, ...);\nDEFINE_FAKE_VOID_FUNC_VARARG(void_function_vargs, const char *, int, ...);\n\n```\n\n## Specifying GCC Function Attributes\n\nYou can specify GCC function attributes for your fakes using the `FFF_GCC_FUNCTION_ATTRIBUTES` directive.\n\n### Weak Functions\n\nOne usful attribute is the _weak_ attribute that marks a function such that it can be overridden by a non-weak variant at link time.  Using weak functions in combination with fff can help simplify your testing approach.\n\nFor example:\n* Define a library of fake functions, e.g. libfake.a.\n* Link a binary (you might have many) that defines a subset of real variants of the fake functions to the aforementioned fake library.\n* This has the benefit of allowing a binary to selectively use a subset of the required fake functions while testing the real variants without the need for many different make targets.\n\nYou can mark all fakes with the weak attribute like so:\n```\n#define FFF_GCC_FUNCTION_ATTRIBUTES __attribute__((weak))\n#include \"fff.h\"\n```\n\nSee the example project that demonstrates the above approach: _./examples/weak_linking_.\n\n## Find Out More\n\nLook under the examples directory for full length examples in both C and C++.\nThere is also a test suite for the framework under the test directory.\n\n-------------------------\n\n## Benefits\nSo whats the point?\n\n * To make it easy to create fake functions for testing C code.\n * It is simple - just include a header file and you are good to go.\n * To work in both C and C++ test environments\n\n\n## Under the Hood\n * The fff.h header file is generated by a ruby script\n * There are tests under _./test_\n * There is an example for testing an embedded UI and a hardware driver under _./examples_\n * There is an example of weak_linking under _./examples_\n\n\n## Cheat Sheet\n| Macro | Description | Example |\n|-------|-------------|---------|\n| FAKE_VOID_FUNC(fn [,arg_types*]); | Define a fake function named fn returning void with n arguments | FAKE_VOID_FUNC(DISPLAY_output_message, const char*); |\n| FAKE_VALUE_FUNC(return_type, fn [,arg_types*]); | Define a fake function returning a value with type return_type taking n arguments | FAKE_VALUE_FUNC(int, DISPLAY_get_line_insert_index); |\n| FAKE_VOID_FUNC_VARARG(fn [,arg_types*], ...); | Define a fake variadic function returning void with type return_type taking n arguments and n variadic arguments | FAKE_VOID_FUNC_VARARG(fn, const char*, ...) |\n| FAKE_VALUE_FUNC_VARARG(return_type, fn [,arg_types*], ...); | Define a fake variadic function returning a value with type return_type taking n arguments and n variadic arguments | FAKE_VALUE_FUNC_VARARG(int, fprintf, FILE*, const char*, ...) |\n| RESET_FAKE(fn); | Reset the state of fake function called fn | RESET_FAKE(DISPLAY_init); |\n","funding_links":[],"categories":["TODO scan for Android support in followings","Debug","C++","Test Frameworks","Testing"],"sub_categories":["Mocking and Hardware Simulation","Unit tests"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeekrosoft%2Ffff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeekrosoft%2Ffff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeekrosoft%2Ffff/lists"}