Skip to content
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

tests: add tests on g_strtrim() #2015

Merged
merged 2 commits into from
Oct 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 63 additions & 0 deletions tests/common/test_string_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,68 @@ START_TEST(test_bm2str__overflow_some_bits_undefined)
END_TEST

/******************************************************************************/

START_TEST(test_strtrim__trim_left)
{
/* setup */
char output[] = "\t\t \tDone is better than perfect.\t\t \n\n";

/* test */
g_strtrim(output, 1);

/* verify */
ck_assert_str_eq(output, "Done is better than perfect.\t\t \n\n");
}
END_TEST

START_TEST(test_strtrim__trim_right)
{
/* setup */
char output[] = "\t\t \tDone is better than perfect.\t\t \n\n";

/* test */
g_strtrim(output, 2);

/* verify */
ck_assert_str_eq(output, "\t\t \tDone is better than perfect.");
}
END_TEST

START_TEST(test_strtrim__trim_both)
{
/* setup */
char output[] = "\t\t \tDone is better than perfect.\t\t \n\n";

/* test */
g_strtrim(output, 3);

/* verify */
ck_assert_str_eq(output, "Done is better than perfect.");
}
END_TEST

START_TEST(test_strtrim__trim_through)
{
/* setup */
char output[] = "\t\t \tDone is better than perfect.\t\t \n\n";

/* test */
g_strtrim(output, 4);

/* verify */
ck_assert_str_eq(output, "Doneisbetterthanperfect.");
}
END_TEST

/******************************************************************************/

Suite *
make_suite_test_string(void)
{
Suite *s;
TCase *tc_strnjoin;
TCase *tc_bm2str;
TCase *tc_strtrim;

s = suite_create("String");

Expand All @@ -355,5 +411,12 @@ make_suite_test_string(void)
tcase_add_test(tc_bm2str, test_bm2str__overflow_all_bits_defined);
tcase_add_test(tc_bm2str, test_bm2str__overflow_some_bits_undefined);

tc_strtrim = tcase_create("strtrim");
suite_add_tcase(s, tc_strtrim);
tcase_add_test(tc_strtrim, test_strtrim__trim_left);
tcase_add_test(tc_strtrim, test_strtrim__trim_right);
tcase_add_test(tc_strtrim, test_strtrim__trim_both);
tcase_add_test(tc_strtrim, test_strtrim__trim_through);

return s;
}