mirror of https://github.com/xemu-project/xemu.git
check-qjson: Consolidate partly redundant string tests
simple_string() and single_quote_string() have become redundant with escaped_string(), except for embedded single and double quotes. Replace them by a test that covers just that. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180823164025.12553-12-armbru@redhat.com>
This commit is contained in:
parent
e0fe2a978e
commit
069946f402
|
@ -126,59 +126,24 @@ static void escaped_string(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void simple_string(void)
|
static void string_with_quotes(void)
|
||||||
{
|
{
|
||||||
int i;
|
const char *test_cases[] = {
|
||||||
struct {
|
"\"the bee's knees\"",
|
||||||
const char *encoded;
|
"'double quote \"'",
|
||||||
const char *decoded;
|
NULL
|
||||||
} test_cases[] = {
|
|
||||||
{ "\"hello world\"", "hello world" },
|
|
||||||
{ "\"the quick brown fox jumped over the fence\"",
|
|
||||||
"the quick brown fox jumped over the fence" },
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i = 0; test_cases[i].encoded; i++) {
|
|
||||||
QObject *obj;
|
|
||||||
QString *str;
|
|
||||||
|
|
||||||
obj = qobject_from_json(test_cases[i].encoded, &error_abort);
|
|
||||||
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);
|
|
||||||
g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0);
|
|
||||||
|
|
||||||
qobject_unref(obj);
|
|
||||||
|
|
||||||
qobject_unref(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void single_quote_string(void)
|
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
struct {
|
QString *str;
|
||||||
const char *encoded;
|
char *cstr;
|
||||||
const char *decoded;
|
|
||||||
} test_cases[] = {
|
|
||||||
{ "'hello world'", "hello world" },
|
|
||||||
{ "'the quick brown fox \\' jumped over the fence'",
|
|
||||||
"the quick brown fox ' jumped over the fence" },
|
|
||||||
{}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (i = 0; test_cases[i].encoded; i++) {
|
for (i = 0; test_cases[i]; i++) {
|
||||||
QObject *obj;
|
str = qobject_to(QString,
|
||||||
QString *str;
|
qobject_from_json(test_cases[i], &error_abort));
|
||||||
|
|
||||||
obj = qobject_from_json(test_cases[i].encoded, &error_abort);
|
|
||||||
str = qobject_to(QString, obj);
|
|
||||||
g_assert(str);
|
g_assert(str);
|
||||||
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
|
cstr = g_strndup(test_cases[i] + 1, strlen(test_cases[i]) - 2);
|
||||||
|
g_assert_cmpstr(qstring_get_str(str), ==, cstr);
|
||||||
|
g_free(cstr);
|
||||||
qobject_unref(str);
|
qobject_unref(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1525,10 +1490,9 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
|
||||||
g_test_add_func("/literals/string/simple", simple_string);
|
|
||||||
g_test_add_func("/literals/string/escaped", escaped_string);
|
g_test_add_func("/literals/string/escaped", escaped_string);
|
||||||
|
g_test_add_func("/literals/string/quotes", string_with_quotes);
|
||||||
g_test_add_func("/literals/string/utf8", utf8_string);
|
g_test_add_func("/literals/string/utf8", utf8_string);
|
||||||
g_test_add_func("/literals/string/single_quote", single_quote_string);
|
|
||||||
g_test_add_func("/literals/string/vararg", vararg_string);
|
g_test_add_func("/literals/string/vararg", vararg_string);
|
||||||
|
|
||||||
g_test_add_func("/literals/number/simple", simple_number);
|
g_test_add_func("/literals/number/simple", simple_number);
|
||||||
|
|
Loading…
Reference in New Issue