From b98825d20a6673a5a6fe2b31721b0ec01fc61a0b Mon Sep 17 00:00:00 2001 From: Mike Long Date: Tue, 26 Apr 2011 17:38:00 +0100 Subject: [PATCH] Update documentation with new declaration style --- README.md | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4c86b9e..2864847 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Here's how you would define a fake function for this in your test suite: // test.c(pp) #include "fff.h" - FAKE_VOID_FUNC0(DISPLAY_init); + FAKE_VOID_FUNC(DISPLAY_init); And the unit test might look something like this: @@ -38,7 +38,7 @@ So what has happened here? The first thing to note is that the framework is header only, all you need to do to use it is download fff.h and include it in your test suite. -The magic is in the FAKE_VOID_FUNC0. This +The magic is in the FAKE_VOID_FUNC. This expands a macro that defines a function returning void which has zero arguments. It also defines a variable "function_name"_call_count which is incremented every time the faked @@ -66,7 +66,7 @@ Ok, enough with the toy examples. What about faking functions with arguments? Here's how you would define a fake function for this in your test suite: - FAKE_VOID_FUNC1(DISPLAY_output_message, const char*); + FAKE_VOID_FUNC(DISPLAY_output_message, const char*); And the unit test might look something like this: @@ -78,9 +78,9 @@ And the unit test might look something like this: ASSERT_EQ(name, DISPLAY_output_message_arg0_val); } -There is no more magic here, the FAKE_VOID_FUNC1 works as in the -previous example. The "1" defines the number of arguments that the function -takes, and the macro arguments following the function name defines the argument +There is no more magic here, the FAKE_VOID_FUNC works as in the +previous example. The number of arguments that the function takes is calculated, + and the macro arguments following the function name defines the argument type (a char pointer in this example). A variable is created for every argument in the form @@ -91,7 +91,7 @@ A variable is created for every argument in the form ## Return values When you want to define a fake function that returns a value, you should use the -FAKE_VOID_FUNC family of macros. For instance: +FAKE_VOID_FUNC macro. For instance: // UI.c ... @@ -101,8 +101,8 @@ When you want to define a fake function that returns a value, you should use the Here's how you would define a fake functions for these in your test suite: - FAKE_VALUE_FUNC0(int, DISPLAY_get_line_insert_index); - FAKE_VALUE_FUNC0(int, DISPLAY_get_line_capacity); + FAKE_VALUE_FUNC(int, DISPLAY_get_line_insert_index); + FAKE_VALUE_FUNC(int, DISPLAY_get_line_capacity); And the unit test might look something like this: @@ -126,7 +126,7 @@ arguments, for instance to fake: you would use a syntax like this: - FAKE_VALUE_FUNC2(double, pow, double, double); + FAKE_VALUE_FUNC(double, pow, double, double); @@ -163,8 +163,8 @@ history so that it is easy to assert these expectations. Here's how it works: - FAKE_VOID_FUNC2(voidfunc2, char, char); - FAKE_VALUE_FUNC0(long, longfunc0); + FAKE_VOID_FUNC(voidfunc2, char, char); + FAKE_VALUE_FUNC(long, longfunc0); TEST_F(FFFTestSuite, calls_in_correct_order) { @@ -236,7 +236,7 @@ events. One way to do this with fff is to specify a sequence of return values with for the fake function. It is probably easier to describe with an example: // faking "long longfunc();" - FAKE_VALUE_FUNC0(long, longfunc0); + FAKE_VALUE_FUNC(long, longfunc0); TEST_F(FFFTestSuite, return_value_sequences_exhausted) { @@ -260,6 +260,9 @@ value in the sequence indefinitely. Look under the examlples directory for full length examples in both C and C++. There is also a test suite for the framework under the test directory. +## Brief Intorduction, Powerpoint Style! +
Unit Testing Legacy C
View more presentations from Michael Long
+ ------------------------- ## Benefits @@ -294,14 +297,14 @@ So whats the point? Example - FAKE_VOID_FUNC{n}(fn [,arg_types*]); + FAKE_VOID_FUNC(fn [,arg_types*]); Define a fake function named fn returning void with n arguments - FAKE_VOID_FUNC1(DISPLAY_output_message, const char*); + FAKE_VOID_FUNC(DISPLAY_output_message, const char*); - FAKE_VALUE_FUNC{n}(return_type, fn [,arg_types*]); + FAKE_VALUE_FUNC(return_type, fn [,arg_types*]); Define a fake function returning a value with type return_type taking n arguments - FAKE_VALUE_FUNC0(int, DISPLAY_get_line_insert_index); + FAKE_VALUE_FUNC(int, DISPLAY_get_line_insert_index); RESET_FAKE(fn);