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:
parent
df2d365b80
commit
aac32681e5
48
tests/test.c
48
tests/test.c
|
@ -32,15 +32,8 @@ static void test_loop_print_result(bool passed, unsigned int i,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static void test_equal_common(gchar *lhs, gchar *rhs, bool passed)
|
||||||
* 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)
|
|
||||||
{
|
{
|
||||||
bool passed = strcmp(lhs, rhs) == 0;
|
|
||||||
|
|
||||||
test_print_result(passed, line);
|
|
||||||
if (!passed) {
|
if (!passed) {
|
||||||
printf("\t\t Actual: %s\n", lhs);
|
printf("\t\t Actual: %s\n", lhs);
|
||||||
printf("\t\tExpected: %s\n", rhs);
|
printf("\t\tExpected: %s\n", rhs);
|
||||||
|
@ -49,15 +42,32 @@ void test_strings_equal(gchar *lhs, gchar *rhs, unsigned int line)
|
||||||
g_free(rhs);
|
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)
|
void test_strings_not_equal(gchar *lhs, gchar *rhs, unsigned int line)
|
||||||
{
|
{
|
||||||
bool passed = strcmp(lhs, rhs) != 0;
|
bool passed = strcmp(lhs, rhs) != 0;
|
||||||
|
|
||||||
test_print_result(passed, line);
|
test_print_result(passed, line);
|
||||||
if (!passed)
|
test_not_equal_common(lhs, rhs, passed);
|
||||||
printf("\t\tUnexpected: %s\n", lhs);
|
|
||||||
g_free(lhs);
|
|
||||||
g_free(rhs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop_strings_equal(gchar *lhs, gchar *rhs, unsigned int i,
|
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;
|
bool passed = strcmp(lhs, rhs) == 0;
|
||||||
|
|
||||||
test_loop_print_result(passed, i, line);
|
test_loop_print_result(passed, i, line);
|
||||||
if (!passed) {
|
test_equal_common(lhs, rhs, passed);
|
||||||
printf("\t\t Actual: %s\n", lhs);
|
|
||||||
printf("\t\tExpected: %s\n", rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(lhs);
|
|
||||||
g_free(rhs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop_strings_not_equal(gchar *lhs, gchar *rhs, unsigned int i,
|
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;
|
bool passed = strcmp(lhs, rhs) != 0;
|
||||||
|
|
||||||
test_loop_print_result(passed, i, line);
|
test_loop_print_result(passed, i, line);
|
||||||
if (!passed)
|
test_not_equal_common(lhs, rhs, passed);
|
||||||
printf("\t\tUnexpected: %s\n", lhs);
|
|
||||||
|
|
||||||
g_free(lhs);
|
|
||||||
g_free(rhs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run_test(struct UnitTest *test)
|
static void run_test(struct UnitTest *test)
|
||||||
|
|
Loading…
Reference in New Issue