BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdljsn_jsontestsuiteutil.h
Go to the documentation of this file.
1/// @file bdljsn_jsontestsuiteutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdljsn_jsontestsuiteutil.h -*-C++-*-
8#ifndef INCLUDED_BDLJSN_JSONTESTSUITEUTIL
9#define INCLUDED_BDLJSN_JSONTESTSUITEUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdljsn_jsontestsuiteutil bdljsn_jsontestsuiteutil
15/// @brief Provide JSON Test Suite for BDE table-driven testing.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdljsn
19/// @{
20/// @addtogroup bdljsn_jsontestsuiteutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdljsn_jsontestsuiteutil-purpose"> Purpose</a>
25/// * <a href="#bdljsn_jsontestsuiteutil-classes"> Classes </a>
26/// * <a href="#bdljsn_jsontestsuiteutil-description"> Description </a>
27/// * <a href="#bdljsn_jsontestsuiteutil-usage"> Usage </a>
28/// * <a href="#bdljsn_jsontestsuiteutil-example-1-basic-use"> Example 1: Basic Use </a>
29///
30/// # Purpose {#bdljsn_jsontestsuiteutil-purpose}
31/// Provide JSON Test Suite for BDE table-driven testing.
32///
33/// # Classes {#bdljsn_jsontestsuiteutil-classes}
34///
35/// - bdljsn::JsonTestSuiteUtil: data/types representing the JSON Test Suite
36///
37/// @see bdljsn_jsonutil
38///
39/// # Description {#bdljsn_jsontestsuiteutil-description}
40/// This component provides a utility `struct`,
41/// `bdljsn::JsonTestSuiteUtil`, that encapsulates the JSON Test Suite found at:
42/// https://github.com/nst/JSONTestSuite/tree/master. Note that the test suite
43/// is itself an appendix to the article *Parsing* *JSON* *is* *a* *Minefield*
44/// by Nicolas Seriot (see https://seriot.ch/projects/parsing_json.html).
45///
46/// The test points are constructed from the files found under:
47/// https://github.com/nst/JSONTestSuite/blob/master/test_parsers. The name of
48/// these files indicate whether or not their contents should be accepted or
49/// rejected.
50/// @code
51/// +--------+-------+----------------------------------------------+
52/// | Prefix | Count | Expected Result |
53/// +--------+-------+----------------------------------------------+
54/// | 'y_' | 95 | content must be accepted by parsers |
55/// | 'n_' | 188 | content must be rejected by parsers |
56/// | 'i_' | 35 | parsers are free to accept or reject content |
57/// +--------+-------+----------------------------------------------+
58/// @endcode
59/// Note that this component provides one additional `y_` (not counted above),
60/// `y_henry_verschell_smiley_surrogate_smiley.json`, that does not exist in
61/// downloaded test suite.
62///
63/// ## Usage {#bdljsn_jsontestsuiteutil-usage}
64///
65///
66/// This section illustrates intended use of this component.
67///
68/// ### Example 1: Basic Use {#bdljsn_jsontestsuiteutil-example-1-basic-use}
69///
70///
71/// Generally, BDE table-drive testing uses tables defined locally in the test
72/// driver. To conveniently use the table defined in the
73/// @ref bdljsn_jsontestsuiteutil component, some small adaptation to the test
74/// driver is recommended.
75///
76/// First, create aliases for symbols conventionally used in BDE table-driven
77/// tests:
78/// @code
79/// typedef bdljsn::JsonTestSuiteUtil JTSU;
80/// typedef bdljsn::JsonTestSuiteUtil::Expected Expected;
81/// @endcode
82/// Now, use these symbols in a typical table-driven `for`-loop:
83/// @code
84/// for (bsl::size_t ti = 0; ti < JTSU::numData(); ++ti) {
85/// const int LINE = JTSU::data(ti)->d_line;
86/// const char *const TEST_NAME = JTSU::data(ti)->d_testName_p;
87/// const char *const JSON = JTSU::data(ti)->d_JSON_p;
88/// const bsl::size_t LENGTH = JTSU::data(ti)->d_length;
89/// const Expected EXPECTED = JTSU::data(ti)->d_expected;
90///
91/// if (veryVerbose) {
92/// P_(ti) P_(LINE) P_(LENGTH) P(EXPECTED)
93/// P(TEST_NAME);
94/// P(JSON)
95/// }
96///
97/// // testing code...
98/// }
99/// @endcode
100/// @}
101/** @} */
102/** @} */
103
104/** @addtogroup bdl
105 * @{
106 */
107/** @addtogroup bdljsn
108 * @{
109 */
110/** @addtogroup bdljsn_jsontestsuiteutil
111 * @{
112 */
113
114#include <bsl_cstddef.h> // 'bsl::size_t'
115
116
117namespace bdljsn {
118
119 // ========================
120 // struct JsonTestSuiteUtil
121 // ========================
122
123/// This utility `struct` provides a namespace for the test points of the
124/// *JSON* *Test* *Suite*.
126
127 public:
128 // TYPES
129 enum Expected {
130 e_EITHER = -1
133 };
134
135 /// This aggregate type describes a test-point of the *JSON* *Test*
136 /// *Suite*.
137 struct Datum {
138
140 const char *d_testName_p; // name of the JSON test file
141 const char *d_JSON_p; // contents of the JSON test file
142 bsl::size_t d_length; // length of the 'd_JSON_p' contents
143 Expected d_expected; // accept/reject/either
144 };
145
146 private:
147 // CLASS DATA
148 static Datum s_data[]; // 'y_'/'n_'/'i_' test points
149 static const bsl::size_t s_numData; // number of test points
150
151 public:
152 // CLASS METHODS
153
154 /// Return the test-point `Datum` for the specified `index`. The
155 /// behavior is undefined unless `0 <= index < numData()`.
156 static const Datum *data(bsl::size_t index);
157
158 /// Return the number of test points in the *JSON* *Test* *Suite*.
159 static bsl::size_t numData();
160};
161
162} // close package namespace
163
164
165#endif
166
167// ----------------------------------------------------------------------------
168// Copyright 2023 Bloomberg Finance L.P.
169//
170// Licensed under the Apache License, Version 2.0 (the "License");
171// you may not use this file except in compliance with the License.
172// You may obtain a copy of the License at
173//
174// http://www.apache.org/licenses/LICENSE-2.0
175//
176// Unless required by applicable law or agreed to in writing, software
177// distributed under the License is distributed on an "AS IS" BASIS,
178// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
179// See the License for the specific language governing permissions and
180// limitations under the License.
181// ----------------------------- END-OF-FILE ----------------------------------
182
183/** @} */
184/** @} */
185/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdljsn_error.h:143
Definition bdljsn_jsontestsuiteutil.h:137
Expected d_expected
Definition bdljsn_jsontestsuiteutil.h:143
int d_line
Definition bdljsn_jsontestsuiteutil.h:139
const char * d_testName_p
Definition bdljsn_jsontestsuiteutil.h:140
bsl::size_t d_length
Definition bdljsn_jsontestsuiteutil.h:142
const char * d_JSON_p
Definition bdljsn_jsontestsuiteutil.h:141
Definition bdljsn_jsontestsuiteutil.h:125
static const Datum * data(bsl::size_t index)
static bsl::size_t numData()
Return the number of test points in the JSON Test Suite.
Expected
Definition bdljsn_jsontestsuiteutil.h:129
@ e_ACCEPT
Definition bdljsn_jsontestsuiteutil.h:132
@ e_REJECT
Definition bdljsn_jsontestsuiteutil.h:131
@ e_EITHER
Definition bdljsn_jsontestsuiteutil.h:130