2 $var n = 50 $$ Maximum length of type lists we want to support.
3 // Copyright 2008 Google Inc.
4 // All Rights Reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
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
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.
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.
32 // Author: wan@google.com (Zhanyong Wan)
34 // Type utilities needed for implementing typed and type-parameterized
35 // tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
37 // Currently we support at most $n types in a list, and at most $n
38 // type-parameterized tests in one type-parameterized test case.
39 // Please contact googletestframework@googlegroups.com if you need
42 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
43 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
45 #include <gtest/internal/gtest-port.h>
46 #include <gtest/internal/gtest-string.h>
48 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
59 // AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
60 // type. This can be used as a compile-time assertion to ensure that
61 // two types are equal.
63 template <typename T1, typename T2>
67 struct AssertTypeEq<T, T> {
71 // GetTypeName<T>() returns a human-readable name of type T.
73 String GetTypeName() {
76 const char* const name = typeid(T).name();
79 // gcc's implementation of typeid(T).name() mangles the type name,
80 // so we have to demangle it.
81 char* const readable_name = abi::__cxa_demangle(name, 0, 0, &status);
82 const String name_str(status == 0 ? readable_name : name);
91 #endif // GTEST_HAS_RTTI
94 // A unique type used as the default value for the arguments of class
95 // template Types. This allows us to simulate variadic templates
96 // (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
100 // The following family of struct and struct templates are used to
101 // represent type lists. In particular, TypesN<T1, T2, ..., TN>
102 // represents a type list with N types (T1, T2, ..., and TN) in it.
103 // Except for Types0, every struct in the family has two member types:
104 // Head for the first type in the list, and Tail for the rest of the
107 // The empty type list.
110 // Type lists of length 1, 2, 3, and so on.
112 template <typename T1>
123 template <$for j, [[typename T$j]]>
126 typedef Types$(i-1)<$for k, [[T$k]]> Tail;
132 } // namespace internal
134 // We don't want to require the users to write TypesN<...> directly,
135 // as that would require them to count the length. Types<...> is much
136 // easier to write, but generates horrible messages when there is a
137 // compiler error, as gcc insists on printing out each template
138 // argument, even if it has the default value (this means Types<int>
139 // will appear as Types<int, None, None, ..., None> in the compiler
142 // Our solution is to combine the best part of the two approaches: a
143 // user would write Types<T1, ..., TN>, and Google Test will translate
144 // that to TypesN<T1, ..., TN> internally to make error messages
145 // readable. The translation is done by the 'type' member of the
149 template <$for i, [[typename T$i = internal::None]]>
151 typedef internal::Types$n<$for i, [[T$i]]> type;
155 struct Types<$for i, [[internal::None]]> {
156 typedef internal::Types0 type;
163 template <$for j, [[typename T$j]]>
164 struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
165 typedef internal::Types$i<$for j, [[T$j]]> type;
172 #define GTEST_TEMPLATE_ template <typename T> class
174 // The template "selector" struct TemplateSel<Tmpl> is used to
175 // represent Tmpl, which must be a class template with one type
176 // parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
177 // as the type Tmpl<T>. This allows us to actually instantiate the
178 // template "selected" by TemplateSel<Tmpl>.
180 // This trick is necessary for simulating typedef for class templates,
181 // which C++ doesn't support directly.
182 template <GTEST_TEMPLATE_ Tmpl>
184 template <typename T>
186 typedef Tmpl<T> type;
190 #define GTEST_BIND_(TmplSel, T) \
191 TmplSel::template Bind<T>::type
193 // A unique struct template used as the default value for the
194 // arguments of class template Templates. This allows us to simulate
195 // variadic templates (e.g. Templates<int>, Templates<int, double>,
196 // and etc), which C++ doesn't support directly.
197 template <typename T>
200 // The following family of struct and struct templates are used to
201 // represent template lists. In particular, TemplatesN<T1, T2, ...,
202 // TN> represents a list of N templates (T1, T2, ..., and TN). Except
203 // for Templates0, every struct in the family has two member types:
204 // Head for the selector of the first template in the list, and Tail
205 // for the rest of the list.
207 // The empty template list.
208 struct Templates0 {};
210 // Template lists of length 1, 2, 3, and so on.
212 template <GTEST_TEMPLATE_ T1>
214 typedef TemplateSel<T1> Head;
215 typedef Templates0 Tail;
223 template <$for j, [[GTEST_TEMPLATE_ T$j]]>
225 typedef TemplateSel<T1> Head;
226 typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
232 // We don't want to require the users to write TemplatesN<...> directly,
233 // as that would require them to count the length. Templates<...> is much
234 // easier to write, but generates horrible messages when there is a
235 // compiler error, as gcc insists on printing out each template
236 // argument, even if it has the default value (this means Templates<list>
237 // will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
240 // Our solution is to combine the best part of the two approaches: a
241 // user would write Templates<T1, ..., TN>, and Google Test will translate
242 // that to TemplatesN<T1, ..., TN> internally to make error messages
243 // readable. The translation is done by the 'type' member of the
244 // Templates template.
247 template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
249 typedef Templates$n<$for i, [[T$i]]> type;
253 struct Templates<$for i, [[NoneT]]> {
254 typedef Templates0 type;
261 template <$for j, [[GTEST_TEMPLATE_ T$j]]>
262 struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
263 typedef Templates$i<$for j, [[T$j]]> type;
268 // The TypeList template makes it possible to use either a single type
269 // or a Types<...> list in TYPED_TEST_CASE() and
270 // INSTANTIATE_TYPED_TEST_CASE_P().
272 template <typename T>
273 struct TypeList { typedef Types1<T> type; };
277 template <$for i, [[typename T$i]]>
278 struct TypeList<Types<$for i, [[T$i]]> > {
279 typedef typename Types<$for i, [[T$i]]>::type type;
282 } // namespace internal
283 } // namespace testing
285 #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
287 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_