mirror of
https://github.com/meekrosoft/fff
synced 2026-01-23 08:25:59 +01:00
Added basic argument history of fixed size
This commit is contained in:
21
fakegen.rb
21
fakegen.rb
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
$cpp_output = true
|
$cpp_output = true
|
||||||
$MAX_ARGS = 10
|
$MAX_ARGS = 10
|
||||||
$MAX_ARG_HISTORY = 10
|
$DEFAULT_ARG_HISTORY = 10
|
||||||
$MAX_CALL_HISTORY = 10
|
$MAX_CALL_HISTORY = 10
|
||||||
|
|
||||||
def output_macro(args, is_value_function)
|
def output_macro(args, is_value_function)
|
||||||
@@ -90,14 +90,15 @@ def output_argument_capture_variables(i)
|
|||||||
# last argument
|
# last argument
|
||||||
puts " static ARG#{i}_TYPE FUNCNAME##_arg#{i}_val; \\"
|
puts " static ARG#{i}_TYPE FUNCNAME##_arg#{i}_val; \\"
|
||||||
# argument history array
|
# argument history array
|
||||||
# puts " static ARG#{i}_TYPE FUNCNAME##_arg#{i}_history[];"
|
puts " static ARG#{i}_TYPE FUNCNAME##_arg#{i}_history[#{$DEFAULT_ARG_HISTORY}];\\"
|
||||||
# puts " static int FUNCNAME##_arg#{i}_history_idx;"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def output_variables(arg_count, is_value_function)
|
def output_variables(arg_count, is_value_function)
|
||||||
arg_count.times { |i| output_argument_capture_variables(i) }
|
arg_count.times { |i| output_argument_capture_variables(i) }
|
||||||
puts " static RETURN_TYPE FUNCNAME##_return_val; \\" unless not is_value_function
|
puts " static RETURN_TYPE FUNCNAME##_return_val; \\" unless not is_value_function
|
||||||
puts " static int FUNCNAME##_call_count = 0; \\"
|
puts " static unsigned int FUNCNAME##_call_count = 0; \\"
|
||||||
|
puts " static unsigned int FUNCNAME##_arg_history_len = #{$DEFAULT_ARG_HISTORY};\\"
|
||||||
|
puts " static unsigned int FUNCNAME##_arg_histories_dropped = 0; \\"
|
||||||
end
|
end
|
||||||
|
|
||||||
def output_function_signature(args_count, is_value_function)
|
def output_function_signature(args_count, is_value_function)
|
||||||
@@ -117,6 +118,18 @@ end
|
|||||||
def output_function_body(arg_count, is_value_function)
|
def output_function_body(arg_count, is_value_function)
|
||||||
# capture arguments
|
# capture arguments
|
||||||
arg_count.times { |i| puts " FUNCNAME##_arg#{i}_val = arg#{i}; \\" }
|
arg_count.times { |i| puts " FUNCNAME##_arg#{i}_val = arg#{i}; \\" }
|
||||||
|
# store in argument history
|
||||||
|
arg_count.times { |i|
|
||||||
|
puts " if(FUNCNAME##_call_count < FUNCNAME##_arg_history_len){\\"
|
||||||
|
puts " FUNCNAME##_arg#{i}_history[FUNCNAME##_call_count] = arg#{i}; \\"
|
||||||
|
puts " }\\"
|
||||||
|
}
|
||||||
|
|
||||||
|
# update dropped argument history counts
|
||||||
|
puts " if(FUNCNAME##_call_count >= FUNCNAME##_arg_history_len){\\"
|
||||||
|
puts " FUNCNAME##_arg_histories_dropped++;\\"
|
||||||
|
puts " }\\"
|
||||||
|
|
||||||
# update call count
|
# update call count
|
||||||
puts " FUNCNAME##_call_count++; \\"
|
puts " FUNCNAME##_call_count++; \\"
|
||||||
#register call
|
#register call
|
||||||
|
|||||||
@@ -85,6 +85,45 @@ TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_and_reset_then_captu
|
|||||||
ASSERT_EQ(voidfunc2_arg1_val, 0);
|
ASSERT_EQ(voidfunc2_arg1_val, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Argument history
|
||||||
|
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_created_default_history_is_ten_calls)
|
||||||
|
{
|
||||||
|
ASSERT_EQ(10u, (sizeof voidfunc2_arg0_history) / (sizeof voidfunc2_arg0_history[0]));
|
||||||
|
ASSERT_EQ(10u, (sizeof voidfunc2_arg1_history) / (sizeof voidfunc2_arg1_history[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_then_arguments_captured_in_history)
|
||||||
|
{
|
||||||
|
voidfunc2('g', 'h');
|
||||||
|
ASSERT_EQ('g', voidfunc2_arg0_history[0]);
|
||||||
|
ASSERT_EQ('h', voidfunc2_arg1_history[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_max_times_then_no_argument_histories_dropped)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
voidfunc2('1'+i, '2'+i);
|
||||||
|
}
|
||||||
|
ASSERT_EQ(0u, voidfunc2_arg_histories_dropped);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_max_times_plus_one_then_one_argument_history_dropped)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
voidfunc2('1'+i, '2'+i);
|
||||||
|
}
|
||||||
|
voidfunc2('1', '2');
|
||||||
|
ASSERT_EQ(1u, voidfunc2_arg_histories_dropped);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Return values
|
// Return values
|
||||||
TEST_F(FFFTestSuite, value_func_will_return_zero_by_default)
|
TEST_F(FFFTestSuite, value_func_will_return_zero_by_default)
|
||||||
{
|
{
|
||||||
@@ -147,6 +186,7 @@ TEST_F(FFFTestSuite, calling_fake_registers_one_call)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
setbuf(stdout, NULL);
|
setbuf(stdout, NULL);
|
||||||
@@ -165,6 +205,12 @@ int main()
|
|||||||
RUN_TEST(FFFTestSuite, when_void_func_with_2_char_args_called_then_last_args_captured);
|
RUN_TEST(FFFTestSuite, when_void_func_with_2_char_args_called_then_last_args_captured);
|
||||||
RUN_TEST(FFFTestSuite, when_void_func_with_2_char_args_called_twice_then_last_args_captured);
|
RUN_TEST(FFFTestSuite, when_void_func_with_2_char_args_called_twice_then_last_args_captured);
|
||||||
RUN_TEST(FFFTestSuite, when_void_func_with_2_char_args_called_and_reset_then_captured_arg_is_zero);
|
RUN_TEST(FFFTestSuite, when_void_func_with_2_char_args_called_and_reset_then_captured_arg_is_zero);
|
||||||
|
|
||||||
|
RUN_TEST(FFFTestSuite, when_void_func_with_2_char_args_created_default_history_is_ten_calls);
|
||||||
|
RUN_TEST(FFFTestSuite, when_void_func_with_2_char_args_called_then_arguments_captured_in_history);
|
||||||
|
RUN_TEST(FFFTestSuite, when_void_func_with_2_char_args_called_max_times_then_no_argument_histories_dropped);
|
||||||
|
RUN_TEST(FFFTestSuite, when_void_func_with_2_char_args_called_max_times_plus_one_then_one_argument_history_dropped);
|
||||||
|
|
||||||
RUN_TEST(FFFTestSuite, value_func_will_return_zero_by_default);
|
RUN_TEST(FFFTestSuite, value_func_will_return_zero_by_default);
|
||||||
RUN_TEST(FFFTestSuite, value_func_will_return_value_given);
|
RUN_TEST(FFFTestSuite, value_func_will_return_value_given);
|
||||||
RUN_TEST(FFFTestSuite, value_func_will_return_zero_after_reset);
|
RUN_TEST(FFFTestSuite, value_func_will_return_zero_after_reset);
|
||||||
|
|||||||
@@ -25,20 +25,20 @@ public:
|
|||||||
// Call counting
|
// Call counting
|
||||||
TEST_F(FFFTestSuite, when_void_func_never_called_then_callcount_is_zero)
|
TEST_F(FFFTestSuite, when_void_func_never_called_then_callcount_is_zero)
|
||||||
{
|
{
|
||||||
ASSERT_EQ(voidfunc1_call_count, 0);
|
ASSERT_EQ(voidfunc1_call_count, 0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FFFTestSuite, when_void_func_called_once_then_callcount_is_one)
|
TEST_F(FFFTestSuite, when_void_func_called_once_then_callcount_is_one)
|
||||||
{
|
{
|
||||||
voidfunc1(66);
|
voidfunc1(66);
|
||||||
ASSERT_EQ(voidfunc1_call_count, 1);
|
ASSERT_EQ(voidfunc1_call_count, 1u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FFFTestSuite, when_void_func_called_once_and_reset_then_callcount_is_zero)
|
TEST_F(FFFTestSuite, when_void_func_called_once_and_reset_then_callcount_is_zero)
|
||||||
{
|
{
|
||||||
voidfunc1(66);
|
voidfunc1(66);
|
||||||
RESET_FAKE(voidfunc1);
|
RESET_FAKE(voidfunc1);
|
||||||
ASSERT_EQ(voidfunc1_call_count, 0);
|
ASSERT_EQ(voidfunc1_call_count, 0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Single Argument
|
// Single Argument
|
||||||
@@ -86,6 +86,45 @@ TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_and_reset_then_captu
|
|||||||
ASSERT_EQ(voidfunc2_arg1_val, 0);
|
ASSERT_EQ(voidfunc2_arg1_val, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Argument history
|
||||||
|
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_created_default_history_is_ten_calls)
|
||||||
|
{
|
||||||
|
ASSERT_EQ(10u, (sizeof voidfunc2_arg0_history) / (sizeof voidfunc2_arg0_history[0]));
|
||||||
|
ASSERT_EQ(10u, (sizeof voidfunc2_arg1_history) / (sizeof voidfunc2_arg1_history[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_then_arguments_captured_in_history)
|
||||||
|
{
|
||||||
|
voidfunc2('g', 'h');
|
||||||
|
ASSERT_EQ('g', voidfunc2_arg0_history[0]);
|
||||||
|
ASSERT_EQ('h', voidfunc2_arg1_history[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_max_times_then_no_argument_histories_dropped)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
voidfunc2('1'+i, '2'+i);
|
||||||
|
}
|
||||||
|
ASSERT_EQ(0u, voidfunc2_arg_histories_dropped);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FFFTestSuite, when_void_func_with_2_char_args_called_max_times_plus_one_then_one_argument_history_dropped)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
voidfunc2('1'+i, '2'+i);
|
||||||
|
}
|
||||||
|
voidfunc2('1', '2');
|
||||||
|
ASSERT_EQ(1u, voidfunc2_arg_histories_dropped);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Return values
|
// Return values
|
||||||
TEST_F(FFFTestSuite, value_func_will_return_zero_by_default)
|
TEST_F(FFFTestSuite, value_func_will_return_zero_by_default)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user