mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-12 14:17:53 +00:00
flesh out tests for arrays and pointers and separate.
This commit is contained in:
@@ -86,7 +86,8 @@ class CMockGeneratorUtils
|
||||
|
||||
def code_assign_argument_quickly(dest, arg)
|
||||
if arg[:ptr?] || @treat_as.include?(arg[:type])
|
||||
" #{dest} = #{arg[:name]};\n"
|
||||
cast = arg[:array_dims] ? "(#{arg[:type]})" : ''
|
||||
" #{dest} = #{cast}#{arg[:name]};\n"
|
||||
else
|
||||
assert_expr = "sizeof(#{arg[:name]}) == sizeof(#{arg[:type]}) ? 1 : -1"
|
||||
comment = "/* add #{arg[:type]} to :treat_as_array if this causes an error */"
|
||||
|
||||
@@ -561,7 +561,6 @@ module RakefileHelpers
|
||||
total_tests = 0
|
||||
total_failures = 0
|
||||
total_ignored = 0
|
||||
puts "DEBUG DIS #{$cmock_test_config_file}"
|
||||
cfg_file = "#{($cmock_test_config_file =~ /[\\\/]/) ? '../' : ''}#{$cmock_test_config_file}"
|
||||
|
||||
# Determine which examples are valid for this platform
|
||||
|
||||
@@ -0,0 +1,519 @@
|
||||
# =========================================================================
|
||||
# CMock - Automatic Mock Generation for C
|
||||
# ThrowTheSwitch.org
|
||||
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
|
||||
# SPDX-License-Identifier: MIT
|
||||
# =========================================================================
|
||||
|
||||
---
|
||||
:cmock:
|
||||
:when_ptr: :smart
|
||||
:array_size_name: 'size|len|count'
|
||||
:plugins:
|
||||
- :array
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
} POINT_T;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
int value;
|
||||
} SENSOR_T;
|
||||
|
||||
typedef enum {
|
||||
STATUS_OK = 0,
|
||||
STATUS_ERROR = 1,
|
||||
STATUS_PENDING = 2
|
||||
} STATUS_E;
|
||||
|
||||
typedef union {
|
||||
int raw;
|
||||
unsigned char bytes[4];
|
||||
} SAMPLE_U;
|
||||
|
||||
#define ARRAY_A_SIZE (5)
|
||||
|
||||
:mockable: |
|
||||
POINT_T* bar(void);
|
||||
void fooa(POINT_T a[ARRAY_A_SIZE]);
|
||||
void no_pointers(int a, const char* b);
|
||||
int mixed(int a, int* b, int c);
|
||||
void process_sensors(SENSOR_T sensors[], int count);
|
||||
void process_statuses(STATUS_E statuses[], int count);
|
||||
void process_samples(SAMPLE_U samples[], int count);
|
||||
void fill_matrix(int matrix[13][4]);
|
||||
void transform_grid(int grid[][4], int rows);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
void function_a(void);
|
||||
int function_b(void);
|
||||
void function_c(void);
|
||||
void function_d(void);
|
||||
void function_e(void);
|
||||
void function_f(void);
|
||||
void function_g(void);
|
||||
|
||||
:code: |
|
||||
void function_a(void)
|
||||
{
|
||||
fooa(bar());
|
||||
}
|
||||
|
||||
int function_b(void)
|
||||
{
|
||||
int test_list[] = {1, 2, 3, 4, 5};
|
||||
no_pointers(1, "silly");
|
||||
return mixed(6, test_list, 7);
|
||||
}
|
||||
|
||||
void function_c(void)
|
||||
{
|
||||
SENSOR_T sensors[] = {{1, 100}, {2, 200}, {3, 300}};
|
||||
process_sensors(sensors, 3);
|
||||
}
|
||||
|
||||
void function_d(void)
|
||||
{
|
||||
STATUS_E statuses[] = {STATUS_OK, STATUS_ERROR, STATUS_PENDING};
|
||||
process_statuses(statuses, 3);
|
||||
}
|
||||
|
||||
void function_e(void)
|
||||
{
|
||||
SAMPLE_U samples[3];
|
||||
samples[0].raw = 111;
|
||||
samples[1].raw = 222;
|
||||
samples[2].raw = 333;
|
||||
process_samples(samples, 3);
|
||||
}
|
||||
|
||||
void function_f(void)
|
||||
{
|
||||
int matrix[13][4];
|
||||
int i, j;
|
||||
for (i = 0; i < 13; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
matrix[i][j] = i * 4 + j;
|
||||
fill_matrix(matrix);
|
||||
}
|
||||
|
||||
void function_g(void)
|
||||
{
|
||||
int grid[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};
|
||||
transform_grid(grid, 3);
|
||||
}
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
:units:
|
||||
- :pass: TRUE
|
||||
:should: 'handle passing null to an array parameter'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
bar_ExpectAndReturn(NULL);
|
||||
fooa_Expect(NULL);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare a single struct array element and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {4, 8};
|
||||
POINT_T ex = {4, 8};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
fooa_Expect(&ex);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in single struct array element'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {4, 8};
|
||||
POINT_T ex = {4, 9};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
fooa_Expect(&ex);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect when null array is passed but non-null was expected'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {4, 8};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
fooa_Expect(NULL);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare multiple struct array elements via ExpectWithArray and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
|
||||
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 6}};
|
||||
bar_ExpectAndReturn(pt);
|
||||
fooa_ExpectWithArray(ex, 3);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in first struct array element via ExpectWithArray'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
|
||||
POINT_T ex[] = {{9, 2}, {3, 4}, {5, 6}};
|
||||
bar_ExpectAndReturn(pt);
|
||||
fooa_ExpectWithArray(ex, 3);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in middle struct array element via ExpectWithArray'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
|
||||
POINT_T ex[] = {{1, 2}, {3, 9}, {5, 6}};
|
||||
bar_ExpectAndReturn(pt);
|
||||
fooa_ExpectWithArray(ex, 3);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in last struct array element via ExpectWithArray'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}};
|
||||
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}};
|
||||
bar_ExpectAndReturn(pt);
|
||||
fooa_ExpectWithArray(ex, 3);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle creating int array expects for mixed-argument function and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expect_list[] = {1, 9};
|
||||
no_pointers_Expect(1, "silly");
|
||||
mixed_ExpectAndReturn(6, expect_list, 7, 13);
|
||||
|
||||
TEST_ASSERT_EQUAL(13, function_b());
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in int array for mixed-argument function'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expect_list[] = {9, 1};
|
||||
no_pointers_Expect(1, "silly");
|
||||
mixed_ExpectAndReturn(6, expect_list, 7, 13);
|
||||
|
||||
TEST_ASSERT_EQUAL(13, function_b());
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare multiple int array elements for mixed-argument function and pass'
|
||||
: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_b());
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch when checking too many int array elements'
|
||||
: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_b());
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare an array of sensors (struct) and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
SENSOR_T expected[] = {{1, 100}, {2, 200}, {3, 300}};
|
||||
process_sensors_Expect(expected, 3);
|
||||
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in sensor id field'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
SENSOR_T expected[] = {{9, 100}, {2, 200}, {3, 300}};
|
||||
process_sensors_Expect(expected, 3);
|
||||
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in sensor value field'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
SENSOR_T expected[] = {{1, 100}, {2, 999}, {3, 300}};
|
||||
process_sensors_Expect(expected, 3);
|
||||
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare a subset of sensor elements via ExpectWithArray and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
SENSOR_T expected[] = {{1, 100}, {2, 200}};
|
||||
process_sensors_ExpectWithArray(expected, 2, 3);
|
||||
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch when comparing sensor subset via ExpectWithArray'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
SENSOR_T expected[] = {{1, 100}, {2, 999}};
|
||||
process_sensors_ExpectWithArray(expected, 2, 3);
|
||||
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare an array of statuses (enum) and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
STATUS_E expected[] = {STATUS_OK, STATUS_ERROR, STATUS_PENDING};
|
||||
process_statuses_Expect(expected, 3);
|
||||
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in first status enum element'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
STATUS_E expected[] = {STATUS_ERROR, STATUS_ERROR, STATUS_PENDING};
|
||||
process_statuses_Expect(expected, 3);
|
||||
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in last status enum element'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
STATUS_E expected[] = {STATUS_OK, STATUS_ERROR, STATUS_OK};
|
||||
process_statuses_Expect(expected, 3);
|
||||
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare a subset of status elements via ExpectWithArray and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
STATUS_E expected[] = {STATUS_OK, STATUS_ERROR};
|
||||
process_statuses_ExpectWithArray(expected, 2, 3);
|
||||
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in status subset via ExpectWithArray'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
STATUS_E expected[] = {STATUS_OK, STATUS_PENDING};
|
||||
process_statuses_ExpectWithArray(expected, 2, 3);
|
||||
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare an array of samples (union) and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
SAMPLE_U expected[3];
|
||||
expected[0].raw = 111;
|
||||
expected[1].raw = 222;
|
||||
expected[2].raw = 333;
|
||||
process_samples_Expect(expected, 3);
|
||||
|
||||
function_e();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in first sample union element'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
SAMPLE_U expected[3];
|
||||
expected[0].raw = 999;
|
||||
expected[1].raw = 222;
|
||||
expected[2].raw = 333;
|
||||
process_samples_Expect(expected, 3);
|
||||
|
||||
function_e();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in last sample union element'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
SAMPLE_U expected[3];
|
||||
expected[0].raw = 111;
|
||||
expected[1].raw = 222;
|
||||
expected[2].raw = 999;
|
||||
process_samples_Expect(expected, 3);
|
||||
|
||||
function_e();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare a subset of sample elements via ExpectWithArray and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
SAMPLE_U expected[3];
|
||||
expected[0].raw = 111;
|
||||
expected[1].raw = 222;
|
||||
process_samples_ExpectWithArray(expected, 2, 3);
|
||||
|
||||
function_e();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in sample subset via ExpectWithArray'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
SAMPLE_U expected[3];
|
||||
expected[0].raw = 111;
|
||||
expected[1].raw = 999;
|
||||
process_samples_ExpectWithArray(expected, 2, 3);
|
||||
|
||||
function_e();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare a fully-specified 2D matrix [13][4] and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expected[13][4];
|
||||
int i, j;
|
||||
for (i = 0; i < 13; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
expected[i][j] = i * 4 + j;
|
||||
fill_matrix_ExpectWithArray(expected, 13*4);
|
||||
|
||||
function_f();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in a fully-specified 2D matrix [13][4]'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expected[13][4];
|
||||
int i, j;
|
||||
for (i = 0; i < 13; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
expected[i][j] = i * 4 + j;
|
||||
expected[6][2] = 999;
|
||||
fill_matrix_ExpectWithArray(expected, 13*4);
|
||||
|
||||
function_f();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare only the first row of a fully-specified 2D matrix [13][4]'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expected[13][4] = {{0,1,2,3}};
|
||||
fill_matrix_ExpectWithArray(expected, 4);
|
||||
|
||||
function_f();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare a partially-specified 2D grid [][4] and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expected[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};
|
||||
transform_grid_ExpectWithArray(expected, 3*4, 3);
|
||||
|
||||
function_g();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in a partially-specified 2D grid [][4]'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expected[3][4] = {{1,2,3,4},{5,6,7,99},{9,10,11,12}};
|
||||
transform_grid_ExpectWithArray(expected, 3*4, 3);
|
||||
|
||||
function_g();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare only the first two rows of a partially-specified 2D grid [][4]'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expected[3][4] = {{1,2,3,4},{5,6,7,8}};
|
||||
transform_grid_ExpectWithArray(expected, 2*4, 3);
|
||||
|
||||
function_g();
|
||||
}
|
||||
|
||||
...
|
||||
+191
-179
@@ -13,21 +13,32 @@
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
typedef struct _POINT_T {
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
} POINT_T;
|
||||
#define ARRAY_A_SIZE (5)
|
||||
|
||||
typedef enum {
|
||||
RED = 0,
|
||||
GREEN = 1,
|
||||
BLUE = 2
|
||||
} COLOR_E;
|
||||
|
||||
typedef union {
|
||||
int as_int;
|
||||
unsigned short as_shorts[2];
|
||||
} RESULT_U;
|
||||
|
||||
: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 foos(const char* a);
|
||||
const char* bars(void);
|
||||
void poke_color(COLOR_E* c);
|
||||
COLOR_E* peek_color(void);
|
||||
void poke_result(RESULT_U* r);
|
||||
RESULT_U* peek_result(void);
|
||||
void potential_packing_problem(short* a);
|
||||
void voidpointerfunc(void* a);
|
||||
|
||||
:source:
|
||||
@@ -35,7 +46,7 @@
|
||||
void function_a(void);
|
||||
void function_b(void);
|
||||
void function_c(void);
|
||||
int function_d(void);
|
||||
void function_d(void);
|
||||
void function_e(void);
|
||||
void function_f(void);
|
||||
|
||||
@@ -45,26 +56,29 @@
|
||||
foo(bar());
|
||||
}
|
||||
|
||||
void function_b(void) {
|
||||
fooa(bar());
|
||||
}
|
||||
|
||||
void function_c(void) {
|
||||
void function_b(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_c(void)
|
||||
{
|
||||
poke_color(peek_color());
|
||||
}
|
||||
|
||||
void function_e(void) {
|
||||
void function_d(void)
|
||||
{
|
||||
poke_result(peek_result());
|
||||
}
|
||||
|
||||
void function_e(void)
|
||||
{
|
||||
short test_list[] = {-1, -2, -3, -4};
|
||||
potential_packing_problem(&test_list[1]);
|
||||
}
|
||||
|
||||
void function_f(void) {
|
||||
void function_f(void)
|
||||
{
|
||||
char arg[6] = "hello";
|
||||
voidpointerfunc(arg);
|
||||
}
|
||||
@@ -76,7 +90,7 @@
|
||||
|
||||
:units:
|
||||
- :pass: TRUE
|
||||
:should: 'handle the situation where we pass nulls to pointers'
|
||||
:should: 'handle null struct pointers in both directions'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -87,7 +101,7 @@
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle the situation where we expected nulls to pointers but did not get that'
|
||||
:should: 'detect mismatch when expecting null struct pointer but receiving non-null'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -99,7 +113,7 @@
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle the situation where we did not expect nulls to pointers but got null'
|
||||
:should: 'detect mismatch when expecting non-null struct pointer but receiving null'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -111,7 +125,33 @@
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle the situation where it falls back to pointers because you asked it to compare 0 elements'
|
||||
:should: 'compare struct pointer contents and pass when contents match'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {3, 7};
|
||||
POINT_T ex = {3, 7};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
foo_Expect(&ex);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'compare struct pointer contents and fail when contents differ'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {3, 7};
|
||||
POINT_T ex = {3, 9};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
foo_Expect(&ex);
|
||||
|
||||
function_a();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'fall back to pointer comparison when depth is zero and pointers match'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -123,7 +163,7 @@
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle the situation where it fails because you asked it to compare zero elements and the pointers do not match'
|
||||
:should: 'fail pointer comparison when depth is zero and pointers differ'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -136,59 +176,7 @@
|
||||
}
|
||||
|
||||
- :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'
|
||||
:should: 'compare multiple struct elements via ExpectWithArray and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -201,7 +189,7 @@
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at start'
|
||||
:should: 'detect mismatch in first element of struct array comparison'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -214,20 +202,7 @@
|
||||
}
|
||||
|
||||
- :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'
|
||||
:should: 'detect mismatch in middle element of struct array comparison'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -240,68 +215,20 @@
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle the situation where we pass nulls to pointers and fail'
|
||||
:should: 'detect mismatch in last element of struct array comparison'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
POINT_T pt = {1, 2};
|
||||
bar_ExpectAndReturn(&pt);
|
||||
foo_Expect(NULL);
|
||||
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 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'
|
||||
:should: 'handle string pointer matching on null-terminated content'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -309,11 +236,11 @@
|
||||
bars_ExpectAndReturn((char*)retval);
|
||||
foos_Expect("This is a\0 wacky string");
|
||||
|
||||
function_c();
|
||||
function_b();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures'
|
||||
:should: 'detect string pointer mismatch on content'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -321,81 +248,167 @@
|
||||
bars_ExpectAndReturn((char*)retval);
|
||||
foos_Expect("This is a wacky string");
|
||||
|
||||
function_b();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle null enum pointers in both directions'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
peek_color_ExpectAndReturn(NULL);
|
||||
poke_color_Expect(NULL);
|
||||
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle creating array expects when we have mixed arguments for single object'
|
||||
:should: 'compare enum pointer contents and pass when contents match'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expect_list[] = { 1, 9 };
|
||||
no_pointers_Expect(1, "silly");
|
||||
mixed_ExpectAndReturn(6, expect_list, 7, 13);
|
||||
COLOR_E actual = GREEN;
|
||||
COLOR_E expected = GREEN;
|
||||
peek_color_ExpectAndReturn(&actual);
|
||||
poke_color_Expect(&expected);
|
||||
|
||||
TEST_ASSERT_EQUAL(13, function_d());
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle creating array expects when we have mixed arguments and handle failures for single object'
|
||||
:should: 'detect mismatch in enum pointer contents'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expect_list[] = { 9, 1 };
|
||||
no_pointers_Expect(1, "silly");
|
||||
mixed_ExpectAndReturn(6, expect_list, 7, 13);
|
||||
COLOR_E actual = GREEN;
|
||||
COLOR_E expected = BLUE;
|
||||
peek_color_ExpectAndReturn(&actual);
|
||||
poke_color_Expect(&expected);
|
||||
|
||||
TEST_ASSERT_EQUAL(13, function_d());
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle creating array expects when we have mixed arguments for multiple objects'
|
||||
:should: 'compare multiple enum elements via ExpectWithArray and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expect_list[] = { 1, 2, 3, 4, 6 };
|
||||
no_pointers_Expect(1, "silly");
|
||||
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13);
|
||||
COLOR_E actual[] = {RED, GREEN, BLUE};
|
||||
COLOR_E expected[] = {RED, GREEN, BLUE};
|
||||
peek_color_ExpectAndReturn(actual);
|
||||
poke_color_ExpectWithArray(expected, 3);
|
||||
|
||||
TEST_ASSERT_EQUAL(13, function_d());
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects'
|
||||
:should: 'detect mismatch when comparing multiple enum elements'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
int expect_list[] = { 1, 2, 3, 4, 6 };
|
||||
no_pointers_Expect(1, "silly");
|
||||
mixed_ExpectWithArrayAndReturn(6, expect_list, 5, 7, 13);
|
||||
COLOR_E actual[] = {RED, GREEN, BLUE};
|
||||
COLOR_E expected[] = {RED, BLUE, BLUE};
|
||||
peek_color_ExpectAndReturn(actual);
|
||||
poke_color_ExpectWithArray(expected, 3);
|
||||
|
||||
TEST_ASSERT_EQUAL(13, function_d());
|
||||
function_c();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle a passing version of a potential packing problem (particularly try with ARM simulators)'
|
||||
:should: 'handle null union pointers in both directions'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
short expect_list[] = { -2, -3, -4 };
|
||||
peek_result_ExpectAndReturn(NULL);
|
||||
poke_result_Expect(NULL);
|
||||
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare union pointer contents and pass when contents match'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
RESULT_U actual;
|
||||
RESULT_U expected;
|
||||
actual.as_int = 42;
|
||||
expected.as_int = 42;
|
||||
peek_result_ExpectAndReturn(&actual);
|
||||
poke_result_Expect(&expected);
|
||||
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch in union pointer contents'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
RESULT_U actual;
|
||||
RESULT_U expected;
|
||||
actual.as_int = 42;
|
||||
expected.as_int = 99;
|
||||
peek_result_ExpectAndReturn(&actual);
|
||||
poke_result_Expect(&expected);
|
||||
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'compare multiple union elements via ExpectWithArray and pass'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
RESULT_U actual[3];
|
||||
RESULT_U expected[3];
|
||||
actual[0].as_int = 1; actual[1].as_int = 2; actual[2].as_int = 3;
|
||||
expected[0].as_int = 1; expected[1].as_int = 2; expected[2].as_int = 3;
|
||||
peek_result_ExpectAndReturn(actual);
|
||||
poke_result_ExpectWithArray(expected, 3);
|
||||
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'detect mismatch when comparing multiple union elements'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
RESULT_U actual[3];
|
||||
RESULT_U expected[3];
|
||||
actual[0].as_int = 1; actual[1].as_int = 2; actual[2].as_int = 3;
|
||||
expected[0].as_int = 1; expected[1].as_int = 9; expected[2].as_int = 3;
|
||||
peek_result_ExpectAndReturn(actual);
|
||||
poke_result_ExpectWithArray(expected, 3);
|
||||
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle a passing packing problem comparison'
|
||||
: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)'
|
||||
:should: 'detect a failing packing problem comparison'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
short expect_list[] = { -2, -3, 4 };
|
||||
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'
|
||||
:should: 'handle void pointer with array comparison passing'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -406,7 +419,7 @@
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle a void pointers as arguments and still be able to use the array plugin (short)'
|
||||
:should: 'handle void pointer with partial array comparison passing'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -417,7 +430,7 @@
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle a void pointers as arguments and still be able to use the array plugin (fail)'
|
||||
:should: 'detect void pointer content mismatch with array comparison'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -428,7 +441,7 @@
|
||||
}
|
||||
|
||||
- :pass: TRUE
|
||||
:should: 'handle a void pointer with a standard expectation (pass)'
|
||||
:should: 'handle void pointer with standard expect passing'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -439,7 +452,7 @@
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'handle a void pointer with a standard expectation (fail)'
|
||||
:should: 'detect void pointer mismatch with standard expect'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
@@ -449,5 +462,4 @@
|
||||
function_f();
|
||||
}
|
||||
|
||||
|
||||
...
|
||||
Reference in New Issue
Block a user