OpenVPN
Data Structures | Macros | Typedefs | Functions | Variables
calculator_test.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include "cmocka.h"
#include <stdio.h>
Include dependency graph for calculator_test.c:

Go to the source code of this file.

Data Structures

struct  OperatorFunction
 

Macros

#define vsnprintf   _vsnprintf
 
#define array_length(x)   (sizeof(x) / sizeof((x)[0]))
 

Typedefs

typedef int(* BinaryOperator) (int a, int b)
 
typedef struct OperatorFunction OperatorFunction
 

Functions

int add (int a, int b)
 
int subtract (int a, int b)
 
int multiply (int a, int b)
 
int divide (int a, int b)
 
BinaryOperator find_operator_function_by_string (const size_t number_of_operator_functions, const OperatorFunction *const operator_functions, const char *const operator_string)
 
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)
 
int example_main (int argc, char *argv[])
 
int example_test_fprintf (FILE *const file, const char *format,...) CMOCKA_PRINTF_ATTRIBUTE(2
 
int int example_test_printf (const char *format,...) CMOCKA_PRINTF_ATTRIBUTE(1
 
static int binary_operator (int a, int b)
 
static void test_add (void **state)
 
static void test_subtract (void **state)
 
static void test_multiply (void **state)
 
static void test_divide (void **state)
 
static void test_divide_by_zero (void **state)
 
static void test_find_operator_function_by_string_null_functions (void **state)
 
static void test_find_operator_function_by_string_null_string (void **state)
 
static void test_find_operator_function_by_string_valid_null_functions (void **state)
 
static void test_find_operator_function_by_string_not_found (void **state)
 
static void test_find_operator_function_by_string_found (void **state)
 
static void test_perform_operation_null_args (void **state)
 
static void test_perform_operation_null_operator_functions (void **state)
 
static void test_perform_operation_null_number_of_intermediate_values (void **state)
 
static void test_perform_operation_null_intermediate_values (void **state)
 
static void test_perform_operation_no_arguments (void **state)
 
static void test_perform_operation_first_arg_not_integer (void **state)
 
static void test_perform_operation_unknown_operator (void **state)
 
static void test_perform_operation_missing_argument (void **state)
 
static void test_perform_operation_no_integer_after_operator (void **state)
 
static void test_perform_operation (void **state)
 
static void test_example_main_no_args (void **state)
 
static void test_example_main (void **state)
 
int main (void)
 

Variables

int int static char temporary_buffer [256]
 

Macro Definition Documentation

◆ array_length

#define array_length (   x)    (sizeof(x) / sizeof((x)[0]))

◆ vsnprintf

#define vsnprintf   _vsnprintf

Typedef Documentation

◆ BinaryOperator

typedef int(* BinaryOperator) (int a, int b)

Definition at line 34 of file calculator_test.c.

◆ OperatorFunction

Function Documentation

◆ add()

int add ( int  a,
int  b 
)

◆ binary_operator()

static int binary_operator ( int  a,
int  b 
)
static

◆ divide()

int divide ( int  a,
int  b 
)

Referenced by test_divide(), and test_divide_by_zero().

◆ example_main()

int example_main ( int  argc,
char *  argv[] 
)

◆ example_test_fprintf()

int example_test_fprintf ( FILE *const  file,
const char *  format,
  ... 
)

◆ example_test_printf()

int example_test_printf ( const char *  format,
  ... 
)

Definition at line 78 of file calculator_test.c.

References check_expected_ptr, temporary_buffer, and vsnprintf.

Referenced by test_example_main().

◆ find_operator_function_by_string()

BinaryOperator find_operator_function_by_string ( const size_t  number_of_operator_functions,
const OperatorFunction *const  operator_functions,
const char *const  operator_string 
)

◆ main()

int main ( void  )

◆ multiply()

int multiply ( int  a,
int  b 
)

Referenced by test_multiply().

◆ perform_operation()

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 
)

◆ subtract()

int subtract ( int  a,
int  b 
)

Referenced by test_subtract().

◆ test_add()

static void test_add ( void **  state)
static

Definition at line 98 of file calculator_test.c.

References add(), and assert_int_equal.

Referenced by main().

◆ test_divide()

static void test_divide ( void **  state)
static

Definition at line 122 of file calculator_test.c.

References assert_int_equal, and divide().

Referenced by main().

◆ test_divide_by_zero()

static void test_divide_by_zero ( void **  state)
static

Definition at line 130 of file calculator_test.c.

References divide(), and expect_assert_failure.

Referenced by main().

◆ test_example_main()

static void test_example_main ( void **  state)
static

◆ test_example_main_no_args()

static void test_example_main_no_args ( void **  state)
static

Definition at line 427 of file calculator_test.c.

References array_length, assert_int_equal, and example_main().

Referenced by main().

◆ test_find_operator_function_by_string_found()

static void test_find_operator_function_by_string_found ( void **  state)
static

◆ test_find_operator_function_by_string_not_found()

static void test_find_operator_function_by_string_not_found ( void **  state)
static

Definition at line 167 of file calculator_test.c.

References array_length, assert_null, binary_operator(), and find_operator_function_by_string().

Referenced by main().

◆ test_find_operator_function_by_string_null_functions()

static void test_find_operator_function_by_string_null_functions ( void **  state)
static

Definition at line 138 of file calculator_test.c.

References expect_assert_failure, and find_operator_function_by_string().

Referenced by main().

◆ test_find_operator_function_by_string_null_string()

static void test_find_operator_function_by_string_null_string ( void **  state)
static

◆ test_find_operator_function_by_string_valid_null_functions()

static void test_find_operator_function_by_string_valid_null_functions ( void **  state)
static

Definition at line 159 of file calculator_test.c.

References assert_null, and find_operator_function_by_string().

Referenced by main().

◆ test_multiply()

static void test_multiply ( void **  state)
static

Definition at line 114 of file calculator_test.c.

References assert_int_equal, and multiply().

Referenced by main().

◆ test_perform_operation()

static void test_perform_operation ( void **  state)
static

◆ test_perform_operation_first_arg_not_integer()

static void test_perform_operation_first_arg_not_integer ( void **  state)
static

◆ test_perform_operation_missing_argument()

static void test_perform_operation_missing_argument ( void **  state)
static

◆ test_perform_operation_no_arguments()

static void test_perform_operation_no_arguments ( void **  state)
static

Definition at line 273 of file calculator_test.c.

References assert_int_equal, and perform_operation().

Referenced by main().

◆ test_perform_operation_no_integer_after_operator()

static void test_perform_operation_no_integer_after_operator ( void **  state)
static

◆ test_perform_operation_null_args()

static void test_perform_operation_null_args ( void **  state)
static

Definition at line 200 of file calculator_test.c.

References array_length, binary_operator(), expect_assert_failure, and perform_operation().

Referenced by main().

◆ test_perform_operation_null_intermediate_values()

static void test_perform_operation_null_intermediate_values ( void **  state)
static

Definition at line 254 of file calculator_test.c.

References array_length, binary_operator(), expect_assert_failure, and perform_operation().

Referenced by main().

◆ test_perform_operation_null_number_of_intermediate_values()

static void test_perform_operation_null_number_of_intermediate_values ( void **  state)
static

Definition at line 235 of file calculator_test.c.

References array_length, binary_operator(), expect_assert_failure, and perform_operation().

Referenced by main().

◆ test_perform_operation_null_operator_functions()

static void test_perform_operation_null_operator_functions ( void **  state)
static

Definition at line 218 of file calculator_test.c.

References array_length, expect_assert_failure, and perform_operation().

Referenced by main().

◆ test_perform_operation_unknown_operator()

static void test_perform_operation_unknown_operator ( void **  state)
static

◆ test_subtract()

static void test_subtract ( void **  state)
static

Definition at line 106 of file calculator_test.c.

References assert_int_equal, and subtract().

Referenced by main().

Variable Documentation

◆ temporary_buffer

int int static char temporary_buffer[256]
static