check-qjson: convert to gtest
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
91479dd0b5
commit
ef76dc59fa
318
check-qjson.c
318
check-qjson.c
@ -8,7 +8,7 @@
|
|||||||
* See the COPYING.LIB file in the top-level directory.
|
* See the COPYING.LIB file in the top-level directory.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <check.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include "qstring.h"
|
#include "qstring.h"
|
||||||
#include "qint.h"
|
#include "qint.h"
|
||||||
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include "qemu-common.h"
|
#include "qemu-common.h"
|
||||||
|
|
||||||
START_TEST(escaped_string)
|
static void escaped_string(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
@ -52,28 +52,23 @@ START_TEST(escaped_string)
|
|||||||
|
|
||||||
obj = qobject_from_json(test_cases[i].encoded);
|
obj = qobject_from_json(test_cases[i].encoded);
|
||||||
|
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QSTRING);
|
g_assert(qobject_type(obj) == QTYPE_QSTRING);
|
||||||
|
|
||||||
str = qobject_to_qstring(obj);
|
str = qobject_to_qstring(obj);
|
||||||
fail_unless(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0,
|
g_assert_cmpstr(qstring_get_str(str), ==, test_cases[i].decoded);
|
||||||
"%s != %s\n", qstring_get_str(str), test_cases[i].decoded);
|
|
||||||
|
|
||||||
if (test_cases[i].skip == 0) {
|
if (test_cases[i].skip == 0) {
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
fail_unless(strcmp(qstring_get_str(str),test_cases[i].encoded) == 0,
|
g_assert_cmpstr(qstring_get_str(str), ==, test_cases[i].encoded);
|
||||||
"%s != %s\n", qstring_get_str(str),
|
|
||||||
test_cases[i].encoded);
|
|
||||||
|
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(simple_string)
|
static void simple_string(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
@ -92,23 +87,22 @@ START_TEST(simple_string)
|
|||||||
|
|
||||||
obj = qobject_from_json(test_cases[i].encoded);
|
obj = qobject_from_json(test_cases[i].encoded);
|
||||||
|
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QSTRING);
|
g_assert(qobject_type(obj) == QTYPE_QSTRING);
|
||||||
|
|
||||||
str = qobject_to_qstring(obj);
|
str = qobject_to_qstring(obj);
|
||||||
fail_unless(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
|
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
|
||||||
|
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
fail_unless(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0);
|
g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0);
|
||||||
|
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
|
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(single_quote_string)
|
static void single_quote_string(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
@ -127,18 +121,17 @@ START_TEST(single_quote_string)
|
|||||||
|
|
||||||
obj = qobject_from_json(test_cases[i].encoded);
|
obj = qobject_from_json(test_cases[i].encoded);
|
||||||
|
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QSTRING);
|
g_assert(qobject_type(obj) == QTYPE_QSTRING);
|
||||||
|
|
||||||
str = qobject_to_qstring(obj);
|
str = qobject_to_qstring(obj);
|
||||||
fail_unless(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
|
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
|
||||||
|
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(vararg_string)
|
static void vararg_string(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
@ -155,18 +148,17 @@ START_TEST(vararg_string)
|
|||||||
|
|
||||||
obj = qobject_from_jsonf("%s", test_cases[i].decoded);
|
obj = qobject_from_jsonf("%s", test_cases[i].decoded);
|
||||||
|
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QSTRING);
|
g_assert(qobject_type(obj) == QTYPE_QSTRING);
|
||||||
|
|
||||||
str = qobject_to_qstring(obj);
|
str = qobject_to_qstring(obj);
|
||||||
fail_unless(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
|
g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) == 0);
|
||||||
|
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(simple_number)
|
static void simple_number(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
@ -187,25 +179,24 @@ START_TEST(simple_number)
|
|||||||
QInt *qint;
|
QInt *qint;
|
||||||
|
|
||||||
obj = qobject_from_json(test_cases[i].encoded);
|
obj = qobject_from_json(test_cases[i].encoded);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QINT);
|
g_assert(qobject_type(obj) == QTYPE_QINT);
|
||||||
|
|
||||||
qint = qobject_to_qint(obj);
|
qint = qobject_to_qint(obj);
|
||||||
fail_unless(qint_get_int(qint) == test_cases[i].decoded);
|
g_assert(qint_get_int(qint) == test_cases[i].decoded);
|
||||||
if (test_cases[i].skip == 0) {
|
if (test_cases[i].skip == 0) {
|
||||||
QString *str;
|
QString *str;
|
||||||
|
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
fail_unless(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0);
|
g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0);
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDECREF(qint);
|
QDECREF(qint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(float_number)
|
static void float_number(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
@ -225,26 +216,25 @@ START_TEST(float_number)
|
|||||||
QFloat *qfloat;
|
QFloat *qfloat;
|
||||||
|
|
||||||
obj = qobject_from_json(test_cases[i].encoded);
|
obj = qobject_from_json(test_cases[i].encoded);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QFLOAT);
|
g_assert(qobject_type(obj) == QTYPE_QFLOAT);
|
||||||
|
|
||||||
qfloat = qobject_to_qfloat(obj);
|
qfloat = qobject_to_qfloat(obj);
|
||||||
fail_unless(qfloat_get_double(qfloat) == test_cases[i].decoded);
|
g_assert(qfloat_get_double(qfloat) == test_cases[i].decoded);
|
||||||
|
|
||||||
if (test_cases[i].skip == 0) {
|
if (test_cases[i].skip == 0) {
|
||||||
QString *str;
|
QString *str;
|
||||||
|
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
fail_unless(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0);
|
g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) == 0);
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDECREF(qfloat);
|
QDECREF(qfloat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(vararg_number)
|
static void vararg_number(void)
|
||||||
{
|
{
|
||||||
QObject *obj;
|
QObject *obj;
|
||||||
QInt *qint;
|
QInt *qint;
|
||||||
@ -254,85 +244,83 @@ START_TEST(vararg_number)
|
|||||||
double valuef = 2.323423423;
|
double valuef = 2.323423423;
|
||||||
|
|
||||||
obj = qobject_from_jsonf("%d", value);
|
obj = qobject_from_jsonf("%d", value);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QINT);
|
g_assert(qobject_type(obj) == QTYPE_QINT);
|
||||||
|
|
||||||
qint = qobject_to_qint(obj);
|
qint = qobject_to_qint(obj);
|
||||||
fail_unless(qint_get_int(qint) == value);
|
g_assert(qint_get_int(qint) == value);
|
||||||
|
|
||||||
QDECREF(qint);
|
QDECREF(qint);
|
||||||
|
|
||||||
obj = qobject_from_jsonf("%" PRId64, value64);
|
obj = qobject_from_jsonf("%" PRId64, value64);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QINT);
|
g_assert(qobject_type(obj) == QTYPE_QINT);
|
||||||
|
|
||||||
qint = qobject_to_qint(obj);
|
qint = qobject_to_qint(obj);
|
||||||
fail_unless(qint_get_int(qint) == value64);
|
g_assert(qint_get_int(qint) == value64);
|
||||||
|
|
||||||
QDECREF(qint);
|
QDECREF(qint);
|
||||||
|
|
||||||
obj = qobject_from_jsonf("%f", valuef);
|
obj = qobject_from_jsonf("%f", valuef);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QFLOAT);
|
g_assert(qobject_type(obj) == QTYPE_QFLOAT);
|
||||||
|
|
||||||
qfloat = qobject_to_qfloat(obj);
|
qfloat = qobject_to_qfloat(obj);
|
||||||
fail_unless(qfloat_get_double(qfloat) == valuef);
|
g_assert(qfloat_get_double(qfloat) == valuef);
|
||||||
|
|
||||||
QDECREF(qfloat);
|
QDECREF(qfloat);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(keyword_literal)
|
static void keyword_literal(void)
|
||||||
{
|
{
|
||||||
QObject *obj;
|
QObject *obj;
|
||||||
QBool *qbool;
|
QBool *qbool;
|
||||||
QString *str;
|
QString *str;
|
||||||
|
|
||||||
obj = qobject_from_json("true");
|
obj = qobject_from_json("true");
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QBOOL);
|
g_assert(qobject_type(obj) == QTYPE_QBOOL);
|
||||||
|
|
||||||
qbool = qobject_to_qbool(obj);
|
qbool = qobject_to_qbool(obj);
|
||||||
fail_unless(qbool_get_int(qbool) != 0);
|
g_assert(qbool_get_int(qbool) != 0);
|
||||||
|
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
fail_unless(strcmp(qstring_get_str(str), "true") == 0);
|
g_assert(strcmp(qstring_get_str(str), "true") == 0);
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
|
|
||||||
QDECREF(qbool);
|
QDECREF(qbool);
|
||||||
|
|
||||||
obj = qobject_from_json("false");
|
obj = qobject_from_json("false");
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QBOOL);
|
g_assert(qobject_type(obj) == QTYPE_QBOOL);
|
||||||
|
|
||||||
qbool = qobject_to_qbool(obj);
|
qbool = qobject_to_qbool(obj);
|
||||||
fail_unless(qbool_get_int(qbool) == 0);
|
g_assert(qbool_get_int(qbool) == 0);
|
||||||
|
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
fail_unless(strcmp(qstring_get_str(str), "false") == 0);
|
g_assert(strcmp(qstring_get_str(str), "false") == 0);
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
|
|
||||||
QDECREF(qbool);
|
QDECREF(qbool);
|
||||||
|
|
||||||
obj = qobject_from_jsonf("%i", false);
|
obj = qobject_from_jsonf("%i", false);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QBOOL);
|
g_assert(qobject_type(obj) == QTYPE_QBOOL);
|
||||||
|
|
||||||
qbool = qobject_to_qbool(obj);
|
qbool = qobject_to_qbool(obj);
|
||||||
fail_unless(qbool_get_int(qbool) == 0);
|
g_assert(qbool_get_int(qbool) == 0);
|
||||||
|
|
||||||
QDECREF(qbool);
|
QDECREF(qbool);
|
||||||
|
|
||||||
obj = qobject_from_jsonf("%i", true);
|
obj = qobject_from_jsonf("%i", true);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QBOOL);
|
g_assert(qobject_type(obj) == QTYPE_QBOOL);
|
||||||
|
|
||||||
qbool = qobject_to_qbool(obj);
|
qbool = qobject_to_qbool(obj);
|
||||||
fail_unless(qbool_get_int(qbool) != 0);
|
g_assert(qbool_get_int(qbool) != 0);
|
||||||
|
|
||||||
QDECREF(qbool);
|
QDECREF(qbool);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
typedef struct LiteralQDictEntry LiteralQDictEntry;
|
typedef struct LiteralQDictEntry LiteralQDictEntry;
|
||||||
typedef struct LiteralQObject LiteralQObject;
|
typedef struct LiteralQObject LiteralQObject;
|
||||||
@ -426,7 +414,7 @@ static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST(simple_dict)
|
static void simple_dict(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
@ -460,26 +448,25 @@ START_TEST(simple_dict)
|
|||||||
QString *str;
|
QString *str;
|
||||||
|
|
||||||
obj = qobject_from_json(test_cases[i].encoded);
|
obj = qobject_from_json(test_cases[i].encoded);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QDICT);
|
g_assert(qobject_type(obj) == QTYPE_QDICT);
|
||||||
|
|
||||||
fail_unless(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
||||||
|
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
|
|
||||||
obj = qobject_from_json(qstring_get_str(str));
|
obj = qobject_from_json(qstring_get_str(str));
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QDICT);
|
g_assert(qobject_type(obj) == QTYPE_QDICT);
|
||||||
|
|
||||||
fail_unless(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(simple_list)
|
static void simple_list(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
@ -524,26 +511,25 @@ START_TEST(simple_list)
|
|||||||
QString *str;
|
QString *str;
|
||||||
|
|
||||||
obj = qobject_from_json(test_cases[i].encoded);
|
obj = qobject_from_json(test_cases[i].encoded);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QLIST);
|
g_assert(qobject_type(obj) == QTYPE_QLIST);
|
||||||
|
|
||||||
fail_unless(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
||||||
|
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
|
|
||||||
obj = qobject_from_json(qstring_get_str(str));
|
obj = qobject_from_json(qstring_get_str(str));
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QLIST);
|
g_assert(qobject_type(obj) == QTYPE_QLIST);
|
||||||
|
|
||||||
fail_unless(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(simple_whitespace)
|
static void simple_whitespace(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
@ -593,27 +579,26 @@ START_TEST(simple_whitespace)
|
|||||||
QString *str;
|
QString *str;
|
||||||
|
|
||||||
obj = qobject_from_json(test_cases[i].encoded);
|
obj = qobject_from_json(test_cases[i].encoded);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QLIST);
|
g_assert(qobject_type(obj) == QTYPE_QLIST);
|
||||||
|
|
||||||
fail_unless(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
||||||
|
|
||||||
str = qobject_to_json(obj);
|
str = qobject_to_json(obj);
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
|
|
||||||
obj = qobject_from_json(qstring_get_str(str));
|
obj = qobject_from_json(qstring_get_str(str));
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
fail_unless(qobject_type(obj) == QTYPE_QLIST);
|
g_assert(qobject_type(obj) == QTYPE_QLIST);
|
||||||
|
|
||||||
fail_unless(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) == 1);
|
||||||
|
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
QDECREF(str);
|
QDECREF(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(simple_varargs)
|
static void simple_varargs(void)
|
||||||
{
|
{
|
||||||
QObject *embedded_obj;
|
QObject *embedded_obj;
|
||||||
QObject *obj;
|
QObject *obj;
|
||||||
@ -627,169 +612,122 @@ START_TEST(simple_varargs)
|
|||||||
{}}));
|
{}}));
|
||||||
|
|
||||||
embedded_obj = qobject_from_json("[32, 42]");
|
embedded_obj = qobject_from_json("[32, 42]");
|
||||||
fail_unless(embedded_obj != NULL);
|
g_assert(embedded_obj != NULL);
|
||||||
|
|
||||||
obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj);
|
obj = qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj);
|
||||||
fail_unless(obj != NULL);
|
g_assert(obj != NULL);
|
||||||
|
|
||||||
fail_unless(compare_litqobj_to_qobj(&decoded, obj) == 1);
|
g_assert(compare_litqobj_to_qobj(&decoded, obj) == 1);
|
||||||
|
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(empty_input)
|
static void empty_input(void)
|
||||||
{
|
{
|
||||||
const char *empty = "";
|
const char *empty = "";
|
||||||
|
|
||||||
QObject *obj = qobject_from_json(empty);
|
QObject *obj = qobject_from_json(empty);
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(unterminated_string)
|
static void unterminated_string(void)
|
||||||
{
|
{
|
||||||
QObject *obj = qobject_from_json("\"abc");
|
QObject *obj = qobject_from_json("\"abc");
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(unterminated_sq_string)
|
static void unterminated_sq_string(void)
|
||||||
{
|
{
|
||||||
QObject *obj = qobject_from_json("'abc");
|
QObject *obj = qobject_from_json("'abc");
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(unterminated_escape)
|
static void unterminated_escape(void)
|
||||||
{
|
{
|
||||||
QObject *obj = qobject_from_json("\"abc\\\"");
|
QObject *obj = qobject_from_json("\"abc\\\"");
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(unterminated_array)
|
static void unterminated_array(void)
|
||||||
{
|
{
|
||||||
QObject *obj = qobject_from_json("[32");
|
QObject *obj = qobject_from_json("[32");
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(unterminated_array_comma)
|
static void unterminated_array_comma(void)
|
||||||
{
|
{
|
||||||
QObject *obj = qobject_from_json("[32,");
|
QObject *obj = qobject_from_json("[32,");
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(invalid_array_comma)
|
static void invalid_array_comma(void)
|
||||||
{
|
{
|
||||||
QObject *obj = qobject_from_json("[32,}");
|
QObject *obj = qobject_from_json("[32,}");
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(unterminated_dict)
|
static void unterminated_dict(void)
|
||||||
{
|
{
|
||||||
QObject *obj = qobject_from_json("{'abc':32");
|
QObject *obj = qobject_from_json("{'abc':32");
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(unterminated_dict_comma)
|
static void unterminated_dict_comma(void)
|
||||||
{
|
{
|
||||||
QObject *obj = qobject_from_json("{'abc':32,");
|
QObject *obj = qobject_from_json("{'abc':32,");
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
START_TEST(invalid_dict_comma)
|
static void invalid_dict_comma(void)
|
||||||
{
|
{
|
||||||
QObject *obj = qobject_from_json("{'abc':32,}");
|
QObject *obj = qobject_from_json("{'abc':32,}");
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST(unterminated_literal)
|
static void unterminated_literal(void)
|
||||||
{
|
{
|
||||||
QObject *obj = qobject_from_json("nul");
|
QObject *obj = qobject_from_json("nul");
|
||||||
fail_unless(obj == NULL);
|
g_assert(obj == NULL);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Suite *qjson_suite(void)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
Suite *suite;
|
g_test_init(&argc, &argv, NULL);
|
||||||
TCase *string_literals, *number_literals, *keyword_literals;
|
|
||||||
TCase *dicts, *lists, *whitespace, *varargs, *errors;
|
|
||||||
|
|
||||||
string_literals = tcase_create("String Literals");
|
g_test_add_func("/literals/string/simple", simple_string);
|
||||||
tcase_add_test(string_literals, simple_string);
|
g_test_add_func("/literals/string/escaped", escaped_string);
|
||||||
tcase_add_test(string_literals, escaped_string);
|
g_test_add_func("/literals/string/single_quote", single_quote_string);
|
||||||
tcase_add_test(string_literals, single_quote_string);
|
g_test_add_func("/literals/string/vararg", vararg_string);
|
||||||
tcase_add_test(string_literals, vararg_string);
|
|
||||||
|
|
||||||
number_literals = tcase_create("Number Literals");
|
g_test_add_func("/literals/number/simple", simple_number);
|
||||||
tcase_add_test(number_literals, simple_number);
|
g_test_add_func("/literals/number/float", float_number);
|
||||||
tcase_add_test(number_literals, float_number);
|
g_test_add_func("/literals/number/vararg", vararg_number);
|
||||||
tcase_add_test(number_literals, vararg_number);
|
|
||||||
|
|
||||||
keyword_literals = tcase_create("Keywords");
|
g_test_add_func("/literals/keyword", keyword_literal);
|
||||||
tcase_add_test(keyword_literals, keyword_literal);
|
|
||||||
dicts = tcase_create("Objects");
|
|
||||||
tcase_add_test(dicts, simple_dict);
|
|
||||||
lists = tcase_create("Lists");
|
|
||||||
tcase_add_test(lists, simple_list);
|
|
||||||
|
|
||||||
whitespace = tcase_create("Whitespace");
|
g_test_add_func("/dicts/simple_dict", simple_dict);
|
||||||
tcase_add_test(whitespace, simple_whitespace);
|
g_test_add_func("/lists/simple_list", simple_list);
|
||||||
|
|
||||||
varargs = tcase_create("Varargs");
|
g_test_add_func("/whitespace/simple_whitespace", simple_whitespace);
|
||||||
tcase_add_test(varargs, simple_varargs);
|
|
||||||
|
|
||||||
errors = tcase_create("Invalid JSON");
|
g_test_add_func("/varargs/simple_varargs", simple_varargs);
|
||||||
tcase_add_test(errors, empty_input);
|
|
||||||
tcase_add_test(errors, unterminated_string);
|
g_test_add_func("/errors/empty_input", empty_input);
|
||||||
tcase_add_test(errors, unterminated_escape);
|
g_test_add_func("/errors/unterminated/string", unterminated_string);
|
||||||
tcase_add_test(errors, unterminated_sq_string);
|
g_test_add_func("/errors/unterminated/escape", unterminated_escape);
|
||||||
tcase_add_test(errors, unterminated_array);
|
g_test_add_func("/errors/unterminated/sq_string", unterminated_sq_string);
|
||||||
tcase_add_test(errors, unterminated_array_comma);
|
g_test_add_func("/errors/unterminated/array", unterminated_array);
|
||||||
tcase_add_test(errors, invalid_array_comma);
|
g_test_add_func("/errors/unterminated/array_comma", unterminated_array_comma);
|
||||||
tcase_add_test(errors, unterminated_dict);
|
g_test_add_func("/errors/unterminated/dict", unterminated_dict);
|
||||||
tcase_add_test(errors, unterminated_dict_comma);
|
g_test_add_func("/errors/unterminated/dict_comma", unterminated_dict_comma);
|
||||||
|
g_test_add_func("/errors/invalid_array_comma", invalid_array_comma);
|
||||||
#if 0
|
#if 0
|
||||||
/* FIXME: this print parse error messages on stderr. */
|
/* FIXME: this print parse error messages on stderr. */
|
||||||
tcase_add_test(errors, invalid_dict_comma);
|
g_test_add_func("/errors/invalid_dict_comma", invalid_dict_comma);
|
||||||
tcase_add_test(errors, unterminated_literal);
|
g_test_add_func("/errors/unterminated/literal", unterminated_literal);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
suite = suite_create("QJSON test-suite");
|
return g_test_run();
|
||||||
suite_add_tcase(suite, string_literals);
|
|
||||||
suite_add_tcase(suite, number_literals);
|
|
||||||
suite_add_tcase(suite, keyword_literals);
|
|
||||||
suite_add_tcase(suite, dicts);
|
|
||||||
suite_add_tcase(suite, lists);
|
|
||||||
suite_add_tcase(suite, whitespace);
|
|
||||||
suite_add_tcase(suite, varargs);
|
|
||||||
suite_add_tcase(suite, errors);
|
|
||||||
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int nf;
|
|
||||||
Suite *s;
|
|
||||||
SRunner *sr;
|
|
||||||
|
|
||||||
s = qjson_suite();
|
|
||||||
sr = srunner_create(s);
|
|
||||||
|
|
||||||
srunner_run_all(sr, CK_NORMAL);
|
|
||||||
nf = srunner_ntests_failed(sr);
|
|
||||||
srunner_free(sr);
|
|
||||||
|
|
||||||
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
4
configure
vendored
4
configure
vendored
@ -2800,9 +2800,9 @@ if test "$softmmu" = yes ; then
|
|||||||
tools="qemu-ga\$(EXESUF) $tools"
|
tools="qemu-ga\$(EXESUF) $tools"
|
||||||
fi
|
fi
|
||||||
if [ "$check_utests" = "yes" ]; then
|
if [ "$check_utests" = "yes" ]; then
|
||||||
checks="check-qjson $checks"
|
checks="$checks"
|
||||||
fi
|
fi
|
||||||
test_progs="$checks check-qdict check-qfloat check-qint check-qstring check-qlist test-coroutine test-qmp-output-visitor test-qmp-input-visitor"
|
test_progs="$checks check-qdict check-qfloat check-qint check-qstring check-qlist check-qjson test-coroutine test-qmp-output-visitor test-qmp-input-visitor"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user