Bump to gtest 1.10.0
[platform/upstream/gtest.git] / googletest / include / gtest / internal / gtest-type-util.h.pump
1 $$ -*- mode: c++; -*-
2 $var n = 50  $$ Maximum length of type lists we want to support.
3 // Copyright 2008 Google Inc.
4 // All Rights Reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 //     * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //     * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 //     * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32
33 // Type utilities needed for implementing typed and type-parameterized
34 // tests.  This file is generated by a SCRIPT.  DO NOT EDIT BY HAND!
35 //
36 // Currently we support at most $n types in a list, and at most $n
37 // type-parameterized tests in one type-parameterized test suite.
38 // Please contact googletestframework@googlegroups.com if you need
39 // more.
40
41 // GOOGLETEST_CM0001 DO NOT DELETE
42
43 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
44 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
45
46 #include "gtest/internal/gtest-port.h"
47
48 // #ifdef __GNUC__ is too general here.  It is possible to use gcc without using
49 // libstdc++ (which is where cxxabi.h comes from).
50 # if GTEST_HAS_CXXABI_H_
51 #  include <cxxabi.h>
52 # elif defined(__HP_aCC)
53 #  include <acxx_demangle.h>
54 # endif  // GTEST_HASH_CXXABI_H_
55
56 namespace testing {
57 namespace internal {
58
59 // Canonicalizes a given name with respect to the Standard C++ Library.
60 // This handles removing the inline namespace within `std` that is
61 // used by various standard libraries (e.g., `std::__1`).  Names outside
62 // of namespace std are returned unmodified.
63 inline std::string CanonicalizeForStdLibVersioning(std::string s) {
64   static const char prefix[] = "std::__";
65   if (s.compare(0, strlen(prefix), prefix) == 0) {
66     std::string::size_type end = s.find("::", strlen(prefix));
67     if (end != s.npos) {
68       // Erase everything between the initial `std` and the second `::`.
69       s.erase(strlen("std"), end - strlen("std"));
70     }
71   }
72   return s;
73 }
74
75 // GetTypeName<T>() returns a human-readable name of type T.
76 // NB: This function is also used in Google Mock, so don't move it inside of
77 // the typed-test-only section below.
78 template <typename T>
79 std::string GetTypeName() {
80 # if GTEST_HAS_RTTI
81
82   const char* const name = typeid(T).name();
83 #  if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
84   int status = 0;
85   // gcc's implementation of typeid(T).name() mangles the type name,
86   // so we have to demangle it.
87 #   if GTEST_HAS_CXXABI_H_
88   using abi::__cxa_demangle;
89 #   endif  // GTEST_HAS_CXXABI_H_
90   char* const readable_name = __cxa_demangle(name, nullptr, nullptr, &status);
91   const std::string name_str(status == 0 ? readable_name : name);
92   free(readable_name);
93   return CanonicalizeForStdLibVersioning(name_str);
94 #  else
95   return name;
96 #  endif  // GTEST_HAS_CXXABI_H_ || __HP_aCC
97
98 # else
99
100   return "<type>";
101
102 # endif  // GTEST_HAS_RTTI
103 }
104
105 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
106
107 // A unique type used as the default value for the arguments of class
108 // template Types.  This allows us to simulate variadic templates
109 // (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
110 // support directly.
111 struct None {};
112
113 // The following family of struct and struct templates are used to
114 // represent type lists.  In particular, TypesN<T1, T2, ..., TN>
115 // represents a type list with N types (T1, T2, ..., and TN) in it.
116 // Except for Types0, every struct in the family has two member types:
117 // Head for the first type in the list, and Tail for the rest of the
118 // list.
119
120 // The empty type list.
121 struct Types0 {};
122
123 // Type lists of length 1, 2, 3, and so on.
124
125 template <typename T1>
126 struct Types1 {
127   typedef T1 Head;
128   typedef Types0 Tail;
129 };
130
131 $range i 2..n
132
133 $for i [[
134 $range j 1..i
135 $range k 2..i
136 template <$for j, [[typename T$j]]>
137 struct Types$i {
138   typedef T1 Head;
139   typedef Types$(i-1)<$for k, [[T$k]]> Tail;
140 };
141
142
143 ]]
144
145 }  // namespace internal
146
147 // We don't want to require the users to write TypesN<...> directly,
148 // as that would require them to count the length.  Types<...> is much
149 // easier to write, but generates horrible messages when there is a
150 // compiler error, as gcc insists on printing out each template
151 // argument, even if it has the default value (this means Types<int>
152 // will appear as Types<int, None, None, ..., None> in the compiler
153 // errors).
154 //
155 // Our solution is to combine the best part of the two approaches: a
156 // user would write Types<T1, ..., TN>, and Google Test will translate
157 // that to TypesN<T1, ..., TN> internally to make error messages
158 // readable.  The translation is done by the 'type' member of the
159 // Types template.
160
161 $range i 1..n
162 template <$for i, [[typename T$i = internal::None]]>
163 struct Types {
164   typedef internal::Types$n<$for i, [[T$i]]> type;
165 };
166
167 template <>
168 struct Types<$for i, [[internal::None]]> {
169   typedef internal::Types0 type;
170 };
171
172 $range i 1..n-1
173 $for i [[
174 $range j 1..i
175 $range k i+1..n
176 template <$for j, [[typename T$j]]>
177 struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
178   typedef internal::Types$i<$for j, [[T$j]]> type;
179 };
180
181 ]]
182
183 namespace internal {
184
185 # define GTEST_TEMPLATE_ template <typename T> class
186
187 // The template "selector" struct TemplateSel<Tmpl> is used to
188 // represent Tmpl, which must be a class template with one type
189 // parameter, as a type.  TemplateSel<Tmpl>::Bind<T>::type is defined
190 // as the type Tmpl<T>.  This allows us to actually instantiate the
191 // template "selected" by TemplateSel<Tmpl>.
192 //
193 // This trick is necessary for simulating typedef for class templates,
194 // which C++ doesn't support directly.
195 template <GTEST_TEMPLATE_ Tmpl>
196 struct TemplateSel {
197   template <typename T>
198   struct Bind {
199     typedef Tmpl<T> type;
200   };
201 };
202
203 # define GTEST_BIND_(TmplSel, T) \
204   TmplSel::template Bind<T>::type
205
206 // A unique struct template used as the default value for the
207 // arguments of class template Templates.  This allows us to simulate
208 // variadic templates (e.g. Templates<int>, Templates<int, double>,
209 // and etc), which C++ doesn't support directly.
210 template <typename T>
211 struct NoneT {};
212
213 // The following family of struct and struct templates are used to
214 // represent template lists.  In particular, TemplatesN<T1, T2, ...,
215 // TN> represents a list of N templates (T1, T2, ..., and TN).  Except
216 // for Templates0, every struct in the family has two member types:
217 // Head for the selector of the first template in the list, and Tail
218 // for the rest of the list.
219
220 // The empty template list.
221 struct Templates0 {};
222
223 // Template lists of length 1, 2, 3, and so on.
224
225 template <GTEST_TEMPLATE_ T1>
226 struct Templates1 {
227   typedef TemplateSel<T1> Head;
228   typedef Templates0 Tail;
229 };
230
231 $range i 2..n
232
233 $for i [[
234 $range j 1..i
235 $range k 2..i
236 template <$for j, [[GTEST_TEMPLATE_ T$j]]>
237 struct Templates$i {
238   typedef TemplateSel<T1> Head;
239   typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
240 };
241
242
243 ]]
244
245 // We don't want to require the users to write TemplatesN<...> directly,
246 // as that would require them to count the length.  Templates<...> is much
247 // easier to write, but generates horrible messages when there is a
248 // compiler error, as gcc insists on printing out each template
249 // argument, even if it has the default value (this means Templates<list>
250 // will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
251 // errors).
252 //
253 // Our solution is to combine the best part of the two approaches: a
254 // user would write Templates<T1, ..., TN>, and Google Test will translate
255 // that to TemplatesN<T1, ..., TN> internally to make error messages
256 // readable.  The translation is done by the 'type' member of the
257 // Templates template.
258
259 $range i 1..n
260 template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
261 struct Templates {
262   typedef Templates$n<$for i, [[T$i]]> type;
263 };
264
265 template <>
266 struct Templates<$for i, [[NoneT]]> {
267   typedef Templates0 type;
268 };
269
270 $range i 1..n-1
271 $for i [[
272 $range j 1..i
273 $range k i+1..n
274 template <$for j, [[GTEST_TEMPLATE_ T$j]]>
275 struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
276   typedef Templates$i<$for j, [[T$j]]> type;
277 };
278
279 ]]
280
281 // The TypeList template makes it possible to use either a single type
282 // or a Types<...> list in TYPED_TEST_SUITE() and
283 // INSTANTIATE_TYPED_TEST_SUITE_P().
284
285 template <typename T>
286 struct TypeList {
287   typedef Types1<T> type;
288 };
289
290
291 $range i 1..n
292 template <$for i, [[typename T$i]]>
293 struct TypeList<Types<$for i, [[T$i]]> > {
294   typedef typename Types<$for i, [[T$i]]>::type type;
295 };
296
297 #endif  // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
298
299 }  // namespace internal
300 }  // namespace testing
301
302 #endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_