BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdljsn_jsontestsuiteutil

Detailed Description

Outline

Purpose

Provide JSON Test Suite for BDE table-driven testing.

Classes

See also
bdljsn_jsonutil

Description

This component provides a utility struct, bdljsn::JsonTestSuiteUtil, that encapsulates the JSON Test Suite found at: https://github.com/nst/JSONTestSuite/tree/master. Note that the test suite is itself an appendix to the article Parsing JSON is a Minefield by Nicolas Seriot (see https://seriot.ch/projects/parsing_json.html).

The test points are constructed from the files found under: https://github.com/nst/JSONTestSuite/blob/master/test_parsers. The name of these files indicate whether or not their contents should be accepted or rejected.

+--------+-------+----------------------------------------------+
| Prefix | Count | Expected Result |
+--------+-------+----------------------------------------------+
| 'y_' | 95 | content must be accepted by parsers |
| 'n_' | 188 | content must be rejected by parsers |
| 'i_' | 35 | parsers are free to accept or reject content |
+--------+-------+----------------------------------------------+

Note that this component provides one additional y_ (not counted above), y_henry_verschell_smiley_surrogate_smiley.json, that does not exist in downloaded test suite.

Usage

This section illustrates intended use of this component.

Example 1: Basic Use

Generally, BDE table-drive testing uses tables defined locally in the test driver. To conveniently use the table defined in the bdljsn_jsontestsuiteutil component, some small adaptation to the test driver is recommended.

First, create aliases for symbols conventionally used in BDE table-driven tests:

Definition bdljsn_jsontestsuiteutil.h:125
Expected
Definition bdljsn_jsontestsuiteutil.h:129

Now, use these symbols in a typical table-driven for-loop:

for (bsl::size_t ti = 0; ti < JTSU::numData(); ++ti) {
const int LINE = JTSU::data(ti)->d_line;
const char *const TEST_NAME = JTSU::data(ti)->d_testName_p;
const char *const JSON = JTSU::data(ti)->d_JSON_p;
const bsl::size_t LENGTH = JTSU::data(ti)->d_length;
const Expected EXPECTED = JTSU::data(ti)->d_expected;
if (veryVerbose) {
P_(ti) P_(LINE) P_(LENGTH) P(EXPECTED)
P(TEST_NAME);
P(JSON)
}
// testing code...
}