1
0
mirror of https://github.com/meekrosoft/fff synced 2026-01-23 00:15:59 +01:00

New feature: no longer need to specify argument count in the declaration

This commit is contained in:
Mike Long
2011-04-26 17:20:48 +01:00
parent 01aebe40e0
commit e34f577a4f
4 changed files with 95 additions and 17 deletions

View File

@@ -223,9 +223,60 @@ def include_guard
puts "#endif // FAKE_FUNCTIONS"
end
def output_macro_counting_shortcuts
puts <<-MACRO_COUNTING
#define PP_NARG_MINUS2(...) \
PP_NARG_MINUS2_(__VA_ARGS__, PP_RSEQ_N_MINUS2())
#define PP_NARG_MINUS2_(...) \
PP_ARG_MINUS2_N(__VA_ARGS__)
#define PP_ARG_MINUS2_N(returnVal, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
#define PP_RSEQ_N_MINUS2() \
9,8,7,6,5,4,3,2,1,0
#define FAKE_VALUE_FUNC(...) \
FUNC_VALUE_(PP_NARG_MINUS2(__VA_ARGS__), __VA_ARGS__)
#define FUNC_VALUE_(N,...) \
FUNC_VALUE_N(N,__VA_ARGS__)
#define FUNC_VALUE_N(N,...) \
FAKE_VALUE_FUNC ## N(__VA_ARGS__)
#define PP_NARG_MINUS1(...) \
PP_NARG_MINUS1_(__VA_ARGS__, PP_RSEQ_N_MINUS1())
#define PP_NARG_MINUS1_(...) \
PP_ARG_MINUS1_N(__VA_ARGS__)
#define PP_ARG_MINUS1_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
#define PP_RSEQ_N_MINUS1() \
9,8,7,6,5,4,3,2,1,0
#define FAKE_VOID_FUNC(...) \
FUNC_VOID_(PP_NARG_MINUS1(__VA_ARGS__), __VA_ARGS__)
#define FUNC_VOID_(N,...) \
FUNC_VOID_N(N,__VA_ARGS__)
#define FUNC_VOID_N(N,...) \
FAKE_VOID_FUNC ## N(__VA_ARGS__)
MACRO_COUNTING
end
def output_c_and_cpp
include_guard {
output_constants
puts "#ifdef __cplusplus"
$cpp_output = true
yield
@@ -235,12 +286,13 @@ def output_c_and_cpp
$cpp_output = false
yield
puts "#endif /* cpp/ansi c */"
output_macro_counting_shortcuts
}
end
# lets generate!!
output_c_and_cpp{
output_constants
define_reset_fake
define_call_history
define_return_sequence

41
fff.h
View File

@@ -1,7 +1,6 @@
#ifndef FAKE_FUNCTIONS
#define FAKE_FUNCTIONS
#ifdef __cplusplus
#define FFF_MAX_ARGS (10u)
#ifndef FFF_ARG_HISTORY_LEN
#define FFF_ARG_HISTORY_LEN (50u)
@@ -9,6 +8,7 @@
#ifndef FFF_CALL_HISTORY_LEN
#define FFF_CALL_HISTORY_LEN (50u)
#endif
#ifdef __cplusplus
/* Defining a function to reset a fake function */
#define RESET_FAKE(FUNCNAME) { \
@@ -1320,13 +1320,6 @@ extern "C"{ \
STATIC_INIT(FUNCNAME) \
#else /* ansi c */
#define FFF_MAX_ARGS (10u)
#ifndef FFF_ARG_HISTORY_LEN
#define FFF_ARG_HISTORY_LEN (50u)
#endif
#ifndef FFF_CALL_HISTORY_LEN
#define FFF_CALL_HISTORY_LEN (50u)
#endif
/* Defining a function to reset a fake function */
#define RESET_FAKE(FUNCNAME) { \
@@ -2555,4 +2548,36 @@ static void RESET_HISTORY() {
#endif /* cpp/ansi c */
#define PP_NARG_MINUS2(...) PP_NARG_MINUS2_(__VA_ARGS__, PP_RSEQ_N_MINUS2())
#define PP_NARG_MINUS2_(...) PP_ARG_MINUS2_N(__VA_ARGS__)
#define PP_ARG_MINUS2_N(returnVal, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
#define PP_RSEQ_N_MINUS2() 9,8,7,6,5,4,3,2,1,0
#define FAKE_VALUE_FUNC(...) FUNC_VALUE_(PP_NARG_MINUS2(__VA_ARGS__), __VA_ARGS__)
#define FUNC_VALUE_(N,...) FUNC_VALUE_N(N,__VA_ARGS__)
#define FUNC_VALUE_N(N,...) FAKE_VALUE_FUNC ## N(__VA_ARGS__)
#define PP_NARG_MINUS1(...) PP_NARG_MINUS1_(__VA_ARGS__, PP_RSEQ_N_MINUS1())
#define PP_NARG_MINUS1_(...) PP_ARG_MINUS1_N(__VA_ARGS__)
#define PP_ARG_MINUS1_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
#define PP_RSEQ_N_MINUS1() 9,8,7,6,5,4,3,2,1,0
#define FAKE_VOID_FUNC(...) FUNC_VOID_(PP_NARG_MINUS1(__VA_ARGS__), __VA_ARGS__)
#define FUNC_VOID_(N,...) FUNC_VOID_N(N,__VA_ARGS__)
#define FUNC_VOID_N(N,...) FAKE_VOID_FUNC ## N(__VA_ARGS__)
#endif // FAKE_FUNCTIONS

View File

@@ -25,11 +25,11 @@ struct MyStruct {
int y;
};
FAKE_VOID_FUNC1(voidfunc1, int);
FAKE_VOID_FUNC2(voidfunc2, char, char);
FAKE_VALUE_FUNC0(long, longfunc0);
FAKE_VALUE_FUNC0(enum MYBOOL, enumfunc0);
FAKE_VALUE_FUNC0(struct MyStruct, structfunc0);
FAKE_VOID_FUNC(voidfunc1, int);
FAKE_VOID_FUNC(voidfunc2, char, char);
FAKE_VALUE_FUNC(long, longfunc0);
FAKE_VALUE_FUNC(enum MYBOOL, enumfunc0);
FAKE_VALUE_FUNC(struct MyStruct, structfunc0);
void setup()
@@ -254,6 +254,7 @@ TEST_F(FFFTestSuite, default_constants_can_be_overridden)
ASSERT_EQ(OVERRIDE_ARG_HIST_LEN, voidfunc2_arg_history_len);
}
int main()
{
setbuf(stdout, NULL);

View File

@@ -15,9 +15,9 @@
#include "../fff.h"
#include <gtest/gtest.h>
FAKE_VOID_FUNC1(voidfunc1, int);
FAKE_VOID_FUNC2(voidfunc2, char, char);
FAKE_VALUE_FUNC0(long, longfunc0);
FAKE_VOID_FUNC(voidfunc1, int);
FAKE_VOID_FUNC(voidfunc2, char, char);
FAKE_VALUE_FUNC(long, longfunc0);
class FFFTestSuite: public testing::Test
{