-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add memory location comparison macros (ck_assert_mem_*) #64
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -553,6 +553,94 @@ START_TEST(test_ck_assert_ptr_ne) | |
} | ||
END_TEST | ||
|
||
START_TEST(test_ck_assert_mem_eq) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there is a limit on the number of characters printed in the assert message, there will need to be a test that check the boundary conditions of the message. Namely, a test comparing 0 bytes (should never produce a message), a test where all the bytes are printed (covered already), a test which is the max number of bytes allowed, and a test with too many bytes. Can you add tests for these cases? |
||
{ | ||
const char *s = "\x00\x00\x00\x00\x02"; | ||
ck_assert_mem_eq("\x00\x00\x00\x00\x02", s, 5); | ||
record_failure_line_num(__LINE__); | ||
ck_assert_mem_eq("\x00\x00\x00\x00\x01", s, 5); | ||
} | ||
END_TEST | ||
|
||
START_TEST(test_ck_assert_mem_ne) | ||
{ | ||
const char *s = "\x00\x00\x00\x00\x02"; | ||
const char *t = "\x00\x00\x00\x00\x01"; | ||
ck_assert_mem_ne(t, s, 5); | ||
t = "\x00\x00\x00\x00\x02"; | ||
record_failure_line_num(__LINE__); | ||
ck_assert_mem_ne(t, s, 5); | ||
} | ||
END_TEST | ||
|
||
START_TEST(test_ck_assert_mem_lt) | ||
{ | ||
const char *s = "\x00\x00\x00\x00\x01"; | ||
const char *t = "\x00\x00\x00\x00\x02"; | ||
ck_assert_mem_lt(s, t, 5); | ||
record_failure_line_num(__LINE__); | ||
ck_assert_mem_lt(s, s, 5); | ||
} | ||
END_TEST | ||
|
||
START_TEST(test_ck_assert_mem_le) | ||
{ | ||
const char *s = "\x00\x00\x00\x00\x01"; | ||
const char *t = "\x00\x00\x00\x00\x02"; | ||
ck_assert_mem_le(s, t, 5); | ||
ck_assert_mem_le(s, s, 5); | ||
record_failure_line_num(__LINE__); | ||
ck_assert_mem_le(t, s, 5); | ||
} | ||
END_TEST | ||
|
||
START_TEST(test_ck_assert_mem_gt) | ||
{ | ||
const char *s = "\x00\x00\x00\x00\x01"; | ||
const char *t = "\x00\x00\x00\x00\x02"; | ||
ck_assert_mem_gt(t, s, 5); | ||
record_failure_line_num(__LINE__); | ||
ck_assert_mem_gt(t, t, 5); | ||
} | ||
END_TEST | ||
|
||
START_TEST(test_ck_assert_mem_ge) | ||
{ | ||
const char *s = "\x00\x00\x00\x00\x01"; | ||
const char *t = "\x00\x00\x00\x00\x02"; | ||
ck_assert_mem_ge(t, s, 5); | ||
ck_assert_mem_ge(t, t, 5); | ||
record_failure_line_num(__LINE__); | ||
ck_assert_mem_ge(s, t, 5); | ||
} | ||
END_TEST | ||
|
||
START_TEST(test_ck_assert_mem_zerolen) | ||
{ | ||
const char *s = "\x00\x00\x00\x00\x02"; | ||
const char *t = "\x00\x00\x00\x00\x01"; | ||
ck_assert_mem_eq(t, s, 0); | ||
} | ||
END_TEST | ||
|
||
START_TEST(test_ck_assert_mem_eq_exact) | ||
{ | ||
const char *s = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"; | ||
const char *t = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"; | ||
record_failure_line_num(__LINE__); | ||
ck_assert_mem_eq(t, s, 64); | ||
} | ||
END_TEST | ||
|
||
START_TEST(test_ck_assert_mem_eq_longer) | ||
{ | ||
const char *s = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"; | ||
const char *t = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To easily check that the two arrays are both at least 65 characters long, might it be easier to: const char s[65] = {0}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but I need a different character at the end of the array, not at the beginning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is fine, it is OK as is. |
||
record_failure_line_num(__LINE__); | ||
ck_assert_mem_eq(t, s, 65); | ||
} | ||
END_TEST | ||
|
||
#if defined(HAVE_FORK) && HAVE_FORK == 1 | ||
START_TEST(test_segv_pass) | ||
{ | ||
|
@@ -1095,6 +1183,15 @@ Suite *make_sub_suite(void) | |
tcase_add_test (tc_simple, test_ck_assert_str_expr); | ||
tcase_add_test (tc_simple, test_ck_assert_ptr_eq); | ||
tcase_add_test (tc_simple, test_ck_assert_ptr_ne); | ||
tcase_add_test (tc_simple, test_ck_assert_mem_eq); | ||
tcase_add_test (tc_simple, test_ck_assert_mem_ne); | ||
tcase_add_test (tc_simple, test_ck_assert_mem_lt); | ||
tcase_add_test (tc_simple, test_ck_assert_mem_le); | ||
tcase_add_test (tc_simple, test_ck_assert_mem_gt); | ||
tcase_add_test (tc_simple, test_ck_assert_mem_ge); | ||
tcase_add_test (tc_simple, test_ck_assert_mem_zerolen); | ||
tcase_add_test (tc_simple, test_ck_assert_mem_eq_exact); | ||
tcase_add_test (tc_simple, test_ck_assert_mem_eq_longer); | ||
|
||
#if defined(HAVE_FORK) && HAVE_FORK==1 | ||
tcase_add_test (tc_signal, test_segv); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there would be a difference between one check against CK_MAX_ASSERT_MEM_PRINT_SIZE characters and one with CK_MAX_ASSERT_MEM_PRINT_SIZE+1 characters, can there be a test using exactly CK_MAX_ASSERT_MEM_PRINT_SIZE characters to show that there is no .. at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.