[修改] 增加freeRTOS

1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
2023-05-06 16:43:01 +00:00
commit a345df017b
20944 changed files with 11094377 additions and 0 deletions

View File

@ -0,0 +1,205 @@
# ==========================================
# CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
require 'yaml'
SYS_TEST_GEN_ROOT = File.expand_path( File.dirname( __FILE__ ) ) + '/'
GENERATED_PATH = SYS_TEST_GEN_ROOT + 'generated/'
BUILD_PATH = SYS_TEST_GEN_ROOT + 'build/'
CASES_PATH = SYS_TEST_GEN_ROOT + 'cases/'
TYPES_H = 'types.h'
UNITY_H = 'unity.h'
CMOCK_H = 'cmock.h'
UNITY_HELPER_H = 'unity_helper.h'
UNITY_HELPER_C = 'unity_helper.c'
MOCKABLE_H = 'mockable.h'
YAML_EXTENSION = '.yml'
TEST_PREFIX = 'test_'
MOCK_PREFIX = 'mock_'
H_EXTENSION = '.h'
C_EXTENSION = '.c'
class SystemTestGenerator
def generate_files(test_cases)
test_cases.each do |filename|
yaml_hash = YAML.load_file(filename)
name = File.basename(filename, YAML_EXTENSION)
namix = "#{name}_"
generate_cmock_config(yaml_hash, namix)
generate_code(yaml_hash, namix, name)
end
end
private
def generate_cmock_config(yaml_hash, namix)
cmock_yaml = yaml_hash.clone
cmock_yaml.delete(:systest)
cmock = cmock_yaml[:cmock]
cmock[:mock_path] = GENERATED_PATH
cmock[:includes] = (cmock[:includes] || []) + [namix + TYPES_H]
cmock[:mock_prefix] = MOCK_PREFIX
if not yaml_hash[:systest][:unity_helper].nil?
cmock[:includes] << namix + UNITY_HELPER_H
cmock[:unity_helper_path] = GENERATED_PATH + namix + UNITY_HELPER_H
end
File.open(GENERATED_PATH + namix + 'cmock' + YAML_EXTENSION, 'w') do |out|
YAML.dump(cmock_yaml, out)
end
end
def generate_code(yaml_hash, namix, name)
generate_types_file(yaml_hash, namix)
generate_mockable_file(yaml_hash, namix)
generate_unity_helper_files(yaml_hash, namix)
generate_test_file(yaml_hash, namix, name)
generate_source_file(yaml_hash, namix, name)
generate_skeleton_file(yaml_hash, namix, name)
end
def generate_types_file(yaml_hash, namix)
types = yaml_hash[:systest][:types]
return if types.nil?
write_header_file(GENERATED_PATH + namix + TYPES_H, namix.upcase + 'TYPES_H') do |out|
out.puts(types)
end
end
def generate_mockable_file(yaml_hash, namix)
mockable = yaml_hash[:systest][:mockable]
return if mockable.nil?
write_header_file(GENERATED_PATH + namix + MOCKABLE_H, namix.upcase + 'MOCKABLE_H', [namix + TYPES_H]) do |out|
out.puts(mockable)
end
end
def generate_unity_helper_files(yaml_hash, namix)
unity_helper = yaml_hash[:systest][:unity_helper]
return if unity_helper.nil?
write_header_file(GENERATED_PATH + namix + UNITY_HELPER_H, namix.upcase + 'UNITY_HELPER_H', [namix + TYPES_H]) do |out|
out.puts(unity_helper[:header])
end
write_source_file(GENERATED_PATH + namix + UNITY_HELPER_C, ["unity.h", namix + UNITY_HELPER_H]) do |out|
out.puts(unity_helper[:code])
end
end
def generate_test_file(yaml_hash, namix, name)
tests = yaml_hash[:systest][:tests]
return if tests.nil?
includes = [UNITY_H, CMOCK_H]
includes << [MOCK_PREFIX + namix + MOCKABLE_H]
includes << [name + H_EXTENSION]
write_source_file(GENERATED_PATH + TEST_PREFIX + name + C_EXTENSION, includes.flatten) do |out|
out.puts(tests[:common])
out.puts('')
tests[:units].each_with_index do |test, index|
out.puts('// should ' + test[:should])
out.puts(test[:code].gsub!(/test\(\)/, "void test#{index+1}(void)"))
out.puts('')
end
end
end
def generate_source_file(yaml_hash, namix, name)
source = yaml_hash[:systest][:source]
return if source.nil?
header_file = name + H_EXTENSION
includes = yaml_hash[:systest][:types].nil? ? [] : [(namix + TYPES_H)]
write_header_file(GENERATED_PATH + header_file, name.upcase, includes) do |out|
out.puts(source[:header])
end
includes = []
includes << (namix + TYPES_H) if not yaml_hash[:systest][:types].nil?
includes << (namix + MOCKABLE_H) if not yaml_hash[:systest][:mockable].nil?
includes << header_file
unless (source[:code].nil?)
write_source_file(GENERATED_PATH + name + C_EXTENSION, includes.flatten) do |out|
out.puts(source[:code])
end
end
end
def generate_skeleton_file(yaml_hash, namix, name)
source = yaml_hash[:systest][:skeleton]
return if source.nil?
require 'cmock.rb'
cmock = CMock.new(GENERATED_PATH + namix + 'cmock' + YAML_EXTENSION)
cmock.setup_skeletons("#{$cfg['compiler']['source_path']}#{name}.h")
end
def write_header_file(filename, upcase_name, include_list=[])
File.open(filename, 'w') do |out|
out.puts("#ifndef _#{upcase_name}")
out.puts("#define _#{upcase_name}")
out.puts('')
include_list.each do |include|
out.puts("#include \"#{include}\"")
end
out.puts('')
out.puts("#if defined(__GNUC__) && !defined(__ICC)")
out.puts("#if !defined(__clang__)")
out.puts("#pragma GCC diagnostic ignored \"-Wpragmas\"")
out.puts("#endif")
out.puts('#pragma GCC diagnostic ignored "-Wunknown-pragmas"')
out.puts('#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"')
out.puts("#endif")
out.puts('')
yield(out)
out.puts('')
out.puts("#endif // _#{upcase_name}")
out.puts('')
end
end
def write_source_file(filename, include_list=[])
File.open(filename, 'w') do |out|
include_list.each do |include|
out.puts("#include \"#{include}\"")
end
out.puts('')
out.puts("#if defined(__GNUC__) && !defined(__ICC)")
out.puts("#if !defined(__clang__)")
out.puts("#pragma GCC diagnostic ignored \"-Wpragmas\"")
out.puts("#endif")
out.puts('#pragma GCC diagnostic ignored "-Wunknown-pragmas"')
out.puts('#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"')
out.puts("#endif")
out.puts('')
yield(out)
out.puts('')
end
end
end
if ($0 == __FILE__)
SystemTestGenerator.new.generate_files(Dir[CASES_PATH + "*#{YAML_EXTENSION}"])
end

View File

@ -0,0 +1,11 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
#ifndef __stdcall
#define __stdcall
#endif
int __stdcall this_uses_calling_conventions(int b);

View File

@ -0,0 +1,10 @@
---
:cmock:
:plugins: []
:includes: []
:mock_path: ./system/generated/
:mock_prefix: mock_
:treat_inlines: :include
:treat_as_void:
- OSEK_TASK
- VOID_TYPE_CRAZINESS

View File

@ -0,0 +1,37 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
#if defined(__GNUC__) && !defined(__ICC)
#if !defined(__clang__)
#pragma GCC diagnostic ignored "-Wpragmas"
#endif
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wduplicate-decl-specifier"
#endif
struct _DUMMY_T { unsigned int a; float b; };
void const_variants1( const char* a, int const, unsigned short const * c );
void const_variants2(
struct _DUMMY_T const * const param1,
const unsigned long int const * const param2,
const struct _DUMMY_T const * param3 );
const int * const_retval1(void); /* nicety version for pointer to constant int */
int const * const_retval2(void); /* formal version for pointer to constant int */
//int * const const_retval3(void); /* formal version for constant pointer to int */
//int const * const const_retval4(void); /* formal version for constant pointer to constant int */
const int* const_retval5(void); /* sticky-left nicety version for pointer to constant int */
int const* const_retval6(void); /* sticky-left formal version for pointer to constant int */
//int* const const_retval7(void); /* sticky-left formal version for constant pointer to int */
//int const* const const_retval8(void); /* sticky-left formal version for constant pointer to constant int */
const int *const_retval9(void); /* sticky-right nicety version for pointer to constant int */
int const *const_retvalA(void); /* sticky-right formal version for pointer to constant int */
//int *const const_retvalB(void); /* sticky-right formal version for constant pointer to int */
//int const *const const_retvalC(void); /* sticky-right formal version for constant pointer to constant int */

View File

@ -0,0 +1,23 @@
static inline int dummy_func_0(void) {
return 5;
}
inline static int dummy_func_1(int a) {
int a = dummy_func_0();
int b = 10;
return a + b;
}
int inline static dummy_func_2(int a, char b, float c) {
c += 3.14;
b -= 32;
return a + (int)(b) + (int)c;
}
void dummy_normal_func(int a);
inline void dummy_func_3(void) {
//NOP
}

View File

@ -0,0 +1,275 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
typedef unsigned char OSServiceIdType;
typedef void (*OSEKOS_VOIDFUNCPTR)(void);
typedef unsigned char StatusType;
typedef unsigned char OSEK_U8;
typedef unsigned short OSEK_U16;
typedef unsigned long OSEK_U32;
void OSEKOSDisableAll(void);
void OSEKOSEnableAll(void);
typedef unsigned long * OSEKOSSaveType;
typedef void OSEK_TASK;
typedef OSEK_U8 OSEKOSPrioType;
enum {
Task_DbgCAN
,
Task_ALS
,
CalibrateMagTask
,
Task_IAQ
,
SmartBeam
,
Task_QbertTestImage
,
Task_TestQbertMem
,
Task_Cyclic1000
,
ProcessMagForCompass
,
ReadMag
,
Task_Cyclic10
,
Task_Wdm
,
BackgroundTask
,
Task_Cyclic20
,
Task_Cyclic2
};
OSEK_TASK OSEKOS_T_Task_DbgCAN(void);
OSEK_TASK OSEKOS_T_Task_ALS(void);
OSEK_TASK OSEKOS_T_CalibrateMagTask(void);
OSEK_TASK OSEKOS_T_Task_IAQ(void);
OSEK_TASK OSEKOS_T_SmartBeam(void);
OSEK_TASK OSEKOS_T_Task_QbertTestImage(void);
OSEK_TASK OSEKOS_T_Task_TestQbertMem(void);
OSEK_TASK OSEKOS_T_Task_Cyclic1000(void);
OSEK_TASK OSEKOS_T_ProcessMagForCompass(void);
OSEK_TASK OSEKOS_T_ReadMag(void);
OSEK_TASK OSEKOS_T_Task_Cyclic10(void);
OSEK_TASK OSEKOS_T_Task_Wdm(void);
OSEK_TASK OSEKOS_T_BackgroundTask(void);
OSEK_TASK OSEKOS_T_Task_Cyclic20(void);
OSEK_TASK OSEKOS_T_Task_Cyclic2(void);
OSEK_TASK OSEKOS_Twrap_Task_DbgCAN(void);
OSEK_TASK OSEKOS_Twrap_Task_ALS(void);
OSEK_TASK OSEKOS_Twrap_CalibrateMagTask(void);
OSEK_TASK OSEKOS_Twrap_Task_IAQ(void);
OSEK_TASK OSEKOS_Twrap_SmartBeam(void);
OSEK_TASK OSEKOS_Twrap_Task_QbertTestImage(void);
OSEK_TASK OSEKOS_Twrap_Task_TestQbertMem(void);
OSEK_TASK OSEKOS_Twrap_Task_Cyclic1000(void);
OSEK_TASK OSEKOS_Twrap_ProcessMagForCompass(void);
OSEK_TASK OSEKOS_Twrap_ReadMag(void);
OSEK_TASK OSEKOS_Twrap_Task_Cyclic10(void);
OSEK_TASK OSEKOS_Twrap_Task_Wdm(void);
OSEK_TASK OSEKOS_Twrap_BackgroundTask(void);
OSEK_TASK OSEKOS_Twrap_Task_Cyclic20(void);
OSEK_TASK OSEKOS_Twrap_Task_Cyclic2(void);
typedef OSEK_U8 TaskType;
typedef OSEK_U8 TaskStateType;
typedef OSEK_U16 EventMaskType;
typedef OSEK_U8 ResourceType;
void OSEKOSEnableSystemTimers(void);
typedef OSEK_U8 CounterType;
typedef OSEK_U32 TickType;
typedef OSEK_U8 AlarmType;
void OSEKOS_ISR_CanTxInterrupt(void);
void OSEKOS_ISR_CanRxInterrupt(void);
void OSEKOS_ISR_CanErrInterrupt(void);
void OSEKOS_ISR_SCIRxInterrupt(void);
void OSEKOS_ISR_SCITxInterrupt(void);
void OSEKOS_ISR_UP_DMA_Interrupt_0(void);
void OSEKOS_ISR_UP_DMA_Interrupt_1(void);
void OSEKOS_ISR_UP_DMA_Interrupt_2(void);
void OSEKOS_ISR_UP_DMA_Interrupt_3(void);
void OSEKOS_ISR_CompFreqHandler(void);
void OSEKOS_ISR_AmbientReturnInt(void);
void OSEKOS_ISR_GlareReturnInt(void);
void OSEKOS_ISR_ALSTimeoutInt(void);
void OSEKOS_ISR_LINTimerInt(void);
void OSEKOS_ISR_LINDelayInt(void);
void OSEKOS_ISR_TimerMExpire(void);
void OSEKOS_ISR_LINRxTx_SCI1(void);
void OSEKOS_ISR_CanRxInterrupt_1(void);
void OSEKOS_ISR_LINError_SCI1(void);
void OSEKOS_ISR_SysCounter(void);
// defined multiple times (slightly different forms) These should be ignored because they are externed
extern void OSEKOS_ISR_CanTxInterrupt( void );
extern void OSEKOS_ISR_CanRxInterrupt( void );
unsigned long OSEKOSrtcGetSeconds ( void );
void OSEKOSrtcIncrement ( unsigned long nsec );
enum
{
E_OS_ACCESS = 1,
E_OS_CALLEVEL = 2,
E_OS_ID = 3,
E_OS_LIMIT = 4,
E_OS_NOFUNC = 5,
E_OS_RESOURCE = 6,
E_OS_STATE = 7,
E_OS_VALUE = 8,
E_OS_SYS_StackOverflow = 20,
E_OS_SYS_StackUnderflow = 21,
E_OS_SYS_INIT = 22,
E_OS_SYS_CONFIG = 23,
E_OS_SYS_CODE = 24,
E_OS_SYS_TOOL = 25,
E_OS_SYS_TimerRange = 26
};
enum
{
SUSPENDED = 0x00,
READY = 0x01,
RUNNING = 0x02,
WAITING = 0x03,
INTSTART = 0x08,
SETSTART = 0x10,
NPRTASK = 0x20,
USEFP = 0x40
};
typedef struct
{
TickType maxallowedvalue;
TickType ticksperbase;
} AlarmBaseType;
typedef TaskType *TaskRefType;
typedef TaskStateType *TaskStateRefType;
typedef EventMaskType *EventMaskRefType;
typedef TickType *TickRefType;
typedef AlarmBaseType *AlarmBaseRefType;
typedef OSEK_U8 AppModeType;
typedef OSEK_U8 OSEKOSTaskActCntType;
TaskType OSEKOStidact;
OSEKOSPrioType OSEKOSrunprio;
StatusType OSEKOSError ( register StatusType );
void ErrorHook ( StatusType );
void StartupHook ( void );
void ShutdownHook ( StatusType );
int getUsedTaskStack ( TaskType );
int getUnusedTaskStack ( TaskType );
int getUsedIsrStack ( void );
int getUnusedIsrStack ( void );
void OSEKOStaskStackCheckInit ( void );
signed char OSEKOStaskStackCheck ( OSEK_U8 * );
signed char OSEKOSisrStackCheck ( OSEK_U8 * );
void OSEKOStaskStackCheckFatal ( OSEK_U8 * );
void OSEKOSisrStackCheckFatal ( OSEK_U8 * );
OSEK_U8 * OSEKOSgetStackPointer ( void );
void OSEKOSTaskSwitch ( void );
StatusType OSEKOSReturn ( StatusType );
StatusType OSEKOSActivateTask ( register TaskType );
void OSEKOSTerminateTask ( TaskType, TaskType );
extern void OSEKOSGetResource ( ResourceType );
extern void OSEKOSReleaseResource ( ResourceType );
int OSEKOSSetEvent ( TaskType, EventMaskType );
int OSEKOSWaitEvent ( EventMaskType );
TickType OSEKOSGetAlarm(register AlarmType);
void OSEKOSSetAlarm ( AlarmType, TickType, TickType );
StatusType OSEKOSSetAbsAlarm ( AlarmType a, TickType b, TickType c );
StatusType OSEKOSCancelAlarm ( register AlarmType );
void OSEKOSAdvCntr ( void );
AppModeType GetActiveApplicationMode ( void );
void StartOS ( AppModeType );
void OSEKOSShutdownOS ( StatusType );
StatusType ActivateTask ( TaskType A );
StatusType TerminateTask ( void );
StatusType ChainTask ( TaskType A );
StatusType GetTaskState ( TaskType A, TaskStateRefType B );
StatusType GetTaskID ( TaskRefType A );
StatusType Schedule ( void );
StatusType GetResource ( ResourceType A );
StatusType ReleaseResource ( ResourceType A );
StatusType SetEvent ( TaskType A, EventMaskType B );
StatusType ClearEvent ( EventMaskType A );
StatusType WaitEvent ( EventMaskType A );
StatusType GetEvent ( TaskType A, EventMaskRefType B );
StatusType GetAlarm ( AlarmType A, TickRefType B );
StatusType GetAlarmBase ( AlarmType A, AlarmBaseRefType B );
StatusType SetRelAlarm ( AlarmType A, TickType B, TickType C );
StatusType SetAbsAlarm ( AlarmType A, TickType B, TickType C );
StatusType CancelAlarm ( AlarmType A );
StatusType AdvCntr ( CounterType A );
StatusType IAdvCntr ( CounterType A );
void SuspendOSInterrupts ( void );
void ResumeOSInterrupts ( void );
void SuspendAllInterrupts ( void );
void ResumeAllInterrupts ( void );
void DisableAllInterrupts ( void );
void EnableAllInterrupts ( void );
void OSEKOSDisable(void);
void OSEKOSEnable(void);
void OSEKOSAsmIDispatch(unsigned long *);
void OSEKOSAsmDispatch(OSEKOSPrioType p);
void OSEKOSStartupEnable(void);
void OSEKOSNop(void);
unsigned int OSEKOSV850CheckIsrSwitch(void);
void OSEKOSV850InitInterrupts(void);
void OSEKOSV850SetupInterrupts();
void OSEKOSV850SyncContextLoad(OSEKOSSaveType);
void OSEKOSV850SyncContextLoadFromIRQ(OSEKOSSaveType);
void OSEKOSV850ASyncContextLoad(OSEKOSSaveType);
void OSEKOSV850ASyncContextLoadFromIRQ(OSEKOSSaveType);
// arrays of function pointers - they look like function prototypes
void ( ( * const OSEKOStaskStartAddress [10] ) ( void ) );
StatusType (* OSEKOStaskStatuses [10][5]) ( void );
void OSEKOSV850StartContext
(
OSEK_TASK (( * const ) ( void )),
OSEK_U8 * const
);
void OSEKOSV850StartContextFromIRQ
(
OSEK_TASK (( * const ) ( void )),
OSEK_U8 * const
);
void OSEKOSSuspendOSInterrupts(void);
void OSEKOSResumeOSInterrupts(void);
void OSEKOSSuspendAllInterrupts(void);
void OSEKOSResumeAllInterrupts(void);
void OSEKOScheckSuspendResumeNesting(void);
void OSEKOSgetSR(void);
void OSEKOSEnableInterrupt_intern(int nr);
void OSEKOSDisableInterrupt_intern(int nr);

View File

@ -0,0 +1,89 @@
/* ==========================================
CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
typedef unsigned short U16;
typedef signed int int32_t;
/* CMock should handle UTF-8 characters in comments. The world is an awesomely diverse place! */
/* my µC Rocks! Open Source, not ©! My language has no Ümlauts! ǺƜǝƧǾɱɛ! */ /**! Illegal: åäö */
typedef struct _POINT_T
{
int x;
int y;
} POINT_T;
// typedef edge case;
// not ANSI C but it has been done and will break cmock if not handled
typedef void VOID_TYPE_CRAZINESS;
/* fun parsing & mock generation cases */
void var_args1(int a, ...);
void var_args2(int a, int b, ...);
VOID_TYPE_CRAZINESS void_type_craziness1(int, float, double, char, short, long, long int, long long, void*);
int void_type_craziness2( VOID_TYPE_CRAZINESS );
void crazy_whitespace ( int lint, double shot , short stack ) ;
char
crazy_multiline
(
int a,
unsigned int b);
U16 *ptr_return1(int a);
U16* ptr_return2(int a);
U16 * ptr_return3(int a);
unsigned int** ptr_ptr_return1(unsigned int** a);
unsigned int* *ptr_ptr_return2(unsigned int* *a);
unsigned int **ptr_ptr_return3(unsigned int **a);
unsigned int ** ptr_ptr_return4(unsigned int ** a);
extern unsigned long int incredible_descriptors(register const unsigned short a);
int32_t example_c99_type(int32_t param1);
void I2CIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
/* these are function pointers, not function declarations USING a function pointer, and so should NOT get mocked */
int (* func_pointer)(void);
extern int (*another_func_pointer)(unsigned int argument);
struct struct_to_be_ignored {
union {
int i32;
void *p;
} variant;
void (*a_function_pointer_in_a_struct)(void *);
};
typedef struct
{
uint32_t a;
struct
{
uint32_t bb;
float bc;
float bd;
} b;
int (*another_function_pointer_in_a_struct) (void);
} another_thing_that_should_get_ignored;
inline int stuff(int num)
{
int reg = 0x12;
if (num > 0)
{
reg |= (0x0Eu);
}
else
{
reg |= (0x07u);
}
return reg;
}

View File

@ -0,0 +1,375 @@
---
#this test is different than all_plugins_coexist primarily because of these options
:cmock:
:enforce_strict_ordering: 1
:treat_externs: :include
:plugins:
- :array
- :cexception
- :ignore
- :callback
- :return_thru_ptr
- :ignore_arg
- :expect_any_args
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
:mockable: |
#include "CException.h"
void foo(POINT_T* a);
POINT_T* bar(void);
void fooa(POINT_T a[]);
void foos(const char * a);
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);
:source:
:header: |
#include "CException.h"
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
void function_e(void);
:code: |
void function_a(void)
{
foo(bar());
}
void function_b(void) {
fooa(bar());
}
void function_c(void) {
CEXCEPTION_T e;
Try {
foos(bars());
} Catch(e) { foos("err"); }
}
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) {
foos("Hello");
foos("Tuna");
foos("Oranges");
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle the situation where we pass nulls to pointers'
:code: |
test()
{
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: |
test()
{
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: |
test()
{
POINT_T ex = {1, 2};
bar_ExpectAndReturn(NULL);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
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 end'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single array element with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: TRUE
:should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, passing'
:code: |
test()
{
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();
}
- :pass: FALSE
:should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, finding failures'
:code: |
test()
{
const char* constretval = "This is a silly string";
char* retval = (char*)constretval;
bars_ExpectAndReturn(retval);
foos_Expect("This is a wacky string");
function_c();
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for single object'
:code: |
test()
{
int expect_list[] = { 1, 9 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for single object'
:code: |
test()
{
int expect_list[] = { 9, 1 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for multiple objects'
:code: |
test()
{
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());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects'
:code: |
test()
{
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());
}
- :pass: TRUE
:should: 'handle an exception being caught'
:code: |
test()
{
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");
function_c();
}
- :pass: FALSE
:should: 'handle an exception being caught but still catch following errors'
:code: |
test()
{
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");
function_c();
}
- :pass: FALSE
:should: 'fail strict ordering problems even though we would otherwise have passed'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
no_pointers_Expect(1, "silly");
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'properly ExpectAnyArgs first function but the other will work properly'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
no_pointers_ExpectAnyArgs();
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'properly ExpectAnyArgs last function but the other will work properly'
:code: |
test()
{
no_pointers_Expect(1, "silly");
mixed_ExpectAnyArgsAndReturn(13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'be ok if we ExpectAnyArgs a call each because we are counting calls'
:code: |
test()
{
foos_ExpectAnyArgs();
foos_ExpectAnyArgs();
foos_ExpectAnyArgs();
function_e();
}
- :pass: TRUE
:should: 'be ok if we ExpectAnyArgs and Expect intermixed because we are counting calls'
:code: |
test()
{
foos_Expect("Hello");
foos_ExpectAnyArgs();
foos_ExpectAnyArgs();
function_e();
}
- :pass: FALSE
:should: 'be able to detect Expect problem if we ExpectAnyArgs and Expect intermixed'
:code: |
test()
{
foos_Expect("Hello");
foos_ExpectAnyArgs();
foos_Expect("Wrong");
function_e();
}
- :pass: FALSE
:should: 'fail if we do not ExpectAnyArgs a call once because we are counting calls'
:code: |
test()
{
foos_ExpectAnyArgs();
foos_ExpectAnyArgs();
function_e();
}
...

View File

@ -0,0 +1,460 @@
---
:cmock:
:enforce_strict_ordering: 1
:plugins:
- :array
- :cexception
- :ignore
- :callback
- :return_thru_ptr
- :ignore_arg
- :expect_any_args
:callback_after_arg_check: true
:callback_include_count: false
:treat_externs: :include
:treat_inlines: :include
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
:mockable: |
#include "CException.h"
extern void foo(POINT_T* a);
POINT_T* bar(void);
void fooa(POINT_T a[]);
void foos(const char * a);
const char * bars(void);
void no_pointers(int a, const char* b);
int mixed(int a, int* b, int c);
void no_args(void);
:source:
:header: |
#include "CException.h"
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
void function_e(void);
int function_f(void);
:code: |
void function_a(void)
{
foo(bar());
}
void function_b(void) {
fooa(bar());
}
void function_c(void) {
CEXCEPTION_T e;
Try {
foos(bars());
} Catch(e) { foos("err"); }
}
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) {
foos("Hello");
foos("Tuna");
foos("Oranges");
}
int function_f(void) {
int a = 1;
int b = 2;
int c;
POINT_T* pt = bar();
c = pt->x;
c = mixed(a, &b, c);
return b + c;
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
void my_foo_callback(POINT_T* a) { TEST_ASSERT_EQUAL_INT(2, a->x); }
int my_mixed_callback(int a, int* b, int c) { return a + *b + c; }
:units:
- :pass: TRUE
:should: 'handle the situation where we pass nulls to pointers'
:code: |
test()
{
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: |
test()
{
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: |
test()
{
POINT_T ex = {1, 2};
bar_ExpectAndReturn(NULL);
foo_Expect(&ex);
function_a();
}
- :pass: FALSE
:should: 'handle the situation where we pass single object with expect and it is wrong'
:code: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
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 end'
:code: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}};
bar_ExpectAndReturn(pt);
foo_ExpectWithArray(ex, 3);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single array element with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
POINT_T ex = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(&ex);
function_b();
}
- :pass: TRUE
:should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, passing'
:code: |
test()
{
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 and not do crappy memory compares of a byte, finding failures'
:code: |
test()
{
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 creating array expects when we have mixed arguments for single object'
:code: |
test()
{
int expect_list[] = { 1, 9 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for single object'
:code: |
test()
{
int expect_list[] = { 9, 1 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for multiple objects'
:code: |
test()
{
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());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects'
:code: |
test()
{
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());
}
- :pass: TRUE
:should: 'handle an exception being caught'
:code: |
test()
{
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");
function_c();
}
- :pass: FALSE
:should: 'handle an exception being caught but still catch following errors'
:code: |
test()
{
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");
function_c();
}
- :pass: FALSE
:should: 'fail strict ordering problems even though we would otherwise have passed'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
no_pointers_Expect(1, "silly");
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'that we can properly ignore last function but the other will work properly'
:code: |
test()
{
int expect_list[] = { 1, 2, 3, 4, 6 };
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
no_pointers_Ignore();
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'that we can properly ignore first function but the other will work properly'
:code: |
test()
{
mixed_IgnoreAndReturn(13);
no_pointers_Expect(1, "silly");
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'that we just have to ignore a call once because we are not counting calls'
:code: |
test()
{
foos_Ignore();
function_e();
}
- :pass: TRUE
:should: 'that we can use a callback and an expect'
:code: |
test()
{
POINT_T pt1 = {2, 3};
POINT_T pt2 = {2, 3};
bar_ExpectAndReturn(&pt1);
foo_Expect(&pt2);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: FALSE
:should: 'that we can fail even when using a callback if we want to expect call but did not and we are checking that'
:code: |
test()
{
POINT_T pt = {2, 3};
bar_ExpectAndReturn(&pt);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: FALSE
:should: 'that we can fail even when using a callback if args are wrong and we are checking those'
:code: |
test()
{
POINT_T pt1 = {2, 3};
POINT_T pt2 = {1, 3};
bar_ExpectAndReturn(&pt1);
foo_Expect(&pt2);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: FALSE
:should: 'that we can fail from the callback itself'
:code: |
test()
{
POINT_T pt = {3, 3};
bar_ExpectAndReturn(&pt);
foo_Expect(&pt);
foo_StubWithCallback((CMOCK_foo_CALLBACK)my_foo_callback);
function_a();
}
- :pass: TRUE
:should: 'that a callback return value overrides the one from ExpectAndReturn'
:code: |
test()
{
int b = 2;
POINT_T pt1 = {3, 4};
bar_ExpectAndReturn(&pt1);
mixed_StubWithCallback((CMOCK_mixed_CALLBACK)my_mixed_callback);
mixed_ExpectAndReturn(1,&b,3,100);
TEST_ASSERT_EQUAL(8, function_f());
}
- :pass: TRUE
:should: 'that a callback return value overrides the one from ExpectAndReturn AND ReturnThruPtr still works'
:code: |
test()
{
int b_in = 2;
int b_out = 3;
POINT_T pt1 = {3, 4};
bar_ExpectAndReturn(&pt1);
mixed_StubWithCallback((CMOCK_mixed_CALLBACK)my_mixed_callback);
mixed_ExpectAndReturn(1,&b_in,3,100);
mixed_ReturnThruPtr_b(&b_out);
TEST_ASSERT_EQUAL(9, function_f()); // (a=1, bin=2, c=pt.x=3, bout=3, sum=9)
}
- :pass: TRUE
:should: 'that a callback return value overrides the one from ExpectAnyArgs'
:code: |
test()
{
POINT_T pt1 = {5, 4};
bar_ExpectAndReturn(&pt1);
mixed_StubWithCallback((CMOCK_mixed_CALLBACK)my_mixed_callback);
mixed_ExpectAnyArgsAndReturn(100);
TEST_ASSERT_EQUAL(10, function_f()); // (a=1, bin=2, c=pt.x=5, bout=2, sum=10)
}
- :pass: TRUE
:should: 'that a callback return value overrides the one from ExpectAnyArgs AND ReturnThruPtr still works'
:code: |
test()
{
int b_out = 3;
POINT_T pt1 = {5, 4};
bar_ExpectAndReturn(&pt1);
mixed_StubWithCallback((CMOCK_mixed_CALLBACK)my_mixed_callback);
mixed_ExpectAnyArgsAndReturn(100);
mixed_ReturnThruPtr_b(&b_out);
TEST_ASSERT_EQUAL(11, function_f()); // (a=1, bin=2, c=pt.x=5, bout=3, sum=11)
}
...

View File

@ -0,0 +1,446 @@
---
:cmock:
:when_ptr: :smart
:plugins:
- :array
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
#define ARRAY_A_SIZE (5)
:mockable: |
void foo(POINT_T* a);
POINT_T* bar(void);
void fooa(POINT_T a[ARRAY_A_SIZE+1-1]);
void foos(const char * a);
const char * bars(void);
void no_pointers(int a, const char* b);
int mixed(int a, int* b, int c);
void potential_packing_problem(short *a);
void voidpointerfunc(void* a);
:source:
:header: |
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
void function_e(void);
void function_f(void);
:code: |
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]);
}
void function_f(void) {
char arg[6] = "hello";
voidpointerfunc(arg);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle the situation where we pass nulls to pointers'
:code: |
test()
{
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: |
test()
{
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: |
test()
{
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: |
test()
{
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: |
test()
{
POINT_T ex = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
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: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
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: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
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: |
test()
{
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
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: |
test()
{
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: |
test()
{
bar_ExpectAndReturn(NULL);
fooa_Expect(NULL);
function_b();
}
- :pass: TRUE
:should: 'handle the situation where we pass single array element with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(NULL);
function_b();
}
- :pass: TRUE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing'
:code: |
test()
{
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()
{
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 creating array expects when we have mixed arguments for single object'
:code: |
test()
{
int expect_list[] = { 1, 9 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for single object'
:code: |
test()
{
int expect_list[] = { 9, 1 };
no_pointers_Expect(1, "silly");
mixed_ExpectAndReturn(6, expect_list, 7, 13);
TEST_ASSERT_EQUAL(13, function_d());
}
- :pass: TRUE
:should: 'handle creating array expects when we have mixed arguments for multiple objects'
:code: |
test()
{
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());
}
- :pass: FALSE
:should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects'
:code: |
test()
{
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());
}
- :pass: TRUE
:should: 'handle a passing version of a potential packing problem (particularly try with ARM simulators)'
:code: |
test()
{
short expect_list[] = { -2, -3, -4 };
potential_packing_problem_ExpectWithArray(expect_list, 3);
function_e();
}
- :pass: FALSE
:should: 'handle a failing version of a potential packing problem (particularly try with ARM simulators)'
:code: |
test()
{
short expect_list[] = { -2, -3, 4 };
potential_packing_problem_ExpectWithArray(expect_list, 3);
function_e();
}
- :pass: TRUE
:should: 'handle a void pointers as arguments and still be able to use the array plugin'
:code: |
test()
{
char expect_list[6] = "hello";
voidpointerfunc_ExpectWithArray(expect_list, 5);
function_f();
}
- :pass: TRUE
:should: 'handle a void pointers as arguments and still be able to use the array plugin (short)'
:code: |
test()
{
char expect_list[6] = "help!";
voidpointerfunc_ExpectWithArray(expect_list, 3);
function_f();
}
- :pass: FALSE
:should: 'handle a void pointers as arguments and still be able to use the array plugin (fail)'
:code: |
test()
{
char expect_list[6] = "help!";
voidpointerfunc_ExpectWithArray(expect_list, 4);
function_f();
}
- :pass: TRUE
:should: 'handle a void pointer with a standard expectation (pass)'
:code: |
test()
{
char expect_list[2] = "h";
voidpointerfunc_Expect(expect_list);
function_f();
}
- :pass: FALSE
:should: 'handle a void pointer with a standard expectation (fail)'
:code: |
test()
{
char expect_list[2] = "g";
voidpointerfunc_Expect(expect_list);
function_f();
}
...

View File

@ -0,0 +1,124 @@
---
:cmock:
:plugins:
- # none
: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, ...);
const char* foo_char_strings(const char a[], const char* b);
:source:
:header: |
UINT32 function_a(int a, int b);
void function_b(void);
UINT32 function_c(int a);
const char* function_d(const char a[], const char* b);
:code: |
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)
{
return foo_varargs((custom_type)a, "ignored", 5);
}
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'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
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: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is called but is not expected'
:code: |
test()
{
bar_ExpectAndReturn((custom_type)1, 10);
function_b();
}
- :pass: TRUE
:should: 'consume var args passed to mocked function'
:code: |
test()
{
foo_varargs_ExpectAndReturn((custom_type)3, 10);
TEST_ASSERT_EQUAL(10, function_c(3));
}
- :pass: TRUE
:should: 'handle char strings'
:code: |
test()
{
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: |
test()
{
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: |
test()
{
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));
}
...

View File

@ -0,0 +1,87 @@
---
:cmock:
:plugins:
- # none
:systest:
:types: |
:mockable: |
// no argument names
void foo(char const*, char* const, const char*);
// argument names
void bar(char const* param1, char* const param2, const char* param3);
:source:
:header: |
void exercise_const1(char const* param1, char* const param2, const char* param3);
void exercise_const2(char const* param1, char* const param2, const char* param3);
:code: |
char value1 = '1';
char value2 = '2';
const char* A = &value1;
char* const B = &value2;
const char* C = "C";
const char* D = "D";
void exercise_const1(char const* param1, char* const param2, const char* param3)
{
foo(param1, param2, param3);
}
void exercise_const2(char const* param1, char* const param2, const char* param3)
{
bar(param1, param2, param3);
}
:tests:
:common: |
extern const char* A;
extern char* const B;
extern const char* C;
extern const char* D;
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully pass several const parameters'
:code: |
test()
{
foo_Expect( A, B, C );
exercise_const1( A, B, C );
}
- :pass: FALSE
:should: 'should fail upon wrong const arguments passed'
:code: |
test()
{
foo_Expect( A, B, C );
exercise_const1( (const char*)B, (char * const)A, C );
}
- :pass: FALSE
:should: 'should fail upon wrong const arguments passed'
:code: |
test()
{
foo_Expect( A, B, C );
exercise_const1( A, B, D );
}
- :pass: FALSE
:should: 'should fail upon wrong const arguments passed'
:code: |
test()
{
bar_Expect( A, B, C );
exercise_const2( A, (char * const)C, (const char *)B );
}
...

View File

@ -0,0 +1,308 @@
---
:cmock:
:enforce_strict_ordering: 1
:plugins:
- :array
- :cexception
- :ignore
- :callback
- :return_thru_ptr
- :ignore_arg
- :expect_any_args
:callback_after_arg_check: false
:callback_include_count: false
:treat_externs: :include
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
:mockable: |
#include "CException.h"
extern void foo(POINT_T* a);
POINT_T* bar(void);
void no_args(void);
:source:
:header: |
#include "CException.h"
void function_a(void);
int function_b(void);
:code: |
void function_a(void)
{
foo(bar());
no_args();
}
int function_b(void)
{
POINT_T pt = { 1, 2 };
foo(&pt);
return (pt.x + pt.y);
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
void my_foo_callback(POINT_T* a) { TEST_ASSERT_EQUAL_INT(2, a->x); }
:units:
- :pass: TRUE
:should: 'just pass if we do not insert anything ugly into it'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after an expect and return'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
foo_Expect(NULL);
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after an expect'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after throw expectation'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
CEXCEPTION_T e;
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_ExpectAndThrow(5);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
Try { function_a(); } Catch(e) {}
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after a mock call'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after throw'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
CEXCEPTION_T e;
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_ExpectAndThrow(5);
Try { function_a(); } Catch(e) {}
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after ignore'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Ignore();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after ignored mock'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
no_args_Ignore();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after callback setup'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_StubWithCallback(my_foo_callback);
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock with callback'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_StubWithCallback(my_foo_callback);
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after expect any args'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_ExpectAnyArgs();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which expected any args'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_ExpectAnyArgs();
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after ignored arg'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
foo_IgnoreArg_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
no_args_Expect();
function_a();
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which ignored an arg'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
POINT_T pt = { 2, 2 };
bar_ExpectAndReturn(&pt);
foo_Expect(NULL);
foo_IgnoreArg_a();
no_args_Expect();
function_a();
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which threw a CException'
:verify_error: 'FAIL: Expected 1 Was 2. CustomFail'
:code: |
test()
{
CEXCEPTION_T e;
bar_ExpectAndThrow(0x12);
Try {
function_a();
}
Catch(e) {}
TEST_ASSERT_EQUAL_INT_MESSAGE(1,2,"CustomFail");
}
- :pass: FALSE
:should: 'not contain mock details in failed assertion after mock which used a return thru ptr'
:verify_error: 'FAIL: Expected 3 Was 7. CustomFail'
:code: |
test()
{
POINT_T pt1 = { 1, 2 };
POINT_T pt2 = { 3, 4 };
foo_Expect(&pt1);
foo_ReturnThruPtr_a(&pt2);
TEST_ASSERT_EQUAL_INT_MESSAGE(3, function_b(), "CustomFail");
}
...

View File

@ -0,0 +1,247 @@
---
:cmock:
:enforce_strict_ordering: 1
:plugins:
- :ignore
- :cexception
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
#include "CException.h"
UINT32 foo(custom_type a);
UINT32 bar(custom_type b);
void baz(custom_type c);
:source:
:header: |
#include "CException.h"
UINT32 function_a(int a, int b);
void function_b(void);
void function_c(void);
void function_d(void);
:code: |
UINT32 function_a(int a, int b)
{
return foo((custom_type)a) + bar((custom_type)b);
}
void function_b(void)
{
baz((custom_type)1);
foo((custom_type)2);
bar((custom_type)3);
baz((custom_type)4);
foo((custom_type)5);
bar((custom_type)6);
baz((custom_type)7);
}
void function_c(void)
{
foo((custom_type)1);
foo((custom_type)2);
bar((custom_type)3);
bar((custom_type)4);
foo((custom_type)5);
}
void function_d(void)
{
CEXCEPTION_T e;
Try
{
foo((custom_type)1);
}
Catch(e) {}
Try
{
bar((custom_type)2);
}
Catch(e) {}
Try
{
foo((custom_type)3);
}
Catch(e) {}
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is called but is not expected'
:verify_error: 'Called more times than expected'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is called twice but is expected once'
:verify_error: 'Called fewer times than expected'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
bar_ExpectAndReturn((custom_type)3, 30);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar and foo called in reverse order'
:verify_error: 'Called earlier than expected'
:code: |
test()
{
bar_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndReturn((custom_type)1, 10);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: TRUE
:should: 'pass because bar and foo called in order with multiple params'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)2, 10);
bar_ExpectAndReturn((custom_type)3, 20);
bar_ExpectAndReturn((custom_type)4, 10);
foo_ExpectAndReturn((custom_type)5, 10);
function_c();
}
- :pass: FALSE
:should: 'fail because bar and foo called out of order at end'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)2, 10);
bar_ExpectAndReturn((custom_type)3, 20);
foo_ExpectAndReturn((custom_type)5, 10);
bar_ExpectAndReturn((custom_type)4, 10);
function_c();
}
- :pass: FALSE
:should: 'fail because bar and foo called out of order at start'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)2, 10);
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)3, 20);
bar_ExpectAndReturn((custom_type)4, 10);
foo_ExpectAndReturn((custom_type)5, 10);
function_c();
}
- :pass: TRUE
:should: 'pass because we are properly ignoring baz'
:code: |
test()
{
baz_Ignore();
foo_ExpectAndReturn((custom_type)2, 10);
bar_ExpectAndReturn((custom_type)3, 20);
foo_ExpectAndReturn((custom_type)5, 10);
bar_ExpectAndReturn((custom_type)6, 10);
function_b();
}
- :pass: FALSE
:should: 'fail because bar and foo out of order, even though baz is ignored'
:code: |
test()
{
baz_Ignore();
foo_ExpectAndReturn((custom_type)2, 10);
foo_ExpectAndReturn((custom_type)5, 10);
bar_ExpectAndReturn((custom_type)3, 20);
bar_ExpectAndReturn((custom_type)6, 10);
function_b();
}
- :pass: TRUE
:should: 'pass when using cexception, as long as the order is right'
:code: |
test()
{
foo_ExpectAndThrow((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndReturn((custom_type)3, 10);
function_d();
}
- :pass: FALSE
:should: 'fail when an throw call is made out of order'
:code: |
test()
{
bar_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndThrow((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)3, 10);
function_d();
}
- :pass: TRUE
:should: 'successfully handle back to back ExpectAndReturn setup and mock calls'
:code: |
test()
{
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));
foo_ExpectAndReturn((custom_type)1, 50);
bar_ExpectAndReturn((custom_type)9, 60);
TEST_ASSERT_EQUAL(110, function_a(1, 9));
}
- :pass: FALSE
:should: 'successfully catch errors during back to back ExpectAndReturn setup and mock calls'
:verify_error: 'Called earlier than expected'
:code: |
test()
{
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));
bar_ExpectAndReturn((custom_type)9, 60);
foo_ExpectAndReturn((custom_type)1, 50);
TEST_ASSERT_EQUAL(110, function_a(1, 9));
}
...

View File

@ -0,0 +1,108 @@
---
:cmock:
:plugins:
- # none
:memcmp_if_unknown: false
:unity_helper_path: expect_and_return_custom_types_unity_helper.h
:systest:
:types: |
typedef struct _EXAMPLE_STRUCT_T { int x; int y; } EXAMPLE_STRUCT_T;
:mockable: |
EXAMPLE_STRUCT_T foo(EXAMPLE_STRUCT_T a);
: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 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 retval = foo(b);
retval.x *= a.x;
retval.y *= a.y;
return retval;
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise simple ExpectAndReturn mock calls'
:code: |
test()
{
EXAMPLE_STRUCT_T c = {1,2};
EXAMPLE_STRUCT_T d = {3,4};
EXAMPLE_STRUCT_T e = {2,4};
EXAMPLE_STRUCT_T f = {5,8};
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: |
test()
{
EXAMPLE_STRUCT_T c = {1,2};
EXAMPLE_STRUCT_T d = {3,4};
EXAMPLE_STRUCT_T e = {2,4};
EXAMPLE_STRUCT_T f = {5,8};
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: |
test()
{
EXAMPLE_STRUCT_T c = {1,2};
EXAMPLE_STRUCT_T d = {3,4};
EXAMPLE_STRUCT_T e = {2,4};
EXAMPLE_STRUCT_T f = {2,8};
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: |
test()
{
EXAMPLE_STRUCT_T c = {1,2};
EXAMPLE_STRUCT_T d = {3,4};
EXAMPLE_STRUCT_T e = {2,4};
EXAMPLE_STRUCT_T f = {2,8};
foo_ExpectAndReturn(c, e);
TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(f, function_b(c,d));
}
: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, (unsigned short)line);}
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, __LINE__, NULL);
:code: |
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual, unsigned short line)
{
UNITY_TEST_ASSERT_EQUAL_INT(expected.x, actual.x, line, "Example Struct Failed For Field x");
UNITY_TEST_ASSERT_EQUAL_INT(expected.y, actual.y, line, "Example Struct Failed For Field y");
}
...

View File

@ -0,0 +1,173 @@
---
:cmock:
:plugins:
- # none
:treat_as:
MY_STRING: STRING
MY_INT: INT
PTR_INT: INT*
MY_HEX: HEX32
:systest:
:types: |
typedef const char* MY_STRING;
typedef int MY_INT;
typedef unsigned int MY_HEX;
typedef int* PTR_INT;
:mockable: |
MY_INT foo(MY_HEX a);
MY_INT bar(MY_HEX b);
MY_STRING foo_char_strings(MY_STRING a, MY_STRING b);
float float_adder(float a, float b);
MY_INT* pointer_foo(MY_HEX* a);
void pointer_bar(PTR_INT a);
: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);
MY_INT function_d(MY_HEX a);
void function_e(PTR_INT a);
:code: |
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'
:code: |
test()
{
foo_ExpectAndReturn((MY_HEX)1, 10);
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: |
test()
{
foo_ExpectAndReturn((MY_HEX)1, 10);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because foo_char_strings() is called but is not expected'
:code: |
test()
{
foo_char_strings_ExpectAndReturn((MY_STRING)"jello", (MY_STRING)"jiggle", (MY_STRING)"boing!");
function_a(1,2);
}
- :pass: TRUE
:should: 'handle char strings'
:code: |
test()
{
foo_char_strings_ExpectAndReturn((MY_STRING)"jello", (MY_STRING)"jiggle", (MY_STRING)"boing!");
TEST_ASSERT_EQUAL_STRING("boing!", function_b((MY_STRING)"jello", (MY_STRING)"jiggle"));
}
- :pass: TRUE
:should: 'handle floating point numbers with Unity support: pass'
:code: |
test()
{
float_adder_ExpectAndReturn(1.2345f, 6.7890f, 8.0235f);
TEST_ASSERT_EQUAL_FLOAT(8.0235f, function_c(6.7890f, 1.2345f));
}
- :pass: FALSE
:should: 'handle floating point numbers with Unity support: fail'
:code: |
test()
{
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: |
test()
{
MY_HEX TestHex = (MY_HEX)45;
MY_INT TestInt = (MY_INT)33;
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'
:code: |
test()
{
MY_HEX TestHex = (MY_HEX)45;
MY_INT TestInt = (MY_INT)33;
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: |
test()
{
MY_INT ExpInt = (MY_INT)33;
PTR_INT ExpPtr = (PTR_INT)(&ExpInt);
MY_INT ActInt = (MY_INT)33;
PTR_INT ActPtr = (PTR_INT)(&ActInt);
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'
:code: |
test()
{
MY_INT ExpInt = (MY_INT)33;
PTR_INT ExpPtr = (PTR_INT)(&ExpInt);
MY_INT ActInt = (MY_INT)45;
PTR_INT ActPtr = (PTR_INT)(&ActInt);
pointer_bar_Expect(ExpPtr);
function_e(ActPtr);
}
...

View File

@ -0,0 +1,170 @@
---
:cmock:
:plugins:
- :cexception
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
#include "CException.h"
UINT32 foo(custom_type a);
UINT32 bar(custom_type b);
UINT32 foo_varargs(custom_type a, ...);
:source:
:header: |
#include "CException.h"
UINT32 function_a(int a);
void function_b(char a);
:code: |
UINT32 function_a(int a)
{
UINT32 r = 0;
CEXCEPTION_T e;
Try
{
r = (UINT32)foo((custom_type)a);
}
Catch(e)
{
r = (UINT32)e*2;
}
return r;
}
void function_b(char a)
{
if (a)
{
Throw((CEXCEPTION_T)a);
}
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise a simple ExpectAndReturn mock calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
TEST_ASSERT_EQUAL(10, function_a(1));
}
- :pass: TRUE
:should: 'successfully throw an error on first call'
:code: |
test()
{
foo_ExpectAndThrow((custom_type)1, 55);
TEST_ASSERT_EQUAL(110, function_a(1));
}
- :pass: TRUE
:should: 'successfully throw an error on later calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndThrow((custom_type)3, 15);
foo_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(10, function_a(1));
TEST_ASSERT_EQUAL(20, function_a(2));
TEST_ASSERT_EQUAL(30, function_a(3));
TEST_ASSERT_EQUAL(40, function_a(4));
}
- :pass: TRUE
:should: 'pass because we nothing happens'
:code: |
test()
{
function_b(0);
}
- :pass: FALSE
:should: 'fail because we did not expect function B to throw'
:code: |
test()
{
function_b(1);
}
- :pass: TRUE
:should: 'fail because we expect function B to throw'
:code: |
test()
{
CEXCEPTION_T e;
Try
{
function_b(3);
TEST_FAIL_MESSAGE("Should Have Thrown");
}
Catch(e)
{
TEST_ASSERT_EQUAL(3, e);
}
}
- :pass: TRUE
:should: 'successfully throw an error on consecutive calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)1, 20);
foo_ExpectAndThrow((custom_type)1, 15);
foo_ExpectAndThrow((custom_type)3, 40);
TEST_ASSERT_EQUAL(10, function_a(1));
TEST_ASSERT_EQUAL(20, function_a(1));
TEST_ASSERT_EQUAL(30, function_a(1));
TEST_ASSERT_EQUAL(80, function_a(3));
}
- :pass: TRUE
:should: 'successfully throw an error on later calls and after a previous mock call'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)1, 20);
foo_ExpectAndThrow((custom_type)1, 15);
TEST_ASSERT_EQUAL(10, function_a(1));
TEST_ASSERT_EQUAL(20, function_a(1));
TEST_ASSERT_EQUAL(30, function_a(1));
foo_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndThrow((custom_type)3, 40);
TEST_ASSERT_EQUAL(20, function_a(2));
TEST_ASSERT_EQUAL(80, function_a(3));
}
- :pass: TRUE
:should: 'successfully throw an error if expects and mocks called before it'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
foo_ExpectAndReturn((custom_type)1, 20);
TEST_ASSERT_EQUAL(10, function_a(1));
TEST_ASSERT_EQUAL(20, function_a(1));
foo_ExpectAndReturn((custom_type)2, 20);
foo_ExpectAndThrow((custom_type)3, 40);
TEST_ASSERT_EQUAL(20, function_a(2));
TEST_ASSERT_EQUAL(80, function_a(3));
}
...

View File

@ -0,0 +1,238 @@
---
:cmock:
:plugins:
- 'expect_any_args'
:systest:
:types: |
:mockable: |
int foo(int a);
void bar(int b);
:source:
:header: |
int function(int a, int b, int c);
void func_b(int a);
:code: |
int function(int a, int b, int c)
{
bar(b);
return foo(a) + foo(b) + foo(c);
}
void func_b(int a)
{
bar(a);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise simple ExpectAndReturn mock calls'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 10);
foo_ExpectAndReturn(2, 20);
foo_ExpectAndReturn(3, 30);
TEST_ASSERT_EQUAL(60, function(1, 2, 3));
}
- :pass: TRUE
:should: 'ignore foo() call details'
:code: |
test()
{
bar_Expect(4);
foo_ExpectAnyArgsAndReturn(10);
foo_ExpectAnyArgsAndReturn(40);
foo_ExpectAnyArgsAndReturn(80);
TEST_ASSERT_EQUAL(130, function(3, 4, 3));
}
- :pass: FALSE
:should: 'ignore foo() call details and notice if we called foo() more times than expected'
:code: |
test()
{
bar_Expect(4);
foo_ExpectAnyArgsAndReturn(20);
foo_ExpectAnyArgsAndReturn(30);
TEST_ASSERT_EQUAL(50, function(3, 4, 9));
}
- :pass: FALSE
:should: 'ignore foo() call details and notice if we called foo() fewer times than expected'
:code: |
test()
{
bar_Expect(4);
foo_ExpectAnyArgsAndReturn(20);
foo_ExpectAnyArgsAndReturn(10);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(60);
TEST_ASSERT_EQUAL(70, function(3, 4, 9));
}
- :pass: TRUE
:should: 'ignore bar() and foo() call details'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(50);
TEST_ASSERT_EQUAL(150, function(0, 0, 0));
}
- :pass: TRUE
:should: 'be able to handle an expect after ignore calls since we are ignoring args only'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAndReturn(3, 50);
TEST_ASSERT_EQUAL(150, function(1, 2, 3));
}
- :pass: TRUE
:should: 'be able to handle an ignore after an expect call since we are ignoring args only'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAndReturn(1, 50);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(50);
TEST_ASSERT_EQUAL(150, function(1, 2, 3));
}
- :pass: TRUE
:should: 'be able to handle an ignore within expect calls since we are ignoring args only'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAndReturn(1, 50);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAndReturn(3, 50);
TEST_ASSERT_EQUAL(150, function(1, 2, 3));
}
- :pass: FALSE
:should: 'be able to detect problems with an expect even when using ignores'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAndReturn(1, 50);
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAndReturn(4, 50);
TEST_ASSERT_EQUAL(150, function(1, 2, 3));
}
- :pass: TRUE
:should: 'be able to handle a lone ExpectAnyArg call'
:code: |
test()
{
bar_ExpectAnyArgs();
func_b(1);
}
- :pass: FALSE
:should: 'be able to handle a lone ExpectAnyArg call that does not get called'
:code: |
test()
{
bar_ExpectAnyArgs();
}
- :pass: FALSE
:should: 'be able to handle a missing ExpectAnyArg call'
:code: |
test()
{
func_b(1);
}
- :pass: TRUE
:should: 'ignore foo() calls over multiple mock calls'
:code: |
test()
{
bar_ExpectAnyArgs();
foo_ExpectAnyArgsAndReturn(50);
foo_ExpectAnyArgsAndReturn(60);
foo_ExpectAnyArgsAndReturn(70);
TEST_ASSERT_EQUAL(180, function(0, 0, 0));
bar_ExpectAnyArgs();
foo_ExpectAnyArgsAndReturn(30);
foo_ExpectAnyArgsAndReturn(80);
foo_ExpectAnyArgsAndReturn(10);
TEST_ASSERT_EQUAL(120, function(0, 0, 0));
bar_ExpectAnyArgs();
foo_ExpectAnyArgsAndReturn(70);
foo_ExpectAnyArgsAndReturn(20);
foo_ExpectAnyArgsAndReturn(20);
TEST_ASSERT_EQUAL(110, function(0, 0, 0));
}
- :pass: TRUE
:should: 'have multiple cycles of expects still pass when this plugin enabled'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'have multiple cycles of expects still fail when this plugin enabled'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(0, 8, 9));
}
...

View File

@ -0,0 +1,210 @@
---
:cmock:
:plugins:
- # none
:treat_as:
INT_PTR: INT*
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
typedef int* INT_PTR;
:mockable: |
void foo(POINT_T* a);
POINT_T* bar(void);
void fooa(POINT_T a[]);
void foos(const char *a);
const char* bars(void);
INT_PTR zoink(INT_PTR a);
:source:
:header: |
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
:code: |
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'
:code: |
test()
{
bar_ExpectAndReturn(NULL);
foo_Expect(NULL);
function_a();
}
- :pass: TRUE
:should: 'handle the situation where we pass single object with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
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: |
test()
{
bar_ExpectAndReturn(NULL);
fooa_Expect(NULL);
function_b();
}
- :pass: TRUE
:should: 'handle the situation where we pass single array element with expect'
:code: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
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: |
test()
{
POINT_T pt = {1, 2};
bar_ExpectAndReturn(&pt);
fooa_Expect(NULL);
function_b();
}
- :pass: TRUE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing'
:code: |
test()
{
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()
{
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: |
test()
{
int e = 456;
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: |
test()
{
int e = 457;
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());
}
...

View File

@ -0,0 +1,83 @@
---
:cmock:
:plugins:
- # none
:treat_as:
FUNCTION_T: PTR
:systest:
:types: |
typedef void (*FUNCTION_T)(void);
:mockable: |
void takes_function_type( FUNCTION_T myfunc );
void takes_function_ptr( unsigned int (*func_ptr)(int, char) );
void takes_function_ptr_shorthand( unsigned int func_ptr(int, char*) );
void takes_const_function_ptr( unsigned int (* const)(int, char) );
unsigned short (*returns_function_ptr( const char op_code ))( int, long int );
:source:
:header: |
void exercise_function_pointer_param(void);
unsigned short (*exercise_function_pointer_return( const char op_code ))( int, long int );
// functions for function pointer tests
unsigned int dummy_function1(int a, char b);
unsigned short dummy_function2(int a, long int b);
:code: |
/*
* functions used in tests
*/
unsigned int dummy_function1(int a, char b)
{
// prevent compiler warnings by using everything
return (unsigned int)a + (unsigned int)b;
}
unsigned short dummy_function2(int a, long int b)
{
// prevent compiler warnings by using everything
return (unsigned short)a + (unsigned short)b;
}
/*
* functions executed by tests
*/
void exercise_function_pointer_param(void)
{
takes_function_ptr(dummy_function1);
}
unsigned short (*exercise_function_pointer_return( const char op_code ))( int, long int )
{
return returns_function_ptr(op_code);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'expect a function pointer param'
:code: |
test()
{
takes_function_ptr_Expect(dummy_function1);
exercise_function_pointer_param();
}
- :pass: TRUE
:should: 'return a function pointer'
:code: |
test()
{
returns_function_ptr_ExpectAndReturn('z', dummy_function2);
TEST_ASSERT_EQUAL_PTR(dummy_function2, exercise_function_pointer_return('z'));
}
...

View File

@ -0,0 +1,329 @@
---
:cmock:
:plugins:
- 'ignore'
:systest:
:types: |
:mockable: |
int foo(int a);
void bar(int b);
:source:
:header: |
int function(int a, int b, int c);
:code: |
int function(int a, int b, int c)
{
bar(b);
return foo(a) + foo(b) + foo(c);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise simple ExpectAndReturn mock calls'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 10);
foo_ExpectAndReturn(2, 20);
foo_ExpectAndReturn(3, 30);
TEST_ASSERT_EQUAL(60, function(1, 2, 3));
}
- :pass: TRUE
:should: 'ignore foo() calls'
:code: |
test()
{
bar_Expect(4);
foo_IgnoreAndReturn(10);
foo_IgnoreAndReturn(40);
foo_IgnoreAndReturn(80);
TEST_ASSERT_EQUAL(130, function(3, 4, 3));
}
- :pass: TRUE
:should: 'ignore the situation where foo() is not called even though we explicitly ignored it'
:code: |
test()
{
foo_IgnoreAndReturn(20);
//notice we do not call foo
}
- :pass: TRUE
:should: 'ignore foo() calls and always return last item if we run out'
:code: |
test()
{
bar_Expect(4);
foo_IgnoreAndReturn(20);
foo_IgnoreAndReturn(30);
TEST_ASSERT_EQUAL(80, function(3, 4, 9));
}
- :pass: TRUE
:should: 'ignore foo() calls and always return only item if only one specified'
:code: |
test()
{
bar_Expect(4);
foo_IgnoreAndReturn(20);
TEST_ASSERT_EQUAL(60, function(3, 4, 9));
}
- :pass: TRUE
:should: 'ignore bar() and foo() calls'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(50);
TEST_ASSERT_EQUAL(150, function(0, 0, 0));
}
- :pass: TRUE
:should: 'ignore foo() calls over multiple mock calls'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(50);
foo_IgnoreAndReturn(60);
foo_IgnoreAndReturn(70);
TEST_ASSERT_EQUAL(180, function(0, 0, 0));
bar_Ignore();
foo_IgnoreAndReturn(30);
foo_IgnoreAndReturn(80);
foo_IgnoreAndReturn(10);
TEST_ASSERT_EQUAL(120, function(0, 0, 0));
foo_IgnoreAndReturn(70);
foo_IgnoreAndReturn(20);
TEST_ASSERT_EQUAL(110, function(0, 0, 0));
}
- :pass: TRUE
:should: 'multiple cycles of expects still pass when ignores enabled'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'multiple cycles of expects still fail when ignores enabled'
:code: |
test()
{
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(0, 8, 9));
}
- :pass: FALSE
:should: 'With "fail_on_unexpected_calls" enabled, Expect/Ignore/... of bar is required and test fails.'
:code: |
test()
{
function(1, 2, 3);
}
- :pass: TRUE
:should: 'we can override an ignore with an expect and pass'
:code: |
test()
{
bar_Ignore();
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'we can override an ignore with an expect and fail'
:code: |
test()
{
bar_Ignore();
bar_Expect(2);
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(9);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: TRUE
:should: 'we can override an ignore and return with an expect and pass'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(30);
TEST_ASSERT_EQUAL(90, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(8);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: FALSE
:should: 'we can override an ignore and return with an expect and fail'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(0);
TEST_ASSERT_EQUAL(0, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_ExpectAndReturn(6, 10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Expect(9);
foo_ExpectAndReturn(7, 70);
foo_ExpectAndReturn(8, 20);
foo_ExpectAndReturn(9, 20);
TEST_ASSERT_EQUAL(110, function(7, 8, 9));
}
- :pass: TRUE
:should: 'we can override an an expect with an ignore'
:code: |
test()
{
bar_Expect(5);
bar_Ignore();
foo_ExpectAndReturn(1, 50);
foo_ExpectAndReturn(2, 60);
foo_ExpectAndReturn(3, 70);
TEST_ASSERT_EQUAL(180, function(1, 2, 3));
}
- :pass: TRUE
:should: 'we can override an expect with an ignore and return and pass'
:code: |
test()
{
bar_Ignore();
foo_IgnoreAndReturn(0);
TEST_ASSERT_EQUAL(0, function(1, 2, 3));
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 80);
foo_IgnoreAndReturn(10);
TEST_ASSERT_EQUAL(120, function(4, 5, 6));
bar_Ignore();
foo_IgnoreAndReturn(60);
TEST_ASSERT_EQUAL(180, function(7, 8, 9));
}
- :pass: FALSE
:should: 'we can override an expect with an ignore and return and fail after'
:code: |
test()
{
bar_Expect(5);
foo_ExpectAndReturn(4, 30);
foo_ExpectAndReturn(5, 50);
foo_IgnoreAndReturn(20);
TEST_ASSERT_EQUAL(100, function(4, 5, 6));
bar_Expect(5);
foo_ExpectAndReturn(9, 30); //THIS ONE WILL FAIL
foo_ExpectAndReturn(2, 80);
foo_ExpectAndReturn(3, 60);
TEST_ASSERT_EQUAL(170, function(1, 2, 3));
}
- :pass: TRUE
:should: 'we can override an expect with an ignore and return and the expected values are ignored'
:code: |
test()
{
bar_Expect(5);
foo_ExpectAndReturn(2, 30); //NOTE THIS WOULD NORMALLY FAIL
foo_ExpectAndReturn(5, 50);
foo_IgnoreAndReturn(20); //BUT WE SAID WE NO LONGER CARE
TEST_ASSERT_EQUAL(100, function(4, 5, 6));
}
...

View File

@ -0,0 +1,37 @@
---
:cmock:
:plugins:
- 'ignore'
:fail_on_unexpected_calls: FALSE
:systest:
:types: |
:mockable: |
int foo(int a);
void bar(int b);
:source:
:header: |
int function(int a, int b, int c);
:code: |
int function(int a, int b, int c)
{
bar(b);
return foo(a) + foo(b) + foo(c);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'With "fail_on_unexpected_calls" disabled, Expect/Ignore/... of bar is NOT required.'
:code: |
test()
{
function(1, 2, 3);
}
...

View File

@ -0,0 +1,52 @@
---
#The purpose of this test is to pull in some standard library stuff from C99
:cmock:
:includes:
- "<stdint.h>"
- "<limits.h>"
:systest:
:types: |
#include <stdint.h>
#include <limits.h>
:mockable: |
int32_t foo(int32_t a);
:source:
:header: |
int8_t function_a(void);
:code: |
int8_t function_a(void) {
return (int8_t)(INT_MIN == foo(INT_MAX));
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle handle a simple comparison of C99 types which pass'
:code: |
test()
{
foo_ExpectAndReturn(INT_MAX, INT_MIN);
TEST_ASSERT_TRUE(function_a());
}
- :pass: FALSE
:should: 'handle handle a simple comparison of C99 types which fail'
:code: |
test()
{
foo_ExpectAndReturn(INT_MIN, INT_MIN);
TEST_ASSERT_TRUE(function_a());
}
...

View File

@ -0,0 +1,91 @@
---
#The purpose of this test is to play with things like "const char const *" which isn't supported by some compilers
:cmock:
:enforce_strict_ordering: 1
:plugins:
- :array
- :cexception
- :ignore
:systest:
:types: |
typedef struct _POINT_T {
int x;
int y;
} POINT_T;
:mockable: |
#include "CException.h"
void foos(const char const * a);
const char const * bars(void);
:source:
:header: |
#include "CException.h"
void function_a(void);
void function_b(void);
void function_c(void);
int function_d(void);
:code: |
void function_c(void) {
CEXCEPTION_T e;
Try {
foos(bars());
} Catch(e) { foos("err"); }
}
:tests:
:common: |
#include "CException.h"
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing'
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
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");
foos_Expect("This is a wacky string");
function_c();
}
- :pass: TRUE
:should: 'handle an exception being caught'
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("err");
function_c();
}
- :pass: FALSE
:should: 'handle an exception being caught but still catch following errors'
:code: |
test()
{
bars_ExpectAndReturn("This is a\0 silly string");
foos_ExpectAndThrow("This is a\0 wacky string", 55);
foos_Expect("wrong error");
function_c();
}
...

View File

@ -0,0 +1,59 @@
---
#The purpose of this test is to play with our really rough multidimensional array support, which involves an implicit cast not supported everywhere
:cmock:
:plugins:
- :array
:systest:
:types: |
:mockable: |
void foo(unsigned char** a);
unsigned char** bar(void);
:source:
:header: |
void function_a(void);
:code: |
void function_a(void) {
foo(bar());
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle two dimensional array of unsigned characters just like we would handle a single dimensional array in expect (where we really only care about first element)'
:code: |
test()
{
unsigned char a[] = { 1, 2, 3, 4, 5, 6 };
unsigned char** pa = (unsigned char**)(&a);
bar_ExpectAndReturn(pa);
foo_Expect(pa);
function_a();
}
- :pass: FALSE
:should: 'handle two dimensional array of unsigned characters just like we would handle a single dimensional array in expect as failures (where we really only care about first element)'
:code: |
test()
{
unsigned char a[] = { 1, 2, 3, 4, 5, 6 };
unsigned char b[] = { 5, 6, 7, 8, 9, 0 };
unsigned char** pa = (unsigned char**)(&a);
unsigned char** pb = (unsigned char**)(&b);
bar_ExpectAndReturn(pa);
foo_Expect(pb);
function_a();
}
...

View File

@ -0,0 +1,65 @@
---
:cmock:
:plugins: []
:treat_as:
custom_type: INT
:systest:
:types: |
typedef struct _BIG_FAT_STRUCT_T
{
char bytes[512];
} BIG_FAT_STRUCT_T;
:mockable: |
void foo(BIG_FAT_STRUCT_T a);
:source:
:header: |
void function_a(void);
void function_b(void);
:code: |
void function_a(void)
{
BIG_FAT_STRUCT_T stuff = { { 8, 0 } };
foo(stuff);
}
void function_b(void)
{
BIG_FAT_STRUCT_T stuff1 = { { 9, 1, 0 } };
BIG_FAT_STRUCT_T stuff2 = { { 9, 2, 0 } };
foo(stuff1);
foo(stuff2);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully should be able to run function a because it only takes half the memory'
:code: |
test()
{
BIG_FAT_STRUCT_T expected = { { 8, 0 } };
foo_Expect(expected);
function_a();
}
- :pass: FALSE
:should: 'should error out because we do not have eough memory to handle two of these structures'
:code: |
test()
{
BIG_FAT_STRUCT_T expected1 = { { 9, 1, 0 } };
BIG_FAT_STRUCT_T expected2 = { { 9, 2, 0 } };
foo_Expect(expected1);
foo_Expect(expected2);
function_b();
}
...

View File

@ -0,0 +1,242 @@
---
:cmock:
:plugins:
- # no plugins
:treat_as_void:
- VOID_TYPE_CRAZINESS_CFG
:treat_as:
TypeDefInt: HEX8
VOID_TYPE_CRAZINESS_CFG*: PTR
:systest:
:types: |
typedef unsigned short U16;
typedef struct _POINT_T
{
int x;
int y;
} POINT_T;
typedef void VOID_TYPE_CRAZINESS_CFG;
typedef int TypeDefInt;
:mockable: |
/* Make sure we ignore the following
#include "NonExistantFile.h
*/
//#include "AndIgnoreThisToo.h"
#ifdef __cplusplus
extern "C" {
#endif
#define SHOULD_IGNORE_NEXT_FUNC_DEF_AS_PART_OF_MACRO \
void IgnoredFunction(NotAValidType ToMakeItFailIfWeActuallyMockedThis);
// typedef edge case; must be in mockable.h for test to compile
// not ANSI C but it has been done and will break cmock if not handled
typedef void VOID_TYPE_CRAZINESS_LCL;
VOID_TYPE_CRAZINESS_LCL void_type_craziness1(int * a, int *b, int* c);
void void_type_craziness2(VOID_TYPE_CRAZINESS_CFG);
void void_type_craziness3(VOID_TYPE_CRAZINESS_CFG* a);
// pointer parsing exercise
U16 *ptr_return1(int a);
U16* ptr_return2(int a);
U16 * ptr_return3(int a);
unsigned int** ptr_ptr_return1(unsigned int** a);
unsigned int* *ptr_ptr_return2(unsigned int* *a);
unsigned int **ptr_ptr_return3(unsigned int **a);
unsigned int ** ptr_ptr_return4(unsigned int ** a);
// variable argument lists
void var_args1(int a, ...);
void var_args2(int a, int b, ...);
// parsing "stress tests"
char
crazy_multiline(
int a,
unsigned int b);
unsigned long int incredible_descriptors(register const unsigned short a);
TypeDefInt uses_typedef_like_names(TypeDefInt typedefvar);
void oh_brackets1(int fudge[5]);
void oh_brackets2(int caramel[]);
void oh_brackets3(int toffee[(32)]);
void oh_brackets4(int taffy[ (64) ]);
#ifdef __cplusplus
}
#endif
:source:
:header: |
U16* exercise_return_pointers(int a);
void exercise_var_args(int a, int b);
void exercise_arglist_pointers(void);
char exercise_multiline_declarations(int a, unsigned int b);
void exercise_double_pointers(unsigned int** a);
int exercise_many_descriptors(int a);
void exercise_type_craziness3(VOID_TYPE_CRAZINESS_CFG* a);
TypeDefInt exercise_typedef_like_names(TypeDefInt a);
:code: |
int A, B, C;
unsigned int *pA, *pB, *pC;
U16* exercise_return_pointers(int a)
{
ptr_return1(a);
ptr_return2(a);
return ptr_return3(a);
}
void exercise_var_args(int a, int b)
{
var_args1(a, 3);
var_args2(a, b, 'c');
}
void exercise_arglist_pointers(void)
{
void_type_craziness1(&A, &B, &C);
void_type_craziness2();
}
char exercise_multiline_declarations(int a, unsigned int b)
{
return crazy_multiline(a, b);
}
void exercise_double_pointers(unsigned int** a)
{
ptr_ptr_return1((unsigned int**)a);
ptr_ptr_return2((unsigned int**)a);
ptr_ptr_return3((unsigned int**)a);
ptr_ptr_return4((unsigned int**)a);
}
int exercise_many_descriptors(int a)
{
return (int)incredible_descriptors((unsigned short)a);
}
void exercise_type_craziness3(VOID_TYPE_CRAZINESS_CFG* a)
{
void_type_craziness3(a);
}
TypeDefInt exercise_typedef_like_names(TypeDefInt a)
{
return uses_typedef_like_names(a);
}
:tests:
:common: |
extern int A, B, C;
extern unsigned int *pA, *pB, *pC;
void setUp(void)
{
A = 100;
B = 200;
C = 300;
pA = (unsigned int*)(&A);
pB = (unsigned int*)(&B);
pC = (unsigned int*)(&C);
}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'execute simple pointer return value check'
:code: |
test()
{
U16 retval;
ptr_return1_ExpectAndReturn(2, NULL);
ptr_return2_ExpectAndReturn(2, NULL);
ptr_return3_ExpectAndReturn(2, &retval);
TEST_ASSERT_EQUAL_PTR(&retval, exercise_return_pointers(2));
}
- :pass: TRUE
:should: 'ignore var args in expect prototype generation'
:code: |
test()
{
var_args1_Expect(2);
var_args2_Expect(2, 3);
exercise_var_args(2, 3);
}
- :pass: TRUE
:should: "not process a typedef'd void as anything other than void"
:code: |
test()
{
void_type_craziness1_Expect(&A, &B, &C);
void_type_craziness2_Expect();
exercise_arglist_pointers();
}
- :pass: TRUE
:should: 'successfully mock crazy multline function prototypes'
:code: |
test()
{
crazy_multiline_ExpectAndReturn(-10, 11, 'z');
TEST_ASSERT_EQUAL('z', exercise_multiline_declarations(-10, 11));
}
- :pass: TRUE
:should: 'mock double pointers just fine'
:code: |
test()
{
ptr_ptr_return1_ExpectAndReturn(&pA, &pB);
ptr_ptr_return2_ExpectAndReturn(&pA, &pB);
ptr_ptr_return3_ExpectAndReturn(&pA, &pB);
ptr_ptr_return4_ExpectAndReturn(&pA, &pB);
exercise_double_pointers((unsigned int**)(&pA));
}
- :pass: TRUE
:should: 'mock prototypes with long lists of return and parameter type descriptors'
:code: |
test()
{
incredible_descriptors_ExpectAndReturn(888, 777);
TEST_ASSERT_EQUAL(777, exercise_many_descriptors(888));
}
- :pass: TRUE
:should: 'handle words like typdef as PART of a variable or type'
:code: |
test()
{
uses_typedef_like_names_ExpectAndReturn((TypeDefInt)54, (TypeDefInt)53);
TEST_ASSERT_EQUAL(53, exercise_typedef_like_names((TypeDefInt)54));
}
- :pass: FALSE
:should: 'handle words like typdef as PART of a variable or type during failing tests'
:code: |
test()
{
uses_typedef_like_names_ExpectAndReturn((TypeDefInt)52, (TypeDefInt)53);
TEST_ASSERT_EQUAL(53, exercise_typedef_like_names((TypeDefInt)54));
}
- :pass: TRUE
:should: 'handle typedef of void used as a void pointer'
:code: |
test()
{
char blah[5] = "blah";
void_type_craziness3_Expect(blah);
exercise_type_craziness3(blah);
}
...

View File

@ -0,0 +1,235 @@
---
:cmock:
:mock_path: test/mocks
:mock_prefix: mock_
:treat_as:
abs_struct: PTR
intptr: INT*
:when_ptr: :smart
:plugins:
- :array
- :ignore_arg
- :return_thru_ptr
:systest:
:types: |
typedef int *intptr;
struct a_struct
{
int i1;
int i2;
int i3;
};
struct _abs_struct
{
int abs_i1;
int abs_i2;
};
typedef struct _abs_struct abs_struct;
:mockable: |
void ptr_ret_int(int *r);
void ptr_ret_ints(int *r, int *s);
void ptr_ret_array(char r[], int len);
void ptr_ret_typedef(intptr r);
void ptr_ret_struct(struct a_struct *r);
void ptr_ret_abstract(abs_struct *r);
void ptr_ret_abstract_array(abs_struct *r, int len);
void ptr_ret_const_int(int *r, const int *s);
void ptr_ret_string(char *s);
:source:
:header: |
#include <string.h>
#define lengthof(x) (sizeof(x)/sizeof((x)[0]))
:code: |
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: "handle a single int* argument"
:code: |
test()
{
int r = 1;
int res = 4;
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
}
- :pass: TRUE
:should: "handle multiple calls"
:code: |
test()
{
int r = 1;
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
:should: "ignore an argument"
:code: |
test()
{
int r = 1, s = 2;
int res = 4;
ptr_ret_int_Expect(&r);
ptr_ret_int_IgnoreArg_r();
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&s);
TEST_ASSERT_EQUAL(4, s);
}
- :pass: TRUE
:should: "ignore a null pointer argument"
:code: |
test()
{
int r = 1;
int res = 4;
ptr_ret_int_Expect(NULL);
ptr_ret_int_IgnoreArg_r();
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
}
- :pass: TRUE
:should: "handle multiple int* arguments"
:code: |
test()
{
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);
ptr_ret_ints(&r, &s);
TEST_ASSERT_EQUAL(4, r);
TEST_ASSERT_EQUAL(6, s);
}
- :pass: TRUE
:should: "only return through pointer when asked to"
:code: |
test()
{
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);
TEST_ASSERT_EQUAL(4, r);
TEST_ASSERT_EQUAL(0xAA55, s);
}
- :pass: TRUE
:should: "return an array through a pointer correctly"
:code: |
test()
{
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, (int)strlen(r_a_ret));
ptr_ret_array(r_a, lengthof(r_a));
TEST_ASSERT_EQUAL_STRING("FEEFIorooboo", r_a);
}
- :pass: TRUE
:should: "handle structs"
:code: |
test()
{
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);
TEST_ASSERT_EQUAL_MEMORY(&r_s_ret, &r_s, sizeof(struct a_struct));
}
- :pass: TRUE
:should: "handle typedefs"
:code: |
test()
{
abs_struct r_as = {.abs_i1 = 0x1234, .abs_i2 = 0x4567};
abs_struct r_as_ret = {.abs_i1 = 0xFFAA55, .abs_i2 = 0xAAFFAA};
ptr_ret_abstract_Expect(&r_as);
ptr_ret_abstract_ReturnMemThruPtr_r(&r_as_ret, sizeof(abs_struct));
ptr_ret_abstract(&r_as);
TEST_ASSERT_EQUAL_MEMORY(&r_as_ret, &r_as, sizeof(abs_struct));
}
- :pass: TRUE
:should: "only generate ReturnThruPtr definitions for non-const arguments"
:code: |
test()
{
#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
}
- :pass: TRUE
:should: "generate ReturnThruPtr definitions for string arguments"
:code: |
test()
{
#if !defined(ptr_ret_string_ReturnThruPtr_s)
TEST_FAIL_MESSAGE("ReturnThruPtr not defined for a string argument.");
#endif
}
- :pass: TRUE
:should: "generate IgnoreArg definitions"
:code: |
test()
{
#if !defined(ptr_ret_array_IgnoreArg_r) \
|| !defined(ptr_ret_array_IgnoreArg_len) \
|| !defined(ptr_ret_const_int_IgnoreArg_s)
TEST_FAIL_MESSAGE("IgnoreArg not defined for an argument.");
#endif
}

View File

@ -0,0 +1,231 @@
---
:cmock:
:mock_path: test/mocks
:mock_prefix: mock_
:treat_as:
abs_struct: PTR
intptr: INT*
:when_ptr: :smart
:plugins:
- :array
- :expect_any_args
- :return_thru_ptr
:systest:
:types: |
typedef int *intptr;
struct a_struct
{
int i1;
int i2;
int i3;
};
struct _abs_struct
{
int abs_i1;
int abs_i2;
};
typedef struct _abs_struct abs_struct;
:mockable: |
void ptr_ret_int(int *r);
void ptr_ret_ints(int *r, int *s);
void ptr_ret_array(char r[], int len);
void ptr_ret_typedef(intptr r);
void ptr_ret_struct(struct a_struct *r);
void ptr_ret_abstract(abs_struct *r);
void ptr_ret_abstract_array(abs_struct *r, int len);
void ptr_ret_const_int(int *r, const int *s);
void ptr_ret_string(char *s);
:source:
:header: |
#include <string.h>
#define lengthof(x) (sizeof(x)/sizeof((x)[0]))
:code: |
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: "handle a single int* argument"
:code: |
test()
{
int r = 1;
int res = 4;
ptr_ret_int_Expect(&r);
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
}
- :pass: TRUE
:should: "handle multiple calls"
:code: |
test()
{
int r = 1;
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
:should: "ignore an argument"
:code: |
test()
{
int s = 2;
int res = 4;
ptr_ret_int_ExpectAnyArgs();
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&s);
TEST_ASSERT_EQUAL(4, s);
}
- :pass: TRUE
:should: "ignore a null pointer argument"
:code: |
test()
{
int r = 1;
int res = 4;
ptr_ret_int_ExpectAnyArgs();
ptr_ret_int_ReturnThruPtr_r(&res);
ptr_ret_int(&r);
TEST_ASSERT_EQUAL(4, r);
}
- :pass: TRUE
:should: "handle multiple int* arguments"
:code: |
test()
{
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);
ptr_ret_ints(&r, &s);
TEST_ASSERT_EQUAL(4, r);
TEST_ASSERT_EQUAL(6, s);
}
- :pass: TRUE
:should: "only return through pointer when asked to"
:code: |
test()
{
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);
TEST_ASSERT_EQUAL(4, r);
TEST_ASSERT_EQUAL(0xAA55, s);
}
- :pass: TRUE
:should: "return an array through a pointer correctly"
:code: |
test()
{
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, (int)strlen(r_a_ret));
ptr_ret_array(r_a, lengthof(r_a));
TEST_ASSERT_EQUAL_STRING("FEEFIorooboo", r_a);
}
- :pass: TRUE
:should: "handle structs"
:code: |
test()
{
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);
TEST_ASSERT_EQUAL_MEMORY(&r_s_ret, &r_s, sizeof(struct a_struct));
}
- :pass: TRUE
:should: "handle typedefs"
:code: |
test()
{
abs_struct r_as = {.abs_i1 = 0x1234, .abs_i2 = 0x4567};
abs_struct r_as_ret = {.abs_i1 = 0xFFAA55, .abs_i2 = 0xAAFFAA};
ptr_ret_abstract_Expect(&r_as);
ptr_ret_abstract_ReturnMemThruPtr_r(&r_as_ret, sizeof(abs_struct));
ptr_ret_abstract(&r_as);
TEST_ASSERT_EQUAL_MEMORY(&r_as_ret, &r_as, sizeof(abs_struct));
}
- :pass: TRUE
:should: "only generate ReturnThruPtr definitions for non-const arguments"
:code: |
test()
{
#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
}
- :pass: TRUE
:should: "generate ReturnThruPtr definitions for string arguments"
:code: |
test()
{
#if !defined(ptr_ret_string_ReturnThruPtr_s)
TEST_FAIL_MESSAGE("ReturnThruPtr not defined for a string argument.");
#endif
}
- :pass: TRUE
:should: "generate ExpectAnyArgs definitions"
:code: |
test()
{
#if !defined(ptr_ret_array_ExpectAnyArgs)
TEST_FAIL_MESSAGE("ExpectAnyArgs not defined for an argument.");
#endif
}

View File

@ -0,0 +1,55 @@
---
:cmock:
:plugins:
- # none
:skeleton_path: system/generated
:systest:
:types: |
#define UINT32 unsigned int
:mockable: |
UINT32 something(int a);
:skeleton: skeleton.h
:source:
:header: |
void function_a(void);
int function_b(int a, int b);
const char* function_c(void);
# we are purposefully not including a :code section because it will be generated with skeleton
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'generate an empty shell for functions with no return values'
:code: |
test()
{
function_a();
}
- :pass: TRUE
:should: 'return numerical zero for numerical return values'
:code: |
test()
{
TEST_ASSERT_EQUAL_INT(0, function_b(1, 2));
}
- :pass: TRUE
:should: 'return null for pointer return values'
:code: |
test()
{
TEST_ASSERT_NULL(function_c());
}
...

View File

@ -0,0 +1,76 @@
---
:cmock:
:plugins:
- # none
:skeleton_path: system/generated
:systest:
:types: |
#define UINT32 unsigned int
:mockable: |
UINT32 something(int a);
:skeleton: skeleton_update.h
:source:
:header: |
void function_a(void);
int function_b(int a, int b);
const char* function_c(void);
# note that this code section exists and will be updated by the skeleton generator
:code: |
const char* donuts = "donuts";
const char* function_c(void)
{
return donuts;
}
int function_d(void)
{
return 77;
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
extern int function_d();
:units:
- :pass: TRUE
:should: 'generate an empty shell for functions with no return values'
:code: |
test()
{
function_a();
}
- :pass: TRUE
:should: 'return numerical zero for numerical return values'
:code: |
test()
{
TEST_ASSERT_EQUAL_INT(0, function_b(1, 2));
}
- :pass: TRUE
:should: 'not overwrite functions that already exist'
:code: |
test()
{
TEST_ASSERT_EQUAL_STRING("donuts", function_c());
}
- :pass: TRUE
:should: 'leave functions it has never heard of'
:code: |
test()
{
TEST_ASSERT_EQUAL_INT(77, function_d());
}
...

View File

@ -0,0 +1,277 @@
---
:cmock:
:plugins:
- # none
:systest:
:types: |
struct THING { int a; int b; };
union STARS_AND_STRIPES { int a; char b; };
enum HOKEY_POKEY { IN, OUT, SHAKE_IT_ALL_ABOUT };
:mockable: |
void foo_struct(struct THING*, struct THING);
struct THING foobar_struct(void);
void foo_union(union STARS_AND_STRIPES*, union STARS_AND_STRIPES);
union STARS_AND_STRIPES foobar_union(void);
void foo_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
enum HOKEY_POKEY foobar_enum(void);
:source:
:header: |
void exercise_struct(struct THING* a, struct THING b);
struct THING return_struct(void);
void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b);
union STARS_AND_STRIPES return_union(void);
void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
enum HOKEY_POKEY return_enum(void);
:code: |
void exercise_struct(struct THING* a, struct THING b)
{
foo_struct(a, b);
}
struct THING return_struct(void)
{
return foobar_struct();
}
void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b)
{
foo_union(a, b);
}
union STARS_AND_STRIPES return_union(void)
{
return foobar_union();
}
void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b)
{
foo_enum(a, b);
}
enum HOKEY_POKEY return_enum(void)
{
return foobar_enum();
}
:tests:
:common: |
struct THING struct1;
struct THING struct2;
struct THING struct3;
struct THING struct4;
struct THING struct5;
struct THING struct6;
union STARS_AND_STRIPES union1;
union STARS_AND_STRIPES union2;
union STARS_AND_STRIPES union3;
union STARS_AND_STRIPES union4;
union STARS_AND_STRIPES union5;
union STARS_AND_STRIPES union6;
enum HOKEY_POKEY enum1;
enum HOKEY_POKEY enum2;
void setUp(void)
{
struct1.a = 1;
struct1.b = 2;
struct2.a = 3;
struct2.b = 4;
struct3.a = 5;
struct3.b = 6;
struct4.a = 7;
struct4.b = 8;
struct5.a = 9;
struct5.b = 10;
struct6.a = 9;
struct6.b = 10;
union1.a = 1;
union2.a = 2;
union3.a = 3;
union4.a = 4;
union5.a = 5;
union6.a = 5;
enum1 = OUT;
enum2 = IN;
}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully compare structs'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct1, struct2);
}
- :pass: FALSE
:should: 'blow up on bad struct pointer comparison'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct3, struct2);
}
- :pass: FALSE
:should: 'blow up on bad structure comparison'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct1, struct4);
}
- :pass: TRUE
:should: 'compare returned structs as equal'
:code: |
test()
{
foobar_struct_ExpectAndReturn(struct5);
TEST_ASSERT_EQUAL_THING(struct6, return_struct());
}
- :pass: FALSE
:should: 'compare returned structs as unequal'
:code: |
test()
{
foobar_struct_ExpectAndReturn(struct4);
TEST_ASSERT_EQUAL_THING(struct5, return_struct());
}
- :pass: TRUE
:should: 'successfully compare unions'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union1, union2);
}
- :pass: FALSE
:should: 'blow up on bad union pointer comparison'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union3, union2);
}
- :pass: FALSE
:should: 'blow up on bad union comparison'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union1, union4);
}
- :pass: TRUE
:should: 'compare returned unions as equal'
:code: |
test()
{
foobar_union_ExpectAndReturn(union5);
TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union6, return_union());
}
- :pass: FALSE
:should: 'compare returned unions as unequal'
:code: |
test()
{
foobar_union_ExpectAndReturn(union4);
TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union5, return_union());
}
- :pass: TRUE
:should: 'successfully pass enum values'
:code: |
test()
{
foo_enum_Expect(OUT, &enum1);
exercise_enum(OUT, &enum1);
}
- :pass: FALSE
:should: 'blow up on bad enum pointer comparison'
:code: |
test()
{
foo_enum_Expect(IN, &enum1);
exercise_enum(IN, &enum2);
}
- :pass: FALSE
:should: 'blow up on bad enum comparison'
:code: |
test()
{
foo_enum_Expect(IN, &enum1);
exercise_enum(SHAKE_IT_ALL_ABOUT, &enum1);
}
- :pass: TRUE
:should: 'compare returned enums as equal'
:code: |
test()
{
foobar_enum_ExpectAndReturn(OUT);
TEST_ASSERT_EQUAL(OUT, return_enum());
}
- :pass: FALSE
:should: 'compare returned unions as unequal'
:code: |
test()
{
foobar_enum_ExpectAndReturn(OUT);
TEST_ASSERT_EQUAL(IN, return_enum());
}
:unity_helper:
:header: |
void AssertEqualTHINGStruct(struct THING expected, struct THING actual);
void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual);
#define TEST_ASSERT_EQUAL_THING(expected, actual) {AssertEqualTHINGStruct(expected, actual);}
#define TEST_ASSERT_EQUAL_STARS_AND_STRIPES(expected, actual) {AssertEqualSTARS_AND_STRIPESUnion(expected, actual);}
:code: |
void AssertEqualTHINGStruct(struct THING expected, struct THING actual)
{
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual struct member \"a\" does not equal expected");
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.b, actual.b, "actual struct member \"b\" does not equal expected");
}
void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual)
{
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual union member \"a\" does not equal expected");
TEST_ASSERT_EQUAL_MESSAGE(expected.b, actual.b, "actual union member \"b\" does not equal expected");
}
...

View File

@ -0,0 +1,280 @@
---
:cmock:
:plugins:
- :array
- :ignore
- :callback
- :return_thru_ptr
:systest:
:types: |
struct THING { int a; int b; };
union STARS_AND_STRIPES { int a; char b; };
enum HOKEY_POKEY { IN, OUT, SHAKE_IT_ALL_ABOUT };
:mockable: |
void foo_struct(struct THING*, struct THING);
struct THING foobar_struct(void);
void foo_union(union STARS_AND_STRIPES*, union STARS_AND_STRIPES);
union STARS_AND_STRIPES foobar_union(void);
void foo_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
enum HOKEY_POKEY foobar_enum(void);
:source:
:header: |
void exercise_struct(struct THING* a, struct THING b);
struct THING return_struct(void);
void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b);
union STARS_AND_STRIPES return_union(void);
void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
enum HOKEY_POKEY return_enum(void);
:code: |
void exercise_struct(struct THING* a, struct THING b)
{
foo_struct(a, b);
}
struct THING return_struct(void)
{
return foobar_struct();
}
void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b)
{
foo_union(a, b);
}
union STARS_AND_STRIPES return_union(void)
{
return foobar_union();
}
void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b)
{
foo_enum(a, b);
}
enum HOKEY_POKEY return_enum(void)
{
return foobar_enum();
}
:tests:
:common: |
struct THING struct1;
struct THING struct2;
struct THING struct3;
struct THING struct4;
struct THING struct5;
struct THING struct6;
union STARS_AND_STRIPES union1;
union STARS_AND_STRIPES union2;
union STARS_AND_STRIPES union3;
union STARS_AND_STRIPES union4;
union STARS_AND_STRIPES union5;
union STARS_AND_STRIPES union6;
enum HOKEY_POKEY enum1;
enum HOKEY_POKEY enum2;
void setUp(void)
{
struct1.a = 1;
struct1.b = 2;
struct2.a = 3;
struct2.b = 4;
struct3.a = 5;
struct3.b = 6;
struct4.a = 7;
struct4.b = 8;
struct5.a = 9;
struct5.b = 10;
struct6.a = 9;
struct6.b = 10;
union1.a = 1;
union2.a = 2;
union3.a = 3;
union4.a = 4;
union5.a = 5;
union6.a = 5;
enum1 = OUT;
enum2 = IN;
}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully compare structs'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct1, struct2);
}
- :pass: FALSE
:should: 'blow up on bad struct pointer comparison'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct3, struct2);
}
- :pass: FALSE
:should: 'blow up on bad structure comparison'
:code: |
test()
{
foo_struct_Expect(&struct1, struct2);
exercise_struct(&struct1, struct4);
}
- :pass: TRUE
:should: 'compare returned structs as equal'
:code: |
test()
{
foobar_struct_ExpectAndReturn(struct5);
TEST_ASSERT_EQUAL_THING(struct6, return_struct());
}
- :pass: FALSE
:should: 'compare returned structs as unequal'
:code: |
test()
{
foobar_struct_ExpectAndReturn(struct4);
TEST_ASSERT_EQUAL_THING(struct5, return_struct());
}
- :pass: TRUE
:should: 'successfully compare unions'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union1, union2);
}
- :pass: FALSE
:should: 'blow up on bad union pointer comparison'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union3, union2);
}
- :pass: FALSE
:should: 'blow up on bad union comparison'
:code: |
test()
{
foo_union_Expect(&union1, union2);
exercise_union(&union1, union4);
}
- :pass: TRUE
:should: 'compare returned unions as equal'
:code: |
test()
{
foobar_union_ExpectAndReturn(union5);
TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union6, return_union());
}
- :pass: FALSE
:should: 'compare returned unions as unequal'
:code: |
test()
{
foobar_union_ExpectAndReturn(union4);
TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union5, return_union());
}
- :pass: TRUE
:should: 'successfully pass enum values'
:code: |
test()
{
foo_enum_Expect(OUT, &enum1);
exercise_enum(OUT, &enum1);
}
- :pass: FALSE
:should: 'blow up on bad enum pointer comparison'
:code: |
test()
{
foo_enum_Expect(IN, &enum1);
exercise_enum(IN, &enum2);
}
- :pass: FALSE
:should: 'blow up on bad enum comparison'
:code: |
test()
{
foo_enum_Expect(IN, &enum1);
exercise_enum(SHAKE_IT_ALL_ABOUT, &enum1);
}
- :pass: TRUE
:should: 'compare returned enums as equal'
:code: |
test()
{
foobar_enum_ExpectAndReturn(OUT);
TEST_ASSERT_EQUAL(OUT, return_enum());
}
- :pass: FALSE
:should: 'compare returned unions as unequal'
:code: |
test()
{
foobar_enum_ExpectAndReturn(OUT);
TEST_ASSERT_EQUAL(IN, return_enum());
}
:unity_helper:
:header: |
void AssertEqualTHINGStruct(struct THING expected, struct THING actual);
void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual);
#define TEST_ASSERT_EQUAL_THING(expected, actual) {AssertEqualTHINGStruct(expected, actual);}
#define TEST_ASSERT_EQUAL_STARS_AND_STRIPES(expected, actual) {AssertEqualSTARS_AND_STRIPESUnion(expected, actual);}
:code: |
void AssertEqualTHINGStruct(struct THING expected, struct THING actual)
{
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual struct member \"a\" does not equal expected");
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.b, actual.b, "actual struct member \"b\" does not equal expected");
}
void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual)
{
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual union member \"a\" does not equal expected");
TEST_ASSERT_EQUAL_MESSAGE(expected.b, actual.b, "actual union member \"b\" does not equal expected");
}
...

View File

@ -0,0 +1,221 @@
---
:cmock:
:plugins:
- :callback
:treat_as:
custom_type: INT
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
UINT32 foo(custom_type* a);
UINT32 bar(custom_type* b);
int baz(void);
void fuz(int* args, int num);
: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)
{
int args[6] = {0, 1, 2, 3, 5, 5};
args[0] = a;
fuz(args, b);
}
UINT32 function_b(void)
{
UINT32 sum = 0;
custom_type a = 0;
custom_type b = 0;
sum = foo(&a) + bar(&b);
return (UINT32)((custom_type)sum + a + b);
}
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 (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;
TEST_ASSERT_MESSAGE(num_args < 5, "No More Than 5 Args Allowed");
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'
:code: |
test()
{
custom_type exp = 0;
foo_ExpectAndReturn(&exp, 10);
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: |
test()
{
custom_type exp = 1;
foo_ExpectAndReturn(&exp, 10);
bar_ExpectAndReturn(&exp, 20);
TEST_ASSERT_EQUAL(30, function_b());
}
- :pass: TRUE
:should: 'successfully exercise using some basic callbacks'
:code: |
test()
{
foo_StubWithCallback((CMOCK_foo_CALLBACK)FooAndBarHelper);
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: |
test()
{
custom_type exp = 500;
foo_ExpectAndReturn(&exp, 10);
foo_StubWithCallback((CMOCK_foo_CALLBACK)FooAndBarHelper);
bar_StubWithCallback((CMOCK_bar_CALLBACK)FooAndBarHelper);
TEST_ASSERT_EQUAL(12, function_b());
}
- :pass: FALSE
:should: 'successfully exercise using some basic callbacks and notice failures'
:code: |
test()
{
foo_StubWithCallback((CMOCK_foo_CALLBACK)FooAndBarHelper);
bar_StubWithCallback((CMOCK_bar_CALLBACK)FooAndBarHelper);
TEST_ASSERT_EQUAL(10, function_b());
}
- :pass: TRUE
:should: 'successfully exercise a callback with no arguments'
:code: |
test()
{
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackPointless);
TEST_ASSERT_EQUAL(3, function_c());
}
- :pass: FALSE
:should: 'successfully throw a failure from within a callback function'
:code: |
test()
{
baz_StubWithCallback((CMOCK_baz_CALLBACK)BazCallbackComplainsIfCalledMoreThanTwice);
function_c();
}
- :pass: TRUE
:should: 'be usable for things like dynamically sized memory checking for passing conditions'
:code: |
test()
{
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: |
test()
{
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: |
test()
{
fuz_StubWithCallback((CMOCK_fuz_CALLBACK)FuzVerifier);
function_a(1, 4);
}
- :pass: TRUE
:should: 'run them interlaced'
:code: |
test()
{
custom_type exp = 0;
foo_ExpectAndReturn(&exp, 10);
foo_ExpectAndReturn(&exp, 15);
bar_ExpectAndReturn(&exp, 20);
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: |
test()
{
custom_type exp = 0;
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());
}
...

View File

@ -0,0 +1,77 @@
---
#The purpose of this test is to play with things 64-bit integers, which aren't supported by all compilers
:cmock:
:plugins:
- :array
- :ignore
:systest:
:types: |
#include "unity_internals.h"
typedef UNITY_UINT64 TEST64;
:mockable: |
TEST64 foo(TEST64 a);
TEST64* bar(TEST64* b);
:source:
:header: |
TEST64 function_a(void);
:code: |
TEST64 function_a(void) {
TEST64 a = 0x1234567890123456;
TEST64 b;
TEST64* c;
b = foo(a);
c = bar(&b);
return *c;
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle a straightforward 64-bit series of calls'
:code: |
test()
{
TEST64 a = 0x0987654321543210;
TEST64 b = 0x5a5a5a5a5a5a5a5a;
foo_ExpectAndReturn(0x1234567890123456, 0x0987654321543210);
bar_ExpectAndReturn(&a, &b);
TEST_ASSERT_EQUAL_HEX64(b, function_a());
}
- :pass: FALSE
:should: 'handle a straightforward 64-bit series of calls with a failure'
:code: |
test()
{
TEST64 a = 0x0987654321543210;
TEST64 b = 0x5a5a5a5a5a5a5a5a;
foo_ExpectAndReturn(0x1234567890123456, 0x0987654321543211);
bar_ExpectAndReturn(&a, &b);
TEST_ASSERT_EQUAL_HEX64(b, function_a());
}
- :pass: FALSE
:should: 'handle a straightforward 64-bit series of calls returning a failure'
:code: |
test()
{
TEST64 a = 0x0987654321543210;
TEST64 b = 0x5a5a5a5a5a5a5a5a;
foo_ExpectAndReturn(0x1234567890123456, 0x0987654321543210);
bar_ExpectAndReturn(&a, &b);
TEST_ASSERT_EQUAL_HEX64(b+1, function_a());
}
...

View File

@ -0,0 +1,139 @@
---
:cmock:
:plugins:
- # none
:systest:
:types: |
#define UINT32 unsigned int
:mockable: |
UINT32 foo(UINT32 a);
void bar(void);
:source:
:header: |
UINT32 function_a(int a);
void function_b(void);
:code: |
UINT32 function_a(int a)
{
bar();
return foo((UINT32)a);
}
void function_b(void)
{
bar();
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: :ignore
:should: 'ignore incorrect expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: :ignore
:should: 'ignore missing expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(20, function_a(10));
}
- :pass: :ignore
:should: 'ignore extra expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
bar_Expect();
bar_Expect();
foo_ExpectAndReturn(10, 20);
foo_ExpectAndReturn(10, 20);
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(20, function_a(10));
}
- :pass: :ignore
:should: 'ignore no expects after the TEST_IGNORE call'
:code: |
test()
{
TEST_IGNORE();
TEST_ASSERT_EQUAL(20, function_a(10));
}
- :pass: :ignore
:should: 'ignore extra expects after the TEST_IGNORE call even if it happens later'
:code: |
test()
{
bar_Expect();
foo_ExpectAndReturn(10, 20);
function_a(10);
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: false
:should: 'still fail if there are expect problems before the TEST_IGNORE'
:code: |
test()
{
bar_Expect();
foo_ExpectAndReturn(10, 20);
function_a(30);
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: false
:should: 'still fail if there are missing expect problems before the TEST_IGNORE'
:code: |
test()
{
bar_Expect();
function_a(10);
TEST_IGNORE();
bar_Expect();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
- :pass: :ignore
:should: 'ignore if extra expects before the TEST_IGNORE because it ignored the rest of the test that might have made calls to it'
:code: |
test()
{
bar_Expect();
bar_Expect();
foo_ExpectAndReturn(10, 20);
function_a(10);
TEST_IGNORE();
foo_ExpectAndReturn(10, 20);
TEST_ASSERT_EQUAL(40, function_a(30));
}
...

View File

@ -0,0 +1,91 @@
---
#The purpose of this test is to verify we handle void pointers as memory compares
:cmock:
:plugins:
- :array
:treat_as_array:
VOID_PTR: unsigned char
:systest:
:types: |
#include "unity_internals.h"
typedef void* VOID_PTR;
:mockable: |
void* ret_v_ptr(void);
void get_v_ptr(void* ptr);
void get_v_ptr_typedefed(VOID_PTR ptr);
:source:
:header: |
void function_a(void);
:code: |
void function_a(void) {
void* stuff = ret_v_ptr();
get_v_ptr(stuff);
get_v_ptr_typedefed((VOID_PTR)stuff);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'handle passing working expects'
:code: |
test()
{
char* a = "Hello";
char* b = "Hello";
ret_v_ptr_ExpectAndReturn(a);
get_v_ptr_Expect(b);
get_v_ptr_typedefed_Expect((VOID_PTR)b);
function_a();
}
- :pass: TRUE
:should: 'handle passing array expects'
:code: |
test()
{
char* a = "Hello";
char* b = "Hello";
ret_v_ptr_ExpectAndReturn(a);
get_v_ptr_ExpectWithArray(b,5);
get_v_ptr_typedefed_ExpectWithArray((VOID_PTR)b,5);
function_a();
}
- :pass: FALSE
:should: 'handle failing expects'
:code: |
test()
{
char* a = "Hello";
char* b = "Jello";
ret_v_ptr_ExpectAndReturn(a);
get_v_ptr_Expect(b);
get_v_ptr_typedefed_Expect((VOID_PTR)b);
function_a();
}
- :pass: FALSE
:should: 'handle failing array expects'
:code: |
test()
{
char* a = "Hello";
char* b = "Hella";
ret_v_ptr_ExpectAndReturn(a);
get_v_ptr_ExpectWithArray(b,5);
get_v_ptr_typedefed_ExpectWithArray((VOID_PTR)b,5);
function_a();
}
...