[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 07/56] check-qjson: Cover escaped characters mor
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH 07/56] check-qjson: Cover escaped characters more thoroughly, part 1 |
Date: |
Fri, 10 Aug 2018 16:11:49 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Eric Blake <address@hidden> writes:
> On 08/08/2018 07:02 AM, Markus Armbruster wrote:
>> escaped_string() first tests double quoted strings, then repeats a few
>> tests with single quotes. Repeat all of them: store the strings to
>> test without quotes, and wrap them in either kind of quote for
>> testing.
>>
>> Signed-off-by: Markus Armbruster <address@hidden>
>> ---
>> tests/check-qjson.c | 94 ++++++++++++++++++++++++++-------------------
>> 1 file changed, 55 insertions(+), 39 deletions(-)
>>
>
>> struct {
>> - const char *encoded;
>> - const char *decoded;
>> + /* Content of JSON string to parse with qobject_from_json() */
>> + const char *json_in;
>> + /* Expected parse output; to unparse with qobject_to_json() */
>> + const char *utf8_out;
>> int skip;
>
> Instead of int skip (and why is that not a bool?),
Ask Anthony ;)
> would it be better
> to have an optional const char *json_out?
>
>> + for (i = 0; test_cases[i].json_in; i++) {
>> + for (j = 0; j < 2; j++) {
>> + cstr = from_json_str(test_cases[i].json_in, &error_abort, j);
>> + g_assert_cmpstr(qstring_get_try_str(cstr),
>> + ==, test_cases[i].utf8_out);
>> + if (test_cases[i].skip == 0) {
>> + jstr = to_json_str(cstr);
>> + g_assert_cmpstr(jstr, ==, test_cases[i].json_in);
>> + g_free(jstr);
>
> and here, write g_assert_cmpstr(jstr, ==, test_cases[i].json_out ?:
> test_cases[i].json_in)? After all, the reason we're skipping is
> because there are some cases of multiple inputs that get canonicalized
> to constant output, such as " " vs. "\u0020", or "\\'" vs. "'".
This would additionally test that qobject_from_json() correctly maps '/'
and ' ' to themselves. Marginal. If we want it, then comparing jstr to
cstr if skip would do. Dunno.
- Re: [Qemu-devel] [PATCH 15/56] check-qjson: Cover interpolation more thoroughly, (continued)
- [Qemu-devel] [PATCH 16/56] json: Fix lexer to include the bad character in JSON_ERROR token, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 03/56] check-qjson: Cover whitespace more thoroughly, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 07/56] check-qjson: Cover escaped characters more thoroughly, part 1, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 08/56] check-qjson: Streamline escaped_string()'s test strings, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 35/56] json: Don't create JSON_ERROR tokens that won't be used, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 17/56] json: Reject unescaped control characters, Markus Armbruster, 2018/08/08
- [Qemu-devel] [PATCH 23/56] json: Leave rejecting invalid UTF-8 to parser, Markus Armbruster, 2018/08/08