aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-02-17 21:38:20 +0100
committerMarkus Armbruster <armbru@redhat.com>2017-02-22 19:52:06 +0100
commit363e13f86eb60bce1e112a35a4c107505a69c9fe (patch)
tree76361fe0824ba2f7488e03af988905b1f307f468
parentcd17ba51f5b25196c52afe5dfdd27c7dc8621cf4 (diff)
tests: Don't check qobject_type() before qobject_to_qstring()
qobject_to_qstring(obj) returns NULL when obj isn't a QString. Check that instead of qobject_type(obj) == QTYPE_QSTRING. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1487363905-9480-10-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
-rw-r--r--tests/check-qjson.c31
-rw-r--r--tests/test-qobject-output-visitor.c37
2 files changed, 25 insertions, 43 deletions
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 49e0259165..dd080a8024 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -54,11 +54,8 @@ static void escaped_string(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, test_cases[i].decoded);
if (test_cases[i].skip == 0) {
@@ -89,11 +86,8 @@ static void simple_string(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
str = qobject_to_json(obj);
@@ -123,11 +117,8 @@ static void single_quote_string(void)
QString *str;
obj = qobject_from_json(test_cases[i].encoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
QDECREF(str);
@@ -820,9 +811,8 @@ static void utf8_string(void)
obj = qobject_from_json(json_in);
if (utf8_out) {
- g_assert(obj);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, utf8_out);
} else {
g_assert(!obj);
@@ -847,9 +837,8 @@ static void utf8_string(void)
*/
if (0 && json_out != json_in) {
obj = qobject_from_json(json_out);
- g_assert(obj);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
str = qobject_to_qstring(obj);
+ g_assert(str);
g_assert_cmpstr(qstring_get_str(str), ==, utf8_out);
}
}
@@ -867,15 +856,11 @@ static void vararg_string(void)
};
for (i = 0; test_cases[i].decoded; i++) {
- QObject *obj;
QString *str;
- obj = qobject_from_jsonf("%s", test_cases[i].decoded);
-
- g_assert(obj != NULL);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
-
- str = qobject_to_qstring(obj);
+ str = qobject_to_qstring(qobject_from_jsonf("%s",
+ test_cases[i].decoded));
+ g_assert(str);
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
QDECREF(str);
diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c
index 13a0a9b3ac..3e34aa5783 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -97,42 +97,41 @@ static void test_visitor_out_string(TestOutputVisitorData *data,
const void *unused)
{
char *string = (char *) "Q E M U";
- QObject *obj;
+ QString *qstr;
visit_type_str(data->ov, NULL, &string, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
- g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, string);
+ qstr = qobject_to_qstring(visitor_get(data));
+ g_assert(qstr);
+ g_assert_cmpstr(qstring_get_str(qstr), ==, string);
}
static void test_visitor_out_no_string(TestOutputVisitorData *data,
const void *unused)
{
char *string = NULL;
- QObject *obj;
+ QString *qstr;
/* A null string should return "" */
visit_type_str(data->ov, NULL, &string, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
- g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, "");
+ qstr = qobject_to_qstring(visitor_get(data));
+ g_assert(qstr);
+ g_assert_cmpstr(qstring_get_str(qstr), ==, "");
}
static void test_visitor_out_enum(TestOutputVisitorData *data,
const void *unused)
{
- QObject *obj;
EnumOne i;
+ QString *qstr;
for (i = 0; i < ENUM_ONE__MAX; i++) {
visit_type_EnumOne(data->ov, "unused", &i, &error_abort);
- obj = visitor_get(data);
- g_assert(qobject_type(obj) == QTYPE_QSTRING);
- g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==,
- EnumOne_lookup[i]);
+ qstr = qobject_to_qstring(visitor_get(data));
+ g_assert(qstr);
+ g_assert_cmpstr(qstring_get_str(qstr), ==, EnumOne_lookup[i]);
visitor_reset(data);
}
}
@@ -365,9 +364,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data,
qbool = qobject_to_qbool(qobj);
g_assert(qbool);
g_assert(qbool_get_bool(qbool) == true);
- qobj = qdict_get(qdict, "string");
- g_assert(qobj);
- qstring = qobject_to_qstring(qobj);
+ qstring = qobject_to_qstring(qdict_get(qdict, "string"));
g_assert(qstring);
g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");
}
@@ -399,6 +396,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
{
QObject *arg;
UserDefAlternate *tmp;
+ QString *qstr;
QDict *qdict;
tmp = g_new0(UserDefAlternate, 1);
@@ -419,10 +417,9 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data,
tmp->u.s = g_strdup("hello");
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
- arg = visitor_get(data);
-
- g_assert(qobject_type(arg) == QTYPE_QSTRING);
- g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg)), ==, "hello");
+ qstr = qobject_to_qstring(visitor_get(data));
+ g_assert(qstr);
+ g_assert_cmpstr(qstring_get_str(qstr), ==, "hello");
qapi_free_UserDefAlternate(tmp);