24 #define vsnprintf _vsnprintf 27 #define array_length(x) (sizeof(x) / sizeof((x)[0])) 41 extern int add(
int a,
int b);
44 extern int divide(
int a,
int b);
46 const size_t number_of_operator_functions,
48 const char*
const operator_string);
50 int number_of_arguments,
char *arguments[],
51 const size_t number_of_operator_functions,
53 int *
const number_of_intermediate_values,
54 int **
const intermediate_values,
int *
const error_occurred);
68 va_start(args, format);
69 return_value =
vsnprintf(temporary_buffer,
sizeof(temporary_buffer),
81 va_start(args, format);
154 array_length(operator_functions), operator_functions, NULL));
177 array_length(operator_functions), operator_functions,
"test"));
204 int number_of_intermediate_values;
205 int *intermediate_values;
211 1, NULL,
array_length(operator_functions), operator_functions,
212 &number_of_intermediate_values, &intermediate_values,
219 const char *args[] = {
220 "1",
"+",
"2",
"*",
"4" 222 int number_of_intermediate_values;
223 int *intermediate_values;
229 array_length(args), (
char **) args, 1, NULL, &number_of_intermediate_values,
230 &intermediate_values, &error_occurred));
239 const char *args[] = {
240 "1",
"+",
"2",
"*",
"4" 242 int *intermediate_values;
248 array_length(args), (
char **) args, 1, operator_functions, NULL,
249 &intermediate_values, &error_occurred));
258 const char *args[] = {
259 "1",
"+",
"2",
"*",
"4" 261 int number_of_intermediate_values;
268 operator_functions, &number_of_intermediate_values, NULL,
274 int number_of_intermediate_values;
275 int *intermediate_values;
281 0, NULL, 0, NULL, &number_of_intermediate_values, &intermediate_values,
282 &error_occurred), 0);
292 const char *args[] = {
293 "test",
"+",
"2",
"*",
"4" 295 int number_of_intermediate_values;
296 int *intermediate_values;
302 "Unable to parse integer from argument test\n");
306 operator_functions, &number_of_intermediate_values,
307 &intermediate_values, &error_occurred), 0);
317 const char *args[] = {
318 "1",
"*",
"2",
"*",
"4" 320 int number_of_intermediate_values;
321 int *intermediate_values;
327 "Unknown operator *, argument 1\n");
331 operator_functions, &number_of_intermediate_values,
332 &intermediate_values, &error_occurred), 0);
342 const char *args[] = {
345 int number_of_intermediate_values;
346 int *intermediate_values;
352 "Binary operator + missing argument\n");
356 operator_functions, &number_of_intermediate_values,
357 &intermediate_values, &error_occurred), 0);
367 const char *args[] = {
370 int number_of_intermediate_values;
371 int *intermediate_values;
377 "Unable to parse integer test of argument 2\n");
381 operator_functions, &number_of_intermediate_values,
382 &intermediate_values, &error_occurred), 0);
393 const char *args[] = {
394 "1",
"+",
"3",
"*",
"10",
396 int number_of_intermediate_values;
397 int *intermediate_values = NULL;
415 operator_functions, &number_of_intermediate_values,
416 &intermediate_values, &error_occurred), 40);
428 const char *args[] = {
441 const char *args[] = {
442 "example",
"1",
"+",
"3",
"*",
"10",
#define assert_non_null(c)
#define cmocka_unit_test(f)
Initializes a CMUnitTest structure.
static void test_perform_operation_no_integer_after_operator(void **state)
static void test_find_operator_function_by_string_not_found(void **state)
static int binary_operator(int a, int b)
static void test_find_operator_function_by_string_null_string(void **state)
static void test_add(void **state)
static void test_perform_operation_unknown_operator(void **state)
static void test_example_main(void **state)
int example_main(int argc, char *argv[])
int int example_test_printf(const char *format,...) CMOCKA_PRINTF_ATTRIBUTE(1
static void test_perform_operation_null_args(void **state)
static void test_perform_operation_null_number_of_intermediate_values(void **state)
static void test_perform_operation_first_arg_not_integer(void **state)
#define expect_value(function, parameter, value)
#define CMOCKA_PRINTF_ATTRIBUTE(a, b)
static void test_perform_operation_no_arguments(void **state)
static void test_perform_operation(void **state)
static void test_find_operator_function_by_string_null_functions(void **state)
int example_test_fprintf(FILE *const file, const char *format,...) CMOCKA_PRINTF_ATTRIBUTE(2
static void test_multiply(void **state)
int(* BinaryOperator)(int a, int b)
int multiply(int a, int b)
int subtract(int a, int b)
static void test_divide_by_zero(void **state)
#define will_return(function, value)
static void test_divide(void **state)
#define cast_ptr_to_largest_integral_type(value)
static void test_perform_operation_null_intermediate_values(void **state)
static void test_find_operator_function_by_string_valid_null_functions(void **state)
#define check_expected(parameter)
static void test_subtract(void **state)
#define cmocka_run_group_tests(group_tests, group_setup, group_teardown)
static void test_perform_operation_missing_argument(void **state)
static void test_perform_operation_null_operator_functions(void **state)
int int static char temporary_buffer[256]
BinaryOperator find_operator_function_by_string(const size_t number_of_operator_functions, const OperatorFunction *const operator_functions, const char *const operator_string)
static void test_example_main_no_args(void **state)
int perform_operation(int number_of_arguments, char *arguments[], const size_t number_of_operator_functions, const OperatorFunction *const operator_functions, int *const number_of_intermediate_values, int **const intermediate_values, int *const error_occurred)
static void test_find_operator_function_by_string_found(void **state)
#define check_expected_ptr(parameter)
struct OperatorFunction OperatorFunction
#define expect_assert_failure(function_call)
#define expect_string(function, parameter, string)
#define assert_int_equal(a, b)