mirror of
https://github.com/meekrosoft/fff
synced 2026-01-23 08:25:59 +01:00
Initial tests for global fakes
This commit is contained in:
69
test/fff_test_global_c.c
Normal file
69
test/fff_test_global_c.c
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
#include "global_fakes.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Test Framework :-) */
|
||||
void setup();
|
||||
#define TEST_F(SUITE, NAME) void NAME()
|
||||
#define RUN_TEST(SUITE, TESTNAME) printf(" Running %s.%s: \n", #SUITE, #TESTNAME); setup(); TESTNAME(); printf(" SUCCESS\n");
|
||||
#define ASSERT_EQ(A, B) assert((A) == (B))
|
||||
#define ASSERT(A) assert((A))
|
||||
|
||||
|
||||
// DECLARE_GLOBAL_FAKE_VOID_FUNC(global_void_func, int);
|
||||
|
||||
// Let's see if I can define a fake here
|
||||
#define MY_FACE_VOID_FUNC0(FUNCNAME) \
|
||||
DECLARE_FAKE_VOID_FUNC0(FUNCNAME) \
|
||||
DEFINE_FAKE_VOID_FUNC0(FUNCNAME)
|
||||
|
||||
MY_FACE_VOID_FUNC0(test_func);
|
||||
|
||||
void setup()
|
||||
{
|
||||
RESET_FAKE(global_void_func);
|
||||
RESET_FAKE(test_func);
|
||||
RESET_HISTORY();
|
||||
}
|
||||
|
||||
|
||||
TEST_F(FFFGlobalTestSuite, when_global_void_func_never_called_then_callcount_is_zero)
|
||||
{
|
||||
ASSERT_EQ(global_void_func_fake.call_count, 0);
|
||||
}
|
||||
|
||||
TEST_F(FFFGlobalTestSuite, when_global_void_func_called_once_then_callcount_is_one)
|
||||
{
|
||||
global_void_func();
|
||||
ASSERT_EQ(global_void_func_fake.call_count, 1);
|
||||
}
|
||||
|
||||
TEST_F(FFFTestSuite, when_void_func_called_once_and_reset_then_callcount_is_zero)
|
||||
{
|
||||
global_void_func();
|
||||
RESET_FAKE(global_void_func);
|
||||
ASSERT_EQ(global_void_func_fake.call_count, 0);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
setbuf(stdout, NULL);
|
||||
fprintf(stdout, "-------------\n");
|
||||
fprintf(stdout, "Running Tests\n");
|
||||
fprintf(stdout, "-------------\n\n");
|
||||
fflush(0);
|
||||
|
||||
/* Run tests */
|
||||
RUN_TEST(FFFGlobalTestSuite, when_global_void_func_never_called_then_callcount_is_zero);
|
||||
RUN_TEST(FFFGlobalTestSuite, when_global_void_func_called_once_then_callcount_is_one);
|
||||
|
||||
printf("\n-------------\n");
|
||||
printf("Complete\n");
|
||||
printf("-------------\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
4
test/global_fakes.c
Normal file
4
test/global_fakes.c
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "global_fakes.h"
|
||||
#include <string.h>
|
||||
DEFINE_FAKE_VOID_FUNC0(global_void_func);
|
||||
|
||||
10
test/global_fakes.h
Normal file
10
test/global_fakes.h
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#ifndef GLOBAL_FAKES_H_
|
||||
#define GLOBAL_FAKES_H_
|
||||
|
||||
#include "../fff3.h"
|
||||
|
||||
void global_void_func(void);
|
||||
DECLARE_FAKE_VOID_FUNC0(global_void_func);
|
||||
|
||||
#endif /* GLOBAL_FAKES_H_ */
|
||||
Reference in New Issue
Block a user