summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlois Klink <alois@aloisklink.com>2022-12-30 12:55:42 +0000
committerAndreas Schneider <asn@cryptomilk.org>2023-01-29 10:35:41 +0100
commit079391e4850af6b23cacaad6f6b7fa51a2eda6c7 (patch)
tree4a0847cba04bbe18c062eb1c9c5fd1545c293389
parent611d089f5ed8841c69e0b3eb6be42c85a367ab33 (diff)
downloadcmocka-079391e4850af6b23cacaad6f6b7fa51a2eda6c7.zip
cmocka-079391e4850af6b23cacaad6f6b7fa51a2eda6c7.tar.gz
cmocka-079391e4850af6b23cacaad6f6b7fa51a2eda6c7.tar.bz2
test: Test expect_string and expect_memory
`expect_string` already had tests in the `example/` folder, but `expect_memory`, `expect_not_memory`, and `expect_not_string` were previously untested. Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--tests/test_expect_check.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/tests/test_expect_check.c b/tests/test_expect_check.c
index 4633c4f..67ea43c 100644
--- a/tests/test_expect_check.c
+++ b/tests/test_expect_check.c
@@ -60,14 +60,73 @@ static void test_expect_check_count_maybe_2(void **state)
expect_check_count(mock_test_a, value, custom_checker, cast_int_to_cmocka_value(0), EXPECT_MAYBE);
}
+static void mock_test_ptr(const void *value)
+{
+ check_expected_ptr(value);
+}
+
+static void test_expect_string(void **state)
+{
+ (void)state; /* unused */
+ const char string[] = "hello world";
+ assert_ptr_not_equal(string,
+ "hello world"); // should be different memory addresses
+
+ expect_string(mock_test_ptr, value, string);
+ mock_test_ptr("hello world");
+
+ expect_not_string(mock_test_ptr, value, string);
+ mock_test_ptr("hello world with extra bytes");
+
+ expect_memory(mock_test_ptr, value, string, sizeof(string));
+ mock_test_ptr("hello world");
+
+ expect_not_memory(mock_test_ptr, value, string, sizeof(string));
+ mock_test_ptr("different data");
+}
+
+static void test_expect_string_count_always(void **state)
+{
+ (void)state; /* unused */
+ const char string[] = "hello world";
+ assert_ptr_not_equal(string,
+ "hello world"); // should be different memory addresses
+
+ expect_string_count(mock_test_ptr, value, string, EXPECT_ALWAYS);
+ mock_test_ptr("hello world");
+ mock_test_ptr("hello world");
+}
+
+static void test_expect_string_count_maybe_1(void **state)
+{
+ (void)state; /* unused */
+ const char string[] = "hello world";
+ assert_ptr_not_equal(string,
+ "hello world"); // should be different memory addresses
+
+ expect_string_count(mock_test_ptr, value, string, EXPECT_MAYBE);
+ mock_test_ptr("hello world");
+ mock_test_ptr("hello world");
+}
+
+static void test_expect_string_count_maybe_2(void **state)
+{
+ (void)state; /* unused */
+ const char string[] = "hello world";
+ expect_string_count(mock_test_ptr, value, string, EXPECT_MAYBE);
+}
+
int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_expect_check),
cmocka_unit_test(test_expect_check_count),
cmocka_unit_test(test_expect_check_count_always),
cmocka_unit_test(test_expect_check_count_maybe_1),
- cmocka_unit_test(test_expect_check_count_maybe_2)
- };
+ cmocka_unit_test(test_expect_check_count_maybe_2),
+ cmocka_unit_test(test_expect_string),
+ cmocka_unit_test(test_expect_string_count_always),
+ cmocka_unit_test(test_expect_string_count_maybe_1),
+ cmocka_unit_test(test_expect_string_count_maybe_2)};
return cmocka_run_group_tests(tests, NULL, NULL);
}