qobject_unref(str);
g_free(jstr);
- /*
- * Parse @json_out right back
- * Disabled, because qobject_from_json() is buggy, and I can't
- * be bothered to add the expected incorrect results.
- * FIXME Enable once these bugs have been fixed.
- */
- if (0 && json_out != json_in) {
+ /* Parse @json_out right back, unless it has replacements */
+ if (!strstr(json_out, "\\uFFFD")) {
str = from_json_str(json_out, j, &error_abort);
- g_assert_cmpstr(qstring_get_try_str(str), ==, utf8_out);
+ g_assert_cmpstr(qstring_get_try_str(str), ==, utf8_in);
+ qobject_unref(str);
}
}
}
static void interpolation_valid(void)
{
long long value_lld = 0x123456789abcdefLL;
+ int64_t value_d64 = value_lld;
long value_ld = (long)value_lld;
int value_d = (int)value_lld;
unsigned long long value_llu = 0xfedcba9876543210ULL;
+ uint64_t value_u64 = value_llu;
unsigned long value_lu = (unsigned long)value_llu;
unsigned value_u = (unsigned)value_llu;
double value_f = 2.323423423;
g_assert_cmpint(qnum_get_int(qnum), ==, value_lld);
qobject_unref(qnum);
+ qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%" PRId64, value_d64));
+ g_assert_cmpint(qnum_get_int(qnum), ==, value_lld);
+ qobject_unref(qnum);
+
qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%u", value_u));
g_assert_cmpuint(qnum_get_uint(qnum), ==, value_u);
qobject_unref(qnum);
g_assert_cmpuint(qnum_get_uint(qnum), ==, value_llu);
qobject_unref(qnum);
+ qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%" PRIu64, value_u64));
+ g_assert_cmpuint(qnum_get_uint(qnum), ==, value_llu);
+ qobject_unref(qnum);
+
qnum = qobject_to(QNum, qobject_from_jsonf_nofail("%f", value_f));
g_assert(qnum_get_double(qnum) == value_f);
qobject_unref(qnum);
}
g_test_trap_subprocess(NULL, 0, 0);
g_test_trap_assert_failed();
+ g_test_trap_assert_stderr("*Unexpected error*"
+ "invalid interpolation '%x'*");
}
static void interpolation_string(void)
{
- QLitObject decoded = QLIT_QLIST(((QLitObject[]){
- QLIT_QSTR("%s"),
- QLIT_QSTR("eins"),
- {}}));
- QObject *qobj;
-
- /* Dangerous misfeature: % is silently ignored in strings */
- qobj = qobject_from_jsonf_nofail("['%s', %s]", "eins", "zwei");
- g_assert(qlit_equal_qobject(&decoded, qobj));
- qobject_unref(qobj);
+ if (g_test_subprocess()) {
+ qobject_from_jsonf_nofail("['%s', %s]", "eins", "zwei");
+ }
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_failed();
+ g_test_trap_assert_stderr("*Unexpected error*"
+ "can't interpolate into string*");
}
static void simple_dict(void)
QObject *obj;
QLitObject decoded = QLIT_QLIST(((QLitObject[]){
QLIT_QNUM(1),
- QLIT_QNUM(2),
+ QLIT_QSTR("100%"),
QLIT_QLIST(((QLitObject[]){
QLIT_QNUM(32),
QLIT_QNUM(42),
embedded_obj = qobject_from_json("[32, 42]", &error_abort);
g_assert(embedded_obj != NULL);
- obj = qobject_from_jsonf_nofail("[%d, 2, %p]", 1, embedded_obj);
+ obj = qobject_from_jsonf_nofail("[%d, '100%%', %p]", 1, embedded_obj);
g_assert(qlit_equal_qobject(&decoded, obj));
qobject_unref(obj);
static void empty_input(void)
{
- QObject *obj = qobject_from_json("", &error_abort);
+ Error *err = NULL;
+ QObject *obj;
+
+ obj = qobject_from_json("", &err);
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
static void blank_input(void)
{
- QObject *obj = qobject_from_json("\n ", &error_abort);
+ Error *err = NULL;
+ QObject *obj;
+
+ obj = qobject_from_json("\n ", &err);
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
QObject *obj;
obj = qobject_from_json("@", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
obj = qobject_from_json("{\x01", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
obj = qobject_from_json("[0\xFF]", &err);
g_assert(obj == NULL);
obj = qobject_from_json("00", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
obj = qobject_from_json("[1e", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
obj = qobject_from_json("truer", &err);
{
Error *err = NULL;
QObject *obj = qobject_from_json("\"abc", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
{
Error *err = NULL;
QObject *obj = qobject_from_json("'abc", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
{
Error *err = NULL;
QObject *obj = qobject_from_json("\"abc\\\"", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
{
Error *err = NULL;
QObject *obj = qobject_from_json("[32", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
{
Error *err = NULL;
QObject *obj = qobject_from_json("[32,", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
{
Error *err = NULL;
QObject *obj = qobject_from_json("{'abc':32", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
{
Error *err = NULL;
QObject *obj = qobject_from_json("{'abc':32,", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
Error *err = NULL;
QObject *obj;
- /* BUG this leaks the syntax tree for "false" */
obj = qobject_from_json("false true", &err);
- g_assert(qbool_get_bool(qobject_to(QBool, obj)));
- g_assert(!err);
- qobject_unref(obj);
+ error_free_or_abort(&err);
+ g_assert(obj == NULL);
- /* BUG simultaneously succeeds and fails */
- /* BUG calls json_parser_parse() with errp pointing to non-null */
obj = qobject_from_json("} true", &err);
- g_assert(qbool_get_bool(qobject_to(QBool, obj)));
error_free_or_abort(&err);
- qobject_unref(obj);
+ g_assert(obj == NULL);
}
int main(int argc, char **argv)