1
0
mirror of https://github.com/meekrosoft/fff synced 2026-01-23 08:25:59 +01:00

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?
This commit is contained in:
Paulo Antonio Alvarez
2016-09-14 01:15:23 -03:00
parent 845a8e2549
commit 961289f578
7 changed files with 63 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ struct MyStruct {
FAKE_VOID_FUNC(voidfunc1, int); FAKE_VOID_FUNC(voidfunc1, int);
FAKE_VOID_FUNC(voidfunc2, char, char); FAKE_VOID_FUNC(voidfunc2, char, char);
FAKE_VOID_FUNC(voidfunc1outparam, char *);
FAKE_VALUE_FUNC(long, longfunc0); FAKE_VALUE_FUNC(long, longfunc0);
FAKE_VALUE_FUNC(enum MYBOOL, enumfunc0); FAKE_VALUE_FUNC(enum MYBOOL, enumfunc0);
FAKE_VALUE_FUNC(struct MyStruct, structfunc0); FAKE_VALUE_FUNC(struct MyStruct, structfunc0);
@@ -36,6 +37,7 @@ void setup()
{ {
RESET_FAKE(voidfunc1); RESET_FAKE(voidfunc1);
RESET_FAKE(voidfunc2); RESET_FAKE(voidfunc2);
RESET_FAKE(voidfunc1outparam);
RESET_FAKE(longfunc0); RESET_FAKE(longfunc0);
RESET_FAKE(enumfunc0); RESET_FAKE(enumfunc0);
RESET_FAKE(structfunc0); RESET_FAKE(structfunc0);

View File

@@ -19,6 +19,7 @@ DEFINE_FFF_GLOBALS
FAKE_VOID_FUNC(voidfunc1, int); FAKE_VOID_FUNC(voidfunc1, int);
FAKE_VOID_FUNC(voidfunc2, char, char); FAKE_VOID_FUNC(voidfunc2, char, char);
FAKE_VOID_FUNC(voidfunc1outparam, char *);
FAKE_VALUE_FUNC(long, longfunc0); 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_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(voidfunc1);
RESET_FAKE(voidfunc2); RESET_FAKE(voidfunc2);
RESET_FAKE(longfunc0); RESET_FAKE(longfunc0);
RESET_FAKE(voidfunc1outparam);
FFF_RESET_HISTORY(); FFF_RESET_HISTORY();
} }
}; };

View File

@@ -10,6 +10,7 @@ void setup()
{ {
RESET_FAKE(voidfunc1); RESET_FAKE(voidfunc1);
RESET_FAKE(voidfunc2); RESET_FAKE(voidfunc2);
RESET_FAKE(voidfunc1outparam);
RESET_FAKE(longfunc0); RESET_FAKE(longfunc0);
RESET_FAKE(enumfunc0); RESET_FAKE(enumfunc0);
RESET_FAKE(structfunc0); RESET_FAKE(structfunc0);

View File

@@ -14,6 +14,7 @@ public:
RESET_FAKE(voidfunc1); RESET_FAKE(voidfunc1);
RESET_FAKE(voidfunc2); RESET_FAKE(voidfunc2);
RESET_FAKE(longfunc0); RESET_FAKE(longfunc0);
RESET_FAKE(voidfunc1outparam);
FFF_RESET_HISTORY(); FFF_RESET_HISTORY();
} }
}; };

View File

@@ -3,6 +3,7 @@
DEFINE_FAKE_VOID_FUNC1(voidfunc1, int); DEFINE_FAKE_VOID_FUNC1(voidfunc1, int);
DEFINE_FAKE_VOID_FUNC2(voidfunc2, char, char); DEFINE_FAKE_VOID_FUNC2(voidfunc2, char, char);
DEFINE_FAKE_VOID_FUNC1(voidfunc1outparam, char *);
DEFINE_FAKE_VALUE_FUNC0(long, longfunc0); DEFINE_FAKE_VALUE_FUNC0(long, longfunc0);
DEFINE_FAKE_VALUE_FUNC0(enum MYBOOL, enumfunc0); DEFINE_FAKE_VALUE_FUNC0(enum MYBOOL, enumfunc0);
DEFINE_FAKE_VALUE_FUNC0(struct MyStruct, structfunc0); DEFINE_FAKE_VALUE_FUNC0(struct MyStruct, structfunc0);

View File

@@ -9,6 +9,7 @@
//// Imaginary production code header file /// //// Imaginary production code header file ///
void voidfunc1(int); void voidfunc1(int);
void voidfunc2(char, char); void voidfunc2(char, char);
void voidfunc1outparam(char *);
long longfunc0(); long longfunc0();
void voidfunc3var(const char *fmt, int argc, ...); void voidfunc3var(const char *fmt, int argc, ...);
int valuefunc3var(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_FUNC1(voidfunc1, int);
DECLARE_FAKE_VOID_FUNC2(voidfunc2, char, char); DECLARE_FAKE_VOID_FUNC2(voidfunc2, char, char);
DECLARE_FAKE_VOID_FUNC1(voidfunc1outparam, char *);
DECLARE_FAKE_VALUE_FUNC0(long, longfunc0); DECLARE_FAKE_VALUE_FUNC0(long, longfunc0);
DECLARE_FAKE_VALUE_FUNC0(enum MYBOOL, enumfunc0); DECLARE_FAKE_VALUE_FUNC0(enum MYBOOL, enumfunc0);
DECLARE_FAKE_VALUE_FUNC0(struct MyStruct, structfunc0); DECLARE_FAKE_VALUE_FUNC0(struct MyStruct, structfunc0);

View File

@@ -225,6 +225,60 @@ TEST_F(FFFTestSuite, can_register_custom_fake)
ASSERT_EQ(1, my_custom_fake_called); 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); //DECLARE_FAKE_VALUE_FUNC0(long, longfunc0);
#define MEANING_OF_LIFE 42 #define MEANING_OF_LIFE 42
long my_custom_value_fake(void) long my_custom_value_fake(void)