BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdls_testutil.h
Go to the documentation of this file.
1/// @file bdls_testutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdls_testutil.h -*-C++-*-
8#ifndef INCLUDED_BDLS_TESTUTIL
9#define INCLUDED_BDLS_TESTUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdls_testutil bdls_testutil
15/// @brief <span style="color: var(--deprecated-color-dark)">DEPRECATED:</span> Provide test utilities for components in `bdl` and above.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdls
19/// @{
20/// @addtogroup bdls_testutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdls_testutil-purpose"> Purpose</a>
25/// * <a href="#bdls_testutil-macros"> Macros </a>
26/// * <a href="#bdls_testutil-description"> Description </a>
27/// * <a href="#bdls_testutil-usage"> Usage </a>
28/// * <a href="#bdls_testutil-example-1-writing-a-test-driver"> Example 1: Writing a Test Driver </a>
29/// * <a href="#bdls_testutil-example-2-print-the-value-of-a-test-type"> Example 2: Print the Value of a Test Type </a>
30///
31/// # Purpose {#bdls_testutil-purpose}
32/// Provide test utilities for components in `bdl` and above.
33///
34/// @deprecated Use @ref bslim_testutil instead.
35///
36/// # Macros {#bdls_testutil-macros}
37///
38/// - BDLS_TESTUTIL_ASSERT(X): record and print error if `!X`
39/// - BDLS_TESTUTIL_LOOP_ASSERT(I, X): print args if `!X`
40/// - BDLS_TESTUTIL_LOOP2_ASSERT(I, J, X): print args if `!X`
41/// - BDLS_TESTUTIL_LOOP3_ASSERT(I, J, K, X): print args if `!X`
42/// - BDLS_TESTUTIL_LOOP4_ASSERT(I, J, K, L, X): print args if `!X`
43/// - BDLS_TESTUTIL_LOOP5_ASSERT(I, J, K, L, M, X): print args if `!X`
44/// - BDLS_TESTUTIL_LOOP6_ASSERT(I, J, K, L, M, N, X): print args if `!X`
45/// - BDLS_TESTUTIL_ASSERTV(..., X): generic print args if `!X`
46/// - BDLS_TESTUTIL_Q(X): quote identifier literally
47/// - BDLS_TESTUTIL_P(X): print identifier and value
48/// - BDLS_TESTUTIL_P_(X): print identifier and value without '\n'
49/// - BDLS_TESTUTIL_L_: current line number
50/// - BDLS_TESTUTIL_T_: print tab without '\n'
51///
52/// @see bslim_testutil
53///
54/// # Description {#bdls_testutil-description}
55/// This component provides the standard print macros used in
56/// BDE-style test drivers (`ASSERT`, `LOOP_ASSERT`, `ASSERTV`, `P`, `Q`, `L`,
57/// and `T`) for components in the `bdl` package group and above.
58///
59/// This component also define a set of overloads for the insertion operator
60/// (`<<`) to support the streaming of test types defined in the `bsltf`
61/// package. This is required for test drivers in the `bdl` package group and
62/// above to print the objects of these types to `bsl::cout`.
63///
64/// Note that the `bsltf` package resides below `bsl+bslhdrs`, in which
65/// `bsl::cout` is defined; therefore, the components in `bsltf` cannot
66/// directly define the overloads of the insertion operator to support printing
67/// the test types. Instead, an alternate method supplied in @ref bsls_bsltestutil
68/// is used for test drivers in the `bsl` package group.
69///
70/// ## Usage {#bdls_testutil-usage}
71///
72///
73/// This section illustrates intended use of this component.
74///
75/// ### Example 1: Writing a Test Driver {#bdls_testutil-example-1-writing-a-test-driver}
76///
77///
78/// First, we write a component to test, which provides a utility class:
79/// @code
80/// namespace bdlabc {
81///
82/// /// This utility class provides sample functionality to demonstrate how
83/// /// a test driver might be written validating its only method.
84/// struct BdlExampleUtil {
85///
86/// /// Return the integer value `42`.
87/// static int fortyTwo();
88/// };
89///
90/// inline
91/// int BdlExampleUtil::fortyTwo()
92/// {
93/// return 42;
94/// }
95///
96/// } // close package namespace
97/// @endcode
98/// Then, we can write a test driver for this component. We start by providing
99/// the standard BDE assert test macro:
100/// @code
101/// //=========================================================================
102/// // STANDARD BDE ASSERT TEST MACRO
103/// //-------------------------------------------------------------------------
104/// static int testStatus = 0;
105///
106/// static void aSsErT(bool b, const char *s, int i)
107/// {
108/// if (b) {
109/// printf("Error " __FILE__ "(%d): %s (failed)\n", i, s);
110/// fflush(stdout);
111/// if (testStatus >= 0 && testStatus <= 100) ++testStatus;
112/// }
113/// }
114/// @endcode
115/// Next, we define the standard print and `LOOP_ASSERT` macros, as aliases to
116/// the macros defined by this component:
117/// @code
118/// //=========================================================================
119/// // STANDARD BDE TEST DRIVER MACROS
120/// //-------------------------------------------------------------------------
121///
122/// #define ASSERT BDLS_TESTUTIL_ASSERT
123/// #define LOOP_ASSERT BDLS_TESTUTIL_LOOP_ASSERT
124/// #define LOOP0_ASSERT BDLS_TESTUTIL_LOOP0_ASSERT
125/// #define LOOP1_ASSERT BDLS_TESTUTIL_LOOP1_ASSERT
126/// #define LOOP2_ASSERT BDLS_TESTUTIL_LOOP2_ASSERT
127/// #define LOOP3_ASSERT BDLS_TESTUTIL_LOOP3_ASSERT
128/// #define LOOP4_ASSERT BDLS_TESTUTIL_LOOP4_ASSERT
129/// #define LOOP5_ASSERT BDLS_TESTUTIL_LOOP5_ASSERT
130/// #define LOOP6_ASSERT BDLS_TESTUTIL_LOOP6_ASSERT
131/// #define ASSERTV BDLS_TESTUTIL_ASSERTV
132///
133/// #define Q BDLS_TESTUTIL_Q // Quote identifier literally.
134/// #define P BDLS_TESTUTIL_P // Print identifier and value.
135/// #define P_ BDLS_TESTUTIL_P_ // P(X) without '\n'.
136/// #define T_ BDLS_TESTUTIL_T_ // Print a tab (w/o newline).
137/// #define L_ BDLS_TESTUTIL_L_ // current Line number
138/// @endcode
139/// Now, using the (standard) abbreviated macro names we have just defined, we
140/// write a test function for the `static` `fortyTwo` method, to be called from
141/// a test case in a test driver.
142/// @code
143/// void testFortyTwo(bool verbose)
144/// {
145/// const int value = bdlabc::BdlExampleUtil::fortyTwo();
146/// if (verbose) P(value);
147/// LOOP_ASSERT(value, 42 == value);
148/// }
149/// @endcode
150/// Finally, when `testFortyTwo` is called from a test case in verbose mode we
151/// observe the console output:
152/// @code
153/// value = 42
154/// @endcode
155///
156/// ### Example 2: Print the Value of a Test Type {#bdls_testutil-example-2-print-the-value-of-a-test-type}
157///
158///
159/// Suppose we want to print the value of an object of a test type defined the
160/// `bsltf` package using `bsl::cout`. This component supplies the necessary
161/// overloads of the insertion operator for this to be done directly.
162///
163/// First, include the header of this component:
164/// @code
165/// #include <bdls_testutil.h>
166/// @endcode
167/// Now, we construct a `SimpleTestType` object and stream its value to
168/// `bsl::cout` using the `<<` operator:
169/// @code
170/// bsltf::SimpleTestType a(10);
171/// bsl::cout << a;
172/// @endcode
173/// Finally, we observe the following console output:
174/// @code
175/// 10
176/// @endcode
177/// @}
178/** @} */
179/** @} */
180
181/** @addtogroup bdl
182 * @{
183 */
184/** @addtogroup bdls
185 * @{
186 */
187/** @addtogroup bdls_testutil
188 * @{
189 */
190
191#include <bdlscm_version.h>
192
193#include <bslim_testutil.h>
194
195 // =================
196 // Macro Definitions
197 // =================
198
199#define BDLS_TESTUTIL_ASSERT(X) \
200 BSLIM_TESTUTIL_ASSERT(X)
201
202#define BDLS_TESTUTIL_LOOP0_ASSERT \
203 BSLIM_TESTUTIL_ASSERT
204
205#define BDLS_TESTUTIL_LOOP_ASSERT(I,X) \
206 BSLIM_TESTUTIL_LOOP_ASSERT(I,X)
207
208#define BDLS_TESTUTIL_LOOP1_ASSERT \
209 BSLIM_TESTUTIL_LOOP_ASSERT
210
211#define BDLS_TESTUTIL_LOOP2_ASSERT(I,J,X) \
212 BSLIM_TESTUTIL_LOOP2_ASSERT(I,J,X)
213
214#define BDLS_TESTUTIL_LOOP3_ASSERT(I,J,K,X) \
215 BSLIM_TESTUTIL_LOOP3_ASSERT(I,J,K,X)
216
217#define BDLS_TESTUTIL_LOOP4_ASSERT(I,J,K,L,X) \
218 BSLIM_TESTUTIL_LOOP4_ASSERT(I,J,K,L,X)
219
220#define BDLS_TESTUTIL_LOOP5_ASSERT(I,J,K,L,M,X) \
221 BSLIM_TESTUTIL_LOOP5_ASSERT(I,J,K,L,M,X)
222
223#define BDLS_TESTUTIL_LOOP6_ASSERT(I,J,K,L,M,N,X) \
224 BSLIM_TESTUTIL_LOOP6_ASSERT(I,J,K,L,M,N,X)
225
226#define BDLS_TESTUTIL_ASSERTV \
227 BSLIM_TESTUTIL_ASSERTV
228
229#define BDLS_TESTUTIL_Q(X) \
230 BSLIM_TESTUTIL_Q(X)
231
232#define BDLS_TESTUTIL_P(X) \
233 BSLIM_TESTUTIL_P(X)
234
235#define BDLS_TESTUTIL_P_(X) \
236 BSLIM_TESTUTIL_P_(X)
237
238#define BDLS_TESTUTIL_L_ \
239 BSLIM_TESTUTIL_L_
240
241#define BDLS_TESTUTIL_T_ \
242 BSLIM_TESTUTIL_T_
243
244#endif
245
246// ----------------------------------------------------------------------------
247// Copyright 2012 Bloomberg Finance L.P.
248//
249// Licensed under the Apache License, Version 2.0 (the "License");
250// you may not use this file except in compliance with the License.
251// You may obtain a copy of the License at
252//
253// http://www.apache.org/licenses/LICENSE-2.0
254//
255// Unless required by applicable law or agreed to in writing, software
256// distributed under the License is distributed on an "AS IS" BASIS,
257// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
258// See the License for the specific language governing permissions and
259// limitations under the License.
260// ----------------------------- END-OF-FILE ----------------------------------
261
262/** @} */
263/** @} */
264/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238