source: gtest-1.7.0/include/gtest/internal/gtest-type-util.h.pump@ 12764

Last change on this file since 12764 was 12746, checked in by hock@…, 11 years ago

integrated the Google Testing Framework (gtest)

and wrote an Hello World test, to ensure the framework is working..

File size: 9.1 KB
Line 
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// Author: wan@google.com (Zhanyong Wan)
33
34// Type utilities needed for implementing typed and type-parameterized
35// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
36//
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
40// more.
41
42#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
43#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
44
45#include "gtest/internal/gtest-port.h"
46
47// #ifdef __GNUC__ is too general here. It is possible to use gcc without using
48// libstdc++ (which is where cxxabi.h comes from).
49# if GTEST_HAS_CXXABI_H_
50# include <cxxabi.h>
51# elif defined(__HP_aCC)
52# include <acxx_demangle.h>
53# endif // GTEST_HASH_CXXABI_H_
54
55namespace testing {
56namespace internal {
57
58// GetTypeName<T>() returns a human-readable name of type T.
59// NB: This function is also used in Google Mock, so don't move it inside of
60// the typed-test-only section below.
61template <typename T>
62std::string GetTypeName() {
63# if GTEST_HAS_RTTI
64
65 const char* const name = typeid(T).name();
66# if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
67 int status = 0;
68 // gcc's implementation of typeid(T).name() mangles the type name,
69 // so we have to demangle it.
70# if GTEST_HAS_CXXABI_H_
71 using abi::__cxa_demangle;
72# endif // GTEST_HAS_CXXABI_H_
73 char* const readable_name = __cxa_demangle(name, 0, 0, &status);
74 const std::string name_str(status == 0 ? readable_name : name);
75 free(readable_name);
76 return name_str;
77# else
78 return name;
79# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
80
81# else
82
83 return "<type>";
84
85# endif // GTEST_HAS_RTTI
86}
87
88#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
89
90// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
91// type. This can be used as a compile-time assertion to ensure that
92// two types are equal.
93
94template <typename T1, typename T2>
95struct AssertTypeEq;
96
97template <typename T>
98struct AssertTypeEq<T, T> {
99 typedef bool type;
100};
101
102// A unique type used as the default value for the arguments of class
103// template Types. This allows us to simulate variadic templates
104// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
105// support directly.
106struct None {};
107
108// The following family of struct and struct templates are used to
109// represent type lists. In particular, TypesN<T1, T2, ..., TN>
110// represents a type list with N types (T1, T2, ..., and TN) in it.
111// Except for Types0, every struct in the family has two member types:
112// Head for the first type in the list, and Tail for the rest of the
113// list.
114
115// The empty type list.
116struct Types0 {};
117
118// Type lists of length 1, 2, 3, and so on.
119
120template <typename T1>
121struct Types1 {
122 typedef T1 Head;
123 typedef Types0 Tail;
124};
125
126$range i 2..n
127
128$for i [[
129$range j 1..i
130$range k 2..i
131template <$for j, [[typename T$j]]>
132struct Types$i {
133 typedef T1 Head;
134 typedef Types$(i-1)<$for k, [[T$k]]> Tail;
135};
136
137
138]]
139
140} // namespace internal
141
142// We don't want to require the users to write TypesN<...> directly,
143// as that would require them to count the length. Types<...> is much
144// easier to write, but generates horrible messages when there is a
145// compiler error, as gcc insists on printing out each template
146// argument, even if it has the default value (this means Types<int>
147// will appear as Types<int, None, None, ..., None> in the compiler
148// errors).
149//
150// Our solution is to combine the best part of the two approaches: a
151// user would write Types<T1, ..., TN>, and Google Test will translate
152// that to TypesN<T1, ..., TN> internally to make error messages
153// readable. The translation is done by the 'type' member of the
154// Types template.
155
156$range i 1..n
157template <$for i, [[typename T$i = internal::None]]>
158struct Types {
159 typedef internal::Types$n<$for i, [[T$i]]> type;
160};
161
162template <>
163struct Types<$for i, [[internal::None]]> {
164 typedef internal::Types0 type;
165};
166
167$range i 1..n-1
168$for i [[
169$range j 1..i
170$range k i+1..n
171template <$for j, [[typename T$j]]>
172struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
173 typedef internal::Types$i<$for j, [[T$j]]> type;
174};
175
176]]
177
178namespace internal {
179
180# define GTEST_TEMPLATE_ template <typename T> class
181
182// The template "selector" struct TemplateSel<Tmpl> is used to
183// represent Tmpl, which must be a class template with one type
184// parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
185// as the type Tmpl<T>. This allows us to actually instantiate the
186// template "selected" by TemplateSel<Tmpl>.
187//
188// This trick is necessary for simulating typedef for class templates,
189// which C++ doesn't support directly.
190template <GTEST_TEMPLATE_ Tmpl>
191struct TemplateSel {
192 template <typename T>
193 struct Bind {
194 typedef Tmpl<T> type;
195 };
196};
197
198# define GTEST_BIND_(TmplSel, T) \
199 TmplSel::template Bind<T>::type
200
201// A unique struct template used as the default value for the
202// arguments of class template Templates. This allows us to simulate
203// variadic templates (e.g. Templates<int>, Templates<int, double>,
204// and etc), which C++ doesn't support directly.
205template <typename T>
206struct NoneT {};
207
208// The following family of struct and struct templates are used to
209// represent template lists. In particular, TemplatesN<T1, T2, ...,
210// TN> represents a list of N templates (T1, T2, ..., and TN). Except
211// for Templates0, every struct in the family has two member types:
212// Head for the selector of the first template in the list, and Tail
213// for the rest of the list.
214
215// The empty template list.
216struct Templates0 {};
217
218// Template lists of length 1, 2, 3, and so on.
219
220template <GTEST_TEMPLATE_ T1>
221struct Templates1 {
222 typedef TemplateSel<T1> Head;
223 typedef Templates0 Tail;
224};
225
226$range i 2..n
227
228$for i [[
229$range j 1..i
230$range k 2..i
231template <$for j, [[GTEST_TEMPLATE_ T$j]]>
232struct Templates$i {
233 typedef TemplateSel<T1> Head;
234 typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
235};
236
237
238]]
239
240// We don't want to require the users to write TemplatesN<...> directly,
241// as that would require them to count the length. Templates<...> is much
242// easier to write, but generates horrible messages when there is a
243// compiler error, as gcc insists on printing out each template
244// argument, even if it has the default value (this means Templates<list>
245// will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
246// errors).
247//
248// Our solution is to combine the best part of the two approaches: a
249// user would write Templates<T1, ..., TN>, and Google Test will translate
250// that to TemplatesN<T1, ..., TN> internally to make error messages
251// readable. The translation is done by the 'type' member of the
252// Templates template.
253
254$range i 1..n
255template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
256struct Templates {
257 typedef Templates$n<$for i, [[T$i]]> type;
258};
259
260template <>
261struct Templates<$for i, [[NoneT]]> {
262 typedef Templates0 type;
263};
264
265$range i 1..n-1
266$for i [[
267$range j 1..i
268$range k i+1..n
269template <$for j, [[GTEST_TEMPLATE_ T$j]]>
270struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
271 typedef Templates$i<$for j, [[T$j]]> type;
272};
273
274]]
275
276// The TypeList template makes it possible to use either a single type
277// or a Types<...> list in TYPED_TEST_CASE() and
278// INSTANTIATE_TYPED_TEST_CASE_P().
279
280template <typename T>
281struct TypeList {
282 typedef Types1<T> type;
283};
284
285
286$range i 1..n
287template <$for i, [[typename T$i]]>
288struct TypeList<Types<$for i, [[T$i]]> > {
289 typedef typename Types<$for i, [[T$i]]>::type type;
290};
291
292#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
293
294} // namespace internal
295} // namespace testing
296
297#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
Note: See TracBrowser for help on using the repository browser.