From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB38c-0003dY-Im for qemu-devel@nongnu.org; Thu, 09 Jun 2016 12:48:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bB38a-00022R-FB for qemu-devel@nongnu.org; Thu, 09 Jun 2016 12:48:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60037) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB38a-000228-6p for qemu-devel@nongnu.org; Thu, 09 Jun 2016 12:48:56 -0400 From: Eric Blake Date: Thu, 9 Jun 2016 10:48:41 -0600 Message-Id: <1465490926-28625-11-git-send-email-eblake@redhat.com> In-Reply-To: <1465490926-28625-1-git-send-email-eblake@redhat.com> References: <1465490926-28625-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v5 10/15] tests: Clean up test-string-output-visitor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, Michael Roth 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 --- v5: new patch, split off independent cleanups from v4 11/28 --- tests/test-string-output-visitor.c | 61 ++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-visitor.c index bfa3e8e..d57a4d3 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); } } -- 2.5.5