diff options
author | Eric Blake <eblake@redhat.com> | 2016-06-09 10:48:41 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2016-07-06 10:52:04 +0200 |
commit | a8fff94d28bd2f0db37b2194cbfa197ba998b7f7 (patch) | |
tree | 9737822bf70c3993d59e74dfc4f578b3e6f563bd /tests/test-string-output-visitor.c | |
parent | 1830f22a6777cedaccd67a08f675d30f7a85ebfd (diff) |
tests: Clean up test-string-output-visitor
Use &error_abort and error_free_or_abort() in more places, use
the generated qapi_free_intList() instead of open-coding it,
reduce the scope of some variables, avoid code duplication
during test setup with visitor_output_setup_internal(), and
copy the visitor_reset() concept from the qmp-output test to
the string-output test.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-11-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/test-string-output-visitor.c')
-rw-r--r-- | tests/test-string-output-visitor.c | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-visitor.c index bfa3e8ec7f..d57a4d3e37 100644 --- a/tests/test-string-output-visitor.c +++ b/tests/test-string-output-visitor.c @@ -25,26 +25,26 @@ typedef struct TestOutputVisitorData { bool human; } TestOutputVisitorData; +static void visitor_output_setup_internal(TestOutputVisitorData *data, + bool human) +{ + data->human = human; + data->sov = string_output_visitor_new(human); + g_assert(data->sov); + data->ov = string_output_get_visitor(data->sov); + g_assert(data->ov); +} + static void visitor_output_setup(TestOutputVisitorData *data, const void *unused) { - data->human = false; - data->sov = string_output_visitor_new(data->human); - g_assert(data->sov != NULL); - - data->ov = string_output_get_visitor(data->sov); - g_assert(data->ov != NULL); + return visitor_output_setup_internal(data, false); } static void visitor_output_setup_human(TestOutputVisitorData *data, const void *unused) { - data->human = true; - data->sov = string_output_visitor_new(data->human); - g_assert(data->sov != NULL); - - data->ov = string_output_get_visitor(data->sov); - g_assert(data->ov != NULL); + return visitor_output_setup_internal(data, true); } static void visitor_output_teardown(TestOutputVisitorData *data, @@ -55,6 +55,14 @@ static void visitor_output_teardown(TestOutputVisitorData *data, data->ov = NULL; } +static void visitor_reset(TestOutputVisitorData *data) +{ + bool human = data->human; + + visitor_output_teardown(data, NULL); + visitor_output_setup_internal(data, human); +} + static void test_visitor_out_int(TestOutputVisitorData *data, const void *unused) { @@ -106,12 +114,7 @@ static void test_visitor_out_intList(TestOutputVisitorData *data, "0-1,3-6,9-16,21-22,9223372036854775806-9223372036854775807"); } g_free(str); - while (list) { - intList *tmp2; - tmp2 = list->next; - g_free(list); - list = tmp2; - } + qapi_free_intList(list); } static void test_visitor_out_bool(TestOutputVisitorData *data, @@ -171,12 +174,10 @@ static void test_visitor_out_no_string(TestOutputVisitorData *data, const void *unused) { char *string = NULL; - Error *err = NULL; char *str; /* A null string should return "" */ - visit_type_str(data->ov, NULL, &string, &err); - g_assert(!err); + visit_type_str(data->ov, NULL, &string, &error_abort); str = string_output_get_string(data->sov); g_assert(str != NULL); @@ -191,27 +192,24 @@ static void test_visitor_out_no_string(TestOutputVisitorData *data, static void test_visitor_out_enum(TestOutputVisitorData *data, const void *unused) { - Error *err = NULL; char *str; EnumOne i; for (i = 0; i < ENUM_ONE__MAX; i++) { - char *str_human; - - visit_type_EnumOne(data->ov, "unused", &i, &err); - g_assert(!err); - - str_human = g_strdup_printf("\"%s\"", EnumOne_lookup[i]); + visit_type_EnumOne(data->ov, "unused", &i, &error_abort); str = string_output_get_string(data->sov); g_assert(str != NULL); if (data->human) { + char *str_human = g_strdup_printf("\"%s\"", EnumOne_lookup[i]); + g_assert_cmpstr(str, ==, str_human); + g_free(str_human); } else { g_assert_cmpstr(str, ==, EnumOne_lookup[i]); } - g_free(str_human); - g_free(str); + g_free(str); + visitor_reset(data); } } @@ -224,8 +222,7 @@ static void test_visitor_out_enum_errors(TestOutputVisitorData *data, for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) { err = NULL; visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err); - g_assert(err); - error_free(err); + error_free_or_abort(&err); } } |