From a31a9ee38c8e827582620c5a950164bbdf831f86 Mon Sep 17 00:00:00 2001 From: James Fraser Date: Fri, 16 Nov 2018 01:55:00 +1100 Subject: [PATCH 1/4] Added support for specifying calling conventions. --- .gitignore | 33 +++ README.md | 16 ++ fakegen.rb | 193 ++++++++++-------- test/fff_test_c.c | 15 +- test/fff_test_cpp.cpp | 12 +- test/global_fakes.c | 17 ++ test/global_fakes.h | 18 +- test/ms_vc_fff_test/fff/fff.vcxproj | 140 +++++++++++++ test/ms_vc_fff_test/fff/fff.vcxproj.filters | 22 ++ test/ms_vc_fff_test/gtest/gtest.vcxproj | 163 +++++++++++++++ .../gtest/gtest.vcxproj.filters | 30 +++ test/ms_vc_fff_test/ms_vc_fff_test.sln | 93 +++++++++ .../ms_vc_fff_test_c/ms_vc_fff_test_c.vcxproj | 150 ++++++++++++++ .../ms_vc_fff_test_c.vcxproj.filters | 30 +++ .../ms_vc_fff_test_cpp.vcxproj | 154 ++++++++++++++ .../ms_vc_fff_test_cpp.vcxproj.filters | 30 +++ .../ms_vc_fff_test_global_c.vcxproj | 147 +++++++++++++ .../ms_vc_fff_test_global_c.vcxproj.filters | 36 ++++ .../ms_vc_fff_test_global_cpp.vcxproj | 149 ++++++++++++++ .../ms_vc_fff_test_global_cpp.vcxproj.filters | 36 ++++ test/test_cases.include | 9 +- 21 files changed, 1402 insertions(+), 91 deletions(-) create mode 100644 test/ms_vc_fff_test/fff/fff.vcxproj create mode 100644 test/ms_vc_fff_test/fff/fff.vcxproj.filters create mode 100644 test/ms_vc_fff_test/gtest/gtest.vcxproj create mode 100644 test/ms_vc_fff_test/gtest/gtest.vcxproj.filters create mode 100644 test/ms_vc_fff_test/ms_vc_fff_test.sln create mode 100644 test/ms_vc_fff_test/ms_vc_fff_test_c/ms_vc_fff_test_c.vcxproj create mode 100644 test/ms_vc_fff_test/ms_vc_fff_test_c/ms_vc_fff_test_c.vcxproj.filters create mode 100644 test/ms_vc_fff_test/ms_vc_fff_test_cpp/ms_vc_fff_test_cpp.vcxproj create mode 100644 test/ms_vc_fff_test/ms_vc_fff_test_cpp/ms_vc_fff_test_cpp.vcxproj.filters create mode 100644 test/ms_vc_fff_test/ms_vc_fff_test_global_c/ms_vc_fff_test_global_c.vcxproj create mode 100644 test/ms_vc_fff_test/ms_vc_fff_test_global_c/ms_vc_fff_test_global_c.vcxproj.filters create mode 100644 test/ms_vc_fff_test/ms_vc_fff_test_global_cpp/ms_vc_fff_test_global_cpp.vcxproj create mode 100644 test/ms_vc_fff_test/ms_vc_fff_test_global_cpp/ms_vc_fff_test_global_cpp.vcxproj.filters diff --git a/.gitignore b/.gitignore index ed09e27..142c463 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,36 @@ build/ *~ *.sublime-project *.sublime-workspace + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb diff --git a/README.md b/README.md index 45a83ed..98302da 100644 --- a/README.md +++ b/README.md @@ -408,6 +408,22 @@ could call the real fprintf() like this: return vfprintf(stream, format, ap); } +## How do I specify calling conventions for my fake functions? +FFF 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`. + +```bash +ruby fakegen.rb --with-calling-conventions > fff.h +``` + +By 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. + +Here 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. + +```c +FAKE_VOID_FUNC(__cdecl, voidfunc1, int); +FAKE_VALUE_FUNC(long, __cdecl, longfunc0); +``` + ## How do I fake a function that returns a value by reference? The basic mechanism that FFF provides you in this case is the custom_fake field described in the *Custom Return Value Delegate* example above. diff --git a/fakegen.rb b/fakegen.rb index b070183..768caa2 100644 --- a/fakegen.rb +++ b/fakegen.rb @@ -159,9 +159,9 @@ def define_value_function_variables_helper puts putd_backslash "#define DECLARE_VALUE_FUNCTION_VARIABLES(RETURN_TYPE)" indent { - putd_backslash "RETURN_TYPE return_val;" - putd_backslash "int return_val_seq_len;" - putd_backslash "int return_val_seq_idx;" + putd_backslash "RETURN_TYPE return_val;" + putd_backslash "int return_val_seq_len;" + putd_backslash "int return_val_seq_idx;" putd_backslash "RETURN_TYPE * return_val_seq;" } end @@ -208,8 +208,8 @@ def define_extern_c_helper puts putd "#ifdef __cplusplus" indent { - putd "#define FFF_EXTERN_C extern \"C\"{" - putd "#define FFF_END_EXTERN_C } " + putd "#define FFF_EXTERN_C extern \"C\"{" + putd "#define FFF_END_EXTERN_C } " } putd "#else /* ansi c */" indent { @@ -254,12 +254,12 @@ def popd end def indent - pushd + pushd yield popd end -def output_macro(arg_count, has_varargs, is_value_function) +def output_macro(arg_count, has_varargs, has_calling_conventions, is_value_function) vararg_name = has_varargs ? "_VARARG" : "" fake_macro_name = is_value_function ? "FAKE_VALUE_FUNC#{arg_count}#{vararg_name}" : "FAKE_VOID_FUNC#{arg_count}#{vararg_name}" @@ -269,19 +269,19 @@ def output_macro(arg_count, has_varargs, is_value_function) return_type = is_value_function ? "RETURN_TYPE" : "" puts - output_macro_header(declare_macro_name, saved_arg_count, has_varargs, return_type) + output_macro_header(declare_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type) indent { extern_c { # define argument capture variables - output_variables(saved_arg_count, has_varargs, is_value_function) + output_variables(saved_arg_count, has_varargs, has_calling_conventions, is_value_function) } } - + puts - output_macro_header(define_macro_name, saved_arg_count, has_varargs, return_type) + output_macro_header(define_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type) indent { extern_c { putd_backslash "FUNCNAME##_Fake FUNCNAME##_fake;" - putd_backslash function_signature(saved_arg_count, has_varargs, is_value_function) + "{" + putd_backslash function_signature(saved_arg_count, has_varargs, has_calling_conventions, is_value_function) + "{" indent { output_function_body(saved_arg_count, has_varargs, is_value_function) } @@ -289,33 +289,34 @@ def output_macro(arg_count, has_varargs, is_value_function) putd_backslash "DEFINE_RESET_FUNCTION(FUNCNAME)" } } - + puts - - output_macro_header(fake_macro_name, saved_arg_count, has_varargs, return_type) + + output_macro_header(fake_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type) indent { - putd macro_signature_for(declare_macro_name, saved_arg_count, has_varargs, return_type) - putd macro_signature_for(define_macro_name, saved_arg_count, has_varargs, return_type) + putd macro_signature_for(declare_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type) + putd macro_signature_for(define_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type) puts } end -def output_macro_header(macro_name, arg_count, has_varargs, return_type) - output_macro_name(macro_name, arg_count, has_varargs, return_type) +def output_macro_header(macro_name, arg_count, has_varargs, has_calling_conventions, return_type) + output_macro_name(macro_name, arg_count, has_varargs, has_calling_conventions, return_type) end # #define #macro_name(RETURN_TYPE, FUNCNAME, ARG0,...) -def output_macro_name(macro_name, arg_count, has_varargs, return_type) - putd "#define " + macro_signature_for(macro_name, arg_count, has_varargs, return_type) +def output_macro_name(macro_name, arg_count, has_varargs, has_calling_conventions, return_type) + putd "#define " + macro_signature_for(macro_name, arg_count, has_varargs, has_calling_conventions, return_type) end # #macro_name(RETURN_TYPE, FUNCNAME, ARG0,...) \ -def macro_signature_for(macro_name, arg_count, has_varargs, return_type) +def macro_signature_for(macro_name, arg_count, has_varargs, has_calling_conventions, return_type) parameter_list = "#{macro_name}(" if return_type != "" parameter_list += return_type parameter_list += ", " end + parameter_list += "CALLING_CONVENTION, " if (has_calling_conventions) parameter_list += "FUNCNAME" arg_count.times { |i| parameter_list += ", ARG#{i}_TYPE" } @@ -327,21 +328,21 @@ def macro_signature_for(macro_name, arg_count, has_varargs, return_type) parameter_list end -def output_variables(arg_count, has_varargs, is_value_function) +def output_variables(arg_count, has_varargs, has_calling_conventions, is_value_function) in_struct{ - arg_count.times { |argN| + arg_count.times { |argN| putd_backslash "DECLARE_ARG(ARG#{argN}_TYPE, #{argN}, FUNCNAME)" } putd_backslash "DECLARE_ALL_FUNC_COMMON" putd_backslash "DECLARE_VALUE_FUNCTION_VARIABLES(RETURN_TYPE)" unless not is_value_function putd_backslash "DECLARE_RETURN_VALUE_HISTORY(RETURN_TYPE)" unless not is_value_function putd_backslash "DECLARE_CUSTOM_FAKE_SEQ_VARIABLES" - output_custom_function_signature(arg_count, has_varargs, is_value_function) - output_custom_function_array(arg_count, has_varargs, is_value_function) + output_custom_function_signature(arg_count, has_varargs, has_calling_conventions, is_value_function) + output_custom_function_array(arg_count, has_varargs, has_calling_conventions, is_value_function) } putd_backslash "extern FUNCNAME##_Fake FUNCNAME##_fake;" putd_backslash "void FUNCNAME##_reset(void);" - putd_backslash function_signature(arg_count, has_varargs, is_value_function) + ";" + putd_backslash function_signature(arg_count, has_varargs, has_calling_conventions, is_value_function) + ";" end #example: ARG0_TYPE arg0, ARG1_TYPE arg1 @@ -360,26 +361,35 @@ def arg_list(args_count) end # RETURN_TYPE (*custom_fake)(ARG0_TYPE arg0);\ +# OR +# RETURN_TYPE (CALLING_CONVENTION *custom_fake)(ARG0_TYPE arg0);\ +# # void (*custom_fake)(ARG0_TYPE arg0, ARG1_TYPE arg1, ARG2_TYPE arg2);\ -def output_custom_function_signature(arg_count, has_varargs, is_value_function) +def output_custom_function_signature(arg_count, has_varargs, has_calling_conventions, is_value_function) return_type = is_value_function ? "RETURN_TYPE" : "void" ap_list = has_varargs ? ", va_list ap" : "" - signature = "(*custom_fake)(#{arg_val_list(arg_count)}#{ap_list});" + signature = has_calling_conventions ? "(CALLING_CONVENTION *custom_fake)" : "(*custom_fake)" + signature += "(#{arg_val_list(arg_count)}#{ap_list});" putd_backslash return_type + signature end -def output_custom_function_array(arg_count, has_varargs, is_value_function) +def output_custom_function_array(arg_count, has_varargs, has_calling_conventions, is_value_function) return_type = is_value_function ? "RETURN_TYPE" : "void" ap_list = has_varargs ? ", va_list ap" : "" - custom_array = "(**custom_fake_seq)(#{arg_val_list(arg_count)}#{ap_list});" + custom_array = has_calling_conventions ? "(CALLING_CONVENTION **custom_fake_seq)" : "(**custom_fake_seq)" + custom_array += "(#{arg_val_list(arg_count)}#{ap_list});" putd_backslash return_type + custom_array end # example: RETURN_TYPE FUNCNAME(ARG0_TYPE arg0, ARG1_TYPE arg1) -def function_signature(arg_count, has_varargs, is_value_function) +# OR +# RETURN_TYPE CALLING_CONVENTION FUNCNAME(ARG0_TYPE arg0, ARG1_TYPE arg1) +def function_signature(arg_count, has_varargs, has_calling_conventions, is_value_function) return_type = is_value_function ? "RETURN_TYPE" : "void" varargs = has_varargs ? ", ..." : "" - "#{return_type} FUNCNAME(#{arg_val_list(arg_count)}#{varargs})" + calling_conventions = has_calling_conventions ? + "#{return_type} CALLING_CONVENTION FUNCNAME(#{arg_val_list(arg_count)}#{varargs})" : + "#{return_type} FUNCNAME(#{arg_val_list(arg_count)}#{varargs})" end def output_function_body(arg_count, has_varargs, is_value_function) @@ -466,11 +476,7 @@ def define_fff_globals putd "FFF_END_EXTERN_C" } puts - putd_backslash "#define FFF_RESET_HISTORY()" - indent { - putd_backslash "fff.call_history_idx = 0;" - putd "memset(fff.call_history, 0, sizeof(fff.call_history));" - } + putd "#define FFF_RESET_HISTORY() fff.call_history_idx = 0;" puts putd_backslash "#define REGISTER_CALL(function)" indent { @@ -483,7 +489,7 @@ end def extern_c putd_backslash "FFF_EXTERN_C" - indent { + indent { yield } putd_backslash "FFF_END_EXTERN_C" @@ -518,9 +524,13 @@ def generate_arg_sequence(args, prefix, do_reverse, joinstr) if do_reverse then fmap.reverse.join(joinstr) else fmap.join(", ") end end -def counting_macro_instance(type, vararg = :non_vararg, prefix = "") +def counting_macro_instance(type, has_calling_conventions, vararg = :non_vararg, prefix = "") appendix = (vararg == :vararg) ? "_VARARG" : "" - minus_count = (type == :VOID) ? 1 : 2 + if has_calling_conventions + minus_count = (type == :VOID) ? 2 : 3 + else + minus_count = (type == :VOID) ? 1 : 2 + end <<-MACRO_COUNTING_INSTANCE #define #{prefix}FAKE_#{type.to_s}_FUNC#{appendix}(...) \ @@ -535,78 +545,95 @@ def counting_macro_instance(type, vararg = :non_vararg, prefix = "") MACRO_COUNTING_INSTANCE end -def output_macro_counting_shortcuts +def output_macro_counting_shortcuts(has_calling_conventions) + has_calling_conventions ? + (arg_depth = ["3", "2"]; calling_conv = "callingConv, ") : + (arg_depth = ["2", "1"]; calling_conv = "") + msvc_expand_macro_fix - putd <<-MACRO_COUNTING + putd <<-MACRO_COUNTING -#define PP_NARG_MINUS2(...) \ - EXPAND(PP_NARG_MINUS2_(__VA_ARGS__, PP_RSEQ_N_MINUS2())) +#define PP_NARG_MINUS#{arg_depth[0]}(...) \ + EXPAND(PP_NARG_MINUS#{arg_depth[0]}_(__VA_ARGS__, PP_RSEQ_N_MINUS#{arg_depth[0]}())) -#define PP_NARG_MINUS2_(...) \ - EXPAND(PP_ARG_MINUS2_N(__VA_ARGS__)) +#define PP_NARG_MINUS#{arg_depth[0]}_(...) \ + EXPAND(PP_ARG_MINUS#{arg_depth[0]}_N(__VA_ARGS__)) -#define PP_ARG_MINUS2_N(returnVal, #{generate_arg_sequence($MAX_ARGS, '_', false, ", ")}, N, ...) N +#define PP_ARG_MINUS#{arg_depth[0]}_N(returnVal, #{calling_conv} #{generate_arg_sequence($MAX_ARGS, '_', false, ", ")}, N, ...) N -#define PP_RSEQ_N_MINUS2() \ - #{generate_arg_sequence($MAX_ARGS, '', true, ',')} +#define PP_RSEQ_N_MINUS#{arg_depth[0]}() \ + #{generate_arg_sequence($MAX_ARGS, '', true, ',')} +#define PP_NARG_MINUS#{arg_depth[1]}(...) \ +EXPAND(PP_NARG_MINUS#{arg_depth[1]}_(__VA_ARGS__, PP_RSEQ_N_MINUS#{arg_depth[1]}())) -#define PP_NARG_MINUS1(...) \ - EXPAND(PP_NARG_MINUS1_(__VA_ARGS__, PP_RSEQ_N_MINUS1())) +#define PP_NARG_MINUS#{arg_depth[1]}_(...) \ +EXPAND(PP_ARG_MINUS#{arg_depth[1]}_N(__VA_ARGS__)) -#define PP_NARG_MINUS1_(...) \ - EXPAND(PP_ARG_MINUS1_N(__VA_ARGS__)) +#define PP_ARG_MINUS#{arg_depth[1]}_N(#{calling_conv} #{generate_arg_sequence($MAX_ARGS, '_', false, ", ")}, N, ...) N -#define PP_ARG_MINUS1_N(#{generate_arg_sequence($MAX_ARGS, '_', false, ", ")}, N, ...) N - -#define PP_RSEQ_N_MINUS1() \ - #{generate_arg_sequence($MAX_ARGS, '', true, ',')} +#define PP_RSEQ_N_MINUS#{arg_depth[1]}() \ + #{generate_arg_sequence($MAX_ARGS, '', true, ',')} /* DECLARE AND DEFINE FAKE FUNCTIONS - PLACE IN TEST FILES */ -#{counting_macro_instance(:VALUE)} -#{counting_macro_instance(:VOID)} -#{counting_macro_instance(:VALUE, :vararg)} -#{counting_macro_instance(:VOID, :vararg)} +#{counting_macro_instance(:VALUE, has_calling_conventions)} +#{counting_macro_instance(:VOID, has_calling_conventions)} +#{counting_macro_instance(:VALUE, has_calling_conventions, :vararg)} +#{counting_macro_instance(:VOID, has_calling_conventions, :vararg)} /* DECLARE FAKE FUNCTIONS - PLACE IN HEADER FILES */ -#{counting_macro_instance(:VALUE, :non_vararg, "DECLARE_")} -#{counting_macro_instance(:VOID, :non_vararg, "DECLARE_")} -#{counting_macro_instance(:VALUE, :vararg, "DECLARE_")} -#{counting_macro_instance(:VOID, :vararg, "DECLARE_")} +#{counting_macro_instance(:VALUE, has_calling_conventions, :non_vararg, "DECLARE_")} +#{counting_macro_instance(:VOID, has_calling_conventions, :non_vararg, "DECLARE_")} +#{counting_macro_instance(:VALUE, has_calling_conventions, :vararg, "DECLARE_")} +#{counting_macro_instance(:VOID, has_calling_conventions, :vararg, "DECLARE_")} /* DEFINE FAKE FUNCTIONS - PLACE IN SOURCE FILES */ -#{counting_macro_instance(:VALUE, :non_vararg, "DEFINE_")} -#{counting_macro_instance(:VOID, :non_vararg, "DEFINE_")} -#{counting_macro_instance(:VALUE, :vararg, "DEFINE_")} -#{counting_macro_instance(:VOID, :vararg, "DEFINE_")} +#{counting_macro_instance(:VALUE, has_calling_conventions, :non_vararg, "DEFINE_")} +#{counting_macro_instance(:VOID, has_calling_conventions, :non_vararg, "DEFINE_")} +#{counting_macro_instance(:VALUE, has_calling_conventions, :vararg, "DEFINE_")} +#{counting_macro_instance(:VOID, has_calling_conventions, :vararg, "DEFINE_")} MACRO_COUNTING end -def output_c_and_cpp - +def output_c_and_cpp(has_calling_conventions) include_guard { include_dependencies output_constants output_internal_helper_macros yield - output_macro_counting_shortcuts + output_macro_counting_shortcuts(has_calling_conventions) } end -# lets generate!! -output_c_and_cpp{ - define_fff_globals - # Create fake generators for 0..MAX_ARGS - num_fake_generators = $MAX_ARGS + 1 - num_fake_generators.times {|arg_count| output_macro(arg_count, false, false)} - num_fake_generators.times {|arg_count| output_macro(arg_count, false, true)} - # generate the varargs variants - (2..$MAX_ARGS).each {|arg_count| output_macro(arg_count, true, false)} - (2..$MAX_ARGS).each {|arg_count| output_macro(arg_count, true, true)} +def help + # Check if we should generate _with_ support for specifying calling conventions + if (ARGV[0] == "--help" or ARGV[0] == "-h") + puts "Usage: fakegen.rb [options] + -h, --help Show this help message + -wcc, --with-calling-conventions Support specifying calling conventions" + exit + end + yield +end + +help { + # Determine if we should generate with support for calling conventions + has_calling_conventions = true if (ARGV[0] == "--with-calling-conventions" or ARGV[0] == "-wcc") + # lets generate!! + output_c_and_cpp(has_calling_conventions) { + define_fff_globals + # Create fake generators for 0..MAX_ARGS + num_fake_generators = $MAX_ARGS + 1 + num_fake_generators.times {|arg_count| output_macro(arg_count, false, has_calling_conventions, false)} + num_fake_generators.times {|arg_count| output_macro(arg_count, false, has_calling_conventions, true)} + # generate the varargs variants + (2..$MAX_ARGS).each {|arg_count| output_macro(arg_count, true, has_calling_conventions, false)} + (2..$MAX_ARGS).each {|arg_count| output_macro(arg_count, true, has_calling_conventions, true)} + } } diff --git a/test/fff_test_c.c b/test/fff_test_c.c index 6763439..8df0287 100644 --- a/test/fff_test_c.c +++ b/test/fff_test_c.c @@ -21,7 +21,7 @@ struct MyStruct { int y; }; - +#ifndef TEST_WITH_CALLING_CONVENTIONS FAKE_VOID_FUNC(voidfunc1, int); FAKE_VOID_FUNC(voidfunc2, char, char); FAKE_VOID_FUNC(voidfunc1outparam, char *); @@ -33,6 +33,19 @@ FAKE_VALUE_FUNC_VARARG(int, valuefunc3var, char *, int, ...); FAKE_VALUE_FUNC(int, strlcpy3, char* const, const char* const, const size_t); FAKE_VOID_FUNC(voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); FAKE_VALUE_FUNC(int, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +#else +FAKE_VOID_FUNC(__cdecl, voidfunc1, int); +FAKE_VOID_FUNC(__cdecl, voidfunc2, char, char); +FAKE_VOID_FUNC(__cdecl, voidfunc1outparam, char *); +FAKE_VALUE_FUNC(long, __cdecl, longfunc0); +FAKE_VALUE_FUNC(enum MYBOOL, __cdecl, enumfunc0); +FAKE_VALUE_FUNC(struct MyStruct, __cdecl, structfunc0); +FAKE_VOID_FUNC_VARARG(__cdecl, voidfunc3var, char *, int, ...); +FAKE_VALUE_FUNC_VARARG(int, __cdecl, valuefunc3var, char *, int, ...); +FAKE_VALUE_FUNC(int, __cdecl, strlcpy3, char* const, const char* const, const size_t); +FAKE_VOID_FUNC(__cdecl, voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +FAKE_VALUE_FUNC(int, __cdecl, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +#endif void setup() { diff --git a/test/fff_test_cpp.cpp b/test/fff_test_cpp.cpp index 4a51b11..4c6d6ae 100644 --- a/test/fff_test_cpp.cpp +++ b/test/fff_test_cpp.cpp @@ -17,12 +17,21 @@ DEFINE_FFF_GLOBALS +#ifndef TEST_WITH_CALLING_CONVENTIONS FAKE_VOID_FUNC(voidfunc1, int); FAKE_VOID_FUNC(voidfunc2, char, char); FAKE_VOID_FUNC(voidfunc1outparam, char *); FAKE_VALUE_FUNC(long, longfunc0); FAKE_VOID_FUNC(voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); FAKE_VALUE_FUNC(int, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +#else +FAKE_VOID_FUNC(__cdecl, voidfunc1, int); +FAKE_VOID_FUNC(__cdecl, voidfunc2, char, char); +FAKE_VOID_FUNC(__cdecl, voidfunc1outparam, char *); +FAKE_VALUE_FUNC(long, __cdecl, longfunc0); +FAKE_VOID_FUNC(__cdecl, voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +FAKE_VALUE_FUNC(int, __cdecl, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +#endif class FFFTestSuite: public testing::Test { @@ -37,8 +46,6 @@ public: } }; -#include "test_cases.include" - TEST_F(FFFTestSuite, default_constants_can_be_overridden) { unsigned sizeCallHistory = (sizeof fff.call_history) / (sizeof fff.call_history[0]); @@ -46,3 +53,4 @@ TEST_F(FFFTestSuite, default_constants_can_be_overridden) ASSERT_EQ(OVERRIDE_ARG_HIST_LEN, voidfunc2_fake.arg_history_len); } +#include "test_cases.include" diff --git a/test/global_fakes.c b/test/global_fakes.c index d418761..cbd57ab 100644 --- a/test/global_fakes.c +++ b/test/global_fakes.c @@ -1,6 +1,7 @@ #include "global_fakes.h" #include // for memcpy +#ifndef TEST_WITH_CALLING_CONVENTIONS DEFINE_FAKE_VOID_FUNC(voidfunc1, int); DEFINE_FAKE_VOID_FUNC(voidfunc2, char, char); DEFINE_FAKE_VOID_FUNC(voidfunc1outparam, char *); @@ -15,3 +16,19 @@ DEFINE_FAKE_VALUE_FUNC(int, strlcpy3, char* const, const char* const, const size #endif /* __cplusplus */ DEFINE_FAKE_VOID_FUNC(voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); DEFINE_FAKE_VALUE_FUNC(int, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +#else +DEFINE_FAKE_VOID_FUNC(__cdecl, voidfunc1, int); +DEFINE_FAKE_VOID_FUNC(__cdecl, voidfunc2, char, char); +DEFINE_FAKE_VOID_FUNC(__cdecl, voidfunc1outparam, char *); + +DEFINE_FAKE_VALUE_FUNC(long, __cdecl, longfunc0); +DEFINE_FAKE_VALUE_FUNC(enum MYBOOL, __cdecl, enumfunc0); +DEFINE_FAKE_VALUE_FUNC(struct MyStruct, __cdecl, structfunc0); +DEFINE_FAKE_VOID_FUNC_VARARG(__cdecl, voidfunc3var, const char *, int, ...); +DEFINE_FAKE_VALUE_FUNC_VARARG(int, __cdecl, valuefunc3var, const char *, int, ...); +#ifndef __cplusplus +DEFINE_FAKE_VALUE_FUNC(int, __cdecl, strlcpy3, char* const, const char* const, const size_t); +#endif /* __cplusplus */ +DEFINE_FAKE_VOID_FUNC(__cdecl, voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +DEFINE_FAKE_VALUE_FUNC(int, __cdecl,valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +#endif diff --git a/test/global_fakes.h b/test/global_fakes.h index 6c26f07..1c0e44a 100644 --- a/test/global_fakes.h +++ b/test/global_fakes.h @@ -1,4 +1,3 @@ - #ifndef GLOBAL_FAKES_H_ #define GLOBAL_FAKES_H_ @@ -16,6 +15,7 @@ enum MYBOOL enumfunc(); struct MyStruct structfunc(); //// End Imaginary production code header file /// +#ifndef TEST_WITH_CALLING_CONVENTIONS DECLARE_FAKE_VOID_FUNC(voidfunc1, int); DECLARE_FAKE_VOID_FUNC(voidfunc2, char, char); DECLARE_FAKE_VOID_FUNC(voidfunc1outparam, char *); @@ -26,8 +26,24 @@ DECLARE_FAKE_VOID_FUNC_VARARG(voidfunc3var, const char *, int, ...); DECLARE_FAKE_VALUE_FUNC_VARARG(int, valuefunc3var, const char *, int, ...); DECLARE_FAKE_VOID_FUNC(voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); DECLARE_FAKE_VALUE_FUNC(int, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +#else +DECLARE_FAKE_VOID_FUNC(__cdecl, voidfunc1, int); +DECLARE_FAKE_VOID_FUNC(__cdecl, voidfunc2, char, char); +DECLARE_FAKE_VOID_FUNC(__cdecl, voidfunc1outparam, char *); +DECLARE_FAKE_VALUE_FUNC(long, __cdecl, longfunc0); +DECLARE_FAKE_VALUE_FUNC(enum MYBOOL, __cdecl, enumfunc0); +DECLARE_FAKE_VALUE_FUNC(struct MyStruct, __cdecl, structfunc0); +DECLARE_FAKE_VOID_FUNC_VARARG(__cdecl, voidfunc3var, const char *, int, ...); +DECLARE_FAKE_VALUE_FUNC_VARARG(int, __cdecl, valuefunc3var, const char *, int, ...); +DECLARE_FAKE_VOID_FUNC(__cdecl, voidfunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +DECLARE_FAKE_VALUE_FUNC(int, __cdecl, valuefunc20, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); +#endif #ifndef __cplusplus +#ifndef TEST_WITH_CALLING_CONVENTIONS DECLARE_FAKE_VALUE_FUNC(int, strlcpy3, char* const, const char* const, const size_t); +#else +DECLARE_FAKE_VALUE_FUNC(int, __cdecl, strlcpy3, char* const, const char* const, const size_t); +#endif #endif /* __cplusplus */ #endif /* GLOBAL_FAKES_H_ */ diff --git a/test/ms_vc_fff_test/fff/fff.vcxproj b/test/ms_vc_fff_test/fff/fff.vcxproj new file mode 100644 index 0000000..c1d6d6d --- /dev/null +++ b/test/ms_vc_fff_test/fff/fff.vcxproj @@ -0,0 +1,140 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {CDBC5A3A-59B8-4638-B818-935395302DAF} + fff2 + 10.0.17134.0 + fff + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + + + del $(SolutionDir)..\..\fff.h +ruby.exe $(SolutionDir)..\..\fakegen.rb -wcc > $(SolutionDir)..\..\fff.h + + + + + Level3 + Disabled + true + true + + + del $(SolutionDir)..\..\fff.h +ruby.exe $(SolutionDir)..\..\fakegen.rb -wcc > $(SolutionDir)..\..\fff.h + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + del $(SolutionDir)..\..\fff.h +ruby.exe $(SolutionDir)..\..\fakegen.rb -wcc > $(SolutionDir)..\..\fff.h + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + del $(SolutionDir)..\..\fff.h +ruby.exe $(SolutionDir)..\..\fakegen.rb -wcc > $(SolutionDir)..\..\fff.h + + + + + + + + + \ No newline at end of file diff --git a/test/ms_vc_fff_test/fff/fff.vcxproj.filters b/test/ms_vc_fff_test/fff/fff.vcxproj.filters new file mode 100644 index 0000000..9de4a18 --- /dev/null +++ b/test/ms_vc_fff_test/fff/fff.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + \ No newline at end of file diff --git a/test/ms_vc_fff_test/gtest/gtest.vcxproj b/test/ms_vc_fff_test/gtest/gtest.vcxproj new file mode 100644 index 0000000..a32d4e9 --- /dev/null +++ b/test/ms_vc_fff_test/gtest/gtest.vcxproj @@ -0,0 +1,163 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {792FDC07-43A6-42BB-ABD5-18BA1A8B17E7} + Win32Proj + gtest + 10.0.17134.0 + + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(IncludePath) + + + true + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(IncludePath) + + + false + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(IncludePath) + + + false + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(IncludePath) + + + + NotUsing + Level3 + Disabled + true + _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + NotUsing + Level3 + Disabled + true + _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/ms_vc_fff_test/gtest/gtest.vcxproj.filters b/test/ms_vc_fff_test/gtest/gtest.vcxproj.filters new file mode 100644 index 0000000..042c6b8 --- /dev/null +++ b/test/ms_vc_fff_test/gtest/gtest.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/test/ms_vc_fff_test/ms_vc_fff_test.sln b/test/ms_vc_fff_test/ms_vc_fff_test.sln new file mode 100644 index 0000000..b55f3c8 --- /dev/null +++ b/test/ms_vc_fff_test/ms_vc_fff_test.sln @@ -0,0 +1,93 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2036 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ms_vc_fff_test_c", "ms_vc_fff_test_c\ms_vc_fff_test_c.vcxproj", "{B7658726-71D3-48B3-8BD2-6D383A60DC8E}" + ProjectSection(ProjectDependencies) = postProject + {CDBC5A3A-59B8-4638-B818-935395302DAF} = {CDBC5A3A-59B8-4638-B818-935395302DAF} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "gtest\gtest.vcxproj", "{792FDC07-43A6-42BB-ABD5-18BA1A8B17E7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ms_vc_fff_test_cpp", "ms_vc_fff_test_cpp\ms_vc_fff_test_cpp.vcxproj", "{00EE1499-1C86-4F7B-8A00-9EBE696D0142}" + ProjectSection(ProjectDependencies) = postProject + {CDBC5A3A-59B8-4638-B818-935395302DAF} = {CDBC5A3A-59B8-4638-B818-935395302DAF} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ms_vc_fff_test_global_cpp", "ms_vc_fff_test_global_cpp\ms_vc_fff_test_global_cpp.vcxproj", "{4384428B-E0FE-404D-A6EB-8CD9A3C88E5C}" + ProjectSection(ProjectDependencies) = postProject + {CDBC5A3A-59B8-4638-B818-935395302DAF} = {CDBC5A3A-59B8-4638-B818-935395302DAF} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ms_vc_fff_test_global_c", "ms_vc_fff_test_global_c\ms_vc_fff_test_global_c.vcxproj", "{0F70375A-2C80-4B07-9EA0-A64E9679B0C7}" + ProjectSection(ProjectDependencies) = postProject + {CDBC5A3A-59B8-4638-B818-935395302DAF} = {CDBC5A3A-59B8-4638-B818-935395302DAF} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fff", "fff\fff.vcxproj", "{CDBC5A3A-59B8-4638-B818-935395302DAF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B7658726-71D3-48B3-8BD2-6D383A60DC8E}.Debug|x64.ActiveCfg = Debug|x64 + {B7658726-71D3-48B3-8BD2-6D383A60DC8E}.Debug|x64.Build.0 = Debug|x64 + {B7658726-71D3-48B3-8BD2-6D383A60DC8E}.Debug|x86.ActiveCfg = Debug|Win32 + {B7658726-71D3-48B3-8BD2-6D383A60DC8E}.Debug|x86.Build.0 = Debug|Win32 + {B7658726-71D3-48B3-8BD2-6D383A60DC8E}.Release|x64.ActiveCfg = Release|x64 + {B7658726-71D3-48B3-8BD2-6D383A60DC8E}.Release|x64.Build.0 = Release|x64 + {B7658726-71D3-48B3-8BD2-6D383A60DC8E}.Release|x86.ActiveCfg = Release|Win32 + {B7658726-71D3-48B3-8BD2-6D383A60DC8E}.Release|x86.Build.0 = Release|Win32 + {792FDC07-43A6-42BB-ABD5-18BA1A8B17E7}.Debug|x64.ActiveCfg = Debug|x64 + {792FDC07-43A6-42BB-ABD5-18BA1A8B17E7}.Debug|x64.Build.0 = Debug|x64 + {792FDC07-43A6-42BB-ABD5-18BA1A8B17E7}.Debug|x86.ActiveCfg = Debug|Win32 + {792FDC07-43A6-42BB-ABD5-18BA1A8B17E7}.Debug|x86.Build.0 = Debug|Win32 + {792FDC07-43A6-42BB-ABD5-18BA1A8B17E7}.Release|x64.ActiveCfg = Release|x64 + {792FDC07-43A6-42BB-ABD5-18BA1A8B17E7}.Release|x64.Build.0 = Release|x64 + {792FDC07-43A6-42BB-ABD5-18BA1A8B17E7}.Release|x86.ActiveCfg = Release|Win32 + {792FDC07-43A6-42BB-ABD5-18BA1A8B17E7}.Release|x86.Build.0 = Release|Win32 + {00EE1499-1C86-4F7B-8A00-9EBE696D0142}.Debug|x64.ActiveCfg = Debug|x64 + {00EE1499-1C86-4F7B-8A00-9EBE696D0142}.Debug|x64.Build.0 = Debug|x64 + {00EE1499-1C86-4F7B-8A00-9EBE696D0142}.Debug|x86.ActiveCfg = Debug|Win32 + {00EE1499-1C86-4F7B-8A00-9EBE696D0142}.Debug|x86.Build.0 = Debug|Win32 + {00EE1499-1C86-4F7B-8A00-9EBE696D0142}.Release|x64.ActiveCfg = Release|x64 + {00EE1499-1C86-4F7B-8A00-9EBE696D0142}.Release|x64.Build.0 = Release|x64 + {00EE1499-1C86-4F7B-8A00-9EBE696D0142}.Release|x86.ActiveCfg = Release|Win32 + {00EE1499-1C86-4F7B-8A00-9EBE696D0142}.Release|x86.Build.0 = Release|Win32 + {4384428B-E0FE-404D-A6EB-8CD9A3C88E5C}.Debug|x64.ActiveCfg = Debug|x64 + {4384428B-E0FE-404D-A6EB-8CD9A3C88E5C}.Debug|x64.Build.0 = Debug|x64 + {4384428B-E0FE-404D-A6EB-8CD9A3C88E5C}.Debug|x86.ActiveCfg = Debug|Win32 + {4384428B-E0FE-404D-A6EB-8CD9A3C88E5C}.Debug|x86.Build.0 = Debug|Win32 + {4384428B-E0FE-404D-A6EB-8CD9A3C88E5C}.Release|x64.ActiveCfg = Release|x64 + {4384428B-E0FE-404D-A6EB-8CD9A3C88E5C}.Release|x64.Build.0 = Release|x64 + {4384428B-E0FE-404D-A6EB-8CD9A3C88E5C}.Release|x86.ActiveCfg = Release|Win32 + {4384428B-E0FE-404D-A6EB-8CD9A3C88E5C}.Release|x86.Build.0 = Release|Win32 + {0F70375A-2C80-4B07-9EA0-A64E9679B0C7}.Debug|x64.ActiveCfg = Debug|x64 + {0F70375A-2C80-4B07-9EA0-A64E9679B0C7}.Debug|x64.Build.0 = Debug|x64 + {0F70375A-2C80-4B07-9EA0-A64E9679B0C7}.Debug|x86.ActiveCfg = Debug|Win32 + {0F70375A-2C80-4B07-9EA0-A64E9679B0C7}.Debug|x86.Build.0 = Debug|Win32 + {0F70375A-2C80-4B07-9EA0-A64E9679B0C7}.Release|x64.ActiveCfg = Release|x64 + {0F70375A-2C80-4B07-9EA0-A64E9679B0C7}.Release|x64.Build.0 = Release|x64 + {0F70375A-2C80-4B07-9EA0-A64E9679B0C7}.Release|x86.ActiveCfg = Release|Win32 + {0F70375A-2C80-4B07-9EA0-A64E9679B0C7}.Release|x86.Build.0 = Release|Win32 + {CDBC5A3A-59B8-4638-B818-935395302DAF}.Debug|x64.ActiveCfg = Debug|x64 + {CDBC5A3A-59B8-4638-B818-935395302DAF}.Debug|x64.Build.0 = Debug|x64 + {CDBC5A3A-59B8-4638-B818-935395302DAF}.Debug|x86.ActiveCfg = Debug|Win32 + {CDBC5A3A-59B8-4638-B818-935395302DAF}.Debug|x86.Build.0 = Debug|Win32 + {CDBC5A3A-59B8-4638-B818-935395302DAF}.Release|x64.ActiveCfg = Release|x64 + {CDBC5A3A-59B8-4638-B818-935395302DAF}.Release|x64.Build.0 = Release|x64 + {CDBC5A3A-59B8-4638-B818-935395302DAF}.Release|x86.ActiveCfg = Release|Win32 + {CDBC5A3A-59B8-4638-B818-935395302DAF}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9DEDA619-1153-4BD1-B292-069D4954391E} + EndGlobalSection +EndGlobal diff --git a/test/ms_vc_fff_test/ms_vc_fff_test_c/ms_vc_fff_test_c.vcxproj b/test/ms_vc_fff_test/ms_vc_fff_test_c/ms_vc_fff_test_c.vcxproj new file mode 100644 index 0000000..bcb67c2 --- /dev/null +++ b/test/ms_vc_fff_test/ms_vc_fff_test_c/ms_vc_fff_test_c.vcxproj @@ -0,0 +1,150 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + ClCompile + + + 15.0 + {B7658726-71D3-48B3-8BD2-6D383A60DC8E} + msvcffftest + 10.0.17134.0 + ms_vc_fff_test_c + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(IncludePath) + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(IncludePath) + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(IncludePath) + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(IncludePath) + + + + Level3 + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;._MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + + + Level3 + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;._MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + + + Level3 + MaxSpeed + true + true + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;._MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;._MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + true + true + + + + + + diff --git a/test/ms_vc_fff_test/ms_vc_fff_test_c/ms_vc_fff_test_c.vcxproj.filters b/test/ms_vc_fff_test/ms_vc_fff_test_c/ms_vc_fff_test_c.vcxproj.filters new file mode 100644 index 0000000..8d3e60a --- /dev/null +++ b/test/ms_vc_fff_test/ms_vc_fff_test_c/ms_vc_fff_test_c.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/test/ms_vc_fff_test/ms_vc_fff_test_cpp/ms_vc_fff_test_cpp.vcxproj b/test/ms_vc_fff_test/ms_vc_fff_test_cpp/ms_vc_fff_test_cpp.vcxproj new file mode 100644 index 0000000..d7754f4 --- /dev/null +++ b/test/ms_vc_fff_test/ms_vc_fff_test_cpp/ms_vc_fff_test_cpp.vcxproj @@ -0,0 +1,154 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + ClCompile + + + 15.0 + {00EE1499-1C86-4F7B-8A00-9EBE696D0142} + msvcffftestcpp + 10.0.17134.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + Level3 + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + + + Level3 + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + + + Level3 + MaxSpeed + true + true + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + true + true + + + + + + + + + {792fdc07-43a6-42bb-abd5-18ba1a8b17e7} + + + + + + + + + diff --git a/test/ms_vc_fff_test/ms_vc_fff_test_cpp/ms_vc_fff_test_cpp.vcxproj.filters b/test/ms_vc_fff_test/ms_vc_fff_test_cpp/ms_vc_fff_test_cpp.vcxproj.filters new file mode 100644 index 0000000..510fbb2 --- /dev/null +++ b/test/ms_vc_fff_test/ms_vc_fff_test_cpp/ms_vc_fff_test_cpp.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/test/ms_vc_fff_test/ms_vc_fff_test_global_c/ms_vc_fff_test_global_c.vcxproj b/test/ms_vc_fff_test/ms_vc_fff_test_global_c/ms_vc_fff_test_global_c.vcxproj new file mode 100644 index 0000000..b92fdae --- /dev/null +++ b/test/ms_vc_fff_test/ms_vc_fff_test_global_c/ms_vc_fff_test_global_c.vcxproj @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {0F70375A-2C80-4B07-9EA0-A64E9679B0C7} + msvcffftestglobalc + 10.0.17134.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + ClCompile + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + Level3 + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + + + + + Level3 + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + + + + + Level3 + MaxSpeed + true + true + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + + + true + true + + + + + + + + + + + + + + + diff --git a/test/ms_vc_fff_test/ms_vc_fff_test_global_c/ms_vc_fff_test_global_c.vcxproj.filters b/test/ms_vc_fff_test/ms_vc_fff_test_global_c/ms_vc_fff_test_global_c.vcxproj.filters new file mode 100644 index 0000000..db5afef --- /dev/null +++ b/test/ms_vc_fff_test/ms_vc_fff_test_global_c/ms_vc_fff_test_global_c.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/test/ms_vc_fff_test/ms_vc_fff_test_global_cpp/ms_vc_fff_test_global_cpp.vcxproj b/test/ms_vc_fff_test/ms_vc_fff_test_global_cpp/ms_vc_fff_test_global_cpp.vcxproj new file mode 100644 index 0000000..1da48b3 --- /dev/null +++ b/test/ms_vc_fff_test/ms_vc_fff_test_global_cpp/ms_vc_fff_test_global_cpp.vcxproj @@ -0,0 +1,149 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {4384428B-E0FE-404D-A6EB-8CD9A3C88E5C} + msvcffftestglobalcpp + 10.0.17134.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + $(SolutionDir)..\..\gtest;$(SolutionDir)..\..\;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + Level3 + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + + + + + Level3 + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + + + + + Level3 + MaxSpeed + true + true + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + _CRT_SECURE_NO_WARNINGS;_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING;TEST_WITH_CALLING_CONVENTIONS;_MBCS;%(PreprocessorDefinitions) + + + true + true + + + + + {792fdc07-43a6-42bb-abd5-18ba1a8b17e7} + + + + + + + + + + + + + + + diff --git a/test/ms_vc_fff_test/ms_vc_fff_test_global_cpp/ms_vc_fff_test_global_cpp.vcxproj.filters b/test/ms_vc_fff_test/ms_vc_fff_test_global_cpp/ms_vc_fff_test_global_cpp.vcxproj.filters new file mode 100644 index 0000000..ebf3bc7 --- /dev/null +++ b/test/ms_vc_fff_test/ms_vc_fff_test_global_cpp/ms_vc_fff_test_global_cpp.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/test/test_cases.include b/test/test_cases.include index 51484c1..5d686b6 100644 --- a/test/test_cases.include +++ b/test/test_cases.include @@ -164,7 +164,6 @@ TEST_F(FFFTestSuite, reset_call_history_resets_call_history) ASSERT_EQ(1u, fff.call_history_idx); ASSERT_EQ(fff.call_history[0], (void *)voidfunc2); - ASSERT_EQ(fff.call_history[1], (void *)0); } TEST_F(FFFTestSuite, call_history_will_not_write_past_array_bounds) @@ -286,17 +285,18 @@ TEST_F(FFFTestSuite, return_value_saved_in_history) ASSERT_EQ(longfunc0_fake.return_val_history[i], i + 1); } } -long custom_longfunc1() + +long custom_longfunc1(void) { return 42; } -long custom_longfunc2() +long custom_longfunc2(void) { return 15; } -long custom_longfunc3() +long custom_longfunc3(void) { return 7; } @@ -306,6 +306,7 @@ TEST_F(FFFTestSuite, custom_fake_seq_return_values_saved_in_history) long (*custom_fakes[])(void) = {custom_longfunc1, custom_longfunc2, custom_longfunc3}; + SET_CUSTOM_FAKE_SEQ(longfunc0, custom_fakes, 3); longfunc0(); From d0a214c5846b4ac47570e19b68886e48e7b45d23 Mon Sep 17 00:00:00 2001 From: James Fraser Date: Fri, 16 Nov 2018 20:14:22 +1100 Subject: [PATCH 2/4] Fixed indentation style. --- fakegen.rb | 64 +++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/fakegen.rb b/fakegen.rb index 768caa2..3382f17 100644 --- a/fakegen.rb +++ b/fakegen.rb @@ -482,7 +482,7 @@ def define_fff_globals indent { putd_backslash "if(fff.call_history_idx < FFF_CALL_HISTORY_LEN)" indent { - putd "fff.call_history[fff.call_history_idx++] = (fff_function_t)function;" + putd "fff.call_history[fff.call_history_idx++] = (fff_function_t)function;" } } end @@ -515,13 +515,13 @@ def include_guard end def msvc_expand_macro_fix - putd "/* MSVC expand macro fix */" - putd "#define EXPAND(x) x" + putd "/* MSVC expand macro fix */" + putd "#define EXPAND(x) x" end def generate_arg_sequence(args, prefix, do_reverse, joinstr) - fmap = (0..args).flat_map {|i| [prefix + i.to_s]} - if do_reverse then fmap.reverse.join(joinstr) else fmap.join(", ") end + fmap = (0..args).flat_map {|i| [prefix + i.to_s]} + if do_reverse then fmap.reverse.join(joinstr) else fmap.join(", ") end end def counting_macro_instance(type, has_calling_conventions, vararg = :non_vararg, prefix = "") @@ -546,12 +546,12 @@ def counting_macro_instance(type, has_calling_conventions, vararg = :non_vararg, end def output_macro_counting_shortcuts(has_calling_conventions) - has_calling_conventions ? - (arg_depth = ["3", "2"]; calling_conv = "callingConv, ") : - (arg_depth = ["2", "1"]; calling_conv = "") + has_calling_conventions ? + (arg_depth = ["3", "2"]; calling_conv = "callingConv, ") : + (arg_depth = ["2", "1"]; calling_conv = "") msvc_expand_macro_fix - putd <<-MACRO_COUNTING + putd <<-MACRO_COUNTING #define PP_NARG_MINUS#{arg_depth[0]}(...) \ EXPAND(PP_NARG_MINUS#{arg_depth[0]}_(__VA_ARGS__, PP_RSEQ_N_MINUS#{arg_depth[0]}())) @@ -565,10 +565,10 @@ def output_macro_counting_shortcuts(has_calling_conventions) #{generate_arg_sequence($MAX_ARGS, '', true, ',')} #define PP_NARG_MINUS#{arg_depth[1]}(...) \ -EXPAND(PP_NARG_MINUS#{arg_depth[1]}_(__VA_ARGS__, PP_RSEQ_N_MINUS#{arg_depth[1]}())) + EXPAND(PP_NARG_MINUS#{arg_depth[1]}_(__VA_ARGS__, PP_RSEQ_N_MINUS#{arg_depth[1]}())) #define PP_NARG_MINUS#{arg_depth[1]}_(...) \ -EXPAND(PP_ARG_MINUS#{arg_depth[1]}_N(__VA_ARGS__)) + EXPAND(PP_ARG_MINUS#{arg_depth[1]}_N(__VA_ARGS__)) #define PP_ARG_MINUS#{arg_depth[1]}_N(#{calling_conv} #{generate_arg_sequence($MAX_ARGS, '_', false, ", ")}, N, ...) N @@ -612,28 +612,28 @@ def output_c_and_cpp(has_calling_conventions) end def help - # Check if we should generate _with_ support for specifying calling conventions - if (ARGV[0] == "--help" or ARGV[0] == "-h") - puts "Usage: fakegen.rb [options] - -h, --help Show this help message - -wcc, --with-calling-conventions Support specifying calling conventions" - exit - end - yield + # Check if we should generate _with_ support for specifying calling conventions + if (ARGV[0] == "--help" or ARGV[0] == "-h") + puts "Usage: fakegen.rb [options] + -h, --help Show this help message + -wcc, --with-calling-conventions Support specifying calling conventions" + exit + end + yield end help { - # Determine if we should generate with support for calling conventions - has_calling_conventions = true if (ARGV[0] == "--with-calling-conventions" or ARGV[0] == "-wcc") - # lets generate!! - output_c_and_cpp(has_calling_conventions) { - define_fff_globals - # Create fake generators for 0..MAX_ARGS - num_fake_generators = $MAX_ARGS + 1 - num_fake_generators.times {|arg_count| output_macro(arg_count, false, has_calling_conventions, false)} - num_fake_generators.times {|arg_count| output_macro(arg_count, false, has_calling_conventions, true)} - # generate the varargs variants - (2..$MAX_ARGS).each {|arg_count| output_macro(arg_count, true, has_calling_conventions, false)} - (2..$MAX_ARGS).each {|arg_count| output_macro(arg_count, true, has_calling_conventions, true)} - } + # Determine if we should generate with support for calling conventions + has_calling_conventions = true if (ARGV[0] == "--with-calling-conventions" or ARGV[0] == "-wcc") + # lets generate!! + output_c_and_cpp(has_calling_conventions) { + define_fff_globals + # Create fake generators for 0..MAX_ARGS + num_fake_generators = $MAX_ARGS + 1 + num_fake_generators.times {|arg_count| output_macro(arg_count, false, has_calling_conventions, false)} + num_fake_generators.times {|arg_count| output_macro(arg_count, false, has_calling_conventions, true)} + # generate the varargs variants + (2..$MAX_ARGS).each {|arg_count| output_macro(arg_count, true, has_calling_conventions, false)} + (2..$MAX_ARGS).each {|arg_count| output_macro(arg_count, true, has_calling_conventions, true)} + } } From 1c981604a13a7c6718bbe453a2f76bfa091cc024 Mon Sep 17 00:00:00 2001 From: James Fraser Date: Fri, 16 Nov 2018 20:25:10 +1100 Subject: [PATCH 3/4] Fixed erroneous change. --- fakegen.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fakegen.rb b/fakegen.rb index 3382f17..aa784f2 100644 --- a/fakegen.rb +++ b/fakegen.rb @@ -476,13 +476,17 @@ def define_fff_globals putd "FFF_END_EXTERN_C" } puts - putd "#define FFF_RESET_HISTORY() fff.call_history_idx = 0;" + putd_backslash "#define FFF_RESET_HISTORY()" + indent { + putd_backslash "fff.call_history_idx = 0;" + putd "memset(fff.call_history, 0, sizeof(fff.call_history));" + } puts putd_backslash "#define REGISTER_CALL(function)" indent { putd_backslash "if(fff.call_history_idx < FFF_CALL_HISTORY_LEN)" indent { - putd "fff.call_history[fff.call_history_idx++] = (fff_function_t)function;" + putd "fff.call_history[fff.call_history_idx++] = (fff_function_t)function;" } } end From 45c4d3169003238b10d37ecf77c5945895b16dc9 Mon Sep 17 00:00:00 2001 From: James Fraser Date: Fri, 16 Nov 2018 20:27:33 +1100 Subject: [PATCH 4/4] Re-instated assert from include fixture as per last commit fix. --- test/test_cases.include | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_cases.include b/test/test_cases.include index 5d686b6..2433892 100644 --- a/test/test_cases.include +++ b/test/test_cases.include @@ -164,6 +164,7 @@ TEST_F(FFFTestSuite, reset_call_history_resets_call_history) ASSERT_EQ(1u, fff.call_history_idx); ASSERT_EQ(fff.call_history[0], (void *)voidfunc2); + ASSERT_EQ(fff.call_history[1], (void *)0); } TEST_F(FFFTestSuite, call_history_will_not_write_past_array_bounds)