mirror of
https://github.com/meekrosoft/fff
synced 2026-01-23 00:15:59 +01:00
Moved fake variables into struct to avoid polluting global namespace
This commit is contained in:
80
fakegen.rb
80
fakegen.rb
@@ -45,8 +45,8 @@ end
|
||||
|
||||
def define_return_sequence_helper
|
||||
puts "#define SET_RETURN_SEQ( FUNCNAME, ARRAY_POINTER, ARRAY_LEN) \\"
|
||||
puts " FUNCNAME##_return_val_seq = ARRAY_POINTER; \\"
|
||||
puts " FUNCNAME##_return_val_seq_len = ARRAY_LEN;"
|
||||
puts " FUNCNAME##_fake.return_val_seq = ARRAY_POINTER; \\"
|
||||
puts " FUNCNAME##_fake.return_val_seq_len = ARRAY_LEN;"
|
||||
end
|
||||
|
||||
def define_reset_fake_helper
|
||||
@@ -60,79 +60,78 @@ end
|
||||
|
||||
def define_declare_arg_helper
|
||||
puts ""
|
||||
puts "#define DECLARE_ARG(type, argN, FUNCNAME) \\"
|
||||
puts " static type FUNCNAME##_arg##argN##_val; \\"
|
||||
puts " static type FUNCNAME##_arg##argN##_history[FFF_ARG_HISTORY_LEN];"
|
||||
#puts "type arg##n##_val; \\"
|
||||
#puts "type arg##n##_history[FFF_ARG_HISTORY_LEN];"
|
||||
puts "#define DECLARE_ARG(type, n, FUNCNAME) \\"
|
||||
puts " type arg##n##_val; \\"
|
||||
puts " type arg##n##_history[FFF_ARG_HISTORY_LEN];"
|
||||
end
|
||||
|
||||
def define_declare_all_func_common_helper
|
||||
puts ""
|
||||
puts "#define DECLARE_ALL_FUNC_COMMON(FUNCNAME) \\"
|
||||
puts " static unsigned int FUNCNAME##_call_count = 0; \\"
|
||||
puts " static unsigned int FUNCNAME##_arg_history_len = FFF_ARG_HISTORY_LEN;\\"
|
||||
puts " static unsigned int FUNCNAME##_arg_histories_dropped = 0;"
|
||||
puts " unsigned int call_count; \\"
|
||||
puts " unsigned int arg_history_len;\\"
|
||||
puts " unsigned int arg_histories_dropped;"
|
||||
end
|
||||
|
||||
def define_save_arg_helper
|
||||
puts ""
|
||||
puts "#define SAVE_ARG(FUNCNAME, n) \\"
|
||||
puts " FUNCNAME##_arg##n##_val = arg##n"
|
||||
puts " FUNCNAME##_fake.arg##n##_val = arg##n"
|
||||
end
|
||||
|
||||
def define_room_for_more_history
|
||||
puts ""
|
||||
puts "#define ROOM_FOR_MORE_HISTORY(FUNCNAME) \\"
|
||||
puts " FUNCNAME##_call_count < FFF_ARG_HISTORY_LEN"
|
||||
puts " FUNCNAME##_fake.call_count < FFF_ARG_HISTORY_LEN"
|
||||
end
|
||||
|
||||
def define_save_arg_history_helper
|
||||
puts ""
|
||||
puts "#define SAVE_ARG_HISTORY(FUNCNAME, ARGN) \\"
|
||||
puts " FUNCNAME##_arg##ARGN##_history[FUNCNAME##_call_count] = arg##ARGN"
|
||||
puts " FUNCNAME##_fake.arg##ARGN##_history[FUNCNAME##_fake.call_count] = arg##ARGN"
|
||||
end
|
||||
|
||||
def define_history_dropped_helper
|
||||
puts ""
|
||||
puts "#define HISTORY_DROPPED(FUNCNAME) \\"
|
||||
puts " FUNCNAME##_arg_histories_dropped++"
|
||||
puts " FUNCNAME##_fake.arg_histories_dropped++"
|
||||
end
|
||||
|
||||
def define_value_function_variables_helper
|
||||
puts ""
|
||||
puts "#define DECLARE_VALUE_FUNCTION_VARIABLES(FUNCNAME, RETURN_TYPE) \\"
|
||||
puts " static RETURN_TYPE FUNCNAME##_return_val; \\"
|
||||
puts " static int FUNCNAME##_return_val_seq_len = 0; \\"
|
||||
puts " static int FUNCNAME##_return_val_seq_idx = 0; \\"
|
||||
puts " static RETURN_TYPE * FUNCNAME##_return_val_seq = 0; \\"
|
||||
puts " RETURN_TYPE return_val; \\"
|
||||
puts " int return_val_seq_len; \\"
|
||||
puts " int return_val_seq_idx; \\"
|
||||
puts " RETURN_TYPE * return_val_seq; \\"
|
||||
end
|
||||
|
||||
def define_increment_call_count_helper
|
||||
puts ""
|
||||
puts "#define INCREMENT_CALL_COUNT(FUNCNAME) \\"
|
||||
puts " FUNCNAME##_call_count++"
|
||||
puts " FUNCNAME##_fake.call_count++"
|
||||
end
|
||||
|
||||
def define_return_fake_result_helper
|
||||
puts ""
|
||||
puts "#define RETURN_FAKE_RESULT(FUNCNAME) \\"
|
||||
puts " if (FUNCNAME##_return_val_seq_len){ /* then its a sequence */ \\"
|
||||
puts " if(FUNCNAME##_return_val_seq_idx < FUNCNAME##_return_val_seq_len) { \\"
|
||||
puts " return FUNCNAME##_return_val_seq[FUNCNAME##_return_val_seq_idx++]; \\"
|
||||
puts " if (FUNCNAME##_fake.return_val_seq_len){ /* then its a sequence */ \\"
|
||||
puts " if(FUNCNAME##_fake.return_val_seq_idx < FUNCNAME##_fake.return_val_seq_len) { \\"
|
||||
puts " return FUNCNAME##_fake.return_val_seq[FUNCNAME##_fake.return_val_seq_idx++]; \\"
|
||||
puts " } \\"
|
||||
puts " return FUNCNAME##_return_val_seq[FUNCNAME##_return_val_seq_len-1]; /* return last element */ \\"
|
||||
puts " return FUNCNAME##_fake.return_val_seq[FUNCNAME##_fake.return_val_seq_len-1]; /* return last element */ \\"
|
||||
puts " } \\"
|
||||
puts " return FUNCNAME##_return_val; \\"
|
||||
puts " return FUNCNAME##_fake.return_val; \\"
|
||||
end
|
||||
|
||||
def define_reset_fake_result_helper
|
||||
puts ""
|
||||
puts "#define RESET_FAKE_RESULT(FUNCNAME) \\"
|
||||
puts " memset(&FUNCNAME##_return_val, 0, sizeof(FUNCNAME##_return_val)); \\"
|
||||
puts " FUNCNAME##_return_val_seq_len = 0; \\"
|
||||
puts " FUNCNAME##_return_val_seq_idx = 0; \\"
|
||||
puts " FUNCNAME##_return_val_seq = 0; \\"
|
||||
puts " memset(&FUNCNAME##_fake.return_val, 0, sizeof(FUNCNAME##_fake.return_val)); \\"
|
||||
puts " FUNCNAME##_fake.return_val_seq_len = 0; \\"
|
||||
puts " FUNCNAME##_fake.return_val_seq_idx = 0; \\"
|
||||
puts " FUNCNAME##_fake.return_val_seq = 0; \\"
|
||||
# puts " FUNCNAME##_fake.arg_history_len = FFF_ARG_HISTORY_LEN;\\"
|
||||
end
|
||||
# ------ End Helper macros ------ #
|
||||
|
||||
@@ -222,10 +221,22 @@ def output_argument_capture_variables(argN)
|
||||
puts " DECLARE_ARG(ARG#{argN}_TYPE, #{argN}, FUNCNAME) \\"
|
||||
end
|
||||
|
||||
|
||||
def in_struct
|
||||
puts "typedef struct FUNCNAME##_Fake { \\"
|
||||
yield
|
||||
puts "} FUNCNAME##_Fake;\\"
|
||||
end
|
||||
|
||||
def output_variables(arg_count, is_value_function)
|
||||
arg_count.times { |i| output_argument_capture_variables(i) }
|
||||
puts " DECLARE_ALL_FUNC_COMMON(FUNCNAME) \\"
|
||||
puts " DECLARE_VALUE_FUNCTION_VARIABLES(FUNCNAME, RETURN_TYPE) \\" unless not is_value_function
|
||||
in_struct{
|
||||
arg_count.times { |argN|
|
||||
puts " DECLARE_ARG(ARG#{argN}_TYPE, #{argN}, FUNCNAME) \\"
|
||||
}
|
||||
puts " DECLARE_ALL_FUNC_COMMON(FUNCNAME) \\"
|
||||
puts " DECLARE_VALUE_FUNCTION_VARIABLES(FUNCNAME, RETURN_TYPE) \\" unless not is_value_function
|
||||
}
|
||||
puts "FUNCNAME##_Fake FUNCNAME##_fake;\\"
|
||||
end
|
||||
|
||||
def output_function_signature(args_count, is_value_function)
|
||||
@@ -262,10 +273,11 @@ end
|
||||
def output_reset_function(arg_count, is_value_function)
|
||||
puts " void FUNCNAME##_reset(){ \\"
|
||||
arg_count.times { |i|
|
||||
puts " FUNCNAME##_arg#{i}_val = (ARG#{i}_TYPE) 0; \\"
|
||||
puts " memset(FUNCNAME##_arg#{i}_history, 0, sizeof(FUNCNAME##_arg#{i}_history)); \\"
|
||||
puts " FUNCNAME##_fake.arg#{i}_val = (ARG#{i}_TYPE) 0; \\"
|
||||
puts " memset(FUNCNAME##_fake.arg#{i}_history, 0, sizeof(FUNCNAME##_fake.arg#{i}_history)); \\"
|
||||
}
|
||||
puts " FUNCNAME##_call_count = 0; \\"
|
||||
puts " FUNCNAME##_fake.call_count = 0; \\"
|
||||
puts " FUNCNAME##_fake.arg_history_len = FFF_ARG_HISTORY_LEN;\\"
|
||||
output_reset_function_return if is_value_function
|
||||
puts " } \\"
|
||||
end
|
||||
|
||||
@@ -45,92 +45,92 @@ void setup()
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_never_called_then_callcount_is_zero)
|
||||
{
|
||||
ASSERT_EQ(voidfunc1_call_count, 0);
|
||||
ASSERT_EQ(voidfunc1_fake.call_count, 0);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_called_once_then_callcount_is_one)
|
||||
{
|
||||
voidfunc1(66);
|
||||
ASSERT_EQ(voidfunc1_call_count, 1);
|
||||
ASSERT_EQ(voidfunc1_fake.call_count, 1);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_called_once_and_reset_then_callcount_is_zero)
|
||||
{
|
||||
voidfunc1(66);
|
||||
RESET_FAKE(voidfunc1);
|
||||
ASSERT_EQ(voidfunc1_call_count, 0);
|
||||
ASSERT_EQ(voidfunc1_fake.call_count, 0);
|
||||
}
|
||||
|
||||
// Single Argument
|
||||
TEST_F(FFFTestSuite, when_void_func_with_1_integer_arg_called_then_last_arg_captured)
|
||||
{
|
||||
voidfunc1(77);
|
||||
ASSERT_EQ(voidfunc1_arg0_val, 77);
|
||||
ASSERT_EQ(voidfunc1_fake.arg0_val, 77);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_with_1_integer_arg_called_twice_then_last_arg_captured)
|
||||
{
|
||||
voidfunc1(77);
|
||||
voidfunc1(12);
|
||||
ASSERT_EQ(voidfunc1_arg0_val, 12);
|
||||
ASSERT_EQ(voidfunc1_fake.arg0_val, 12);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_with_1_integer_arg_called_and_reset_then_captured_arg_is_zero)
|
||||
{
|
||||
voidfunc1(11);
|
||||
RESET_FAKE(voidfunc1);
|
||||
ASSERT_EQ(voidfunc1_arg0_val, 0);
|
||||
ASSERT_EQ(voidfunc1_fake.arg0_val, 0);
|
||||
}
|
||||
|
||||
// Two Arguments
|
||||
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_then_last_args_captured)
|
||||
{
|
||||
voidfunc2('a', 'b');
|
||||
ASSERT_EQ(voidfunc2_arg0_val, 'a');
|
||||
ASSERT_EQ(voidfunc2_arg1_val, 'b');
|
||||
ASSERT_EQ(voidfunc2_fake.arg0_val, 'a');
|
||||
ASSERT_EQ(voidfunc2_fake.arg1_val, 'b');
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_twice_then_last_args_captured)
|
||||
{
|
||||
voidfunc2('a', 'b');
|
||||
voidfunc2('c', 'd');
|
||||
ASSERT_EQ(voidfunc2_arg0_val, 'c');
|
||||
ASSERT_EQ(voidfunc2_arg1_val, 'd');
|
||||
ASSERT_EQ(voidfunc2_fake.arg0_val, 'c');
|
||||
ASSERT_EQ(voidfunc2_fake.arg1_val, 'd');
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_and_reset_then_captured_arg_is_zero)
|
||||
{
|
||||
voidfunc2('e', 'f');
|
||||
RESET_FAKE(voidfunc2);
|
||||
ASSERT_EQ(voidfunc2_arg0_val, 0);
|
||||
ASSERT_EQ(voidfunc2_arg1_val, 0);
|
||||
ASSERT_EQ(voidfunc2_fake.arg0_val, 0);
|
||||
ASSERT_EQ(voidfunc2_fake.arg1_val, 0);
|
||||
}
|
||||
|
||||
// Argument history
|
||||
TEST_F(FFFTestSuite, when_fake_func_created_default_history_is_fifty_calls)
|
||||
{
|
||||
ASSERT_EQ(FFF_ARG_HISTORY_LEN, (sizeof voidfunc2_arg0_history) / (sizeof voidfunc2_arg0_history[0]));
|
||||
ASSERT_EQ(FFF_ARG_HISTORY_LEN, (sizeof voidfunc2_arg1_history) / (sizeof voidfunc2_arg1_history[0]));
|
||||
ASSERT_EQ(FFF_ARG_HISTORY_LEN, (sizeof voidfunc2_fake.arg0_history) / (sizeof voidfunc2_fake.arg0_history[0]));
|
||||
ASSERT_EQ(FFF_ARG_HISTORY_LEN, (sizeof voidfunc2_fake.arg1_history) / (sizeof voidfunc2_fake.arg1_history[0]));
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_fake_func_called_then_arguments_captured_in_history)
|
||||
{
|
||||
voidfunc2('g', 'h');
|
||||
ASSERT_EQ('g', voidfunc2_arg0_history[0]);
|
||||
ASSERT_EQ('h', voidfunc2_arg1_history[0]);
|
||||
ASSERT_EQ('g', voidfunc2_fake.arg0_history[0]);
|
||||
ASSERT_EQ('h', voidfunc2_fake.arg1_history[0]);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, argument_history_is_reset_when_RESET_FAKE_called)
|
||||
{
|
||||
//given
|
||||
voidfunc2('g', 'h');
|
||||
ASSERT_EQ('g', voidfunc2_arg0_history[0]);
|
||||
ASSERT_EQ('h', voidfunc2_arg1_history[0]);
|
||||
ASSERT_EQ('g', voidfunc2_fake.arg0_history[0]);
|
||||
ASSERT_EQ('h', voidfunc2_fake.arg1_history[0]);
|
||||
//when
|
||||
RESET_FAKE(voidfunc2);
|
||||
//then
|
||||
ASSERT_EQ('\0', voidfunc2_arg0_history[0]);
|
||||
ASSERT_EQ('\0', voidfunc2_arg1_history[0]);
|
||||
ASSERT_EQ('\0', voidfunc2_fake.arg0_history[0]);
|
||||
ASSERT_EQ('\0', voidfunc2_fake.arg1_history[0]);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_fake_func_called_max_times_then_no_argument_histories_dropped)
|
||||
@@ -140,7 +140,7 @@ TEST_F(FFFTestSuite, when_fake_func_called_max_times_then_no_argument_histories_
|
||||
{
|
||||
voidfunc2('1' + i, '2' + i);
|
||||
}
|
||||
ASSERT_EQ(0u, voidfunc2_arg_histories_dropped);
|
||||
ASSERT_EQ(0u, voidfunc2_fake.arg_histories_dropped);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_fake_func_called_max_times_plus_one_then_one_argument_history_dropped)
|
||||
@@ -151,9 +151,9 @@ TEST_F(FFFTestSuite, when_fake_func_called_max_times_plus_one_then_one_argument_
|
||||
voidfunc2('1' + i, '2' + i);
|
||||
}
|
||||
voidfunc2('1', '2');
|
||||
ASSERT_EQ(1u, voidfunc2_arg_histories_dropped);
|
||||
ASSERT_EQ(1u, voidfunc2_fake.arg_histories_dropped);
|
||||
// Or in other words...
|
||||
ASSERT(voidfunc2_arg_history_len < voidfunc2_call_count);
|
||||
ASSERT(voidfunc2_fake.arg_history_len < voidfunc2_fake.call_count);
|
||||
}
|
||||
|
||||
// Return values
|
||||
@@ -164,13 +164,13 @@ TEST_F(FFFTestSuite, value_func_will_return_zero_by_default)
|
||||
|
||||
TEST_F(FFFTestSuite, value_func_will_return_value_given)
|
||||
{
|
||||
longfunc0_return_val = 99l;
|
||||
longfunc0_fake.return_val = 99l;
|
||||
ASSERT_EQ(99l, longfunc0());
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, value_func_will_return_zero_after_reset)
|
||||
{
|
||||
longfunc0_return_val = 99l;
|
||||
longfunc0_fake.return_val = 99l;
|
||||
RESET_FAKE(longfunc0);
|
||||
ASSERT_EQ(0l, longfunc0());
|
||||
}
|
||||
@@ -251,7 +251,7 @@ TEST_F(FFFTestSuite, default_constants_can_be_overridden)
|
||||
{
|
||||
unsigned sizeCallHistory = (sizeof call_history) / (sizeof call_history[0]);
|
||||
ASSERT_EQ(OVERRIDE_CALL_HIST_LEN, sizeCallHistory);
|
||||
ASSERT_EQ(OVERRIDE_ARG_HIST_LEN, voidfunc2_arg_history_len);
|
||||
ASSERT_EQ(OVERRIDE_ARG_HIST_LEN, voidfunc2_fake.arg_history_len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,92 +32,92 @@ public:
|
||||
// Call counting
|
||||
TEST_F(FFFTestSuite, when_void_func_never_called_then_callcount_is_zero)
|
||||
{
|
||||
ASSERT_EQ(voidfunc1_call_count, 0u);
|
||||
ASSERT_EQ(voidfunc1_fake.call_count, 0u);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_called_once_then_callcount_is_one)
|
||||
{
|
||||
voidfunc1(66);
|
||||
ASSERT_EQ(voidfunc1_call_count, 1u);
|
||||
ASSERT_EQ(voidfunc1_fake.call_count, 1u);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_called_once_and_reset_then_callcount_is_zero)
|
||||
{
|
||||
voidfunc1(66);
|
||||
RESET_FAKE(voidfunc1);
|
||||
ASSERT_EQ(voidfunc1_call_count, 0u);
|
||||
ASSERT_EQ(voidfunc1_fake.call_count, 0u);
|
||||
}
|
||||
|
||||
// Single Argument
|
||||
TEST_F(FFFTestSuite, when_void_func_with_1_integer_arg_called_then_last_arg_captured)
|
||||
{
|
||||
voidfunc1(77);
|
||||
ASSERT_EQ(voidfunc1_arg0_val, 77);
|
||||
ASSERT_EQ(voidfunc1_fake.arg0_val, 77);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_with_1_integer_arg_called_twice_then_last_arg_captured)
|
||||
{
|
||||
voidfunc1(77);
|
||||
voidfunc1(12);
|
||||
ASSERT_EQ(voidfunc1_arg0_val, 12);
|
||||
ASSERT_EQ(voidfunc1_fake.arg0_val, 12);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_with_1_integer_arg_called_and_reset_then_captured_arg_is_zero)
|
||||
{
|
||||
voidfunc1(11);
|
||||
RESET_FAKE(voidfunc1);
|
||||
ASSERT_EQ(voidfunc1_arg0_val, 0);
|
||||
ASSERT_EQ(voidfunc1_fake.arg0_val, 0);
|
||||
}
|
||||
|
||||
// Two Arguments
|
||||
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_then_last_args_captured)
|
||||
{
|
||||
voidfunc2('a', 'b');
|
||||
ASSERT_EQ(voidfunc2_arg0_val, 'a');
|
||||
ASSERT_EQ(voidfunc2_arg1_val, 'b');
|
||||
ASSERT_EQ(voidfunc2_fake.arg0_val, 'a');
|
||||
ASSERT_EQ(voidfunc2_fake.arg1_val, 'b');
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_twice_then_last_args_captured)
|
||||
{
|
||||
voidfunc2('a', 'b');
|
||||
voidfunc2('c', 'd');
|
||||
ASSERT_EQ(voidfunc2_arg0_val, 'c');
|
||||
ASSERT_EQ(voidfunc2_arg1_val, 'd');
|
||||
ASSERT_EQ(voidfunc2_fake.arg0_val, 'c');
|
||||
ASSERT_EQ(voidfunc2_fake.arg1_val, 'd');
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_and_reset_then_captured_arg_is_zero)
|
||||
{
|
||||
voidfunc2('e', 'f');
|
||||
RESET_FAKE(voidfunc2);
|
||||
ASSERT_EQ(voidfunc2_arg0_val, 0);
|
||||
ASSERT_EQ(voidfunc2_arg1_val, 0);
|
||||
ASSERT_EQ(voidfunc2_fake.arg0_val, 0);
|
||||
ASSERT_EQ(voidfunc2_fake.arg1_val, 0);
|
||||
}
|
||||
|
||||
// Argument history
|
||||
TEST_F(FFFTestSuite, when_fake_func_created_default_history_is_fifty_calls)
|
||||
{
|
||||
ASSERT_EQ(FFF_ARG_HISTORY_LEN, (sizeof voidfunc2_arg0_history) / (sizeof voidfunc2_arg0_history[0]));
|
||||
ASSERT_EQ(FFF_ARG_HISTORY_LEN, (sizeof voidfunc2_arg1_history) / (sizeof voidfunc2_arg1_history[0]));
|
||||
ASSERT_EQ(FFF_ARG_HISTORY_LEN, (sizeof voidfunc2_fake.arg0_history) / (sizeof voidfunc2_fake.arg0_history[0]));
|
||||
ASSERT_EQ(FFF_ARG_HISTORY_LEN, (sizeof voidfunc2_fake.arg1_history) / (sizeof voidfunc2_fake.arg1_history[0]));
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_fake_func_called_then_arguments_captured_in_history)
|
||||
{
|
||||
voidfunc2('g', 'h');
|
||||
ASSERT_EQ('g', voidfunc2_arg0_history[0]);
|
||||
ASSERT_EQ('h', voidfunc2_arg1_history[0]);
|
||||
ASSERT_EQ('g', voidfunc2_fake.arg0_history[0]);
|
||||
ASSERT_EQ('h', voidfunc2_fake.arg1_history[0]);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, argument_history_is_reset_when_RESET_FAKE_called)
|
||||
{
|
||||
//given
|
||||
voidfunc2('g', 'h');
|
||||
ASSERT_EQ('g', voidfunc2_arg0_history[0]);
|
||||
ASSERT_EQ('h', voidfunc2_arg1_history[0]);
|
||||
ASSERT_EQ('g', voidfunc2_fake.arg0_history[0]);
|
||||
ASSERT_EQ('h', voidfunc2_fake.arg1_history[0]);
|
||||
//when
|
||||
RESET_FAKE(voidfunc2);
|
||||
//then
|
||||
ASSERT_EQ('\0', voidfunc2_arg0_history[0]);
|
||||
ASSERT_EQ('\0', voidfunc2_arg1_history[0]);
|
||||
ASSERT_EQ('\0', voidfunc2_fake.arg0_history[0]);
|
||||
ASSERT_EQ('\0', voidfunc2_fake.arg1_history[0]);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_fake_func_called_max_times_then_no_argument_histories_dropped)
|
||||
@@ -127,7 +127,7 @@ TEST_F(FFFTestSuite, when_fake_func_called_max_times_then_no_argument_histories_
|
||||
{
|
||||
voidfunc2('1' + i, '2' + i);
|
||||
}
|
||||
ASSERT_EQ(0u, voidfunc2_arg_histories_dropped);
|
||||
ASSERT_EQ(0u, voidfunc2_fake.arg_histories_dropped);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_fake_func_called_max_times_plus_one_then_one_argument_history_dropped)
|
||||
@@ -138,9 +138,9 @@ TEST_F(FFFTestSuite, when_fake_func_called_max_times_plus_one_then_one_argument_
|
||||
voidfunc2('1' + i, '2' + i);
|
||||
}
|
||||
voidfunc2('1', '2');
|
||||
ASSERT_EQ(1u, voidfunc2_arg_histories_dropped);
|
||||
ASSERT_EQ(1u, voidfunc2_fake.arg_histories_dropped);
|
||||
// or in other words..
|
||||
ASSERT_GT(voidfunc2_call_count, voidfunc2_arg_history_len);
|
||||
ASSERT_GT(voidfunc2_fake.call_count, voidfunc2_fake.arg_history_len);
|
||||
}
|
||||
|
||||
// Return values
|
||||
@@ -151,13 +151,13 @@ TEST_F(FFFTestSuite, value_func_will_return_zero_by_default)
|
||||
|
||||
TEST_F(FFFTestSuite, value_func_will_return_value_given)
|
||||
{
|
||||
longfunc0_return_val = 99l;
|
||||
longfunc0_fake.return_val = 99l;
|
||||
ASSERT_EQ(99l, longfunc0());
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, value_func_will_return_zero_after_reset)
|
||||
{
|
||||
longfunc0_return_val = 99l;
|
||||
longfunc0_fake.return_val = 99l;
|
||||
RESET_FAKE(longfunc0);
|
||||
ASSERT_EQ(0l, longfunc0());
|
||||
}
|
||||
@@ -239,6 +239,6 @@ TEST_F(FFFTestSuite, default_constants_can_be_overridden)
|
||||
{
|
||||
unsigned sizeCallHistory = (sizeof call_history) / (sizeof call_history[0]);
|
||||
ASSERT_EQ(OVERRIDE_CALL_HIST_LEN, sizeCallHistory);
|
||||
ASSERT_EQ(OVERRIDE_ARG_HIST_LEN, voidfunc2_arg_history_len);
|
||||
ASSERT_EQ(OVERRIDE_ARG_HIST_LEN, voidfunc2_fake.arg_history_len);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user