OpenVPN
Macros
Assert Macros

This is a set of useful assert macros like the standard C libary's assert(3) macro. More...

Collaboration diagram for Assert Macros:

Macros

#define assert_true(c)
 
#define assert_false(c)
 
#define assert_return_code(rc, error)
 
#define assert_non_null(c)
 
#define assert_null(c)
 
#define assert_ptr_equal(a, b)
 
#define assert_ptr_not_equal(a, b)
 
#define assert_int_equal(a, b)
 
#define assert_int_not_equal(a, b)
 
#define assert_string_equal(a, b)
 
#define assert_string_not_equal(a, b)
 
#define assert_memory_equal(a, b, size)
 
#define assert_memory_not_equal(a, b, size)
 
#define assert_in_range(value, minimum, maximum)
 
#define assert_not_in_range(value, minimum, maximum)
 
#define assert_in_set(value, values, number_of_values)   _assert_in_set(value, values, number_of_values, __FILE__, __LINE__)
 
#define assert_not_in_set(value, values, number_of_values)   _assert_not_in_set(value, values, number_of_values, __FILE__, __LINE__)
 

Detailed Description

This is a set of useful assert macros like the standard C libary's assert(3) macro.

On an assertion failure a cmocka assert macro will write the failure to the standard error stream and signal a test failure. Due to limitations of the C language the general C standard library assert() and cmocka's assert_true() and assert_false() macros can only display the expression that caused the assert failure. cmocka's type specific assert macros, assert_{type}_equal() and assert_{type}_not_equal(), display the data that caused the assertion failure which increases data visibility aiding debugging of failing test cases.

Macro Definition Documentation

◆ assert_false

#define assert_false (   c)

◆ assert_in_range

#define assert_in_range (   value,
  minimum,
  maximum 
)
Value:
cast_to_largest_integral_type(maximum), __FILE__, __LINE__)
#define cast_to_largest_integral_type(value)
Definition: cmocka.h:96
void _assert_in_range(const LargestIntegralType value, const LargestIntegralType minimum, const LargestIntegralType maximum, const char *const file, const int line)

Definition at line 1297 of file cmocka.h.

Referenced by test_value_range().

◆ assert_in_set

#define assert_in_set (   value,
  values,
  number_of_values 
)    _assert_in_set(value, values, number_of_values, __FILE__, __LINE__)

Definition at line 1342 of file cmocka.h.

◆ assert_int_equal

#define assert_int_equal (   a,
 
)
Value:
__FILE__, __LINE__)
void _assert_int_equal(const LargestIntegralType a, const LargestIntegralType b, const char *const file, const int line)
#define cast_to_largest_integral_type(value)
Definition: cmocka.h:96

Definition at line 1174 of file cmocka.h.

Referenced by __attribute__(), argv_insert_head__empty_argv__head_only(), argv_insert_head__non_empty_argv__head_added(), argv_parse_cmd__command_and_extra_options__argc_correct(), argv_parse_cmd__command_string__argc_correct(), argv_printf__combined_path_with_spaces__argc_correct(), argv_printf__embedded_format_directive__replaced_in_output(), argv_printf__empty_parameter__argc_correct(), argv_printf__group_sep_in_arg__fail_no_ouput(), argv_printf__long_args__data_correct(), argv_printf__multiple_spaces_in_format__parsed_as_one(), argv_printf_cat__multiple_spaces_in_format__parsed_as_one(), argv_printf_cat__used_twice__argc_correct(), auth_token_basic_test(), auth_token_fail_invalid_key(), auth_token_test_empty_user(), auth_token_test_known_keys(), auth_token_test_session_mismatch(), auth_token_test_timeout(), crypto_pem_encode_decode_loopback(), group_setup_failing(), int_test_success(), mock_function_call_times(), prestate_setup_test(), prestate_test(), string_to_status_code_test(), test_add(), test_bad_dish(), test_buffer_list_aggregate_separator_all(), test_buffer_list_aggregate_separator_emptybuffers(), test_buffer_list_aggregate_separator_noop(), test_buffer_list_aggregate_separator_nosep(), test_buffer_list_aggregate_separator_two(), test_buffer_list_aggregate_separator_zerolen(), test_buffer_list_full(), test_connect_to_customer_database(), test_connect_to_product_database(), test_connect_to_product_database_bad_url(), test_connect_to_product_database_missing_parameter(), test_divide(), test_example_main(), test_example_main_no_args(), test_find_item_by_value(), test_find_operator_function_by_string_found(), test_get_customer_id_by_name(), test_multiply(), test_order_hotdog(), test_perform_operation(), test_perform_operation_first_arg_not_integer(), test_perform_operation_missing_argument(), test_perform_operation_no_arguments(), test_perform_operation_no_integer_after_operator(), test_perform_operation_unknown_operator(), test_subtract(), test_value_equal(), tls_crypt_loopback(), tls_crypt_loopback_max_len(), tls_crypt_loopback_zero_len(), torture_test_malloc(), and torture_test_realloc().

◆ assert_int_not_equal

#define assert_int_not_equal (   a,
 
)
Value:
__FILE__, __LINE__)
#define cast_to_largest_integral_type(value)
Definition: cmocka.h:96
void _assert_int_not_equal(const LargestIntegralType a, const LargestIntegralType b, const char *const file, const int line)

Definition at line 1195 of file cmocka.h.

Referenced by auth_token_test_session_mismatch().

◆ assert_memory_equal

#define assert_memory_equal (   a,
  b,
  size 
)
Value:
_assert_memory_equal((const void*)(a), (const void*)(b), size, __FILE__, \
__LINE__)
void _assert_memory_equal(const void *const a, const void *const b, const size_t size, const char *const file, const int line)

Definition at line 1254 of file cmocka.h.

Referenced by crypto_pem_encode_decode_loopback(), crypto_test_tls_prf(), tls_crypt_loopback(), tls_crypt_loopback_max_len(), and tls_crypt_loopback_zero_len().

◆ assert_memory_not_equal

#define assert_memory_not_equal (   a,
  b,
  size 
)
Value:
_assert_memory_not_equal((const void*)(a), (const void*)(b), size, \
__FILE__, __LINE__)
void _assert_memory_not_equal(const void *const a, const void *const b, const size_t size, const char *const file, const int line)

Definition at line 1276 of file cmocka.h.

◆ assert_non_null

#define assert_non_null (   c)
Value:
__FILE__, __LINE__)
#define cast_ptr_to_largest_integral_type(value)
Definition: cmocka.h:133
void _assert_true(const LargestIntegralType result, const char *const expression, const char *const file, const int line)

Definition at line 1102 of file cmocka.h.

Referenced by _expect_function_call(), _test_malloc(), add_symbol_value(), check_for_leftover_values(), check_in_range(), check_memory(), check_not_in_range(), check_not_memory(), display_allocated_blocks(), expect_memory_setup(), expect_set(), free_allocated_blocks(), free_symbol_map_value(), free_value(), get_symbol_value(), group_setup(), initialize_source_location(), int_test_ignored(), list_add(), list_add_value(), list_empty(), list_find(), list_first(), list_free(), list_remove(), list_remove_free(), malloc_setup_test(), malloc_teardown_test(), pattern_not_found__returns_original(), prestate_setup_test(), prestate_test(), remove_always_return_values(), remove_always_return_values_from_list(), replace_longer_text__multiple_times__match_all_matches_are_replaced(), replace_single_char__multiple_times__match_all_matches_are_replaced(), replace_single_char__one_time__match_is_replaced(), set_source_location(), setup(), source_location_is_set(), test_buffer_free_gc_two(), test_perform_operation(), tls_crypt_fail_msg_too_long(), tls_crypt_loopback_max_len(), torture_test_malloc(), torture_test_realloc(), torture_test_realloc_set0(), and value_in_set_display_error().

◆ assert_not_in_range

#define assert_not_in_range (   value,
  minimum,
  maximum 
)
Value:
cast_to_largest_integral_type(maximum), __FILE__, __LINE__)
#define cast_to_largest_integral_type(value)
Definition: cmocka.h:96
void _assert_not_in_range(const LargestIntegralType value, const LargestIntegralType minimum, const LargestIntegralType maximum, const char *const file, const int line)

Definition at line 1320 of file cmocka.h.

◆ assert_not_in_set

#define assert_not_in_set (   value,
  values,
  number_of_values 
)    _assert_not_in_set(value, values, number_of_values, __FILE__, __LINE__)

Definition at line 1361 of file cmocka.h.

◆ assert_null

#define assert_null (   c)
Value:
__FILE__, __LINE__)
#define cast_ptr_to_largest_integral_type(value)
Definition: cmocka.h:133
void _assert_true(const LargestIntegralType result, const char *const expression, const char *const file, const int line)

Definition at line 1119 of file cmocka.h.

Referenced by _run_tests(), pass_any_empty_string__returns_null(), pass_any_null_param__returns_null(), test_bad_dish(), test_buffer_free_gc_one(), test_buffer_list_aggregate_separator_empty(), test_find_operator_function_by_string_not_found(), test_find_operator_function_by_string_valid_null_functions(), and torture_test_realloc_set0().

◆ assert_ptr_equal

#define assert_ptr_equal (   a,
 
)
Value:
__FILE__, __LINE__)
void _assert_int_equal(const LargestIntegralType a, const LargestIntegralType b, const char *const file, const int line)
#define cast_ptr_to_largest_integral_type(value)
Definition: cmocka.h:133

Definition at line 1136 of file cmocka.h.

Referenced by test_buffer_free_gc_one(), test_buffer_free_gc_two(), test_check_ncp_ciphers_list(), and test_poor_man().

◆ assert_ptr_not_equal

#define assert_ptr_not_equal (   a,
 
)
Value:
__FILE__, __LINE__)
#define cast_ptr_to_largest_integral_type(value)
Definition: cmocka.h:133
void _assert_int_not_equal(const LargestIntegralType a, const LargestIntegralType b, const char *const file, const int line)

Definition at line 1155 of file cmocka.h.

Referenced by test_buffer_free_gc_two().

◆ assert_return_code

#define assert_return_code (   rc,
  error 
)
Value:
sizeof(rc), \
#rc, __FILE__, __LINE__)
#define cast_to_largest_integral_type(value)
Definition: cmocka.h:96
void _assert_return_code(const LargestIntegralType result, size_t rlen, const LargestIntegralType error, const char *const expression, const char *const file, const int line)

Definition at line 1082 of file cmocka.h.

Referenced by test_assert_return_code(), and test_assert_return_code_fail().

◆ assert_string_equal

#define assert_string_equal (   a,
 
)

◆ assert_string_not_equal

#define assert_string_not_equal (   a,
 
)
Value:
_assert_string_not_equal((const char*)(a), (const char*)(b), __FILE__, \
__LINE__)
void _assert_string_not_equal(const char *const a, const char *const b, const char *file, const int line)

Definition at line 1232 of file cmocka.h.

◆ assert_true

#define assert_true (   c)