tests: Create test{_not}_equal_common() functions

This lets me cut down on copied code.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-24 10:23:25 -05:00
parent df2d365b80
commit aac32681e5
1 changed files with 24 additions and 24 deletions

View File

@ -32,15 +32,8 @@ static void test_loop_print_result(bool passed, unsigned int i,
}
}
/*
* lhs and rhs should be newly allocated strings so we can
* free them at the end of this function.
*/
void test_strings_equal(gchar *lhs, gchar *rhs, unsigned int line)
static void test_equal_common(gchar *lhs, gchar *rhs, bool passed)
{
bool passed = strcmp(lhs, rhs) == 0;
test_print_result(passed, line);
if (!passed) {
printf("\t\t Actual: %s\n", lhs);
printf("\t\tExpected: %s\n", rhs);
@ -49,15 +42,32 @@ void test_strings_equal(gchar *lhs, gchar *rhs, unsigned int line)
g_free(rhs);
}
static void test_not_equal_common(gchar *lhs, gchar *rhs, bool passed)
{
if (!passed)
printf("\t\tUnexpected: %s\n", lhs);
g_free(lhs);
g_free(rhs);
}
/*
* lhs and rhs should be newly allocated strings so we can
* free them in test{_not}_equal_common().
*/
void test_strings_equal(gchar *lhs, gchar *rhs, unsigned int line)
{
bool passed = strcmp(lhs, rhs) == 0;
test_print_result(passed, line);
test_equal_common(lhs, rhs, passed);
}
void test_strings_not_equal(gchar *lhs, gchar *rhs, unsigned int line)
{
bool passed = strcmp(lhs, rhs) != 0;
test_print_result(passed, line);
if (!passed)
printf("\t\tUnexpected: %s\n", lhs);
g_free(lhs);
g_free(rhs);
test_not_equal_common(lhs, rhs, passed);
}
void loop_strings_equal(gchar *lhs, gchar *rhs, unsigned int i,
@ -66,13 +76,7 @@ void loop_strings_equal(gchar *lhs, gchar *rhs, unsigned int i,
bool passed = strcmp(lhs, rhs) == 0;
test_loop_print_result(passed, i, line);
if (!passed) {
printf("\t\t Actual: %s\n", lhs);
printf("\t\tExpected: %s\n", rhs);
}
g_free(lhs);
g_free(rhs);
test_equal_common(lhs, rhs, passed);
}
void loop_strings_not_equal(gchar *lhs, gchar *rhs, unsigned int i,
@ -81,11 +85,7 @@ void loop_strings_not_equal(gchar *lhs, gchar *rhs, unsigned int i,
bool passed = strcmp(lhs, rhs) != 0;
test_loop_print_result(passed, i, line);
if (!passed)
printf("\t\tUnexpected: %s\n", lhs);
g_free(lhs);
g_free(rhs);
test_not_equal_common(lhs, rhs, passed);
}
static void run_test(struct UnitTest *test)