From 961289f5783c3dc755e16329e2e835373159d659 Mon Sep 17 00:00:00 2001 From: Paulo Antonio Alvarez Date: Wed, 14 Sep 2016 01:15:23 -0300 Subject: [PATCH] Added two test cases for SET_CUSTOM_FAKE_SEQ Using a function that sets a value on a variable via a char pointer, we test the following: 1 - Does the custom fakes are called in the expected order? 2 - When the sequence length is exhausted, do we only call the last custom fake in the sequence from then on? --- test/fff_test_c.c | 2 ++ test/fff_test_cpp.cpp | 2 ++ test/fff_test_global_c.c | 1 + test/fff_test_global_cpp.cpp | 1 + test/global_fakes.c | 1 + test/global_fakes.h | 2 ++ test/test_cases.include | 54 ++++++++++++++++++++++++++++++++++++ 7 files changed, 63 insertions(+) diff --git a/test/fff_test_c.c b/test/fff_test_c.c index 3486c86..7ea1960 100644 --- a/test/fff_test_c.c +++ b/test/fff_test_c.c @@ -24,6 +24,7 @@ struct MyStruct { FAKE_VOID_FUNC(voidfunc1, int); FAKE_VOID_FUNC(voidfunc2, char, char); +FAKE_VOID_FUNC(voidfunc1outparam, char *); FAKE_VALUE_FUNC(long, longfunc0); FAKE_VALUE_FUNC(enum MYBOOL, enumfunc0); FAKE_VALUE_FUNC(struct MyStruct, structfunc0); @@ -36,6 +37,7 @@ void setup() { RESET_FAKE(voidfunc1); RESET_FAKE(voidfunc2); + RESET_FAKE(voidfunc1outparam); RESET_FAKE(longfunc0); RESET_FAKE(enumfunc0); RESET_FAKE(structfunc0); diff --git a/test/fff_test_cpp.cpp b/test/fff_test_cpp.cpp index dcd2889..208ff51 100644 --- a/test/fff_test_cpp.cpp +++ b/test/fff_test_cpp.cpp @@ -19,6 +19,7 @@ DEFINE_FFF_GLOBALS 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); @@ -30,6 +31,7 @@ public: RESET_FAKE(voidfunc1); RESET_FAKE(voidfunc2); RESET_FAKE(longfunc0); + RESET_FAKE(voidfunc1outparam); FFF_RESET_HISTORY(); } }; diff --git a/test/fff_test_global_c.c b/test/fff_test_global_c.c index 8768fed..268693a 100644 --- a/test/fff_test_global_c.c +++ b/test/fff_test_global_c.c @@ -10,6 +10,7 @@ void setup() { RESET_FAKE(voidfunc1); RESET_FAKE(voidfunc2); + RESET_FAKE(voidfunc1outparam); RESET_FAKE(longfunc0); RESET_FAKE(enumfunc0); RESET_FAKE(structfunc0); diff --git a/test/fff_test_global_cpp.cpp b/test/fff_test_global_cpp.cpp index dfe1e88..b4f3275 100644 --- a/test/fff_test_global_cpp.cpp +++ b/test/fff_test_global_cpp.cpp @@ -14,6 +14,7 @@ public: RESET_FAKE(voidfunc1); RESET_FAKE(voidfunc2); RESET_FAKE(longfunc0); + RESET_FAKE(voidfunc1outparam); FFF_RESET_HISTORY(); } }; diff --git a/test/global_fakes.c b/test/global_fakes.c index 0e4c07a..1b93394 100644 --- a/test/global_fakes.c +++ b/test/global_fakes.c @@ -3,6 +3,7 @@ DEFINE_FAKE_VOID_FUNC1(voidfunc1, int); DEFINE_FAKE_VOID_FUNC2(voidfunc2, char, char); +DEFINE_FAKE_VOID_FUNC1(voidfunc1outparam, char *); DEFINE_FAKE_VALUE_FUNC0(long, longfunc0); DEFINE_FAKE_VALUE_FUNC0(enum MYBOOL, enumfunc0); DEFINE_FAKE_VALUE_FUNC0(struct MyStruct, structfunc0); diff --git a/test/global_fakes.h b/test/global_fakes.h index 3b2d49e..8ee7c3f 100644 --- a/test/global_fakes.h +++ b/test/global_fakes.h @@ -9,6 +9,7 @@ //// Imaginary production code header file /// void voidfunc1(int); void voidfunc2(char, char); +void voidfunc1outparam(char *); long longfunc0(); void voidfunc3var(const char *fmt, int argc, ...); int valuefunc3var(const char *fmt, int argc, ...); @@ -25,6 +26,7 @@ struct MyStruct structfunc(); DECLARE_FAKE_VOID_FUNC1(voidfunc1, int); DECLARE_FAKE_VOID_FUNC2(voidfunc2, char, char); +DECLARE_FAKE_VOID_FUNC1(voidfunc1outparam, char *); DECLARE_FAKE_VALUE_FUNC0(long, longfunc0); DECLARE_FAKE_VALUE_FUNC0(enum MYBOOL, enumfunc0); DECLARE_FAKE_VALUE_FUNC0(struct MyStruct, structfunc0); diff --git a/test/test_cases.include b/test/test_cases.include index 61dc0fe..b192c96 100644 --- a/test/test_cases.include +++ b/test/test_cases.include @@ -225,6 +225,60 @@ TEST_F(FFFTestSuite, can_register_custom_fake) ASSERT_EQ(1, my_custom_fake_called); } +void voidfunc1outparam_custom_fake1(char *a) +{ + *a = 'x'; +} + +void voidfunc1outparam_custom_fake2(char *a) +{ + *a = 'y'; +} + +void voidfunc1outparam_custom_fake3(char *a) +{ + *a = 'z'; +} + +TEST_F(FFFTestSuite, custom_fake_sequence_not_exausthed) +{ + void (*custom_fakes[])(char *) = {voidfunc1outparam_custom_fake1, + voidfunc1outparam_custom_fake2, + voidfunc1outparam_custom_fake3}; + char a = 'a'; + + SET_CUSTOM_FAKE_SEQ(voidfunc1outparam, custom_fakes, 3); + + voidfunc1outparam(&a); + ASSERT_EQ('x', a); + voidfunc1outparam(&a); + ASSERT_EQ('y', a); + voidfunc1outparam(&a); + ASSERT_EQ('z', a); +} + +TEST_F(FFFTestSuite, custom_fake_sequence_exhausted) +{ + void (*custom_fakes[])(char *) = {voidfunc1outparam_custom_fake1, + voidfunc1outparam_custom_fake2, + voidfunc1outparam_custom_fake3}; + char a = 'a'; + + SET_CUSTOM_FAKE_SEQ(voidfunc1outparam, custom_fakes, 3); + + voidfunc1outparam(&a); + ASSERT_EQ('x', a); + voidfunc1outparam(&a); + ASSERT_EQ('y', a); + voidfunc1outparam(&a); + ASSERT_EQ('z', a); + a = 'a'; + voidfunc1outparam(&a); + ASSERT_EQ('z', a); + a = 'b'; + voidfunc1outparam(&a); + ASSERT_EQ('z', a); +} //DECLARE_FAKE_VALUE_FUNC0(long, longfunc0); #define MEANING_OF_LIFE 42 long my_custom_value_fake(void)