BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bsltf_templatetestfacility.h
Go to the documentation of this file.
1/// @file bsltf_templatetestfacility.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bsltf_templatetestfacility.h -*-C++-*-
8#ifndef INCLUDED_BSLTF_TEMPLATETESTFACILITY
9#define INCLUDED_BSLTF_TEMPLATETESTFACILITY
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bsltf_templatetestfacility bsltf_templatetestfacility
15/// @brief Provide utilities to help with testing templates.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bsltf
19/// @{
20/// @addtogroup bsltf_templatetestfacility
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bsltf_templatetestfacility-purpose"> Purpose</a>
25/// * <a href="#bsltf_templatetestfacility-classes"> Classes </a>
26/// * <a href="#bsltf_templatetestfacility-macros"> Macros </a>
27/// * <a href="#bsltf_templatetestfacility-description"> Description </a>
28/// * <a href="#bsltf_templatetestfacility-templatetestfacility"> TemplateTestFacility </a>
29/// * <a href="#bsltf_templatetestfacility-macros-and-test-types"> Macros and Test Types </a>
30/// * <a href="#bsltf_templatetestfacility-usage"> Usage </a>
31/// * <a href="#bsltf_templatetestfacility-example-1-using-the-bsltf_templatetestfacility_run_each_type-macro"> Example 1: Using the BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE Macro </a>
32/// * <a href="#bsltf_templatetestfacility-example-2-writing-a-type-independent-test-driver"> Example 2: Writing a Type Independent Test Driver </a>
33///
34/// # Purpose {#bsltf_templatetestfacility-purpose}
35/// Provide utilities to help with testing templates.
36///
37/// # Classes {#bsltf_templatetestfacility-classes}
38///
39/// - bsltf::TemplateTestFacility: namespace for template-testing utilities
40///
41/// # Macros {#bsltf_templatetestfacility-macros}
42///
43/// - BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE(CLASS, METHOD, TYPE...): run all
44/// - BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_PRIMITIVE: list of primitive types
45/// - BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_USER_DEFINED: list user types
46/// - BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_REGULAR: list of typical types
47/// - BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_AWKWARD: list of atypical types
48/// - BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_ALL: list all `bslmf` types
49///
50/// @see bsltf_simpletesttype, bslstl_map
51///
52/// # Description {#bsltf_templatetestfacility-description}
53/// When testing a container template having a type parameter, we
54/// need to ensure that the template supports its contractually specified
55/// categories of parameter types. The `bsltf` package provides a
56/// representative set of types intended for testing that can be used as
57/// template parameters for doing this kind of verification.
58///
59/// Creating a separate test for each category of types supported by a template
60/// would be cumbersome. Instead, writing a single templatized test is usually
61/// preferable. Unfortunately, different types often require different syntaxes
62/// for constructing an object and getting an object's value. This
63/// inconsistency makes writing generic code rather difficult.
64///
65/// This component provides a solution with a utility `struct`,
66/// `TemplateTestFacility`, that defines two class method templates, `create`
67/// and `getIdentifier`, that respectively have consistent syntaxes for creating
68/// objects and getting a integer value representing the state of objects of a
69/// parameterized type.
70///
71/// This component also provides a macro,
72/// `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE`, that serves as a convenient way
73/// to instantiate and invoke a template (for testing) having a type parameter
74/// for a specified list of types. In addition, this component provides a set
75/// of macros referring to commonly useful lists of types intended for testing
76/// that can be used as arguments to `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE`.
77///
78/// The utilities and macros provided by this component, along with the types
79/// defined in the `bsltf` package, are explained in more detail in the
80/// following sections.
81///
82/// ## TemplateTestFacility {#bsltf_templatetestfacility-templatetestfacility}
83///
84///
85/// The `TemplateTestFacility` `struct` provides the following static (class)
86/// method templates to construct objects and get the states of objects of a
87/// supported parameterized type (supported types are those types intended for
88/// testing defined in the `bsltf` package):
89///
90/// * `create`: Return an object of the parameterized `TYPE` whose value is
91/// uniquely associated with a specified integer identifier.
92///
93/// * `getIdentifier`: Return the integer identifier used to create a specified
94/// object of the parameterized `TYPE`.
95///
96/// ## Macros and Test Types {#bsltf_templatetestfacility-macros-and-test-types}
97///
98///
99/// The `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE` macro instantiates a
100/// specified class template for a specified list of types and call a specified
101/// class method of each instantiation. The macro takes in arguments in the
102/// following order:
103///
104/// * The name of the class template to be instantiated
105/// * The name of the class method to be invoked
106/// * The names of the types for which the class template will be instantiated
107/// (up to 20)
108///
109/// This component also defines a set of macros, each providing a list of types,
110/// that can be used as the last argument to
111/// `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE`. The following is a brief
112/// synopsis of these macros (note that all macros names have the
113/// `BSLTF_TEMPLATETESTFACILITY_` prefix, which is omitted for layout
114/// efficiency):
115///
116/// * `TEST_TYPES_PRIMITIVE`: list of primitive types
117/// * `TEST_TYPES_USER_DEFINED`: list of user-defined types
118/// * `TEST_TYPES_REGULAR`: list of typically used types
119/// * `TEST_TYPES_AWKWARD`: list of types with odd behaviors
120/// * `TEST_TYPES_ALL`: list of all of the types
121///
122/// The `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_PRIMITIVE` macro refers to a
123/// representative set of primitive types that are useful for testing:
124/// @code
125/// Type Description
126/// ---- -----------
127/// signed char signed character
128///
129/// size_t signed integral type
130///
131/// TemplateTestFacility::ObjectPtr pointer to an object
132///
133/// TemplateTestFacility::FunctionPtr pointer to a function
134///
135/// TemplateTestFacility::MethodPtr pointer to a method
136/// @endcode
137/// The `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_USER_DEFINED` macro refers to a
138/// representative set of user-defined types that are useful for testing (note
139/// that all types described here belong to the `bsltf` namespace, which is not
140/// explicitly qualified for layout efficiency):
141/// @code
142/// Type Description
143/// ---- -----------
144/// EnumeratedTestType::Enum an enumeration
145///
146/// UnionTestType a union
147///
148/// SimpleTestType class with no special traits defined
149///
150/// AllocTestType class that allocates memory, defines
151/// the 'bslma::UsesBslmaAllocator'
152/// trait, and ensures it is not bitwise
153/// moved
154///
155/// NonOptionalAllocTestType class that allocates memory, defines
156/// the 'bslma::UsesBslmaAllocator'
157/// trait, ensures it is not bitwise
158/// moved, and does not have default ctor.
159///
160/// MovableTestType class that has both move and copy
161/// semantics, and ensures it is not
162/// bitwise moved
163///
164/// MovableAllocTestType class that has both move and copy
165/// semantics, allocates memory, defines
166/// the 'bslma::UsesBslmaAllocator'
167/// trait, and ensures it is not bitwise
168/// moved
169///
170/// MoveOnlyAllocTestType class that has only move semantics,
171/// allocates memory, defines the
172/// 'bslma::UsesBslmaAllocator'
173/// trait, and ensures it is not bitwise
174/// moved
175///
176/// BitwiseCopyableTestType class that is bitwise-copyable and
177/// defines the
178/// 'bsl::is_trivially_copyable'
179/// trait
180///
181/// BitwiseMoveableTestType class that is bitwise-moveable and
182/// defines the
183/// 'bslmf::IsBitwiseMoveable'
184/// trait
185///
186/// AllocatingBitwiseMoveableTestType class that allocates memory, is
187/// bitwisemoveable, and defines the
188/// 'bslma::UsesBslmaAllocator'
189/// and 'bslmf::IsBitwiseMoveable'
190/// traits
191///
192/// NonTypicalOverloadsTestType class that defines and assert on
193/// invocation of certain
194/// non-typically-overloaded operators
195/// ('operator new', 'operator delete',
196/// 'operator&') to ensure that they are
197/// not called
198///
199/// EmplacableTestType class that takes <= 14 non-allocating
200/// arguments and is used to ensure that
201/// arguments are forwarded correctly
202/// from functions and methods taking
203/// variable number of arguments and their
204/// analagous in C++03 environments.
205///
206/// AllocEmplacableTestType class that takes up to 14 allocating
207/// arguments and is used to ensure that
208/// arguments are forwarded correctly
209/// from functions and methods taking
210/// variable number of arguments and their
211/// analagous in C++03 environments.
212/// @endcode
213///
214/// The `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_REGULAR` macro refers to the
215/// union of the types provided by
216/// `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_PRIMITIVE` and
217/// `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_USER_DEFINED`. These types are
218/// designed to work within the regular operating conditions of a typical
219/// template. Typically, a test driver for a template instantiates its tests
220/// (using the `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE` macro) for all of the
221/// types referred by `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_REGULAR`.
222///
223/// The `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_AWKWARD` macro refers to a set of
224/// types that have certain attributes that make them unlikely to work for all
225/// of the operations of a template. Typically, not all methods of a template
226/// are instantiable with these types, so these types are most often used
227/// independently in tests explicitly designed for a (single) type.
228/// @code
229/// Type Description
230/// ---- -----------
231/// NonAssignableTestType class having no assignment operator
232///
233/// NonCopyConstructibleTestType class having no copy constructor (Note
234/// that this class can not be created with
235/// 'TemplateTestFacility::create' because
236/// the class method returns the newly
237/// constructed object by value.)
238///
239/// NonDefaultConstructibleTestType class having no default constructor
240///
241/// NonEqualComparableTestType class having no equality-comparison
242/// operators
243/// @endcode
244/// The `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_ALL` refers to all the test types
245/// provided in the `bsltf` package.
246///
247/// ## Usage {#bsltf_templatetestfacility-usage}
248///
249///
250/// This section illustrates intended use of this component.
251///
252/// ### Example 1: Using the BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE Macro {#bsltf_templatetestfacility-example-1-using-the-bsltf_templatetestfacility_run_each_type-macro}
253///
254///
255/// In this example, we demonstrate how to use
256/// `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE` to call a class method of a
257/// template for a list of types.
258///
259/// First, we define a `struct` template `TestTemplate` taking in a
260/// parameterized `TYPE` that has a class method, `printTypeName`:
261/// @code
262/// template <class TYPE>
263/// struct TestTemplate {
264/// // This 'struct' provides a namespace for a simple test method.
265///
266/// // CLASS METHODS
267/// static void printTypeName();
268/// // Prints the name of the parameterized 'TYPE' to the console.
269/// };
270///
271/// template <>
272/// void TestTemplate<int>::printTypeName()
273/// {
274/// printf("int\n");
275/// }
276///
277/// template <>
278/// void TestTemplate<char>::printTypeName()
279/// {
280/// printf("char\n");
281/// }
282///
283/// template <>
284/// void TestTemplate<double>::printTypeName()
285/// {
286/// printf("double\n");
287/// }
288/// @endcode
289/// Now, we can instantiate the `TestTemplate` class for each of the types
290/// `int`, `char`, and `double`, and call the `printTypeName` class method of
291/// each instantiation using the `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE`
292/// macro:
293/// @code
294/// BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE(TestTemplate,
295/// printTypeName,
296/// int, char, double);
297/// @endcode
298/// Finally, we observe the console output:
299/// @code
300/// int
301/// char
302/// double
303/// @endcode
304///
305/// ### Example 2: Writing a Type Independent Test Driver {#bsltf_templatetestfacility-example-2-writing-a-type-independent-test-driver}
306///
307///
308/// In this example, we demonstrate using the `TemplateTestFacility` `struct`
309/// and the macros provided by this component to test the default constructor
310/// and primary manipulator of a class template in the context of a typical
311/// BDE-style test driver. Note that a goal of the demonstrated test is to
312/// validate the class template with a broad range of types emulating those with
313/// which the template might be instantiated.
314///
315/// First, we define a simple class template, `MyNullableValue`, that we will
316/// later need to test:
317/// @code
318/// template <class TYPE>
319/// class MyNullableValue {
320/// // This (value-semantic) class template extends the parameterized
321/// // 'TYPE' to include the notion of a "null" value.
322///
323/// // DATA
324/// TYPE d_value; // non-null value
325/// bool d_nullFlag; // flag to indicate if the value is null
326///
327/// public:
328/// MyNullableValue()
329/// // Create a 'MyNullableValue' that initially has a value of null.
330/// : d_nullFlag(true)
331/// {
332/// }
333///
334/// bool isNull() const
335/// // Return 'true' if this object is null, and 'false' otherwise.
336/// {
337/// return d_nullFlag;
338/// }
339///
340/// void makeNull()
341/// // Set this object to the null value.
342/// {
343/// d_nullFlag = true;
344/// }
345///
346/// const TYPE& value() const {
347/// // Return a reference providing non-modifiable access to the
348/// // underlying object of the parameterized 'TYPE'. The behavior is
349/// // undefined if the object is null.
350/// return d_value;
351/// }
352///
353/// void makeValue(const TYPE& value)
354/// // Set the value of this object to be that of the specified 'value'
355/// // of the parameterized 'TYPE'.
356/// {
357/// d_nullFlag = false;
358/// d_value = value;
359/// }
360/// };
361/// @endcode
362/// Then, we define some aliases for the micros that will be used by the test
363/// driver:
364/// @code
365/// #define RUN_EACH_TYPE BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE
366/// #define TEST_TYPES_REGULAR BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_REGULAR
367/// @endcode
368/// Next, we define a `struct` template, `MyTestDriver`, that provides a
369/// namespace containing the test cases (here, only `testCase2` is defined for
370/// brevity) of the test driver:
371/// @code
372/// template <class TYPE>
373/// struct MyTestDriver {
374/// // This 'struct' provides a namespace for the class methods used to
375/// // implement the test driver.
376///
377/// // TYPES
378/// typedef MyNullableValue<TYPE> Obj;
379/// // This 'typedef' provides an alias to the type under testing.
380///
381/// static void testCase2();
382/// // Test primary manipulators.
383/// };
384/// @endcode
385/// Now, we define the implementation of `MyTestDriver::testCase2`:
386/// @code
387/// template <class TYPE>
388/// void MyTestDriver<TYPE>::testCase2()
389/// {
390/// // --------------------------------------------------------------------
391/// // DEFAULT CTOR, PRIMARY MANIPULATORS, AND DTOR
392/// // Ensure that we can use the default constructor to create an
393/// // object (having the default-constructed value), use the primary
394/// // manipulators to put that object into any state relevant for
395/// // thorough testing, and use the destructor to destroy it safely.
396/// //
397/// // Concerns:
398/// //: 1 An object created using the default constructor (with or without
399/// //: a supplied allocator) has the contractually specified value.
400/// //:
401/// //: 2 The 'makeValue' method sets the value of a object to any
402/// //: specified value.
403/// //:
404/// //: 3 The 'makeNull' method set the value of a object to null.
405/// //:
406/// //: 4 Objects of different values can coexist.
407/// //:
408/// //: 5 The destructor does not modify other objects.
409/// //
410/// // Plan:
411/// //: 1 Default-construct an object and use the (as yet unproven) salient
412/// //: attribute accessors to verify that the value of the object is the
413/// //: null value. (C-1)
414/// //:
415/// //: 2 Default-construct another object, and use the 'makeValue' method,
416/// //: to set the value of the object to a non-null value. Use the (as
417/// //: yet unproven) salient attribute accessors to verify that the new
418/// //: object has the expected value and the object created in P-1 still
419/// //: has the same value. (C-2, 4)
420/// //:
421/// //: 3 Using the loop-based approach, for each identifier in a range of
422/// //: integer identifiers:
423/// //:
424/// //: 1 Default-construct a modifiable object, 'mL', and use the (as
425/// //: yet unproven) salient attribute accessors to verify the value
426/// //: of the default constructed object is the null value. (C-1)
427/// //:
428/// //: 2 Create an object of the parameterized 'TYPE', 'LV', using the
429/// //: 'TemplateTestFacility::create' class method template,
430/// //: specifying the integer loop identifier.
431/// //:
432/// //: 3 Use the 'makeValue' method to set the value of 'mL' to 'LV'.
433/// //: Use the (as yet unproven) salient attribute accessors to verify
434/// //: 'mL' has the expected value. (C-2)
435/// //:
436/// //: 4 Invoke the 'makeNull' method of 'mL'. Use the attribute
437/// //: accessors to verify the value of the object is now null. (C-3)
438/// //:
439/// //: 4 Create an object in a nested block. Below the block, verify the
440/// //: objects created in P-1 and P-2 still have the same value. (C-5)
441/// //
442/// // Testing:
443/// // MyNullableValue();
444/// // ~MyNullableValue();
445/// // void makeNull();
446/// // void MakeValue(const TYPE& value);
447/// // --------------------------------------------------------------------
448///
449/// if (verbose)
450/// printf("\nDEFAULT CTOR, PRIMARY MANIPULATORS, AND DTOR"
451/// "\n============================================\n");
452///
453///
454/// if (verbose) printf("\nTesting default constructor.\n");
455///
456/// Obj mW; const Obj& W = mW;
457/// assert(true == W.isNull());
458///
459/// Obj mX; const Obj& X = mX;
460/// const TYPE XV = TemplateTestFacility::create<TYPE>(1);
461/// mX.makeValue(XV);
462/// assert(1 == TemplateTestFacility::getIdentifier<TYPE>(X.value()));
463///
464/// if (verbose) printf("\nTesting primary manipulators.\n");
465///
466/// for (size_t ti = 0; ti < 10; ++ti) {
467///
468/// if (veryVerbose) { T_ P(ti) }
469///
470/// Obj mL; const Obj& L = mL;
471/// assert(true == L.isNull());
472///
473/// const TYPE LV = TemplateTestFacility::create<TYPE>(ti);
474///
475/// mL.makeValue(LV);
476/// assert(false == L.isNull());
477/// assert(LV == L.value());
478///
479/// mL.makeNull();
480/// assert(true == L.isNull());
481/// }
482///
483/// if (verbose) printf("\nTesting destructor.\n");
484/// {
485/// Obj Z;
486/// }
487///
488/// assert(true == W.isNull());
489/// assert(XV == X.value());
490/// }
491/// @endcode
492/// Notice that, we create objects of the parameterized `TYPE` using the
493/// `TemplateTestFacility::create` class method template specifying an integer
494/// identifier; the created object has a value that is uniquely associated with
495/// the integer identifier.
496///
497/// Also notice that we verified that an object of the parameterized `TYPE` has
498/// the expected value in two ways:
499///
500/// 1. By equal comparing (1) the integer identifier returned from calling the
501/// `TemplateTestFacility::getIdentifier` class method template (specifying
502/// the object), and (2) the integer identifier uniquely associated with the
503/// expected state of the object.
504/// 2. By directly using the equality-comparison operator for the parameterized
505/// `TYPE`. Note that the equality-comparison operator is defined for all
506/// types intended for testing in the `bsltf` package except for
507/// `bsltf::NonEqualComparableTestType`.
508///
509/// Finally, we use the `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE` macro to
510/// instantiate `MyTestDriver` for each of the types listed in
511/// `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_REGULAR` and invoke the `testCase2`
512/// class method of each instantiation:
513/// @code
514/// case 2: {
515/// // ----------------------------------------------------------------------
516/// // DEFAULT CTOR & PRIMARY MANIPULATORS
517/// // ----------------------------------------------------------------------
518///
519/// if (verbose) printf("\nDEFAULT CTOR & PRIMARY MANIPULATORS"
520/// "\n===================================\n");
521///
522/// RUN_EACH_TYPE(MyTestDriver, testCase2, TEST_TYPES_REGULAR);
523/// } break;
524/// @endcode
525/// @}
526/** @} */
527/** @} */
528
529/** @addtogroup bsl
530 * @{
531 */
532/** @addtogroup bsltf
533 * @{
534 */
535/** @addtogroup bsltf_templatetestfacility
536 * @{
537 */
538
539#include <bslscm_version.h>
540
543#include <bsltf_alloctesttype.h>
551#include <bsltf_movestate.h>
558#include <bsltf_simpletesttype.h>
560#include <bsltf_uniontesttype.h>
562
566#include <bslma_bslallocator.h>
567
568#include <bslmf_assert.h>
569#include <bslmf_movableref.h>
570
571#include <bsls_assert.h>
572#include <bsls_objectbuffer.h>
573#include <bsls_types.h>
574#include <bsls_util.h>
575
576#include <stddef.h> // for 'size_t'
577#include <stdio.h> // for 'printf'
578
579#include <stdlib.h> // for 'atoi'
580
581
582namespace bsltf {
583
584 // ====================================
585 // class TemplateTestFacility_StubClass
586 // ====================================
587
588/// This class provides a single method template, `method`, that simply returns the parameterized integer `IDENTIFIER`.
589///
590/// \note Note that the purpose
591/// of this class is to serve as a stub class and method to be referred by
592/// `TemplateTestFacility::ObjectPtr` and `TemplateTestFacility::MethodPtr`
593/// respectively.
594///
595/// See @ref bsltf_templatetestfacility
597
598 public:
599 // MANIPULATORS
600
601 /// Return the parameterized `IDENTIFIER`.
602 template <int IDENTIFIER>
603 int method();
604};
605
606 // ========================================
607 // class TemplateTestFacility_CompareHelper
608 // ========================================
609
611 public:
612 // CLASS METHODS
613 template <class TYPE>
614 static bool areEqual(const TYPE& lhs, const TYPE& rhs);
615
616 static bool areEqual(const NonEqualComparableTestType& lhs,
617 const NonEqualComparableTestType& rhs);
618
619 template <class TYPE>
620 static bool areNotEqual(const TYPE& lhs, const TYPE& rhs);
621
622 static bool areNotEqual(const NonEqualComparableTestType& lhs,
623 const NonEqualComparableTestType& rhs);
624};
625
626 // ===========================
627 // struct TemplateTestFacility
628 // ===========================
629
630/// This `struct` provides a namespace that contains three aliases for types
631/// intended to be used as template parameters for testing templates. The
632/// namespace also contain two class method templates, `create` and
633/// `getIdentifier`, that respectively provides a consistent interface to
634/// (1) create a specified object of a parameterized type from an integer
635/// identifier and (2) get the identifier value of a specified object. The
636/// identifier value returned from the `getIdentifier` method is undefined
637/// unless the specified object was originally created with the `create`
638/// class method template.
639///
640/// See @ref bsltf_templatetestfacility
642
643 private:
644 /// Return a pointer to a null-terminated string that will parse as
645 /// having the same value as the specified `identifier`.
646 ///
647 /// \pre The behavior is undefined unless `0 <= identifier < 128`.
648 static const char* nullTerminatedStringForIdentifier(int identifier);
649
650 public:
651 // PUBLIC TYPES
652
653 /// This `typedef` is an alias for a pointer to a
654 /// `TemplateTestFacility_StubClass` object.
656
657 /// This `typedef` is an alias for a pointer to a function pointer.
658 typedef void (*FunctionPtr) ();
659
660 /// This `typedef` is an alias for a pointer to a method of
661 /// `TemplateTestFacility_StubClass` taking no arguments and returning
662 /// an `int`.
664
665 // CLASS METHODS
666
667 /// Return a new object of the parameterized `TYPE` whose state is
668 /// unique for the specified `identifier`.
669 ///
670 /// \pre The behavior is undefined unless `0 <= value < 128` and `TYPE` is contained in the macro
671 /// `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_ALL`.
672 template <class TYPE>
673 static TYPE create(int identifier);
674
675 /// Create an object of the parameterized `TYPE` at the specified
676 /// `address` whose state is unique for the specified `identifier`.
677 ///
678 /// \pre The behavior is undefined unless `0 <= identifier < 128` and `TYPE` is
679 /// contained in the macro `BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_ALL`.
680 template <class TYPE, class ALLOCATOR>
681 static void emplace(TYPE *address, int identifier, ALLOCATOR allocator);
682 template <class TYPE, class ALLOCATOR>
683 static void emplace(TYPE *address, int identifier, ALLOCATOR *allocator);
684
685 /// Create a pointer to the parameterized `TYPE` at the specified
686 /// `address` whose value is unique for the specified `identifier`.
687 ///
688 /// \pre The behavior is undefined unless `0 <= identifier < 128`.
689 /// \note Note that no
690 /// object is created at the address of the returned pointer, nor is it
691 /// guaranteed to be a valid address for an object (or function). Also
692 /// note that the same address may be returned for different allocators,
693 /// and is guaranteed to be unique only with respect to the `identifier`
694 /// value.
695 template <class TYPE, class ALLOCATOR>
696 static void emplace(TYPE **address, int identifier, ALLOCATOR allocator);
697 template <class TYPE, class ALLOCATOR>
698 static void emplace(TYPE **address, int identifier, ALLOCATOR *allocator);
699
700 /// Create at the specified `address` a pointer to a null-terminated
701 /// string that will parse as having the same value as the specified
702 /// `identifier`. The specified `allocator` is not used.
703 ///
704 /// \pre The behavior is undefined unless `0 <= identifier < 128`.
705 template <class ALLOCATOR>
706 static void
707 emplace(const char **address, int identifier, ALLOCATOR allocator);
708 template <class ALLOCATOR>
709 static void
710 emplace(const char **address, int identifier, ALLOCATOR *allocator);
711
712 template <class ALLOCATOR>
713 static void emplace(char *address, int identifier, ALLOCATOR allocator);
714 template <class ALLOCATOR>
715 static void
716 emplace(char *address, int identifier, ALLOCATOR *allocator);
717 template <class ALLOCATOR>
718 static void
719 emplace(signed char *address, int identifier, ALLOCATOR allocator);
720 template <class ALLOCATOR>
721 static void
722 emplace(signed char *address, int identifier, ALLOCATOR *allocator);
723 template <class ALLOCATOR>
724 static void
725 emplace(unsigned char *address, int identifier, ALLOCATOR allocator);
726 template <class ALLOCATOR>
727 static void
728 emplace(unsigned char *address, int identifier, ALLOCATOR *allocator);
729
730 /// Set the character object at the specified `address` to the value of
731 /// the specified `identifier`. The specified `allocator` is not used.
732 ///
733 /// \pre The behavior is undefined unless `0 <= identifier < 128`.
734 ///
735 /// \note Note that these overloads are needed only to avoid narrowing conversion
736 /// warnings that will occur in lower-level utilities when using this
737 /// test facility.
738 template <class ALLOCATOR>
739
740 static void
741 emplace(EmplacableTestType *address, int identifier, ALLOCATOR allocator);
742 template <class ALLOCATOR>
743 static void
744 emplace(EmplacableTestType *address, int identifier, ALLOCATOR *allocator);
745
746 template <class ALLOCATOR>
747 static void
749 int identifier,
750 ALLOCATOR allocator);
751 template <class ALLOCATOR>
752 static void
754 int identifier,
755 ALLOCATOR *allocator);
756
757 /// Set the enumeration at the specified `address` to the value of the
758 /// specified `identifier`. The specified `allocator` is not used.
759 ///
760 /// \pre The behavior is undefined unless `0 <= identifier < 128`.
761 template <class ALLOCATOR>
762 static void emplace(EnumeratedTestType::Enum *address,
763 int identifier,
764 ALLOCATOR allocator);
765 template <class ALLOCATOR>
766 static void emplace(EnumeratedTestType::Enum *address,
767 int identifier,
768 ALLOCATOR *allocator);
769
770 /// Set the pointer-to-method at the specified `address` to the value of
771 /// the specified `identifier`. The specified `allocator` is not used.
772 ///
773 /// \pre The behavior is undefined unless `0 <= identifier < 128`.
774 template <class ALLOCATOR>
775 static void
776 emplace(MethodPtr *address, int identifier, ALLOCATOR allocator);
777 template <class ALLOCATOR>
778 static void
779 emplace(MethodPtr *address, int identifier, ALLOCATOR *allocator);
780
781 /// Return the integer identifier that uniquely identifies the specified `object`.
782 ///
783 /// \pre The behavior is undefined unless `object` could be
784 /// created from the `TemplateTestFacility::create` class method
785 /// template.
786 template <class TYPE>
787 static int getIdentifier(const TYPE& object);
788
789 /// Return the integer identifier that uniquely identifies the specified `object`.
790 ///
791 /// \pre The behavior is undefined unless `object` was created by
792 /// a call to the `TemplateTestFacility::create` class method template,
793 /// or is a copy of such an object.
794 template <class TYPE>
795 static int getIdentifier(TYPE*const& object);
796
797 /// Return the integer identifier that uniquely identifies the specified `object`.
798 ///
799 /// \pre The behavior is undefined unless `object` could be
800 /// created from the `TemplateTestFacility::create` class method
801 /// template.
802 static int getIdentifier(const char*const& object);
803
804 /// Return the integer identifier that uniquely identifies the specified `object`.
805 ///
806 /// \pre The behavior is undefined unless `object` could be
807 /// created from the `TemplateTestFacility::create` class method
808 /// template.
809 template <class ALLOC>
810 static int getIdentifier(const StdAllocTestType<ALLOC>& object);
811
812 /// Return the moved-from state of the specified `object, or `e_UNKNOWN'
813 /// if (template parameter) `TYPE` does not support such a query.
814 template <class TYPE>
815 static bsltf::MoveState::Enum getMovedFromState(const TYPE& object);
816
817 /// Return the moved-into state of the specified `object, or `e_UNKNOWN'
818 /// if (template parameter) `TYPE` does not support such a query.
819 template <class TYPE>
820 static bsltf::MoveState::Enum getMovedIntoState(const TYPE& object);
821
822 /// Set the moved-into state of the specified 'object to the specified
823 /// `value` if (template parameter) `TYPE` does supports move states.
824 template <class TYPE>
825 static void setMovedIntoState(TYPE *object, bsltf::MoveState::Enum value);
826};
827
828// FREE FUNCTIONS
829
830/// Print the value of the specified `obj` to the console.
831/// \note Note that this
832/// free function is provided to allow @ref bsls_bsltestutil to support these
833/// types intended for testing. See the component-level documentation for
834/// @ref bsls_bsltestutil for more details.
835void debugprint(const AllocTestType& obj);
836void debugprint(const NonOptionalAllocTestType& obj);
838void debugprint(const AllocEmplacableTestType& obj);
839void debugprint(const BitwiseCopyableTestType& obj);
840void debugprint(const BitwiseMoveableTestType& obj);
841void debugprint(const EmplacableTestType& obj);
842void debugprint(const EnumeratedTestType::Enum& obj);
843void debugprint(const MovableAllocTestType& obj);
844void debugprint(const MovableTestType& obj);
845void debugprint(const MoveOnlyAllocTestType& obj);
847void debugprint(const NonAssignableTestType& obj);
851void debugprint(const SimpleTestType& obj);
852template <class ALLOC> void debugprint(const StdAllocTestType<ALLOC>& obj);
853void debugprint(const UnionTestType& obj);
855
856 // =================
857 // Macro Definitions
858 // =================
859
860/// This macro refers to all of the primitive test types defined in this package.
861///
862/// \note Note that it can be used as the last argument to the
863/// `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE` macro.
864#define BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_PRIMITIVE \
865 signed char, \
866 size_t, \
867 const char *, \
868 bsltf::TemplateTestFacility::ObjectPtr, \
869 bsltf::TemplateTestFacility::FunctionPtr, \
870 bsltf::TemplateTestFacility::MethodPtr
871
872/// This macro refers to all of the user-defined test types defined in this package.
873///
874/// \note Note that the macro can be used as the last argument to the
875/// `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE` macro.
876#define BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_USER_DEFINED \
877 bsltf::EnumeratedTestType::Enum, \
878 bsltf::UnionTestType, \
879 bsltf::SimpleTestType, \
880 bsltf::AllocTestType, \
881 bsltf::BitwiseCopyableTestType, \
882 bsltf::BitwiseMoveableTestType, \
883 bsltf::AllocBitwiseMoveableTestType, \
884 bsltf::MovableTestType, \
885 bsltf::MovableAllocTestType, \
886 bsltf::NonTypicalOverloadsTestType
887
888/// This macro refers to all of the regular test types defined in this package.
889///
890/// \note Note that the macro can be used as the last argument to the
891/// `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE` macro.
892#define BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_REGULAR \
893 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_PRIMITIVE, \
894 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_USER_DEFINED
895
896#define BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_AWKWARD \
897 bsltf::NonAssignableTestType, \
898 bsltf::NonDefaultConstructibleTestType, \
899 bsltf::NonEqualComparableTestType
900 // TBD: move-only types should be in a separate movable macro, as many
901 // existing test rely on copying.
902 // bsltf::MoveOnlyAllocTestType
903 // TBD: cannot add following as they support only 14 valid values, and
904 // 'create'/'getIdentifier' require support for (at least) 128
905 // distinct values. 'bool' has the same issue, as do empty types.
906 // bsltf::AllocEmplacableTestType
907 // bsltf::EmplacableTestType
908 // This macro refers to all of the awkward test types defined in this
909 // package. Note that the macro can be used as the last argument to the
910 // 'BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE' macro.
911
912/// This macro refers to all of the test types defined in this package.
913///
914/// \note Note that the macro can be used as the last argument to the
915/// `BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE` macro.
916#define BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_ALL \
917 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_REGULAR, \
918 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_AWKWARD
919
920
921#define BSLTF_TEMPLATETESTFACILITY_NUM_ARGS_IMPL(X20, X19, X18, X17, X16, \
922 X15, X14, X13, X12, X11, \
923 X10, X9, X8, X7, X6, \
924 X5, X4, X3, X2, X1, \
925 N, ...) \
926 N
927
928// The 'BSLTF_TEMPLATETESTFACILITY_EXPAND' macro is required to workaround a
929// pre-processor issue on windows that prevents __VA_ARGS__ to be expanded in
930// the definition of some macros.
931#define BSLTF_TEMPLATETESTFACILITY_EXPAND(X) \
932 X
933
934#define BSLTF_TEMPLATETESTFACILITY_NUM_ARGS(...) \
935 BSLTF_TEMPLATETESTFACILITY_EXPAND( \
936 BSLTF_TEMPLATETESTFACILITY_NUM_ARGS_IMPL(__VA_ARGS__, \
937 20, 19, 18, 17, 16, 15, 14, \
938 13, 12, 11, 10, 9, 8, 7, \
939 6, 5, 4, 3, 2, 1, 0))
940
941#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL1(C, M, T1) \
942 C<T1>::M();
943
944#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL2(C, M, T1, T2) \
945 C<T1>::M(); C<T2>::M();
946
947#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL3(C, M, T1, T2, T3) \
948 C<T1>::M(); C<T2>::M(); C<T3>::M();
949
950#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL4(C, M, T1, T2, T3, T4) \
951 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M();
952
953#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL5(C, M, T1, T2, T3, T4, \
954 T5) \
955 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M();
956
957#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL6(C, M, T1, T2, T3, T4, \
958 T5, T6) \
959 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
960 C<T6>::M();
961
962#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL7(C, M, T1, T2, T3, T4, \
963 T5, T6, T7) \
964 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
965 C<T6>::M(); C<T7>::M();
966
967#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL8(C, M, T1, T2, T3, T4, \
968 T5, T6, T7, T8) \
969 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
970 C<T6>::M(); C<T7>::M(); C<T8>::M();
971
972#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL9(C, M, T1, T2, T3, T4, \
973 T5, T6, T7, T8, T9) \
974 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
975 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M();
976
977#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL10(C, M, T1, T2, T3, T4, \
978 T5, T6, T7, T8, T9, \
979 T10) \
980 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
981 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M();
982
983#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL11(C, M, T1, T2, T3, T4, \
984 T5, T6, T7, T8, T9, \
985 T10, T11) \
986 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
987 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M(); \
988 C<T11>::M();
989
990#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL12(C, M, T1, T2, T3, T4, \
991 T5, T6, T7, T8, T9, \
992 T10, T11, T12) \
993 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
994 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M(); \
995 C<T11>::M(); C<T12>::M();
996
997#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL13(C, M, T1, T2, T3, T4, \
998 T5, T6, T7, T8, T9, \
999 T10, T11, T12, T13) \
1000 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
1001 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M(); \
1002 C<T11>::M(); C<T12>::M(); C<T13>::M();
1003
1004#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL14(C, M, T1, T2, T3, T4, \
1005 T5, T6, T7, T8, T9, \
1006 T10, T11, T12, T13, \
1007 T14) \
1008 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
1009 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M(); \
1010 C<T11>::M(); C<T12>::M(); C<T13>::M(); C<T14>::M();
1011
1012#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL15(C, M, T1, T2, T3, T4, \
1013 T5, T6, T7, T8, T9, \
1014 T10, T11, T12, T13, \
1015 T14, T15) \
1016 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
1017 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M(); \
1018 C<T11>::M(); C<T12>::M(); C<T13>::M(); C<T14>::M(); C<T15>::M();
1019
1020#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL16(C, M, T1, T2, T3, T4, \
1021 T5, T6, T7, T8, T9, \
1022 T10, T11, T12, T13, \
1023 T14, T15, T16) \
1024 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
1025 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M(); \
1026 C<T11>::M(); C<T12>::M(); C<T13>::M(); C<T14>::M(); C<T15>::M(); \
1027 C<T16>::M();
1028
1029#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL17(C, M, T1, T2, T3, T4, \
1030 T5, T6, T7, T8, T9, \
1031 T10, T11, T12, T13, \
1032 T14, T15, T16, T17) \
1033 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
1034 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M(); \
1035 C<T11>::M(); C<T12>::M(); C<T13>::M(); C<T14>::M(); C<T15>::M(); \
1036 C<T16>::M(); C<T17>::M();
1037
1038#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL18(C, M, T1, T2, T3, T4, \
1039 T5, T6, T7, T8, T9, \
1040 T10, T11, T12, T13, \
1041 T14, T15, T16, T17, \
1042 T18) \
1043 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
1044 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M(); \
1045 C<T11>::M(); C<T12>::M(); C<T13>::M(); C<T14>::M(); C<T15>::M(); \
1046 C<T16>::M(); C<T17>::M(); C<T18>::M();
1047
1048#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL19(C, M, T1, T2, T3, T4, \
1049 T5, T6, T7, T8, T9, \
1050 T10, T11, T12, T13, \
1051 T14, T15, T16, T17, \
1052 T18, T19) \
1053 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
1054 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M(); \
1055 C<T11>::M(); C<T12>::M(); C<T13>::M(); C<T14>::M(); C<T15>::M(); \
1056 C<T16>::M(); C<T17>::M(); C<T18>::M(); C<T19>::M();
1057
1058#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL20(C, M, T1, T2, T3, T4, \
1059 T5, T6, T7, T8, T9, \
1060 T10, T11, T12, T13, \
1061 T14, T15, T16, T17, \
1062 T18, T19, T20) \
1063 C<T1>::M(); C<T2>::M(); C<T3>::M(); C<T4>::M(); C<T5>::M(); \
1064 C<T6>::M(); C<T7>::M(); C<T8>::M(); C<T9>::M(); C<T10>::M(); \
1065 C<T11>::M(); C<T12>::M(); C<T13>::M(); C<T14>::M(); C<T15>::M(); \
1066 C<T16>::M(); C<T17>::M(); C<T18>::M(); C<T19>::M(); C<T20>::M();
1067
1068#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL(C, M, N, ...) \
1069 BSLTF_TEMPLATETESTFACILITY_EXPAND( \
1070 BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL ## N(C, M, __VA_ARGS__))
1071
1072#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_(C, M, N, ...) \
1073 BSLTF_TEMPLATETESTFACILITY_EXPAND( \
1074 BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_IMPL(C, M, N, __VA_ARGS__))
1075
1076#define BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE(CLASS, METHOD, ...) \
1077 BSLTF_TEMPLATETESTFACILITY_RUN_EACH_TYPE_( \
1078 CLASS, \
1079 METHOD, \
1080 BSLTF_TEMPLATETESTFACILITY_NUM_ARGS(__VA_ARGS__), \
1081 __VA_ARGS__) \
1082 // Instantiates the specified 'CLASS' for each of the types specified
1083 // in the third to last arguments of this macro. Call the specified
1084 // class 'METHOD' of each instantiation. The compilation will fail if
1085 // the number of specified types is more than 20.
1086
1087#define BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT(TYPE) \
1088 inline void dbg_print(const TYPE& val) \
1089 { printf("%d", bsltf::TemplateTestFacility::getIdentifier<TYPE>(val)); }
1090
1091#define BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINTS() \
1092 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1093 bsltf::EnumeratedTestType::Enum) \
1094 \
1095 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1096 bsltf::UnionTestType) \
1097 \
1098 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1099 bsltf::SimpleTestType) \
1100 \
1101 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1102 bsltf::AllocTestType) \
1103 \
1104 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1105 bsltf::NonOptionalAllocTestType) \
1106 \
1107 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1108 bsltf::MovableAllocTestType) \
1109 \
1110 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1111 bsltf::MovableTestType) \
1112 \
1113 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1114 bsltf::MoveOnlyAllocTestType) \
1115 \
1116 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1117 bsltf::AllocEmplacableTestType) \
1118 \
1119 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1120 bsltf::EmplacableTestType) \
1121 \
1122 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1123 bsltf::BitwiseCopyableTestType) \
1124 \
1125 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1126 bsltf::BitwiseMoveableTestType) \
1127 \
1128 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1129 bsltf::AllocBitwiseMoveableTestType) \
1130 \
1131 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1132 bsltf::NonTypicalOverloadsTestType) \
1133 \
1134 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1135 bsltf::NonCopyConstructibleTestType) \
1136 \
1137 BSLTF_TEMPLATETESTFACILITY_TEST_TYPES_DEFINE_DBG_PRINT( \
1138 bsltf::NonDefaultConstructibleTestType)
1139
1140 // Defines a list of @ref dbg_print overloads for use in the test driver.
1141 // FIXME: Change this to integrate with Alisdair's test driver print
1142 // facility once its ready.
1143
1144#define BSLTF_TEMPLATETESTFACILITY_COMPARE_EQUAL(FIRST_ARGUMENT, \
1145 SECOND_ARGUMENT) \
1146 ::BloombergLP::bsltf::TemplateTestFacility_CompareHelper:: \
1147 areEqual(FIRST_ARGUMENT, SECOND_ARGUMENT)
1148
1149#define BSLTF_TEMPLATETESTFACILITY_COMPARE_NOT_EQUAL(FIRST_ARGUMENT, \
1150 SECOND_ARGUMENT) \
1151 ::BloombergLP::bsltf::TemplateTestFacility_CompareHelper:: \
1152 areNotEqual(FIRST_ARGUMENT, SECOND_ARGUMENT)
1153
1154// ============================================================================
1155// INLINE FUNCTION DEFINITIONS
1156// ============================================================================
1157
1158 // ------------------------------------
1159 // class TemplateTestFacility_StubClass
1160 // ------------------------------------
1161
1162template <int IDENTIFIER>
1164{
1165 return IDENTIFIER;
1166}
1167
1168 // ----------------------------------------
1169 // class TemplateTestFacility_CompareHelper
1170 // ----------------------------------------
1171
1172template <class TYPE>
1173inline
1175 const TYPE& rhs)
1176{
1177 return lhs == rhs;
1178}
1179
1180template <class TYPE>
1181inline
1183 const TYPE& rhs)
1184{
1185 return lhs != rhs;
1186}
1187
1188inline
1190 const NonEqualComparableTestType& lhs,
1191 const NonEqualComparableTestType& rhs)
1192{
1193 return lhs.data() == rhs.data();
1194}
1195
1196inline
1198 const NonEqualComparableTestType& lhs,
1199 const NonEqualComparableTestType& rhs)
1200{
1201 return lhs.data() != rhs.data();
1202}
1203
1204 // ---------------------------
1205 // struct TemplateTestFacility
1206 // ---------------------------
1207
1208// CLASS METHODS
1209template <class TYPE>
1210inline
1212{
1214 emplace(obj.address(),
1215 identifier,
1217 bslma::DestructorGuard<TYPE> destructor(obj.address());
1218 return TYPE(bslmf::MovableRefUtil::move(obj.object()));
1219}
1220
1221template <class TYPE, class ALLOCATOR>
1222inline
1224 int identifier,
1225 ALLOCATOR allocator)
1226{
1227 BSLS_ASSERT_SAFE(address);
1228 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1229
1231 allocator, address, identifier);
1232}
1233
1234template <class TYPE, class ALLOCATOR>
1235inline
1237 int identifier,
1238 ALLOCATOR *allocator)
1239{
1240 emplace(address, identifier, bsl::allocator<TYPE>(allocator));
1241}
1242
1243template <class TYPE, class ALLOCATOR>
1244inline
1245void TemplateTestFacility::emplace(TYPE **address, int identifier, ALLOCATOR)
1246{
1247 BSLS_ASSERT_SAFE(address);
1248 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1249
1250 *address = reinterpret_cast<TYPE *>(bsls::Types::IntPtr(identifier));
1251}
1252
1253template <class TYPE, class ALLOCATOR>
1254inline
1255void TemplateTestFacility::emplace(TYPE **address, int identifier, ALLOCATOR *)
1256{
1257 BSLS_ASSERT_SAFE(address);
1258 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1259
1260 *address = reinterpret_cast<TYPE *>(bsls::Types::IntPtr(identifier));
1261}
1262
1263template <class ALLOCATOR>
1264void TemplateTestFacility::emplace(const char **address,
1265 int identifier,
1266 ALLOCATOR allocator)
1267{
1268 BSLS_ASSERT_SAFE(address);
1269 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1270
1271 (void)allocator;
1272
1273 *address = nullTerminatedStringForIdentifier(identifier);
1274}
1275
1276template <class ALLOCATOR>
1277void TemplateTestFacility::emplace(const char **address,
1278 int identifier,
1279 ALLOCATOR *allocator)
1280{
1281 BSLS_ASSERT_SAFE(address);
1282 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1283
1284 (void)allocator;
1285
1286 *address = nullTerminatedStringForIdentifier(identifier);
1287}
1288
1289template <class ALLOCATOR>
1290inline
1291void TemplateTestFacility::emplace(char *address, int identifier, ALLOCATOR)
1292{
1293 BSLS_ASSERT_SAFE(address);
1294 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1295
1296 *address = static_cast<char>(identifier);
1297}
1298
1299template <class ALLOCATOR>
1300inline
1302 int identifier,
1303 ALLOCATOR *)
1304{
1305 BSLS_ASSERT_SAFE(address);
1306 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1307
1308 *address = static_cast<char>(identifier);
1309}
1310
1311template <class ALLOCATOR>
1312inline
1313void TemplateTestFacility::emplace(signed char *address,
1314 int identifier,
1315 ALLOCATOR)
1316{
1317 BSLS_ASSERT_SAFE(address);
1318 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1319
1320 *address = static_cast<signed char>(identifier);
1321}
1322
1323template <class ALLOCATOR>
1324inline
1325void TemplateTestFacility::emplace(signed char *address,
1326 int identifier,
1327 ALLOCATOR *)
1328{
1329 BSLS_ASSERT_SAFE(address);
1330 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1331
1332 *address = static_cast<signed char>(identifier);
1333}
1334
1335template <class ALLOCATOR>
1336inline
1338 int identifier,
1339 ALLOCATOR)
1340{
1341 BSLS_ASSERT_SAFE(address);
1342 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1343
1344 *address = static_cast<EnumeratedTestType::Enum>(identifier);
1345}
1346
1347template <class ALLOCATOR>
1348inline
1350 int identifier,
1351 ALLOCATOR *)
1352{
1353 BSLS_ASSERT_SAFE(address);
1354 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1355
1356 *address = static_cast<EnumeratedTestType::Enum>(identifier);
1357}
1358
1359template <class ALLOCATOR>
1360inline
1362 int identifier,
1363 ALLOCATOR)
1364{
1365 BSLS_ASSERT_SAFE(address);
1366 BSLS_ASSERT_SAFE(0 <= identifier); BSLS_ASSERT_SAFE(identifier < 128);
1367
1368 switch (identifier) {
1369 case 0: *address = 0 ; break;
1370 case 1: *address = &TemplateTestFacility_StubClass::method< 1>; break;
1371 case 2: *address = &TemplateTestFacility_StubClass::method< 2>; break;
1372 case 3: *address = &TemplateTestFacility_StubClass::method< 3>; break;
1373 case 4: *address = &TemplateTestFacility_StubClass::method< 4>; break;
1374 case 5: *address = &TemplateTestFacility_StubClass::method< 5>; break;
1375 case 6: *address = &TemplateTestFacility_StubClass::method< 6>; break;
1376 case 7: *address = &TemplateTestFacility_StubClass::method< 7>; break;
1377 case 8: *address = &TemplateTestFacility_StubClass::method< 8>; break;
1378 case 9: *address = &TemplateTestFacility_StubClass::method< 9>; break;
1379 case 10: *address = &TemplateTestFacility_StubClass::method< 10>; break;
1380 case 11: *address = &TemplateTestFacility_StubClass::method< 11>; break;
1381 case 12: *address = &TemplateTestFacility_StubClass::method< 12>; break;
1382 case 13: *address = &TemplateTestFacility_StubClass::method< 13>; break;
1383 case 14: *address = &TemplateTestFacility_StubClass::method< 14>; break;
1384 case 15: *address = &TemplateTestFacility_StubClass::method< 15>; break;
1385 case 16: *address = &TemplateTestFacility_StubClass::method< 16>; break;
1386 case 17: *address = &TemplateTestFacility_StubClass::method< 17>; break;
1387 case 18: *address = &TemplateTestFacility_StubClass::method< 18>; break;
1388 case 19: *address = &TemplateTestFacility_StubClass::method< 19>; break;
1389 case 20: *address = &TemplateTestFacility_StubClass::method< 20>; break;
1390 case 21: *address = &TemplateTestFacility_StubClass::method< 21>; break;
1391 case 22: *address = &TemplateTestFacility_StubClass::method< 22>; break;
1392 case 23: *address = &TemplateTestFacility_StubClass::method< 23>; break;
1393 case 24: *address = &TemplateTestFacility_StubClass::method< 24>; break;
1394 case 25: *address = &TemplateTestFacility_StubClass::method< 25>; break;
1395 case 26: *address = &TemplateTestFacility_StubClass::method< 26>; break;
1396 case 27: *address = &TemplateTestFacility_StubClass::method< 27>; break;
1397 case 28: *address = &TemplateTestFacility_StubClass::method< 28>; break;
1398 case 29: *address = &TemplateTestFacility_StubClass::method< 29>; break;
1399 case 30: *address = &TemplateTestFacility_StubClass::method< 30>; break;
1400 case 31: *address = &TemplateTestFacility_StubClass::method< 31>; break;
1401 case 32: *address = &TemplateTestFacility_StubClass::method< 32>; break;
1402 case 33: *address = &TemplateTestFacility_StubClass::method< 33>; break;
1403 case 34: *address = &TemplateTestFacility_StubClass::method< 34>; break;
1404 case 35: *address = &TemplateTestFacility_StubClass::method< 35>; break;
1405 case 36: *address = &TemplateTestFacility_StubClass::method< 36>; break;
1406 case 37: *address = &TemplateTestFacility_StubClass::method< 37>; break;
1407 case 38: *address = &TemplateTestFacility_StubClass::method< 38>; break;
1408 case 39: *address = &TemplateTestFacility_StubClass::method< 39>; break;
1409 case 40: *address = &TemplateTestFacility_StubClass::method< 40>; break;
1410 case 41: *address = &TemplateTestFacility_StubClass::method< 41>; break;
1411 case 42: *address = &TemplateTestFacility_StubClass::method< 42>; break;
1412 case 43: *address = &TemplateTestFacility_StubClass::method< 43>; break;
1413 case 44: *address = &TemplateTestFacility_StubClass::method< 44>; break;
1414 case 45: *address = &TemplateTestFacility_StubClass::method< 45>; break;
1415 case 46: *address = &TemplateTestFacility_StubClass::method< 46>; break;
1416 case 47: *address = &TemplateTestFacility_StubClass::method< 47>; break;
1417 case 48: *address = &TemplateTestFacility_StubClass::method< 48>; break;
1418 case 49: *address = &TemplateTestFacility_StubClass::method< 49>; break;
1419 case 50: *address = &TemplateTestFacility_StubClass::method< 50>; break;
1420 case 51: *address = &TemplateTestFacility_StubClass::method< 51>; break;
1421 case 52: *address = &TemplateTestFacility_StubClass::method< 52>; break;
1422 case 53: *address = &TemplateTestFacility_StubClass::method< 53>; break;
1423 case 54: *address = &TemplateTestFacility_StubClass::method< 54>; break;
1424 case 55: *address = &TemplateTestFacility_StubClass::method< 55>; break;
1425 case 56: *address = &TemplateTestFacility_StubClass::method< 56>; break;
1426 case 57: *address = &TemplateTestFacility_StubClass::method< 57>; break;
1427 case 58: *address = &TemplateTestFacility_StubClass::method< 58>; break;
1428 case 59: *address = &TemplateTestFacility_StubClass::method< 59>; break;
1429 case 60: *address = &TemplateTestFacility_StubClass::method< 60>; break;
1430 case 61: *address = &TemplateTestFacility_StubClass::method< 61>; break;
1431 case 62: *address = &TemplateTestFacility_StubClass::method< 62>; break;
1432 case 63: *address = &TemplateTestFacility_StubClass::method< 63>; break;
1433 case 64: *address = &TemplateTestFacility_StubClass::method< 64>; break;
1434 case 65: *address = &TemplateTestFacility_StubClass::method< 65>; break;
1435 case 66: *address = &TemplateTestFacility_StubClass::method< 66>; break;
1436 case 67: *address = &TemplateTestFacility_StubClass::method< 67>; break;
1437 case 68: *address = &TemplateTestFacility_StubClass::method< 68>; break;
1438 case 69: *address = &TemplateTestFacility_StubClass::method< 69>; break;
1439 case 70: *address = &TemplateTestFacility_StubClass::method< 70>; break;
1440 case 71: *address = &TemplateTestFacility_StubClass::method< 71>; break;
1441 case 72: *address = &TemplateTestFacility_StubClass::method< 72>; break;
1442 case 73: *address = &TemplateTestFacility_StubClass::method< 73>; break;
1443 case 74: *address = &TemplateTestFacility_StubClass::method< 74>; break;
1444 case 75: *address = &TemplateTestFacility_StubClass::method< 75>; break;
1445 case 76: *address = &TemplateTestFacility_StubClass::method< 76>; break;
1446 case 77: *address = &TemplateTestFacility_StubClass::method< 77>; break;
1447 case 78: *address = &TemplateTestFacility_StubClass::method< 78>; break;
1448 case 79: *address = &TemplateTestFacility_StubClass::method< 79>; break;
1449 case 80: *address = &TemplateTestFacility_StubClass::method< 80>; break;
1450 case 81: *address = &TemplateTestFacility_StubClass::method< 81>; break;
1451 case 82: *address = &TemplateTestFacility_StubClass::method< 82>; break;
1452 case 83: *address = &TemplateTestFacility_StubClass::method< 83>; break;
1453 case 84: *address = &TemplateTestFacility_StubClass::method< 84>; break;
1454 case 85: *address = &TemplateTestFacility_StubClass::method< 85>; break;
1455 case 86: *address = &TemplateTestFacility_StubClass::method< 86>; break;
1456 case 87: *address = &TemplateTestFacility_StubClass::method< 87>; break;
1457 case 88: *address = &TemplateTestFacility_StubClass::method< 88>; break;
1458 case 89: *address = &TemplateTestFacility_StubClass::method< 89>; break;
1459 case 90: *address = &TemplateTestFacility_StubClass::method< 90>; break;
1460 case 91: *address = &TemplateTestFacility_StubClass::method< 91>; break;
1461 case 92: *address = &TemplateTestFacility_StubClass::method< 92>; break;
1462 case 93: *address = &TemplateTestFacility_StubClass::method< 93>; break;
1463 case 94: *address = &TemplateTestFacility_StubClass::method< 94>; break;
1464 case 95: *address = &TemplateTestFacility_StubClass::method< 95>; break;
1465 case 96: *address = &TemplateTestFacility_StubClass::method< 96>; break;
1466 case 97: *address = &TemplateTestFacility_StubClass::method< 97>; break;
1467 case 98: *address = &TemplateTestFacility_StubClass::method< 98>; break;
1468 case 99: *address = &TemplateTestFacility_StubClass::method< 99>; break;
1469 case 100: *address = &TemplateTestFacility_StubClass::method<100>; break;
1470 case 101: *address = &TemplateTestFacility_StubClass::method<101>; break;
1471 case 102: *address = &TemplateTestFacility_StubClass::method<102>; break;
1472 case 103: *address = &TemplateTestFacility_StubClass::method<103>; break;
1473 case 104: *address = &TemplateTestFacility_StubClass::method<104>; break;
1474 case 105: *address = &TemplateTestFacility_StubClass::method<105>; break;
1475 case 106: *address = &TemplateTestFacility_StubClass::method<106>; break;
1476 case 107: *address = &TemplateTestFacility_StubClass::method<107>; break;
1477 case 108: *address = &TemplateTestFacility_StubClass::method<108>; break;
1478 case 109: *address = &TemplateTestFacility_StubClass::method<109>; break;
1479 case 110: *address = &TemplateTestFacility_StubClass::method<110>; break;
1480 case 111: *address = &TemplateTestFacility_StubClass::method<111>; break;
1481 case 112: *address = &TemplateTestFacility_StubClass::method<112>; break;
1482 case 113: *address = &TemplateTestFacility_StubClass::method<113>; break;
1483 case 114: *address = &TemplateTestFacility_StubClass::method<114>; break;
1484 case 115: *address = &TemplateTestFacility_StubClass::method<115>; break;
1485 case 116: *address = &TemplateTestFacility_StubClass::method<116>; break;
1486 case 117: *address = &TemplateTestFacility_StubClass::method<117>; break;
1487 case 118: *address = &TemplateTestFacility_StubClass::method<118>; break;
1488 case 119: *address = &TemplateTestFacility_StubClass::method<119>; break;
1489 case 120: *address = &TemplateTestFacility_StubClass::method<120>; break;
1490 case 121: *address = &TemplateTestFacility_StubClass::method<121>; break;
1491 case 122: *address = &TemplateTestFacility_StubClass::method<122>; break;
1492 case 123: *address = &TemplateTestFacility_StubClass::method<123>; break;
1493 case 124: *address = &TemplateTestFacility_StubClass::method<124>; break;
1494 case 125: *address = &TemplateTestFacility_StubClass::method<125>; break;
1495 case 126: *address = &TemplateTestFacility_StubClass::method<126>; break;
1496 case 127: *address = &TemplateTestFacility_StubClass::method<127>; break;
1497 default : {
1498 BSLS_ASSERT_OPT_UNREACHABLE("`identifier` out of range [0..127]");
1499 }
1500 }
1501}
1502
1503template <class ALLOCATOR>
1504inline
1505void TemplateTestFacility::emplace(MethodPtr *address,
1506 int identifier,
1507 ALLOCATOR *allocator)
1508{
1509 emplace(address, identifier, bsl::allocator<MethodPtr>(allocator));
1510}
1511
1512// TBD: still working on this as part of C++11 project but should not affect
1513// component test drivers
1514template <class ALLOCATOR>
1515inline
1517 int identifier,
1518 ALLOCATOR allocator)
1519{
1520 BSLS_ASSERT_SAFE(identifier >= 0);
1521 BSLS_ASSERT_SAFE(identifier < 128);
1522
1523 EmplacableTestType::ArgType01 A01(identifier);
1537
1538 switch (identifier) {
1539 case 0: {
1541 } break;
1542 case 1: {
1544 allocator,
1545 address,
1547 } break;
1548 case 2: {
1550 allocator,
1551 address,
1554 } break;
1555 case 3: {
1557 allocator,
1558 address,
1562 } break;
1563 case 4: {
1565 allocator,
1566 address,
1571 } break;
1572 case 5: {
1574 allocator,
1575 address,
1581 } break;
1582 case 6: {
1584 allocator,
1585 address,
1592 } break;
1593 case 7: {
1595 allocator,
1596 address,
1604 } break;
1605 case 8: {
1607 allocator,
1608 address,
1617 } break;
1618 case 9: {
1620 allocator,
1621 address,
1631 } break;
1632 case 10: {
1634 allocator,
1635 address,
1646 } break;
1647 case 11: {
1649 allocator,
1650 address,
1662 } break;
1663 case 12: {
1665 allocator,
1666 address,
1679 } break;
1680 case 13: {
1682 allocator,
1683 address,
1697 } break;
1698 case 14: {
1700 allocator,
1701 address,
1716 } break;
1717 default: {
1719 allocator,
1720 address,
1722 }
1723 }
1724}
1725
1726template <class ALLOCATOR>
1727inline
1729 int identifier,
1730 ALLOCATOR *allocator)
1731{
1732 emplace(address,
1733 identifier,
1735}
1736
1737template <class ALLOCATOR>
1738inline
1740 int identifier,
1741 ALLOCATOR allocator)
1742{
1743 BSLS_ASSERT_SAFE(identifier >= 0);
1744 BSLS_ASSERT_SAFE(identifier < 128);
1745
1746 AllocEmplacableTestType::ArgType01 A01(identifier, allocator);
1747 AllocEmplacableTestType::ArgType02 A02( 20, allocator);
1748 AllocEmplacableTestType::ArgType03 A03( 23, allocator);
1749 AllocEmplacableTestType::ArgType04 A04( 44, allocator);
1750 AllocEmplacableTestType::ArgType05 A05( 66, allocator);
1751 AllocEmplacableTestType::ArgType06 A06( 176, allocator);
1752 AllocEmplacableTestType::ArgType07 A07( 878, allocator);
1753 AllocEmplacableTestType::ArgType08 A08( 8, allocator);
1754 AllocEmplacableTestType::ArgType09 A09( 912, allocator);
1755 AllocEmplacableTestType::ArgType10 A10( 102, allocator);
1756 AllocEmplacableTestType::ArgType11 A11( 111, allocator);
1757 AllocEmplacableTestType::ArgType12 A12( 333, allocator);
1758 AllocEmplacableTestType::ArgType13 A13( 712, allocator);
1759 AllocEmplacableTestType::ArgType14 A14(1414, allocator);
1760
1761 switch (identifier) {
1762 case 0: {
1764 } break;
1765 case 1: {
1767 allocator,
1768 address,
1770 } break;
1771 case 2: {
1773 allocator,
1774 address,
1777 } break;
1778 case 3: {
1780 allocator,
1781 address,
1785 } break;
1786 case 4: {
1788 allocator,
1789 address,
1794 } break;
1795 case 5: {
1797 allocator,
1798 address,
1804 } break;
1805 case 6: {
1807 allocator,
1808 address,
1815 } break;
1816 case 7: {
1818 allocator,
1819 address,
1827 } break;
1828 case 8: {
1830 allocator,
1831 address,
1840 } break;
1841 case 9: {
1843 allocator,
1844 address,
1854 } break;
1855 case 10: {
1857 allocator,
1858 address,
1869 } break;
1870 case 11: {
1872 allocator,
1873 address,
1885 } break;
1886 case 12: {
1888 allocator,
1889 address,
1902 } break;
1903 case 13: {
1905 allocator,
1906 address,
1920 } break;
1921 case 14: {
1923 allocator,
1924 address,
1939 } break;
1940 default: {
1942 allocator,
1943 address,
1945 }
1946 }
1947}
1948
1949template <class ALLOCATOR>
1950inline
1952 int identifier,
1953 ALLOCATOR *allocator)
1954{
1955 emplace(address,
1956 identifier,
1958}
1959
1960template <class TYPE>
1961inline
1963{
1964 bsls::Types::IntPtr result = reinterpret_cast<bsls::Types::IntPtr>(object);
1965 return static_cast<int>(result);
1966}
1967
1968template <class TYPE>
1969inline
1971{
1973 // The static assertion catches most improper use of calling this function
1974 // with an explicit instantiation: 'getIdentifier<TYPE>(obj)'. Calls to
1975 // this function should always rely on type deduction to determine 'TYPE'
1976 // and pick the correct overload for this template.
1977
1978 return static_cast<int>(object);
1979}
1980
1981inline
1982int TemplateTestFacility::getIdentifier(const char*const& object)
1983{
1984 return object ? atoi(object) : 0;
1985}
1986
1987template <class ALLOC>
1988inline
1990{
1991 return object.data();
1992}
1993
1994template <>
1995inline
1999{
2000 if (!ptr) {
2001 return 0; // RETURN
2002 }
2003
2005 return (object.*ptr)();
2006}
2007
2008template <>
2009inline
2010int TemplateTestFacility::getIdentifier<bsltf::UnionTestType>(
2011 const bsltf::UnionTestType& object)
2012{
2013 return object.data();
2014}
2015
2016template <>
2017inline
2018int TemplateTestFacility::getIdentifier<bsltf::SimpleTestType>(
2019 const bsltf::SimpleTestType& object)
2020{
2021 return object.data();
2022}
2023
2024template <>
2025inline
2026int TemplateTestFacility::getIdentifier<bsltf::AllocTestType>(
2027 const bsltf::AllocTestType& object)
2028{
2029 return object.data();
2030}
2031
2032template <>
2033inline
2034int TemplateTestFacility::getIdentifier<bsltf::NonOptionalAllocTestType>(
2035 const bsltf::NonOptionalAllocTestType& object)
2036{
2037 return object.data();
2038}
2039
2040template <>
2041inline
2042int TemplateTestFacility::getIdentifier<bsltf::MovableAllocTestType>(
2043 const bsltf::MovableAllocTestType& object)
2044{
2045 return object.data();
2046}
2047
2048template <>
2049inline
2050int TemplateTestFacility::getIdentifier<bsltf::MovableTestType>(
2051 const bsltf::MovableTestType& object)
2052{
2053 return object.data();
2054}
2055
2056template <>
2057inline
2058int TemplateTestFacility::getIdentifier<bsltf::MoveOnlyAllocTestType>(
2059 const bsltf::MoveOnlyAllocTestType& object)
2060{
2061 return object.data();
2062}
2063
2064template <>
2065inline
2066int TemplateTestFacility::getIdentifier<bsltf::BitwiseCopyableTestType>(
2067 const bsltf::BitwiseCopyableTestType& object)
2068{
2069 return object.data();
2070}
2071
2072template <>
2073inline
2074int TemplateTestFacility::getIdentifier<bsltf::BitwiseMoveableTestType>(
2075 const bsltf::BitwiseMoveableTestType& object)
2076{
2077 return object.data();
2078}
2079
2080template <>
2081inline
2082int TemplateTestFacility::getIdentifier<bsltf::AllocBitwiseMoveableTestType>(
2084{
2085 return object.data();
2086}
2087
2088template <>
2089inline
2090int TemplateTestFacility::getIdentifier<bsltf::NonTypicalOverloadsTestType>(
2092{
2093 return object.data();
2094}
2095
2096template <>
2097inline
2098int TemplateTestFacility::getIdentifier<bsltf::NonAssignableTestType>(
2099 const bsltf::NonAssignableTestType& object)
2100{
2101 return object.data();
2102}
2103
2104template <>
2105inline
2112
2113template <>
2114inline
2121
2122template <>
2123inline
2124int TemplateTestFacility::getIdentifier<bsltf::NonEqualComparableTestType>(
2126{
2127 return object.data();
2128}
2129
2130template <>
2131inline
2132int TemplateTestFacility::getIdentifier<bsltf::EmplacableTestType>(
2133 const bsltf::EmplacableTestType& object)
2134{
2135 BSLS_ASSERT_SAFE( 1 <= object.arg01() || 128 > object.arg01());
2136 BSLS_ASSERT_SAFE( 20 == object.arg02() || -1 == object.arg02());
2137 BSLS_ASSERT_SAFE( 23 == object.arg03() || -1 == object.arg03());
2138 BSLS_ASSERT_SAFE( 44 == object.arg04() || -1 == object.arg04());
2139 BSLS_ASSERT_SAFE( 66 == object.arg05() || -1 == object.arg05());
2140 BSLS_ASSERT_SAFE( 176 == object.arg06() || -1 == object.arg06());
2141 BSLS_ASSERT_SAFE( 878 == object.arg07() || -1 == object.arg07());
2142 BSLS_ASSERT_SAFE( 8 == object.arg08() || -1 == object.arg08());
2143 BSLS_ASSERT_SAFE( 912 == object.arg09() || -1 == object.arg09());
2144 BSLS_ASSERT_SAFE( 102 == object.arg10() || -1 == object.arg10());
2145 BSLS_ASSERT_SAFE( 111 == object.arg11() || -1 == object.arg11());
2146 BSLS_ASSERT_SAFE( 333 == object.arg12() || -1 == object.arg12());
2147 BSLS_ASSERT_SAFE( 712 == object.arg13() || -1 == object.arg13());
2148 BSLS_ASSERT_SAFE(1414 == object.arg14() || -1 == object.arg14());
2149
2150 return -1 == object.arg01() ? 0
2151 : -1 == object.arg02() ? object.arg01()
2152 : -1 == object.arg03() ? 2
2153 : -1 == object.arg04() ? 3
2154 : -1 == object.arg05() ? 4
2155 : -1 == object.arg06() ? 5
2156 : -1 == object.arg07() ? 6
2157 : -1 == object.arg08() ? 7
2158 : -1 == object.arg09() ? 8
2159 : -1 == object.arg10() ? 9
2160 : -1 == object.arg11() ? 10
2161 : -1 == object.arg12() ? 11
2162 : -1 == object.arg13() ? 12
2163 : -1 == object.arg14() ? 13
2164 : 14;
2165}
2166
2167template <>
2168inline
2169int TemplateTestFacility::getIdentifier<bsltf::AllocEmplacableTestType>(
2170 const bsltf::AllocEmplacableTestType& object)
2171{
2172 BSLS_ASSERT_SAFE( 1 == object.arg01() || -1 == object.arg01());
2173 BSLS_ASSERT_SAFE( 20 == object.arg02() || -1 == object.arg02());
2174 BSLS_ASSERT_SAFE( 23 == object.arg03() || -1 == object.arg03());
2175 BSLS_ASSERT_SAFE( 44 == object.arg04() || -1 == object.arg04());
2176 BSLS_ASSERT_SAFE( 66 == object.arg05() || -1 == object.arg05());
2177 BSLS_ASSERT_SAFE( 176 == object.arg06() || -1 == object.arg06());
2178 BSLS_ASSERT_SAFE( 878 == object.arg07() || -1 == object.arg07());
2179 BSLS_ASSERT_SAFE( 8 == object.arg08() || -1 == object.arg08());
2180 BSLS_ASSERT_SAFE( 912 == object.arg09() || -1 == object.arg09());
2181 BSLS_ASSERT_SAFE( 102 == object.arg10() || -1 == object.arg10());
2182 BSLS_ASSERT_SAFE( 111 == object.arg11() || -1 == object.arg11());
2183 BSLS_ASSERT_SAFE( 333 == object.arg12() || -1 == object.arg12());
2184 BSLS_ASSERT_SAFE( 712 == object.arg13() || -1 == object.arg13());
2185 BSLS_ASSERT_SAFE(1414 == object.arg14() || -1 == object.arg14());
2186
2187 return -1 == object.arg01() ? 0
2188 : -1 == object.arg02() ? 1
2189 : -1 == object.arg03() ? 2
2190 : -1 == object.arg04() ? 3
2191 : -1 == object.arg05() ? 4
2192 : -1 == object.arg06() ? 5
2193 : -1 == object.arg07() ? 6
2194 : -1 == object.arg08() ? 7
2195 : -1 == object.arg09() ? 8
2196 : -1 == object.arg10() ? 9
2197 : -1 == object.arg11() ? 10
2198 : -1 == object.arg12() ? 11
2199 : -1 == object.arg13() ? 12
2200 : -1 == object.arg14() ? 13
2201 : 14;
2202}
2203
2204template <>
2205inline
2212
2213template <class TYPE>
2216{
2217 return getMovedFrom(object);
2218}
2219
2220template <class TYPE>
2223{
2224 return getMovedInto(object);
2225}
2226
2227template <class TYPE>
2230{
2231 setMovedInto(object, value);
2232}
2233
2234// FREE FUNCTIONS
2235inline
2237{
2239}
2240
2241inline
2243{
2245}
2246
2247inline
2249{
2251}
2252
2253inline
2255{
2257}
2258
2259inline
2261{
2263}
2264
2265template <class ALLOC>
2266inline
2268{
2270}
2271
2272inline
2274{
2276}
2277
2278inline
2280{
2282}
2283
2284inline
2286{
2288}
2289
2290inline
2292{
2294}
2295
2296inline
2298{
2300}
2301
2302inline
2304{
2306}
2307
2308inline
2310{
2312}
2313
2314inline
2316{
2318}
2319
2320inline
2322{
2324}
2325
2326inline
2331
2332inline
2334{
2336}
2337
2338inline
2340{
2342}
2343
2344inline
2346{
2348}
2349
2350inline
2355
2356} // close package namespace
2357
2358
2359#endif
2360
2361// ----------------------------------------------------------------------------
2362// Copyright 2017 Bloomberg Finance L.P.
2363//
2364// Licensed under the Apache License, Version 2.0 (the "License");
2365// you may not use this file except in compliance with the License.
2366// You may obtain a copy of the License at
2367//
2368// http://www.apache.org/licenses/LICENSE-2.0
2369//
2370// Unless required by applicable law or agreed to in writing, software
2371// distributed under the License is distributed on an "AS IS" BASIS,
2372// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2373// See the License for the specific language governing permissions and
2374// limitations under the License.
2375// ----------------------------- END-OF-FILE ----------------------------------
2376
2377/** @} */
2378/** @} */
2379/** @} */
Definition bslma_bslallocator.h:588
Definition bslma_destructorguard.h:132
static MallocFreeAllocator & singleton()
Definition bsltf_allocbitwisemoveabletesttype.h:134
Definition bsltf_allocemplacabletesttype.h:236
Definition bsltf_alloctesttype.h:151
Definition bsltf_bitwisecopyabletesttype.h:131
Definition bsltf_bitwisemoveabletesttype.h:131
Definition bsltf_emplacabletesttype.h:104
Definition bsltf_movablealloctesttype.h:155
Definition bsltf_movabletesttype.h:150
Definition bsltf_moveonlyalloctesttype.h:147
Definition bsltf_nonassignabletesttype.h:104
Definition bsltf_noncopyconstructibletesttype.h:105
int data() const
Return the value of the data attribute of this object.
Definition bsltf_noncopyconstructibletesttype.h:199
Definition bsltf_nondefaultconstructibletesttype.h:97
int data() const
Return the value of the data attribute of this object.
Definition bsltf_nondefaultconstructibletesttype.h:178
Definition bsltf_nonequalcomparabletesttype.h:103
Definition bsltf_nonoptionalalloctesttype.h:141
Definition bsltf_nontypicaloverloadstesttype.h:114
Definition bsltf_simpletesttype.h:130
Definition bsltf_stdalloctesttype.h:164
Definition bsltf_templatetestfacility.h:610
static bool areNotEqual(const TYPE &lhs, const TYPE &rhs)
Definition bsltf_templatetestfacility.h:1182
static bool areEqual(const TYPE &lhs, const TYPE &rhs)
Definition bsltf_templatetestfacility.h:1174
Definition bsltf_templatetestfacility.h:596
int method()
Return the parameterized IDENTIFIER.
Definition bsltf_templatetestfacility.h:1163
Definition bsltf_wellbehavedmoveonlyalloctesttype.h:151
int data() const
Return the value of the data attribute of this object.
Definition bsltf_wellbehavedmoveonlyalloctesttype.h:297
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:231
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_ASSERT_OPT_UNREACHABLE(X)
Definition bsls_assert.h:2065
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bsltf_allocargumenttype.h:92
void debugprint(const ArgumentType< N > &object)
Definition bsltf_argumenttype.h:562
MoveState::Enum getMovedInto(const AllocArgumentType< N > &object)
Return the move-into state of the specified object.
Definition bsltf_allocargumenttype.h:415
void setMovedInto(MovableTestType *object, MoveState::Enum value)
Definition bsltf_movabletesttype.h:315
MoveState::Enum getMovedFrom(const AllocArgumentType< N > &object)
Return the move-from state of the specified object.
Definition bsltf_allocargumenttype.h:408
static void construct(ALLOCATOR_TYPE &basicAllocator, ELEMENT_TYPE *elementAddr, Args &&... arguments)
Definition bslma_allocatortraits.h:1527
Definition bslmf_issame.h:146
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1067
std::ptrdiff_t IntPtr
Definition bsls_types.h:132
Enum
Definition bsltf_enumeratedtesttype.h:96
Enum
Enumeration of move state.
Definition bsltf_movestate.h:119
Definition bsltf_templatetestfacility.h:641
TemplateTestFacility_StubClass * ObjectPtr
Definition bsltf_templatetestfacility.h:655
static void emplace(unsigned char *address, int identifier, ALLOCATOR allocator)
static void emplace(TYPE *address, int identifier, ALLOCATOR allocator)
Definition bsltf_templatetestfacility.h:1223
int(TemplateTestFacility_StubClass::* MethodPtr)()
Definition bsltf_templatetestfacility.h:663
static bsltf::MoveState::Enum getMovedFromState(const TYPE &object)
static void emplace(unsigned char *address, int identifier, ALLOCATOR *allocator)
static int getIdentifier(const TYPE &object)
Definition bsltf_templatetestfacility.h:1970
static bsltf::MoveState::Enum getMovedIntoState(const TYPE &object)
static TYPE create(int identifier)
Definition bsltf_templatetestfacility.h:1211
static void setMovedIntoState(TYPE *object, bsltf::MoveState::Enum value)
Definition bsltf_templatetestfacility.h:2228
void(* FunctionPtr)()
This typedef is an alias for a pointer to a function pointer.
Definition bsltf_templatetestfacility.h:658
Definition bsls_objectbuffer.h:277
TYPE * address()
Definition bsls_objectbuffer.h:335
TYPE & object()
Definition bsls_objectbuffer.h:352
Definition bsltf_uniontesttype.h:107