BDE 4.14.0 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 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/// if (testStatus >= 0 && testStatus <= 100) ++testStatus;
111/// }
112/// }
113/// @endcode
114/// Next, we define the standard print and `LOOP_ASSERT` macros, as aliases to
115/// the macros defined by this component:
116/// @code
117/// //=========================================================================
118/// // STANDARD BDE TEST DRIVER MACROS
119/// //-------------------------------------------------------------------------
120///
121/// #define ASSERT BDLS_TESTUTIL_ASSERT
122/// #define LOOP_ASSERT BDLS_TESTUTIL_LOOP_ASSERT
123/// #define LOOP0_ASSERT BDLS_TESTUTIL_LOOP0_ASSERT
124/// #define LOOP1_ASSERT BDLS_TESTUTIL_LOOP1_ASSERT
125/// #define LOOP2_ASSERT BDLS_TESTUTIL_LOOP2_ASSERT
126/// #define LOOP3_ASSERT BDLS_TESTUTIL_LOOP3_ASSERT
127/// #define LOOP4_ASSERT BDLS_TESTUTIL_LOOP4_ASSERT
128/// #define LOOP5_ASSERT BDLS_TESTUTIL_LOOP5_ASSERT
129/// #define LOOP6_ASSERT BDLS_TESTUTIL_LOOP6_ASSERT
130/// #define ASSERTV BDLS_TESTUTIL_ASSERTV
131///
132/// #define Q BDLS_TESTUTIL_Q // Quote identifier literally.
133/// #define P BDLS_TESTUTIL_P // Print identifier and value.
134/// #define P_ BDLS_TESTUTIL_P_ // P(X) without '\n'.
135/// #define T_ BDLS_TESTUTIL_T_ // Print a tab (w/o newline).
136/// #define L_ BDLS_TESTUTIL_L_ // current Line number
137/// @endcode
138/// Now, using the (standard) abbreviated macro names we have just defined, we
139/// write a test function for the `static` `fortyTwo` method, to be called from
140/// a test case in a test driver.
141/// @code
142/// void testFortyTwo(bool verbose)
143/// {
144/// const int value = bdlabc::BdlExampleUtil::fortyTwo();
145/// if (verbose) P(value);
146/// LOOP_ASSERT(value, 42 == value);
147/// }
148/// @endcode
149/// Finally, when `testFortyTwo` is called from a test case in verbose mode we
150/// observe the console output:
151/// @code
152/// value = 42
153/// @endcode
154///
155/// ### Example 2: Print the Value of a Test Type {#bdls_testutil-example-2-print-the-value-of-a-test-type}
156///
157///
158/// Suppose we want to print the value of an object of a test type defined the
159/// `bsltf` package using `bsl::cout`. This component supplies the necessary
160/// overloads of the insertion operator for this to be done directly.
161///
162/// First, include the header of this component:
163/// @code
164/// #include <bdls_testutil.h>
165/// @endcode
166/// Now, we construct a `SimpleTestType` object and stream its value to
167/// `bsl::cout` using the `<<` operator:
168/// @code
169/// bsltf::SimpleTestType a(10);
170/// bsl::cout << a;
171/// @endcode
172/// Finally, we observe the following console output:
173/// @code
174/// 10
175/// @endcode
176/// @}
177/** @} */
178/** @} */
179
180/** @addtogroup bdl
181 * @{
182 */
183/** @addtogroup bdls
184 * @{
185 */
186/** @addtogroup bdls_testutil
187 * @{
188 */
189
190#include <bdlscm_version.h>
191
192#include <bslim_testutil.h>
193
194 // =================
195 // Macro Definitions
196 // =================
197
198#define BDLS_TESTUTIL_ASSERT(X) \
199 BSLIM_TESTUTIL_ASSERT(X)
200
201#define BDLS_TESTUTIL_LOOP0_ASSERT \
202 BSLIM_TESTUTIL_ASSERT
203
204#define BDLS_TESTUTIL_LOOP_ASSERT(I,X) \
205 BSLIM_TESTUTIL_LOOP_ASSERT(I,X)
206
207#define BDLS_TESTUTIL_LOOP1_ASSERT \
208 BSLIM_TESTUTIL_LOOP_ASSERT
209
210#define BDLS_TESTUTIL_LOOP2_ASSERT(I,J,X) \
211 BSLIM_TESTUTIL_LOOP2_ASSERT(I,J,X)
212
213#define BDLS_TESTUTIL_LOOP3_ASSERT(I,J,K,X) \
214 BSLIM_TESTUTIL_LOOP3_ASSERT(I,J,K,X)
215
216#define BDLS_TESTUTIL_LOOP4_ASSERT(I,J,K,L,X) \
217 BSLIM_TESTUTIL_LOOP4_ASSERT(I,J,K,L,X)
218
219#define BDLS_TESTUTIL_LOOP5_ASSERT(I,J,K,L,M,X) \
220 BSLIM_TESTUTIL_LOOP5_ASSERT(I,J,K,L,M,X)
221
222#define BDLS_TESTUTIL_LOOP6_ASSERT(I,J,K,L,M,N,X) \
223 BSLIM_TESTUTIL_LOOP6_ASSERT(I,J,K,L,M,N,X)
224
225#define BDLS_TESTUTIL_ASSERTV \
226 BSLIM_TESTUTIL_ASSERTV
227
228#define BDLS_TESTUTIL_Q(X) \
229 BSLIM_TESTUTIL_Q(X)
230
231#define BDLS_TESTUTIL_P(X) \
232 BSLIM_TESTUTIL_P(X)
233
234#define BDLS_TESTUTIL_P_(X) \
235 BSLIM_TESTUTIL_P_(X)
236
237#define BDLS_TESTUTIL_L_ \
238 BSLIM_TESTUTIL_L_
239
240#define BDLS_TESTUTIL_T_ \
241 BSLIM_TESTUTIL_T_
242
243#endif
244
245// ----------------------------------------------------------------------------
246// Copyright 2012 Bloomberg Finance L.P.
247//
248// Licensed under the Apache License, Version 2.0 (the "License");
249// you may not use this file except in compliance with the License.
250// You may obtain a copy of the License at
251//
252// http://www.apache.org/licenses/LICENSE-2.0
253//
254// Unless required by applicable law or agreed to in writing, software
255// distributed under the License is distributed on an "AS IS" BASIS,
256// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
257// See the License for the specific language governing permissions and
258// limitations under the License.
259// ----------------------------- END-OF-FILE ----------------------------------
260
261/** @} */
262/** @} */
263/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195