cleanup to follow a more strict C standard

This commit is contained in:
Mark VanderVoord
2014-05-23 11:23:44 -04:00
parent b07e713eb0
commit a4a67519d1
20 changed files with 350 additions and 222 deletions
@@ -26,7 +26,7 @@ class CMockGeneratorPluginReturnThruPtr
lines << "#define #{function[:name]}_ReturnThruPtr_#{arg[:name]}(#{arg[:name]})"
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(*#{arg[:name]}))\n"
lines << "#define #{function[:name]}_ReturnArrayThruPtr_#{arg[:name]}(#{arg[:name]}, cmock_len)"
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, cmock_len * sizeof(*#{arg[:name]}))\n"
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, (int)(cmock_len * (int)sizeof(*#{arg[:name]})))\n"
lines << "#define #{function[:name]}_ReturnMemThruPtr_#{arg[:name]}(#{arg[:name]}, cmock_size)"
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, cmock_size)\n"
lines << "void #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(UNITY_LINE_TYPE cmock_line, #{arg[:type]} #{arg[:name]}, int cmock_size);\n"
+2 -2
View File
@@ -38,7 +38,7 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNew(CMOCK_MEM_INDEX_TYPE size)
{
#ifdef CMOCK_MEM_DYNAMIC
CMock_Guts_BufferSize += CMOCK_MEM_SIZE + size;
CMock_Guts_Buffer = realloc(CMock_Guts_Buffer, CMock_Guts_BufferSize);
CMock_Guts_Buffer = realloc(CMock_Guts_Buffer, (size_t)CMock_Guts_BufferSize);
if (CMock_Guts_Buffer == NULL)
#endif //yes that if will continue to the return below if TRUE
return CMOCK_GUTS_NONE;
@@ -91,7 +91,7 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemChain(CMOCK_MEM_INDEX_TYPE root_index, CMOCK_
if (index > 0)
next = (void*)(&CMock_Guts_Buffer[index]);
} while (index > 0);
*(CMOCK_MEM_INDEX_TYPE*)((CMOCK_MEM_PTR_AS_INT)next - CMOCK_MEM_INDEX_SIZE) = ((CMOCK_MEM_PTR_AS_INT)obj - (CMOCK_MEM_PTR_AS_INT)CMock_Guts_Buffer);
*(CMOCK_MEM_INDEX_TYPE*)((CMOCK_MEM_PTR_AS_INT)next - CMOCK_MEM_INDEX_SIZE) = (CMOCK_MEM_INDEX_TYPE)((CMOCK_MEM_PTR_AS_INT)obj - (CMOCK_MEM_PTR_AS_INT)CMock_Guts_Buffer);
return root_index;
}
}
+1 -1
View File
@@ -12,7 +12,7 @@
#define CMOCK_MEM_INDEX_TYPE unsigned int
#endif
#define CMOCK_GUTS_NONE (0)
#define CMOCK_GUTS_NONE (0)
#define CMOCK_ARG_MODE CMOCK_MEM_INDEX_TYPE
#define CMOCK_ARG_ALL 0
+26 -3
View File
@@ -20,6 +20,29 @@
#endif
//this is used internally during pointer arithmetic. make sure this type is the same size as the target's pointer type
#ifndef CMOCK_MEM_PTR_AS_INT
#ifdef UNITY_POINTER_WIDTH
#ifdef UNITY_INT_WIDTH
#if UNITY_POINTER_WIDTH == UNITY_INT_WIDTH
#define CMOCK_MEM_PTR_AS_INT unsigned int
#endif
#endif
#endif
#endif
#ifndef CMOCK_MEM_PTR_AS_INT
#ifdef UNITY_POINTER_WIDTH
#ifdef UNITY_LONG_WIDTH
#if UNITY_POINTER_WIDTH == UNITY_LONG_WIDTH
#define CMOCK_MEM_PTR_AS_INT unsigned long
#endif
#if UNITY_POINTER_WIDTH > UNITY_LONG_WIDTH
#define CMOCK_MEM_PTR_AS_INT unsigned long long
#endif
#endif
#endif
#endif
#ifndef CMOCK_MEM_PTR_AS_INT
#define CMOCK_MEM_PTR_AS_INT unsigned long
#endif
@@ -35,9 +58,9 @@
#endif
//automatically calculated defs for easier reading
#define CMOCK_MEM_ALIGN_SIZE (1u << CMOCK_MEM_ALIGN)
#define CMOCK_MEM_ALIGN_MASK (CMOCK_MEM_ALIGN_SIZE - 1)
#define CMOCK_MEM_INDEX_SIZE (CMOCK_MEM_PTR_AS_INT)((sizeof(CMOCK_MEM_INDEX_TYPE) > CMOCK_MEM_ALIGN_SIZE) ? sizeof(CMOCK_MEM_INDEX_TYPE) : CMOCK_MEM_ALIGN_SIZE)
#define CMOCK_MEM_ALIGN_SIZE (CMOCK_MEM_INDEX_TYPE)(1u << CMOCK_MEM_ALIGN)
#define CMOCK_MEM_ALIGN_MASK (CMOCK_MEM_INDEX_TYPE)(CMOCK_MEM_ALIGN_SIZE - 1)
#define CMOCK_MEM_INDEX_SIZE (CMOCK_MEM_INDEX_TYPE)(CMOCK_MEM_PTR_AS_INT)((sizeof(CMOCK_MEM_INDEX_TYPE) > CMOCK_MEM_ALIGN_SIZE) ? sizeof(CMOCK_MEM_INDEX_TYPE) : CMOCK_MEM_ALIGN_SIZE)
#endif //CMOCK_FRAMEWORK_INTERNALS
+86
View File
@@ -0,0 +1,86 @@
---
compiler:
path: clang
source_path: &systest_generated_path 'test/system/generated/'
unit_tests_path: &unit_tests_path 'examples/test/'
mocks_path: &systest_mocks_path 'test/system/generated/'
build_path: &systest_build_path 'test/system/build/'
options:
- '-c'
- '-Wall'
- '-Wextra'
- '-Werror'
- '-Wcast-qual'
- '-Wconversion'
- '-Wdisabled-optimization'
- '-Wformat=2'
- '-Winit-self'
- '-Winline'
- '-Winvalid-pch'
- '-Wmissing-declarations'
- '-Wmissing-include-dirs'
- '-Wmissing-prototypes'
- '-Wnonnull'
- '-Wpacked'
- '-Wpointer-arith'
- '-Wredundant-decls'
- '-Wswitch-default'
- '-Wstrict-aliasing'
- '-Wstrict-overflow=5'
- '-Wuninitialized'
- '-Wunused'
- '-Wunreachable-code'
- '-Wreturn-type'
- '-Wshadow'
- '-Wundef'
- '-Wwrite-strings'
- '-Wbad-function-cast'
- '-Wno-missing-prototypes' #we've been lazy about things like setUp and tearDown
- '-Wno-duplicate-decl-specifier' #allows us to test things like "const char const *""
- '-fms-extensions'
- '-fno-omit-frame-pointer'
- '-ffloat-store'
- '-fno-common'
- '-fstrict-aliasing'
- '-std=gnu99'
- '-pedantic'
- '-O0'
includes:
prefix: '-I'
items:
- *systest_generated_path
- *unit_tests_path
- *systest_mocks_path
- 'src/'
- 'vendor/unity/src/'
- 'vendor/c_exception/lib/'
- 'test/system/test_compilation/'
- 'test/'
defines:
prefix: '-D'
items:
- 'UNITY_SUPPORT_64'
- 'UNITY_POINTER_WIDTH=64'
object_files:
prefix: '-o'
extension: '.o'
destination: *systest_build_path
linker:
path: gcc
options:
- -lm
includes:
prefix: '-I'
object_files:
path: *systest_build_path
extension: '.o'
bin_files:
prefix: '-o'
extension: '.exe'
destination: *systest_build_path
unsupported:
- callingconv
colour: true
+2
View File
@@ -8,11 +8,13 @@ compiler:
options:
- '-c'
- '-Wall'
- '-Wextra'
- '-Wunused-parameter'
- '-Wno-duplicate-decl-specifier'
- '-Wno-address'
- '-std=c99'
- '-pedantic'
- '-O0'
includes:
prefix: '-I'
items:
+3 -3
View File
@@ -240,9 +240,9 @@ void test_ThatWeCanAskForAllSortsOfSizes(void)
unsigned int i;
CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE;
CMOCK_MEM_INDEX_TYPE next;
unsigned int sizes[5] = {3, 1, 80, 5, 4};
unsigned int sizes_buffered[5] = {4, 4, 80, 8, 4};
unsigned int sum = 0;
CMOCK_MEM_INDEX_TYPE sizes[5] = {3, 1, 80, 5, 4};
CMOCK_MEM_INDEX_TYPE sizes_buffered[5] = {4, 4, 80, 8, 4};
CMOCK_MEM_INDEX_TYPE sum = 0;
for (i = 0; i < 5; i++)
{
+11 -11
View File
@@ -7,10 +7,10 @@
#include "unity.h"
#include "cmock.h"
#define TEST_MEM_INDEX_SIZE (sizeof(CMOCK_MEM_INDEX_TYPE))
#define TEST_MEM_INDEX_PAD ((sizeof(CMOCK_MEM_INDEX_TYPE) + 7) & ~7) //round up to nearest 4 byte boundary
#define TEST_MEM_INDEX_SIZE (CMOCK_MEM_INDEX_TYPE)(sizeof(CMOCK_MEM_INDEX_TYPE))
#define TEST_MEM_INDEX_PAD (CMOCK_MEM_INDEX_TYPE)(((CMOCK_MEM_INDEX_TYPE)sizeof(CMOCK_MEM_INDEX_TYPE) + 7) & ~7) //round up to nearest 4 byte boundary
unsigned int StartingSize;
CMOCK_MEM_INDEX_TYPE StartingSize;
void setUp(void)
{
@@ -35,11 +35,11 @@ void test_MemNewWillReturnNullIfGivenIllegalSizes(void)
void test_MemNewWillNowSupportSizesGreaterThanTheDefinesCMockSize(void)
{
TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesFree());
TEST_ASSERT_MESSAGE(CMock_Guts_MemNew(CMOCK_MEM_SIZE - TEST_MEM_INDEX_SIZE + 1) != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE");
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE + TEST_MEM_INDEX_PAD, CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
TEST_ASSERT_EQUAL(((CMOCK_MEM_INDEX_TYPE)CMOCK_MEM_SIZE + TEST_MEM_INDEX_PAD), CMock_Guts_MemBytesUsed());
TEST_ASSERT_EQUAL((CMOCK_MEM_INDEX_TYPE)CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree());
}
void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void)
@@ -151,13 +151,13 @@ void test_ThatWeCanClaimAndChainAFewElementsTogether(void)
void test_ThatWeCanAskForAllSortsOfSizes(void)
{
unsigned int i;
CMOCK_MEM_INDEX_TYPE i;
CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE;
CMOCK_MEM_INDEX_TYPE next;
unsigned int sizes[10] = {3, 1, 80, 5, 8, 31, 7, 911, 2, 80};
unsigned int sizes_buffered[10] = {16, 16, 88, 16, 16, 40, 16, 920, 16, 88}; //includes counter
unsigned int sum = 0;
unsigned int cap;
CMOCK_MEM_INDEX_TYPE sizes[10] = {3, 1, 80, 5, 8, 31, 7, 911, 2, 80};
CMOCK_MEM_INDEX_TYPE sizes_buffered[10] = {16, 16, 88, 16, 16, 40, 16, 920, 16, 88}; //includes counter
CMOCK_MEM_INDEX_TYPE sum = 0;
CMOCK_MEM_INDEX_TYPE cap;
for (i = 0; i < 10; i++)
{
@@ -25,8 +25,8 @@
POINT_T* bar(void);
void fooa(POINT_T a[]);
void foos(const char * a);
extern const char * bars(void);
void no_pointers(int a, char* b);
extern const char* bars(void);
void no_pointers(int a, const char* b);
int mixed(int a, int* b, int c);
void no_args(void);
@@ -193,7 +193,9 @@
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
const char* constretval = "This is a\0 silly string";
char* retval = (char*)constretval;
bars_ExpectAndReturn(retval);
foos_Expect("This is a\0 wacky string");
function_c();
@@ -204,7 +206,9 @@
:code: |
test()
{
bars_ExpectAndReturn("This is a silly string");
const char* constretval = "This is a silly string";
char* retval = (char*)constretval;
bars_ExpectAndReturn(retval);
foos_Expect("This is a wacky string");
function_c();
@@ -263,7 +267,9 @@
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
const char* constretval = "This is a\0 silly string";
char* retval = (char*)constretval;
bars_ExpectAndReturn(retval);
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("err");
@@ -275,7 +281,9 @@
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
const char* constretval = "This is a\0 silly string";
char* retval = (char*)constretval;
bars_ExpectAndReturn(retval);
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("wrong error");
@@ -27,7 +27,7 @@
void fooa(POINT_T a[]);
void foos(const char * a);
const char * bars(void);
void no_pointers(int a, char* b);
void no_pointers(int a, const char* b);
int mixed(int a, int* b, int c);
void no_args(void);
@@ -195,7 +195,8 @@
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
const char* retval = "This is a\0 silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a\0 wacky string");
function_c();
@@ -206,7 +207,8 @@
:code: |
test()
{
bars_ExpectAndReturn("This is a silly string");
const char* retval = "This is a silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a wacky string");
function_c();
@@ -265,7 +267,8 @@
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
const char* retval = "This is a\0 silly string";
bars_ExpectAndReturn((char*)retval);
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("err");
@@ -277,7 +280,8 @@
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
const char* retval = "This is a\0 silly string";
bars_ExpectAndReturn((char*)retval);
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("wrong error");
@@ -10,7 +10,7 @@
int x;
int y;
} POINT_T;
#define ARRAY_A_SIZE (5)
#define ARRAY_A_SIZE (5)
:mockable: |
void foo(POINT_T* a);
@@ -18,12 +18,12 @@
void fooa(POINT_T a[ARRAY_A_SIZE+1-1]);
void foos(const char * a);
const char * bars(void);
void no_pointers(int a, char* b);
void no_pointers(int a, const char* b);
int mixed(int a, int* b, int c);
void potential_packing_problem(short *a);
:source:
:header: |
:source:
:header: |
void function_a(void);
void function_b(void);
void function_c(void);
@@ -31,35 +31,35 @@
void function_e(void);
:code: |
void function_a(void)
void function_a(void)
{
foo(bar());
}
}
void function_b(void) {
fooa(bar());
}
void function_c(void) {
foos(bars());
}
int function_d(void) {
int test_list[] = { 1, 2, 3, 4, 5 };
no_pointers(1, "silly");
return mixed(6, test_list, 7);
}
void function_e(void) {
short test_list[] = {-1, -2, -3, -4};
potential_packing_problem(&test_list[1]);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle the situation where we pass nulls to pointers'
@@ -68,10 +68,10 @@
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we expected nulls to pointers but did not get that'
:code: |
@@ -80,10 +80,10 @@
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we did not expect nulls to pointers but got null'
:code: |
@@ -92,10 +92,10 @@
POINT_T ex = {1, 2};
bar_ExpectAndReturn(NULL);
foo_Expect(&ex);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where it falls back to pointers because you asked it to compare 0 elements'
:code: |
@@ -104,10 +104,10 @@
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&ex);
foo_ExpectWithArray(&ex, 0);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where it fails because you asked it to compare zero elements and the pointers do not match'
:code: |
@@ -117,10 +117,10 @@
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 0);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect'
:code: |
@@ -130,10 +130,10 @@
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and it is wrong'
:code: |
@@ -143,10 +143,10 @@
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_Expect(&ex);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect and use array handler'
:code: |
@@ -156,10 +156,10 @@
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and use array handler and it is wrong'
:code: |
@@ -169,10 +169,10 @@
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_ExpectWithArray(&ex, 1);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass multiple objects with expect and use array handler'
:code: |
@@ -182,10 +182,10 @@
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at start'
:code: |
@@ -195,10 +195,10 @@
POINT_T ex[] = {{9, 2}, {3, 4}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at end'
:code: |
@@ -208,10 +208,10 @@
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong in middle'
:code: |
@@ -221,10 +221,10 @@
POINT_T ex[] = {{1, 2}, {3, 9}, {5, 6}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass nulls to pointers and fail'
:code: |
@@ -233,10 +233,10 @@
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass nulls to arrays'
:code: |
@@ -244,7 +244,7 @@
{
bar_ExpectAndReturn(NULL);
fooa_Expect(NULL);
function_b();
}
@@ -257,10 +257,10 @@
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: FALSE
:should: 'handle the situation where we pass single array element with expect and it is wrong'
:code: |
@@ -270,10 +270,10 @@
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: FALSE
:should: 'handle the situation where we pass nulls to arrays and fail'
:code: |
@@ -282,7 +282,7 @@
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(NULL);
function_b();
}
@@ -291,20 +291,22 @@
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
const char* retval = "This is a\0 silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a\0 wacky string");
function_c();
}
- :pass: FALSE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures'
:code: |
test()
{
bars_ExpectAndReturn("This is a silly string");
const char* retval = "This is a silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a wacky string");
function_c();
}
@@ -316,7 +318,7 @@
int expect_list[] = { 1, 9 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
@@ -328,7 +330,7 @@
int expect_list[] = { 9, 1 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
@@ -340,7 +342,7 @@
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
@@ -352,7 +354,7 @@
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_Expect(1, "silly");
mixed_ExpectWithArrayAndReturn(6, expect_list, 5, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
@@ -363,7 +365,7 @@
{
short expect_list[] = { -2, -3, -4 };
potential_packing_problem_ExpectWithArray(expect_list, 3);
function_e();
}
@@ -374,7 +376,7 @@
{
short expect_list[] = { -2, -3, 4 };
potential_packing_problem_ExpectWithArray(expect_list, 3);
function_e();
}
@@ -6,45 +6,45 @@
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
UINT32 foo(custom_type a);
UINT32 bar(custom_type b);
UINT32 foo_varargs(custom_type a, ...);
char* foo_char_strings(char a[], char* b);
const char* foo_char_strings(const char a[], const char* b);
:source:
:header: |
:source:
:header: |
UINT32 function_a(int a, int b);
void function_b(void);
UINT32 function_c(int a);
char* function_d(char a[], char* b);
const char* function_d(const char a[], const char* b);
:code: |
UINT32 function_a(int a, int b)
UINT32 function_a(int a, int b)
{
return foo((custom_type)a) + bar((custom_type)b);
}
}
void function_b(void) { }
UINT32 function_c(int a)
UINT32 function_c(int a)
{
return foo_varargs((custom_type)a, "ignored", 5);
}
char* function_d(char a[], char* b)
const char* function_d(const char a[], const char* b)
{
return foo_char_strings(a, b);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls'
@@ -55,7 +55,7 @@
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is not called but is expected'
:code: |
@@ -88,10 +88,11 @@
:code: |
test()
{
foo_char_strings_ExpectAndReturn("larry", "curly", "moe");
const char* retval = "moe";
foo_char_strings_ExpectAndReturn("larry", "curly", (char*)retval);
TEST_ASSERT_EQUAL_STRING("moe", function_d("larry", "curly"));
}
- :pass: TRUE
:should: 'successfully exercise multiple cycles of expecting and mocking and pass'
:code: |
@@ -100,12 +101,12 @@
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
foo_ExpectAndReturn((custom_type)3, 30);
bar_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(70, function_a(3, 4));
}
- :pass: FALSE
:should: 'successfully exercise multiple cycles of expecting and mocking and fail'
:code: |
@@ -114,7 +115,7 @@
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
foo_ExpectAndReturn((custom_type)3, 30);
bar_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(70, function_a(3, 5));
@@ -3,7 +3,7 @@
:plugins:
- # none
:memcmp_if_unknown: false
:systest:
:types: |
typedef struct _EXAMPLE_STRUCT_T { int x; int y; } EXAMPLE_STRUCT_T;
@@ -11,34 +11,34 @@
:mockable: |
EXAMPLE_STRUCT_T foo(EXAMPLE_STRUCT_T a);
:source:
:header: |
:source:
:header: |
EXAMPLE_STRUCT_T function_a(EXAMPLE_STRUCT_T a, EXAMPLE_STRUCT_T b);
EXAMPLE_STRUCT_T function_b(EXAMPLE_STRUCT_T a, EXAMPLE_STRUCT_T b);
:code: |
EXAMPLE_STRUCT_T function_a(EXAMPLE_STRUCT_T a, EXAMPLE_STRUCT_T b)
EXAMPLE_STRUCT_T function_a(EXAMPLE_STRUCT_T a, EXAMPLE_STRUCT_T b)
{
EXAMPLE_STRUCT_T retval = foo(a);
retval.x += b.x;
retval.y += b.y;
return retval;
}
EXAMPLE_STRUCT_T function_b(EXAMPLE_STRUCT_T a, EXAMPLE_STRUCT_T b)
}
EXAMPLE_STRUCT_T function_b(EXAMPLE_STRUCT_T a, EXAMPLE_STRUCT_T b)
{
EXAMPLE_STRUCT_T retval = foo(b);
retval.x *= a.x;
retval.y *= a.y;
return retval;
}
}
:tests:
:common: |
#include "expect_and_return_custom_types_unity_helper.h"
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise simple ExpectAndReturn mock calls'
@@ -52,7 +52,7 @@
foo_ExpectAndReturn(c, e);
TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(f, function_a(c,d));
}
- :pass: FALSE
:should: 'fail because it is expecting to call foo with c not d'
:code: |
@@ -65,7 +65,7 @@
foo_ExpectAndReturn(d, e);
TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(f, function_a(c,d));
}
- :pass: TRUE
:should: 'successfully exercise simple ExpectAndReturn mock calls on other function'
:code: |
@@ -78,7 +78,7 @@
foo_ExpectAndReturn(d, e);
TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(f, function_b(c,d));
}
- :pass: FALSE
:should: 'fail because it is expecting to call foo with d not c'
:code: |
@@ -95,7 +95,7 @@
:unity_helper:
:header: |
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual, unsigned short line);
#define UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, line, message) {AssertEqualExampleStruct(expected, actual, line);}
#define UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, line, message) {AssertEqualExampleStruct(expected, actual, (unsigned short)line);}
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, __LINE__, NULL);
:code: |
@@ -10,7 +10,7 @@
:systest:
:types: |
typedef char* MY_STRING;
typedef const char* MY_STRING;
typedef int MY_INT;
typedef unsigned int MY_HEX;
typedef int* PTR_INT;
@@ -23,8 +23,8 @@
MY_INT* pointer_foo(MY_HEX* a);
void pointer_bar(PTR_INT a);
:source:
:header: |
:source:
:header: |
MY_INT function_a(MY_INT a, MY_INT b);
MY_STRING function_b(MY_STRING a, MY_STRING b);
float function_c(float a, float b);
@@ -32,38 +32,38 @@
void function_e(PTR_INT a);
:code: |
MY_INT function_a(MY_INT a, MY_INT b)
MY_INT function_a(MY_INT a, MY_INT b)
{
return foo((MY_HEX)a) + bar((MY_HEX)b);
}
}
MY_STRING function_b(MY_STRING a, MY_STRING b)
{
return foo_char_strings(a, b);
}
float function_c(float a, float b)
{
return float_adder(b, a);
}
MY_INT function_d(MY_HEX a)
{
MY_HEX b = a;
MY_INT* c = pointer_foo(&b);
return *c;
}
void function_e(PTR_INT a)
{
pointer_bar(a);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls'
@@ -74,7 +74,7 @@
bar_ExpectAndReturn((MY_HEX)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is expected but not called'
:code: |
@@ -107,8 +107,8 @@
:code: |
test()
{
float_adder_ExpectAndReturn(1.2345, 6.7890, 8.0235);
TEST_ASSERT_EQUAL_FLOAT(8.0235, function_c(6.7890, 1.2345));
float_adder_ExpectAndReturn(1.2345f, 6.7890f, 8.0235f);
TEST_ASSERT_EQUAL_FLOAT(8.0235f, function_c(6.7890f, 1.2345f));
}
- :pass: FALSE
@@ -116,10 +116,10 @@
:code: |
test()
{
float_adder_ExpectAndReturn(1.2345, 6.7892, 8.0235);
TEST_ASSERT_EQUAL_FLOAT(8.0235, function_c(6.7890, 1.2345));
float_adder_ExpectAndReturn(1.2345f, 6.7892f, 8.0235f);
TEST_ASSERT_EQUAL_FLOAT(8.0235f, function_c(6.7890f, 1.2345f));
}
- :pass: TRUE
:should: 'handle pointers to treat_as values just as cleanly as the treat_as itself for passes'
:code: |
@@ -130,7 +130,7 @@
pointer_foo_ExpectAndReturn(&TestHex, &TestInt);
TEST_ASSERT_EQUAL_INT(33, function_d(45));
}
- :pass: FALSE
:should: 'handle pointers to treat_as values just as cleanly as the treat_as itself for failures'
:verify_error: 'Element 0 Expected 0x0000002D Was 0x0000002B'
@@ -142,7 +142,7 @@
pointer_foo_ExpectAndReturn(&TestHex, &TestInt);
TEST_ASSERT_EQUAL_INT(33, function_d(43));
}
- :pass: TRUE
:should: 'handle treat_as values containing pointers for passes'
:code: |
@@ -155,7 +155,7 @@
pointer_bar_Expect(ExpPtr);
function_e(ActPtr);
}
- :pass: FALSE
:should: 'handle treat_as values containing pointers for failures'
:verify_error: 'Element 0 Expected 33 Was 45'
@@ -3,7 +3,7 @@
:plugins:
- # none
:treat_as:
INT_PTR: INT*
INT_PTR: INT*
:systest:
:types: |
@@ -21,38 +21,38 @@
const char* bars(void);
INT_PTR zoink(INT_PTR a);
:source:
:header: |
:source:
:header: |
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
:code: |
void function_a(void)
void function_a(void)
{
foo(bar());
}
}
void function_b(void) {
fooa(bar());
}
void function_c(void) {
foos(bars());
}
int function_d(void) {
int i = 456;
INT_PTR ptr = (INT_PTR)(&i);
return (int)(*(zoink(ptr)));
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle the situation where we pass nulls to pointers'
@@ -61,10 +61,10 @@
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect'
:code: |
@@ -74,10 +74,10 @@
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and it is wrong'
:code: |
@@ -87,10 +87,10 @@
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass nulls to pointers and fail'
:code: |
@@ -99,10 +99,10 @@
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass nulls to arrays'
:code: |
@@ -110,7 +110,7 @@
{
bar_ExpectAndReturn(NULL);
fooa_Expect(NULL);
function_b();
}
@@ -123,10 +123,10 @@
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: FALSE
:should: 'handle the situation where we pass single array element with expect and it is wrong'
:code: |
@@ -136,10 +136,10 @@
POINT_T ex = {1, 3};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: FALSE
:should: 'handle the situation where we pass nulls to arrays and fail'
:code: |
@@ -148,7 +148,7 @@
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(NULL);
function_b();
}
@@ -157,23 +157,25 @@
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
const char* retval = "This is a\0 silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a\0 wacky string");
function_c();
}
- :pass: FALSE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures'
:code: |
test()
{
bars_ExpectAndReturn("This is a silly string");
const char* retval = "This is a silly string";
bars_ExpectAndReturn((char*)retval);
foos_Expect("This is a wacky string");
function_c();
}
- :pass: TRUE
:should: 'handle handle typedefs that ARE pointers by using treat_as'
:code: |
@@ -183,12 +185,12 @@
int r = 789;
INT_PTR ptr_e = (INT_PTR)(&e);
INT_PTR ptr_r = (INT_PTR)(&r);
zoink_ExpectAndReturn(ptr_e, ptr_r);
TEST_ASSERT_EQUAL(r, function_d());
}
- :pass: FALSE
:should: 'handle handle typedefs that ARE pointers by using treat_as and catch failures'
:code: |
@@ -198,9 +200,9 @@
int r = 789;
INT_PTR ptr_e = (INT_PTR)(&e);
INT_PTR ptr_r = (INT_PTR)(&r);
zoink_ExpectAndReturn(ptr_e, ptr_r);
TEST_ASSERT_EQUAL(r, function_d());
}
@@ -21,13 +21,13 @@
int i2;
int i3;
};
struct _abs_struct
struct _abs_struct
{
int abs_i1;
int abs_i2;
};
typedef struct _abs_struct abs_struct;
:mockable: |
@@ -61,7 +61,7 @@
{
int r = 1;
int res = 4;
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&r);
@@ -77,21 +77,21 @@
int res1 = 4;
int res2 = 8;
int res3 = 16;
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res1);
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res2);
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res3);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(8, r);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(16, r);
}
- :pass: TRUE
@@ -101,7 +101,7 @@
{
int r = 1, s = 2;
int res = 4;
ptr_ret_int_Expect(&r);
ptr_ret_int_IgnoreArg_r();
ptr_ret_int_ReturnThruPtr_r(&res);
@@ -116,7 +116,7 @@
{
int r = 1;
int res = 4;
ptr_ret_int_Expect(NULL);
ptr_ret_int_IgnoreArg_r();
ptr_ret_int_ReturnThruPtr_r(&res);
@@ -132,7 +132,7 @@
int r, s = 0x0880AA55;
int r_res = 4;
int s_res = 6;
ptr_ret_ints_Expect(&r, &s);
ptr_ret_ints_ReturnThruPtr_r(&r_res);
ptr_ret_ints_ReturnThruPtr_s(&s_res);
@@ -149,7 +149,7 @@
int r = 0x0880AA55;
int s = 0xAA55;
int r_res = 4;
ptr_ret_ints_Expect(&r, &s);
ptr_ret_ints_ReturnThruPtr_r(&r_res);
ptr_ret_ints(&r, &s);
@@ -164,9 +164,9 @@
{
char r_a[] = "booboorooboo";
char r_a_ret[] = "FEEFI";
ptr_ret_array_Expect(r_a, lengthof(r_a));
ptr_ret_array_ReturnArrayThruPtr_r(r_a_ret, strlen(r_a_ret));
ptr_ret_array_ReturnArrayThruPtr_r(r_a_ret, (int)strlen(r_a_ret));
ptr_ret_array(r_a, lengthof(r_a));
TEST_ASSERT_EQUAL_STRING("FEEFIorooboo", r_a);
}
@@ -178,7 +178,7 @@
{
struct a_struct r_s = { .i1 = 2, .i2 = 3, .i3 = 4, };
struct a_struct r_s_ret = { .i1 = 8, .i2 = 16, .i3 = 32, };
ptr_ret_struct_Expect(&r_s);
ptr_ret_struct_ReturnThruPtr_r(&r_s_ret);
ptr_ret_struct(&r_s);
@@ -206,7 +206,7 @@
#if !defined(ptr_ret_const_int_ReturnThruPtr_r)
TEST_FAIL_MESSAGE("ReturnThruPtr not defined for a pointer argument.");
#endif
#if defined(ptr_ret_const_int_ReturnThruPtr_s)
TEST_FAIL_MESSAGE("ReturnThruPtr defined for a const pointer argument.");
#endif
@@ -164,7 +164,7 @@
char r_a_ret[] = "FEEFI";
ptr_ret_array_Expect(r_a, lengthof(r_a));
ptr_ret_array_ReturnArrayThruPtr_r(r_a_ret, strlen(r_a_ret));
ptr_ret_array_ReturnArrayThruPtr_r(r_a_ret, (int)strlen(r_a_ret));
ptr_ret_array(r_a, lengthof(r_a));
TEST_ASSERT_EQUAL_STRING("FEEFIorooboo", r_a);
}
@@ -8,7 +8,7 @@
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
@@ -17,57 +17,57 @@
int baz(void);
void fuz(int* args, int num);
:source:
:header: |
:source:
:header: |
void function_a(int a, int b);
UINT32 function_b(void);
int function_c(void);
:code: |
void function_a(int a, int b)
void function_a(int a, int b)
{
int args[6] = {0, 1, 2, 3, 5, 5};
args[0] = a;
fuz(args, b);
}
UINT32 function_b(void)
}
UINT32 function_b(void)
{
UINT32 sum = 0;
custom_type a = 0;
custom_type b = 0;
sum = foo(&a) + bar(&b);
return sum + a + b;
return (UINT32)((custom_type)sum + a + b);
}
int function_c(void)
int function_c(void)
{
return (baz() + baz() + baz());
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
UINT32 FooAndBarHelper(custom_type* data, int num)
{
num++;
*data = (custom_type)(num * 2);
return (*data * 2);
return (UINT32)(*data * 2);
}
int BazCallbackPointless(int num)
{
return num;
}
int BazCallbackComplainsIfCalledMoreThanTwice(int num)
{
TEST_ASSERT_MESSAGE(num < 2, "Do Not Call Baz More Than Twice");
return num;
}
void FuzVerifier(int* args, int num_args, int num_calls)
{
int i;
@@ -75,9 +75,9 @@
for (i = 0; i < num_args; i++)
{
TEST_ASSERT_EQUAL(num_calls + i, args[i]);
}
}
}
:units:
- :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls the normal way'
@@ -89,7 +89,7 @@
bar_ExpectAndReturn(&exp, 20);
TEST_ASSERT_EQUAL(30, function_b());
}
- :pass: FALSE
:should: 'successfully exercise two simple ExpectAndReturn mock calls and catch failure the normal way'
:code: |
@@ -100,7 +100,7 @@
bar_ExpectAndReturn(&exp, 20);
TEST_ASSERT_EQUAL(30, function_b());
}
- :pass: TRUE
:should: 'successfully exercise using some basic callbacks'
:code: |
@@ -110,7 +110,7 @@
bar_StubWithCallback((CMOCK_bar_CALLBACK)FooAndBarHelper);
TEST_ASSERT_EQUAL(12, function_b());
}
- :pass: TRUE
:should: 'successfully exercise using some basic callbacks even if there were expects'
:code: |
@@ -132,7 +132,7 @@
bar_StubWithCallback((CMOCK_bar_CALLBACK)FooAndBarHelper);
TEST_ASSERT_EQUAL(10, function_b());
}
- :pass: TRUE
:should: 'successfully exercise a callback with no arguments'
:code: |
@@ -150,7 +150,7 @@
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackComplainsIfCalledMoreThanTwice);
function_c();
}
- :pass: TRUE
:should: 'be usable for things like dynamically sized memory checking for passing conditions'
:code: |
@@ -159,7 +159,7 @@
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(0, 4);
}
- :pass: FALSE
:should: 'be usable for things like dynamically sized memory checking for failing conditions'
:code: |
@@ -168,7 +168,7 @@
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(0, 5);
}
- :pass: FALSE
:should: 'be usable for things like dynamically sized memory checking for failing conditions 2'
:code: |
@@ -177,7 +177,7 @@
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(1, 4);
}
- :pass: TRUE
:should: 'run them interlaced'
:code: |
@@ -190,13 +190,13 @@
bar_ExpectAndReturn(&exp, 40);
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackPointless);
TEST_ASSERT_EQUAL(30, function_b());
TEST_ASSERT_EQUAL(55, function_b());
function_a(0, 4);
TEST_ASSERT_EQUAL(3, function_c());
}
- :pass: TRUE
:should: 'run them back to back'
:code: |
@@ -206,14 +206,14 @@
foo_ExpectAndReturn(&exp, 10);
bar_ExpectAndReturn(&exp, 20);
TEST_ASSERT_EQUAL(30, function_b());
foo_ExpectAndReturn(&exp, 15);
bar_ExpectAndReturn(&exp, 40);
TEST_ASSERT_EQUAL(55, function_b());
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(0, 4);
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackPointless);
TEST_ASSERT_EQUAL(3, function_c());
}
@@ -91,7 +91,7 @@ class CMockGeneratorPluginReturnThruPtrTest < Test::Unit::TestCase
"#define Pine_ReturnThruPtr_tofu(tofu)" +
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, sizeof(*tofu))\n" +
"#define Pine_ReturnArrayThruPtr_tofu(tofu, cmock_len)" +
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, cmock_len * sizeof(*tofu))\n" +
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, (int)(cmock_len * (int)sizeof(*tofu)))\n" +
"#define Pine_ReturnMemThruPtr_tofu(tofu, cmock_size)" +
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, cmock_size)\n" +
"void Pine_CMockReturnMemThruPtr_tofu(UNITY_LINE_TYPE cmock_line, int* tofu, int cmock_size);\n"
+1 -1