<commit_before>/**
 * @file
 * @brief Test assertion macros implementation.
 *
 * @date 12.06.10
 * @author <NAME>
 */

#ifndef FRAMEWORK_TEST_ASSERT_IMPL_H_
#define FRAMEWORK_TEST_ASSERT_IMPL_H_

#include <string.h>

#include <util/location.h>

#include "types.h"
#include "emit_impl.h"

extern void __test_assertion_handle(int pass,
		const struct __test_assertion_point *point);

#define __test_assertion_point_ref(_reason) \
	({                                                                        \
		/* Statically allocate and define. Location and reason message are    \
		 * known at compile time and nobody cares about .rodata section. */   \
		static const struct __test_assertion_point __test_assertion_point = { \
			.location = LOCATION_FUNC_INIT, \
			.reason = _reason,              \
		};                                  \
		&__test_assertion_point;            \
	})

#define __test_fail(reason) \
	__test_assertion_handle(0, \
			__test_assertion_point_ref("test_fail(\"" reason "\")"))

#define __test_assert(condition, condition_str) \
	__test_assertion_handle((int) (condition), \
			__test_assertion_point_ref("test_assert(" condition_str ")"))

#define __test_assert_true(value, value_str) \
	__test_assertion_handle((value), \
			__test_assertion_point_ref("test_assert_true(" value_str ")"))

#define __test_assert_false(value, value_str) \
	__test_assertion_handle(!(value), \
			__test_assertion_point_ref("test_assert_false(" value_str ")"))

#define __test_assert_zero(value, value_str) \
	__test_assertion_handle(!(value), \
			__test_assertion_point_ref("test_assert_zero(" value_str ")"))

#define __test_assert_not_zero(value, value_str) \
	__test_assertion_handle((value), \
			__test_assertion_point_ref("test_assert_not_zero(" value_str ")"))

#define __test_assert_null(value, value_str) \
	__test_assertion_handle(!(value), \
			__test_assertion_point_ref("test_assert_null(" value_str ")"))

#define __test_assert_not_null(value, value_str) \
	__test_assertion_handle((int) (value), \
			__test_assertion_point_ref("test_assert_not_null(" value_str ")"))

#define __test_assert_equal(actual, expected, act_str, exp_str) \
	__test_assertion_handle((actual) == (expected), \
			__test_assertion_point_ref( "test_assert_equal(" act_str ", " \
					exp_str ")"))

#define __test_assert_not_equal(actual, expected, act_str, exp_str) \
	__test_assertion_handle((actual) != (expected), \
			__test_assertion_point_ref( "test_assert_not_equal(" act_str ", " \
					exp_str ")"))

#define __test_assert_str_equal(actual, expected, \
		act_str, exp_str) \
	__test_assertion_handle(0 == strcmp((actual), (expected)), \
			__test_assertion_point_ref( "test_assert_str_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_str_not_equal(actual, expected, \
		act_str, exp_str) \
	__test_assertion_handle(0 != strcmp((actual), (expected)), \
			__test_assertion_point_ref( "test_assert_str_not_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_strn_equal(actual, expected, n, \
		act_str, exp_str, n_str) \
	__test_assertion_handle(0 == strncmp((actual), (expected), (n)), \
			__test_assertion_point_ref( "test_assert_strn_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_strn_not_equal(actual, expected, n, \
		act_str, exp_str, n_str) \
	__test_assertion_handle(0 != strcmp((actual), (expected), (n)), \
			__test_assertion_point_ref( "test_assert_strn_not_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_mem_equal(actual, expected, n, \
		act_str, exp_str, n_str) \
	__test_assertion_handle(0 == memcmp((actual), (expected), (n)), \
			__test_assertion_point_ref( "test_assert_mem_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_mem_not_equal(actual, expected, n, \
		act_str, exp_str, n_str) \
	__test_assertion_handle(0 != memcmp((actual), (expected), (n)), \
			__test_assertion_point_ref( "test_assert_mem_not_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_emitted(expected, exp_str) \
	__test_assertion_handle(0 == strcmp(test_get_emitted(), (expected)), \
			__test_assertion_point_ref( "test_assert_emitted(" exp_str ")"))
<commit_msg>framework: Improve test_assert macros for string<commit_after>/**
 * @file
 * @brief Test assertion macros implementation.
 *
 * @date 12.06.10
 * @author <NAME>
 */

#ifndef FRAMEWORK_TEST_ASSERT_IMPL_H_
#define FRAMEWORK_TEST_ASSERT_IMPL_H_

#include <string.h>

#include <util/location.h>

#include "types.h"
#include "emit_impl.h"

extern void __test_assertion_handle(int pass,
		const struct __test_assertion_point *point);

#define __test_assertion_point_ref(_reason) \
	({                                                                        \
		/* Statically allocate and define. Location and reason message are    \
		 * known at compile time and nobody cares about .rodata section. */   \
		static const struct __test_assertion_point __test_assertion_point = { \
			.location = LOCATION_FUNC_INIT, \
			.reason = _reason,              \
		};                                  \
		&__test_assertion_point;            \
	})

#define __test_fail(reason) \
	__test_assertion_handle(0, \
			__test_assertion_point_ref("test_fail(\"" reason "\")"))

#define __test_assert(condition, condition_str) \
	__test_assertion_handle((int) (condition), \
			__test_assertion_point_ref("test_assert(" condition_str ")"))

#define __test_assert_true(value, value_str) \
	__test_assertion_handle((value), \
			__test_assertion_point_ref("test_assert_true(" value_str ")"))

#define __test_assert_false(value, value_str) \
	__test_assertion_handle(!(value), \
			__test_assertion_point_ref("test_assert_false(" value_str ")"))

#define __test_assert_zero(value, value_str) \
	__test_assertion_handle(!(value), \
			__test_assertion_point_ref("test_assert_zero(" value_str ")"))

#define __test_assert_not_zero(value, value_str) \
	__test_assertion_handle((value), \
			__test_assertion_point_ref("test_assert_not_zero(" value_str ")"))

#define __test_assert_null(value, value_str) \
	__test_assertion_handle(!(value), \
			__test_assertion_point_ref("test_assert_null(" value_str ")"))

#define __test_assert_not_null(value, value_str) \
	__test_assertion_handle((int) (value), \
			__test_assertion_point_ref("test_assert_not_null(" value_str ")"))

#define __test_assert_equal(actual, expected, act_str, exp_str) \
	__test_assertion_handle((actual) == (expected), \
			__test_assertion_point_ref( "test_assert_equal(" act_str ", " \
					exp_str ")"))

#define __test_assert_not_equal(actual, expected, act_str, exp_str) \
	__test_assertion_handle((actual) != (expected), \
			__test_assertion_point_ref( "test_assert_not_equal(" act_str ", " \
					exp_str ")"))

#define __test_assert_str_equal(actual, expected, \
		act_str, exp_str) \
	__test_assertion_handle(((actual) == (expected)) \
			|| (0 == strcmp((actual), (expected))), \
			__test_assertion_point_ref( "test_assert_str_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_str_not_equal(actual, expected, \
		act_str, exp_str) \
	__test_assertion_handle(((actual) != (expected)) \
			&& (0 != strcmp((actual), (expected))), \
			__test_assertion_point_ref( "test_assert_str_not_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_strn_equal(actual, expected, n, \
		act_str, exp_str, n_str) \
	__test_assertion_handle(((actual) == (expected)) \
			|| (0 == strncmp((actual), (expected), (n))), \
			__test_assertion_point_ref( "test_assert_strn_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_strn_not_equal(actual, expected, n, \
		act_str, exp_str, n_str) \
	__test_assertion_handle(((actual) != (expected)) \
			&& (0 != strcmp((actual), (expected), (n))), \
			__test_assertion_point_ref( "test_assert_strn_not_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_mem_equal(actual, expected, n, \
		act_str, exp_str, n_str) \
	__test_assertion_handle(0 == memcmp((actual), (expected), (n)), \
			__test_assertion_point_ref( "test_assert_mem_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_mem_not_equal(actual, expected, n, \
		act_str, exp_str, n_str) \
	__test_assertion_handle(0 != memcmp((actual), (expected), (n)), \
			__test_assertion_point_ref( "test_assert_mem_not_equal(" \
					act_str ", " exp_str ")"))

#define __test_assert_emitted(expected, exp_str) \
	__test_assertion_handle(0 == strcmp(test_get_emitted(), (expected)), \
			__test_assertion_point_ref( "test_assert_emitted(" exp_str ")"))

{'fraction_non_alphanumeric': 0.13409331296274532, 'fraction_numerical': 0.0032906334469385355, 'mean_word_length': 4.742240215924427, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5915700', 'n_tokens_mistral': 3215, 'n_tokens_neox': 3048, 'n_words': 465}