From a3d7cbc1397bf01249b5c39dd1e285bd6aa818dc Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Thu, 6 Mar 2014 10:12:52 +0100 Subject: qdev-monitor-test: Simplify using g_assert_cmpstr() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use g_assert_cmpstr() instead of combining g_assert() and strcmp(3). This simplifies the code since we no longer have to play games to distinguish NULL from "" using "(null)". gcc extension haters will also be happy that ?: was dropped. Suggested-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Andreas Färber --- tests/qdev-monitor-test.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/qdev-monitor-test.c') diff --git a/tests/qdev-monitor-test.c b/tests/qdev-monitor-test.c index ba7f9cc238..eefaab823a 100644 --- a/tests/qdev-monitor-test.c +++ b/tests/qdev-monitor-test.c @@ -32,8 +32,9 @@ static void test_device_add(void) "}}"); g_assert(response); error = qdict_get_qdict(response, "error"); - g_assert(!strcmp(qdict_get_try_str(error, "desc") ?: "", - "Device needs media, but drive is empty")); + g_assert_cmpstr(qdict_get_try_str(error, "desc"), + ==, + "Device needs media, but drive is empty"); QDECREF(response); /* Delete the drive */ @@ -42,7 +43,7 @@ static void test_device_add(void) " \"command-line\": \"drive_del drive0\"" "}}"); g_assert(response); - g_assert(!strcmp(qdict_get_try_str(response, "return") ?: "(null)", "")); + g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, ""); QDECREF(response); /* Try to re-add the drive. This fails with duplicate IDs if a leaked @@ -53,8 +54,7 @@ static void test_device_add(void) " \"command-line\": \"drive_add pci-addr=auto if=none,id=drive0\"" "}}"); g_assert(response); - g_assert(!strcmp(qdict_get_try_str(response, "return") ?: "", - "OK\r\n")); + g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "OK\r\n"); QDECREF(response); qtest_end(); -- cgit 1.4.1 From 49649f23db977137c031a21eee2f0521404f6710 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 6 Mar 2014 10:12:53 +0100 Subject: qdev-monitor-test: Don't test human-readable error message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test the error class instead. Expecting a specific message is fragile. In fact, it broke once already, in commit 75884af. Restore the test of error member "class" dropped there, and drop the test of error member "desc". There are no other tests of "desc" as far as I can tell. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Andreas Färber --- tests/qdev-monitor-test.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/qdev-monitor-test.c') diff --git a/tests/qdev-monitor-test.c b/tests/qdev-monitor-test.c index eefaab823a..e20ffd67a7 100644 --- a/tests/qdev-monitor-test.c +++ b/tests/qdev-monitor-test.c @@ -32,9 +32,7 @@ static void test_device_add(void) "}}"); g_assert(response); error = qdict_get_qdict(response, "error"); - g_assert_cmpstr(qdict_get_try_str(error, "desc"), - ==, - "Device needs media, but drive is empty"); + g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, "GenericError"); QDECREF(response); /* Delete the drive */ -- cgit 1.4.1