mirror of
https://github.com/meekrosoft/fff
synced 2026-01-23 08:25:59 +01:00
Removed src base directory
This commit is contained in:
66
examples/Makefile
Normal file
66
examples/Makefile
Normal file
@@ -0,0 +1,66 @@
|
||||
$(VERBOSE).SILENT:
|
||||
|
||||
BUILD_DIR = ../build
|
||||
TEMPLATE_PROGNAME = $(BUILD_DIR)/template
|
||||
C_PROGNAME = $(BUILD_DIR)/cmock
|
||||
CPP_PROGNAME = $(BUILD_DIR)/cppmock
|
||||
CC = gcc
|
||||
CC += -c
|
||||
CPP = g++
|
||||
CPP += -c
|
||||
LD = g++
|
||||
|
||||
C_OBJFILES = $(BUILD_DIR)/cmocktest.o $(BUILD_DIR)/embedded.o
|
||||
TEMPLATE_OBJFILES = $(BUILD_DIR)/test_suite_template.o
|
||||
CPP_OBJFILES = $(BUILD_DIR)/cppmocktest.o $(BUILD_DIR)/embedded.o
|
||||
CPP_LIBS = -lgtest -lpthread -lgtest_main
|
||||
|
||||
|
||||
all: $(C_PROGNAME) $(CPP_PROGNAME) $(TEMPLATE_PROGNAME)
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
@echo "Cleaning object files"
|
||||
@echo " rm -f $(BUILD_DIR)/*.o"
|
||||
rm -f $(BUILD_DIR)/*.o
|
||||
@echo "Cleaning backups"
|
||||
@echo " rm -f *~"
|
||||
rm -f *~
|
||||
@echo "Removing programs"
|
||||
@echo " rm -f "$(C_PROGNAME)
|
||||
rm -f $(C_PROGNAME)
|
||||
@echo " rm -f "$(CPP_PROGNAME) $(TEMPLATE_PROGNAME)
|
||||
rm -f $(CPP_PROGNAME) $(TEMPLATE_PROGNAME)
|
||||
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c
|
||||
@echo "Compiling "$@
|
||||
@echo " CC "$<
|
||||
$(CC) -o $@ $<
|
||||
|
||||
$(BUILD_DIR)/%.o: %.cpp
|
||||
@echo "Compiling "$@
|
||||
@echo " CPP "$<
|
||||
$(CPP) -I/home/mlong/tools/gtest/gtest-1.5.0/include -o $@ $<
|
||||
|
||||
$(TEMPLATE_PROGNAME): $(TEMPLATE_OBJFILES)
|
||||
@echo "Linking "$@
|
||||
@echo " LD -o "ctemplate" "$(TEMPLATE_OBJFILES)
|
||||
$(LD) -o $(TEMPLATE_PROGNAME) $(TEMPLATE_OBJFILES)
|
||||
|
||||
$(C_PROGNAME): $(C_OBJFILES)
|
||||
@echo "Linking "$@
|
||||
@echo " LD -o "$(C_PROGNAME)" "$(C_OBJFILES)
|
||||
$(LD) -o $(C_PROGNAME) $(C_OBJFILES)
|
||||
|
||||
$(CPP_PROGNAME): $(CPP_OBJFILES) $(C_OBJFILES)
|
||||
@echo "Linking "$@
|
||||
@echo " LD -o "$(CPP_PROGNAME)" "$(CPP_OBJFILES)
|
||||
$(LD) -L/home/mlong/tools/gtest -o $(CPP_PROGNAME) $(CPP_OBJFILES) $(CPP_LIBS)
|
||||
|
||||
|
||||
|
||||
nothing:
|
||||
@echo "Nothing to do; quitting :("
|
||||
@echo "HINT: Try make all"
|
||||
115
examples/cmocktest.c
Normal file
115
examples/cmocktest.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* cmock.c
|
||||
*
|
||||
* Created on: Dec 9, 2010
|
||||
* Author: mlong
|
||||
*/
|
||||
|
||||
#include "embedded.h"
|
||||
#include "../fff.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
FAKE_VOID_FUNC0(DISPLAY_init);
|
||||
FAKE_VOID_FUNC0(DISPLAY_clear);
|
||||
FAKE_VOID_FUNC1(DISPLAY_output_message, const char*);
|
||||
FAKE_VALUE_FUNC0(int, DISPLAY_get_line_capacity);
|
||||
FAKE_VALUE_FUNC0(int, DISPLAY_get_line_insert_index);
|
||||
FAKE_VALUE_FUNC2(unsigned char, DISPLAY_get_pixel, unsigned int, unsigned int);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Register resets
|
||||
RESET_FAKE(DISPLAY_init);
|
||||
RESET_FAKE(DISPLAY_clear);
|
||||
RESET_FAKE(DISPLAY_output_message);
|
||||
RESET_FAKE(DISPLAY_get_line_capacity);
|
||||
RESET_FAKE(DISPLAY_get_line_insert_index);
|
||||
|
||||
// non default init
|
||||
DISPLAY_get_line_capacity_return_val = 10;
|
||||
}
|
||||
|
||||
#define TEST_F(IGNORE, NAME) void NAME()
|
||||
TEST_F(GreeterTests, init_initialises_display)
|
||||
{
|
||||
UI_init();
|
||||
assert(1 == DISPLAY_init_call_count);
|
||||
}
|
||||
|
||||
TEST_F(GreeterTests, given_name_when_greet_called_outputs_name)
|
||||
{
|
||||
// given
|
||||
char name[] = "mike";
|
||||
// when
|
||||
UI_greet(name);
|
||||
// then
|
||||
assert(1 == DISPLAY_output_message_call_count);
|
||||
assert(name == DISPLAY_output_message_arg0_val);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(GreeterTests, given_name_and_3_times_when_greetmultiple_called_outputs_name_3_times)
|
||||
{
|
||||
// given
|
||||
char name[] = "mike";
|
||||
// when
|
||||
UI_greet_multiple_times(name, 3);
|
||||
// then
|
||||
assert(3 == DISPLAY_output_message_call_count);
|
||||
assert(name == DISPLAY_output_message_arg0_val);
|
||||
}
|
||||
|
||||
TEST_F(GreeterTests, given_non_full_screen_will_not_reset_display)
|
||||
{
|
||||
char name[] = "mike";
|
||||
// given
|
||||
DISPLAY_get_line_capacity_return_val = 10;
|
||||
DISPLAY_get_line_insert_index_return_val = 0;
|
||||
// when
|
||||
UI_greet(name);
|
||||
// then
|
||||
assert(0 == DISPLAY_clear_call_count);
|
||||
assert(1 == DISPLAY_output_message_call_count);
|
||||
}
|
||||
|
||||
// Order assumption
|
||||
TEST_F(GreeterTests, given_full_screen_single_will_reset_display_then_output)
|
||||
{
|
||||
char name[] = "mike";
|
||||
// given
|
||||
DISPLAY_get_line_capacity_return_val = 1;
|
||||
DISPLAY_get_line_insert_index_return_val = 1;
|
||||
// when
|
||||
UI_greet(name);
|
||||
// then
|
||||
assert(1 == DISPLAY_clear_call_count);
|
||||
assert(1 == DISPLAY_output_message_call_count);
|
||||
}
|
||||
|
||||
// Order assumption
|
||||
TEST_F(GreeterTests, given_full_screen_multiple_will_reset_display_then_output)
|
||||
{
|
||||
char name[] = "mike";
|
||||
// given
|
||||
DISPLAY_get_line_capacity_return_val = 4;
|
||||
DISPLAY_get_line_insert_index_return_val = 4;
|
||||
// when
|
||||
UI_greet_multiple_times(name, 1);
|
||||
// then
|
||||
assert(1 == DISPLAY_clear_call_count);
|
||||
assert(1 == DISPLAY_output_message_call_count);
|
||||
}
|
||||
|
||||
#define RUN_TEST(TESTNAME) printf("Running %s\n", #TESTNAME); setup(); TESTNAME();
|
||||
int main()
|
||||
{
|
||||
RUN_TEST(init_initialises_display);
|
||||
RUN_TEST(given_name_when_greet_called_outputs_name);
|
||||
RUN_TEST(given_name_when_greet_called_outputs_name);
|
||||
RUN_TEST(given_name_and_3_times_when_greetmultiple_called_outputs_name_3_times);
|
||||
RUN_TEST(given_full_screen_single_will_reset_display_then_output);
|
||||
RUN_TEST(given_full_screen_multiple_will_reset_display_then_output);
|
||||
return 0;
|
||||
}
|
||||
106
examples/cppmocktest.cpp
Normal file
106
examples/cppmocktest.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
//============================================================================
|
||||
// Name : cmock.cpp
|
||||
// Author : Mike Long
|
||||
// Version :
|
||||
// Copyright : Don't steal
|
||||
// Description : Hello World in C++, Ansi-style
|
||||
//============================================================================
|
||||
|
||||
#include "../fff.h"
|
||||
|
||||
extern "C"{
|
||||
#include "embedded.h"
|
||||
}
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
FAKE_VOID_FUNC0(DISPLAY_init);
|
||||
FAKE_VOID_FUNC0(DISPLAY_clear);
|
||||
FAKE_VOID_FUNC1(DISPLAY_output_message, const char*);
|
||||
FAKE_VALUE_FUNC0(int, DISPLAY_get_line_capacity);
|
||||
FAKE_VALUE_FUNC0(int, DISPLAY_get_line_insert_index);
|
||||
|
||||
|
||||
class GreeterTests : public testing::Test
|
||||
{
|
||||
public:
|
||||
|
||||
void SetUp()
|
||||
{
|
||||
// Register resets
|
||||
RESET_FAKES();
|
||||
// non default init
|
||||
DISPLAY_get_line_capacity_return_val = 10;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(GreeterTests, init_initialises_display)
|
||||
{
|
||||
UI_init();
|
||||
ASSERT_EQ(1, DISPLAY_init_call_count);
|
||||
}
|
||||
|
||||
TEST_F(GreeterTests, given_name_when_greet_called_outputs_name)
|
||||
{
|
||||
// given
|
||||
char name[] = "mike";
|
||||
// when
|
||||
UI_greet(name);
|
||||
// then
|
||||
ASSERT_EQ(1, DISPLAY_output_message_call_count);
|
||||
ASSERT_EQ(name, DISPLAY_output_message_arg0_val);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(GreeterTests, given_name_and_3_times_when_greetmultiple_called_outputs_name_3_times)
|
||||
{
|
||||
// given
|
||||
char name[] = "mike";
|
||||
// when
|
||||
UI_greet_multiple_times(name, 3);
|
||||
// then
|
||||
ASSERT_EQ(3, DISPLAY_output_message_call_count);
|
||||
ASSERT_EQ(name, DISPLAY_output_message_arg0_val);
|
||||
}
|
||||
|
||||
TEST_F(GreeterTests, given_non_full_screen_will_not_reset_display)
|
||||
{
|
||||
char name[] = "mike";
|
||||
// given
|
||||
DISPLAY_get_line_capacity_return_val = 10;
|
||||
DISPLAY_get_line_insert_index_return_val = 0;
|
||||
// when
|
||||
UI_greet(name);
|
||||
// then
|
||||
ASSERT_EQ(0, DISPLAY_clear_call_count);
|
||||
ASSERT_EQ(1, DISPLAY_output_message_call_count);
|
||||
}
|
||||
|
||||
// Order assumption
|
||||
TEST_F(GreeterTests, given_full_screen_single_will_reset_display_then_output)
|
||||
{
|
||||
char name[] = "mike";
|
||||
// given
|
||||
DISPLAY_get_line_capacity_return_val = 1;
|
||||
DISPLAY_get_line_insert_index_return_val = 1;
|
||||
// when
|
||||
UI_greet(name);
|
||||
// then
|
||||
ASSERT_EQ(1, DISPLAY_clear_call_count);
|
||||
ASSERT_EQ(1, DISPLAY_output_message_call_count);
|
||||
}
|
||||
|
||||
// Order assumption
|
||||
TEST_F(GreeterTests, given_full_screen_multiple_will_reset_display_then_output)
|
||||
{
|
||||
char name[] = "mike";
|
||||
// given
|
||||
DISPLAY_get_line_capacity_return_val = 4;
|
||||
DISPLAY_get_line_insert_index_return_val = 4;
|
||||
// when
|
||||
UI_greet_multiple_times(name, 1);
|
||||
// then
|
||||
ASSERT_EQ(1, DISPLAY_clear_call_count);
|
||||
ASSERT_EQ(1, DISPLAY_output_message_call_count);
|
||||
}
|
||||
|
||||
35
examples/embedded.c
Normal file
35
examples/embedded.c
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
|
||||
|
||||
void DISPLAY_init();
|
||||
void DISPLAY_clear();
|
||||
int DISPLAY_get_line_capacity();
|
||||
int DISPLAY_get_line_insert_index();
|
||||
void DISPLAY_output_message(char * message);
|
||||
unsigned char DISPLAY_get_pixel(unsigned int x, unsigned int y);
|
||||
|
||||
void UI_init()
|
||||
{
|
||||
DISPLAY_init();
|
||||
}
|
||||
|
||||
void UI_greet(char * name)
|
||||
{
|
||||
if(DISPLAY_get_line_capacity() == DISPLAY_get_line_insert_index())
|
||||
{
|
||||
DISPLAY_clear();
|
||||
}
|
||||
DISPLAY_output_message(name);
|
||||
}
|
||||
|
||||
void UI_greet_multiple_times(char * name, int times)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < times; i++)
|
||||
{
|
||||
UI_greet(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
10
examples/embedded.h
Normal file
10
examples/embedded.h
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#ifndef EMBEDDED_CODE
|
||||
#define EMBEDDED_CODE
|
||||
|
||||
void UI_init();
|
||||
void UI_greet(char * name);
|
||||
void UI_greet_multiple_times(char * name, int times);
|
||||
|
||||
|
||||
#endif /* EMBEDDED_CODE */
|
||||
40
examples/test_suite_template.c
Normal file
40
examples/test_suite_template.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void setup();
|
||||
#define TEST_F(SUITE, NAME) void NAME()
|
||||
#define RUN_TEST(TESTNAME) printf(" Running %s: ", #TESTNAME); fflush(0); setup(); TESTNAME(); printf(" SUCCESS\n");
|
||||
|
||||
|
||||
/* Initialializers called for every test */
|
||||
void setup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* Tests go here */
|
||||
TEST_F(GreeterTests, hello_world)
|
||||
{
|
||||
assert(1 == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
setbuf(stderr, NULL);
|
||||
fprintf(stdout, "-------------\n");
|
||||
fprintf(stdout, "Running Tests\n");
|
||||
fprintf(stdout, "-------------\n\n");
|
||||
fflush(0);
|
||||
|
||||
/* Run tests */
|
||||
RUN_TEST(hello_world);
|
||||
|
||||
|
||||
printf("\n-------------\n");
|
||||
printf("Complete\n");
|
||||
printf("-------------\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user