summaryrefslogtreecommitdiff
path: root/json-glib/tests
Commit message (Collapse)AuthorAgeFilesLines
* generator: ensure valid output double exponential notationMark Nauwelaerts2023-01-261-0/+28
| | | | Fixes #67
* Replace g_print with g_test_messageEmmanuele Bassi2022-10-1310-443/+212
| | | | | | | The test suite for JSON-GLib was written back when we only had gtester-report and freeform verbose test output. These days, we expect everything to conform to the Test Anything Protocol (TAP), which has specific constraints on the output format.
* Add new api json_reader_get_current_nodeFrederic Martinsons2022-10-111-0/+39
| | | | | | | | | | | This can be useful to extract a sub json structure during parsing of another (for example when we don't know in advance the format of this sub json and just want to pass it to another consumer). Closes #9 Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
* Initialise all missing struct fieldsEmmanuele Bassi2022-10-111-1/+14
| | | | Avoid compiler warnings.
* Drop or mark unused parametersEmmanuele Bassi2022-10-113-3/+3
| | | | Avoid compiler warnings when running with `-Wunused-parameter`.
* Fix sign comparison warningsEmmanuele Bassi2022-10-116-44/+24
| | | | | When running with `-Wsign-compare` we're raising a lot of signed/unsigned comparison warnings.
* Drop usage of raw g_assert in reader test in favor of g_assert_*()Frederic Martinsons2022-10-1114-163/+164
| | | | | | | | This will give more informative message in case of fail assertions. Moreover GLib (when compiling with G_DISABLE_ASSERT) disable g_assert totally, that would make these tests no-op Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
* remove/add whitespace for coding conventiontallua2021-10-101-2/+1
|
* set node->data pointer to null when unsettallua2021-04-061-0/+18
|
* parser: Ignore UTF-8 BOM if necessaryhandle-utf8-bomJan-Michael Brummer2020-12-313-0/+31
| | | | | | | | | According to JSON spec BOM shouldn't be part of the JSON data, but also recommends to tolerate files with a BOM marker. As this is common in several Windows JSON generators, handle it graceful in json-glib and skip it for UTF-8 BOM. Fixes: https://gitlab.gnome.org/GNOME/json-glib/-/issues/56
* tests: Add surrogate pair testsJames Westman2020-11-301-0/+3
|
* Gracefully handle empty arrays and objectsEmmanuele Bassi2020-08-241-6/+5
| | | | | | Don't pretty print newlines. This requires a change in the generator test, but the pretty printing format is not stable anyway, so we can get away with it.
* Properly detect multiple top level statementsEmmanuele Bassi2020-08-241-0/+1
| | | | | | | | JSON can only have one top level statement. If we get multiple statements, we should error out appropriately, and we should also avoid leaking the node for the previously parsed statement. Fixes: #45
* Add ordered iterator for JsonObjectEmmanuele Bassi2020-08-241-8/+50
| | | | | | | | | The current iterator API does not guarantee the iteration order, as it's based off of the hash table iterator. JsonObject, though, can guarantee the iteration order—we do that for json_object_foreach_member(). Instead of changing the behaviour of json_object_iter_next(), we can add API to initialize and iterate a JsonObjectIter in insertion order.
* json-parser: Support loading files via memory mappingPhilip Withnall2020-06-093-0/+58
| | | | | | | | | | | | | | | Add a new `json_parser_load_from_mapped_file()` to load JSON from files via memory mapping. It’s otherwise similar to `json_parser_load_from_file()`. It’s in the right position to be able to memory map the file it’s reading from: it reads the input once before building a `JsonNode` structure to represent it, doesn’t write to the file, and often deals with large input files. This should speed things up slightly due to reducing time spent allocating a large chunk of heap memory to load the file into, if a caller can support that. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* tests: Factor out a helper functionPhilip Withnall2020-06-091-9/+17
| | | | | | | This introduces no functional changes, but will allow that code to be reused in the following commit. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* Refresh the build systemEmmanuele Bassi2018-03-131-23/+29
| | | | | | | | | | We should use more idiomatic Meson: - improve the coding style - ensure that the `json_glib_dep` dependency object also includes the introspection data, if enabled - add a separate option for the man page generation - ensure that json-glib can be used as a subproject
* Merge branch 'get-with-default' into 'master'Emmanuele Bassi2017-12-151-0/+20
|\ | | | | | | | | | | | | Add JsonObject getters with fallback value Closes #4 See merge request GNOME/json-glib!4
| * Add with_default() variant for JsonObject gettersEmmanuele Bassi2017-11-141-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When using the typed getters for JsonObject, the existing API will automatically fail if the member requested is not present. This is generally good practice, because JSON data typically does not have a schema, and thus is has to be validated "on the go"; a JSON object member that contains `null`, or `0`, or `false`, is indistinguishable from a JSON object member that does not exist, so we cannot simply return a scalar value and be done with it. We can provide an escape hatch, though, for the crowd writing parsers for JSON data; by using Python as the model, we can add methods that take a default value as a parameter, and return it as a fallback value if the requested object member does not exist, or if it's set to `null`.
* | Merge branch 'leak-fix' into 'master'Emmanuele Bassi2017-12-153-1/+5
|\ \ | | | | | | | | | | | | Leak fix See merge request GNOME/json-glib!6
| * | tests: Fix some memory leaks in the testsPhilip Withnall2017-12-153-1/+5
| |/ | | | | | | | | | | | | | | | | We can’t do this by porting to g_autoptr(), because json-glib needs to be buildable using MSVC. Sad panda. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://gitlab.gnome.org/GNOME/json-glib/issues/30
* | json-parser: Fix getting immutable root nodes from empty inputPhilip Withnall2017-12-151-5/+17
|/ | | | | | | | | | | | | | If parsing an empty document, it’s allowed to return NULL from json_parser_get_root(). This was broken for immutable parsers when immutability support was added (an assertion fails). Fix that, and also document that json_parser_get_root() may return NULL. Do the same for json_parser_steal_root() too, which is another way that the root node may be NULL. Add a unit test. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* Use fuzzy comparison for floating point valuesEmmanuele Bassi2017-11-044-32/+14
| | | | | | Direct comparison should never be used for floating point values. Fixes #27 and #28.
* Add float comparison utility macros for testsEmmanuele Bassi2017-11-041-0/+21
| | | | | We do compare floating point values elsewhere in our code, so we should ensure that we're doing that with a certain amount of fuzziness.
* build: Clean up the hard-coded API version numbersEmmanuele Bassi2017-07-101-2/+2
| | | | | | In order to be resilient towards future API bumps, we should have very few places that deal with the API version encoded inside paths and file names.
* build: Move ancillary build scripts to a separate directoryEmmanuele Bassi2017-06-032-22/+0
| | | | | Avoid cluttering the source directories, and makes finding things easier.
* build: Clean up installed tests rulesEmmanuele Bassi2017-06-031-8/+10
| | | | Use variables for common values, instead of duplicating them.
* build: Don't copy test data in the build directoryEmmanuele Bassi2017-04-011-9/+6
| | | | | | GTest can use environment variables to find the test data in the source and build directory, so we don't need to copy files around using Python scripts.
* build: Use the Meson 'python3' moduleEmmanuele Bassi2017-04-011-1/+1
| | | | | | | This allows finding Python3 on Windows, in order to build and run the tests. https://bugzilla.gnome.org/show_bug.cgi?id=780550
* build: Fix the installed test wrapper fileEmmanuele Bassi2017-03-291-1/+1
| | | | | We need to point to the binary, but we're using the wrong name for the Exec key.
* tests: Add unit for JsonReader NULL value checksEmmanuele Bassi2017-03-181-0/+28
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=758580
* Drop Autotools build systemEmmanuele Bassi2017-03-181-35/+0
| | | | We use Meson to build JSON-GLib, now.
* Install testsEmmanuele Bassi2017-03-132-1/+41
| | | | | | We should install our tests in order to get them executed in environments like GNOME Continuous and other continuous delivery systems.
* Update the Meson buildEmmanuele Bassi2017-03-131-11/+14
| | | | | | Clean up the coding style, and make it a bit more idiomatic. https://bugzilla.gnome.org/show_bug.cgi?id=773603
* meson: Add support for building with the meson build systemThibault Saunier2017-03-131-0/+34
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=773603
* Don't loose decimal in whole-double -> string conversiondjcb2017-03-132-2/+24
| | | | | | | | | | | | | When converting json to its string representation, whole-doubles (such as 1.0) would be converted into strings without decimals ("1"). That can be inconvenient e.g. when converting from/to GVariants. To avoid this, append '.0' to the string representation for doubles if they lost their decimals in the conversion. Also add / update unit tests for this. https://bugzilla.gnome.org/show_bug.cgi?id=753763
* Allow empty string as object member nameDr. David Alan Gilbert2017-03-115-5/+16
| | | | | | | | | | | Commit 028e540 disallowed empty member names in objects, however they are unfortunately valid JSON. This patch reenables an empty string as a member name. Tests are updated to allow the empty string case, and to test the use of an empty string in generation, iteration etc. https://bugzilla.gnome.org/show_bug.cgi?id=747279
* core: Add immutability support to core objectsPhilip Withnall2016-03-011-0/+320
| | | | | | | | | | | Add an immutable mode to JsonNode, JsonObject, JsonArray and JsonValue. This is an optional mode which objects enter by calling json_*_seal(). It is a one-way transition, which means that we can build and manipulate objects as much as desired, before sealing them and enjoying the benefits of immutable objects: no need to take copies when handling them, persistent hash values (still to be implemented). https://bugzilla.gnome.org/show_bug.cgi?id=756121
* parser: Detect missing commas in arraysEmmanuele Bassi2016-02-251-0/+31
| | | | | Just like we detect trailing commas, we should also detect missing ones to avoid parsing invalid JSON successfully.
* object: Add JsonObjectIter to ease iteration over JsonObject membersPhilip Withnall2015-10-061-0/+28
| | | | | | | | | | This is a stack-allocated iterator object similar to GHashTableIter which allows allocation-free iteration over the members in a JsonObject. It differs from json_object_foreach_member() in the order in which it iterates — for JsonObjectIter the order is undefined. https://bugzilla.gnome.org/show_bug.cgi?id=755509
* tests/builder: Don't duplicate test namesIain Lane2015-10-021-1/+1
| | | | | | GLib 2.46.0 forbids this and so the testsuite fails. https://bugzilla.gnome.org/show_bug.cgi?id=755977
* json-gvariant: Parse json doubles that are whole numbersStef Walter2015-01-261-0/+4
| | | | | | | | | The json gvariant serializer encodes whole number doubles without a dot. The deserializer needs to be able to parse these as well. Fix problem, and add test cases. https://bugzilla.gnome.org/show_bug.cgi?id=724319
* reader: Maintain a stack of member namesPhilip Withnall2015-01-251-0/+13
| | | | | | | | | | | | | | | | | | | | | This fixes the case where, with nested objects, we call: json_reader_read_member (reader, "outer"); // json_reader_get_member_name (reader) == "outer" json_reader_read_member (reader, "inner"); // json_reader_get_member_name (reader) == "inner" // do something useful json_reader_end_member (reader); but at the end, the following assertion no longer holds: // json_reader_get_member_name (reader) == "outer" even though the JsonReader state should have been reset after ending the inner node. Fix it by maintaining a stack of member names. This works with both json_reader_read_member() and json_reader_read_element(). Updates to the unit tests are included. https://bugzilla.gnome.org/show_bug.cgi?id=741824
* generator: Add tests for updated string escaping routineStef Walter2014-05-211-0/+47
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=730425
* tests: Add more checks to the parser stream unitEmmanuele Bassi2014-04-171-6/+16
|
* build: Include $(top_builddir)Emmanuele Bassi2014-03-181-0/+2
| | | | Fixes compilation in cases where builddir != srcdir.
* Remove conditional inclusion of config.hEmmanuele Bassi2014-03-183-6/+0
| | | | All the platforms and build system we support have a config.h header.
* tests: Add new test for reader level bugBastien Nocera2014-02-031-0/+43
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=723428
* tests/gvariant: Use G_N_ELEMENTSEmmanuele Bassi2013-12-021-5/+5
| | | | Instead of sizeof(array)/sizeof(type).
* Make JSON to GVariant conversion handle some string to number conversions.Joseph Artsimovich2013-12-021-7/+30
| | | | | | | | | Consider the following JSON: ["123"] Trying to convert it to GVariant with signature "(i)" would previously fail, as string-to-number conversions weren't implemented. This patch implements string-to-number and string-to-boolean conversions. https://bugzilla.gnome.org/show_bug.cgi?id=707382