61 fail_unless(
add_string(NULL) == NULL,
"add_string should null when receiving a null as parameter.");
64 fail_unless(str1 != NULL,
"add_string should not return null when receiving content.");
65 temp = malloc(strlen(str1)+1);
68 fail_unless(str2 == str1,
"add_string should return same pointer for 2 same strings but str1 (%p -> '%s') != str2 (%p -> '%s').", str1, str1, str2, str2);
70 fail_unless(str3 != NULL,
"add_string should handle gracefully empty non null strings.");
81 fail_unless(str1 == str2,
"result of add_refcount (%p) should be the same as original pointer (%p).", str2, str1);
106 fail_unless(str1 ==
result,
"find_string for %s should return %p but returned %p(%s).", str1, str1,
result,
result);
108 fail_unless(str2 ==
result,
"find_string for %s should return %p but returned %p(%s).", str2, str2,
result,
result);
110 fail_unless(
result == NULL,
"Searching for an inexistant string should return NULL but returned %p(%s)",
result,
result);
113 fail_unless(
result == str1,
"Search for empty string should return it(%p), but returned %p", str1,
result);
116 fail_unless(
result == NULL,
"add_string + free_string should mean i can't find the string anymore but find string returned %p(%s)",
result,
result);
127 fail_unless(str2 == NULL,
"find_String should return null after a free_string but it returned %p (%s)", str2, str2);
132 fail_unless(str2 == str1,
"find_string should return the string(%p) after a add_string, add_string, free_string but returned %p", str1, str2);
135 fail_unless(str2 == NULL,
"find_string should return null after add_string, add_string, free_string, free_string but returned %p", str2);
143 fail_unless(i,
"'1' +'22' can't fit in a 3 char buffer but buf_overflow told us there won't be any overflow");
145 fail_unless(i,
"'1' +NULL can't fit in a 1 char buffer but buf_overflow told us there won't be any overflow");
147 fail_unless(!i,
"'1' +NULL can fit in a 2 char buffer but buf_overflow told us it won't");
149 fail_unless(!i,
"EMPTY +NULL can fit in a 1 char buffer but buf_overflow told us it won't");
151 fail_unless(i,
"EMPTY +NULL can't fit in a 0 char buffer but buf_overflow told us there won't be any overflow");
156 Suite *s = suite_create(
"shstr");
157 TCase *tc_core = tcase_create(
"Core");
162 suite_add_tcase(s, tc_core);
163 tcase_add_test(tc_core, test_add_string);
164 tcase_add_test(tc_core, test_add_refcount);
165 tcase_add_test(tc_core, test_query_refcount);
166 tcase_add_test(tc_core, test_find_string);
167 tcase_add_test(tc_core, test_free_string);
168 tcase_add_test(tc_core, test_buf_overflow);
176 SRunner *sr = srunner_create(s);
178 srunner_set_xml(sr, LOGDIR
"/unit/common/shstr.xml");
179 srunner_set_log(sr, LOGDIR
"/unit/common/shstr.out");
180 srunner_run_all(sr, CK_ENV);
181 nf = srunner_ntests_failed(sr);
183 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;