Browse files

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

  • Loading branch information...
1 parent 01aebe4 commit e34f577a4f692c9e5320e7f9507183a2b66889f9 @meekrosoft committed Apr 26, 2011
Showing with 95 additions and 17 deletions.
  1. +53 −1 fakegen.rb
  2. +33 −8 fff.h
  3. +6 −5 test/fff_test_c.c
  4. +3 −3 test/fff_test_cpp.cpp
View
54 fakegen.rb
@@ -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
View
41 fff.h
@@ -1,14 +1,14 @@
#ifndef FAKE_FUNCTIONS
#define FAKE_FUNCTIONS
-#ifdef __cplusplus
#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
+#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
11 test/fff_test_c.c
@@ -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
6 test/fff_test_cpp.cpp
@@ -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
{

0 comments on commit e34f577

Please sign in to comment.