OSDN Git Service

2010-03-23 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / util / testsuite_tr1.h
1 // -*- C++ -*-
2 // Testing utilities for the tr1 testsuite.
3 //
4 // Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3.  If not see
19 // <http://www.gnu.org/licenses/>.
20 //
21
22 #ifndef _GLIBCXX_TESTSUITE_TR1_H
23 #define _GLIBCXX_TESTSUITE_TR1_H
24
25 #include <ext/type_traits.h>
26
27 namespace __gnu_test
28 {
29   // For tr1/type_traits.
30   template<template<typename> class Category, typename Type>
31     bool
32     test_category(bool value)
33     {
34       bool ret = true;
35       ret &= Category<Type>::value == value;
36       ret &= Category<const Type>::value == value;
37       ret &= Category<volatile Type>::value == value;
38       ret &= Category<const volatile Type>::value == value;
39       ret &= Category<Type>::type::value == value;
40       ret &= Category<const Type>::type::value == value;
41       ret &= Category<volatile Type>::type::value == value;
42       ret &= Category<const volatile Type>::type::value == value;
43       return ret;
44     }
45
46   template<template<typename> class Property, typename Type>
47     bool
48     test_property(typename Property<Type>::value_type value)
49     {
50       bool ret = true;
51       ret &= Property<Type>::value == value;
52       ret &= Property<Type>::type::value == value;
53       return ret;
54     }
55
56   // For testing tr1/type_traits/extent, which has a second template
57   // parameter.
58   template<template<typename, unsigned> class Property,
59            typename Type, unsigned Uint>
60     bool
61     test_property(typename Property<Type, Uint>::value_type value)
62     {
63       bool ret = true;
64       ret &= Property<Type, Uint>::value == value;
65       ret &= Property<Type, Uint>::type::value == value;
66       return ret;
67     }
68
69 #ifdef __GXX_EXPERIMENTAL_CXX0X__
70   template<template<typename...> class Property, typename... Types>
71     bool
72     test_property(typename Property<Types...>::value_type value)
73     {
74       bool ret = true;
75       ret &= Property<Types...>::value == value;
76       ret &= Property<Types...>::type::value == value;
77       return ret;
78     }
79 #endif
80
81   template<template<typename, typename> class Relationship,
82            typename Type1, typename Type2>
83     bool
84     test_relationship(bool value)
85     {
86       bool ret = true;
87       ret &= Relationship<Type1, Type2>::value == value;
88       ret &= Relationship<Type1, Type2>::type::value == value;
89       return ret;
90     }
91
92   // Test types.
93   class ClassType { };
94   typedef const ClassType           cClassType;
95   typedef volatile ClassType        vClassType;
96   typedef const volatile ClassType  cvClassType;
97
98   class DerivedType : public ClassType { };
99
100   enum EnumType { e0 };
101
102   struct ConvType
103   { operator int() const; };
104
105   class AbstractClass
106   {
107     virtual void rotate(int) = 0;
108   };
109
110   class PolymorphicClass
111   {
112     virtual void rotate(int);
113   };
114
115   class DerivedPolymorphic : public PolymorphicClass { };
116
117   class VirtualDestructorClass
118   {
119     virtual ~VirtualDestructorClass();
120   };
121
122   union UnionType { };
123
124   class IncompleteClass;
125
126   struct ExplicitClass
127   {
128     ExplicitClass(double&);
129     explicit ExplicitClass(int&);
130   };
131
132   struct NType   // neither trivial nor standard-layout
133   {
134     int i;
135     int j;
136     virtual ~NType();
137   };
138
139   struct TType   // trivial but not standard-layout
140   {
141     int i;
142   private:
143     int j;
144   };
145
146   struct SLType  // standard-layout but not trivial
147   {
148     int i;
149     int j;
150     ~SLType();
151   };
152
153   struct PODType // both trivial and standard-layout
154   {
155     int i;
156     int j;
157   };
158
159   int truncate_float(float x) { return (int)x; }
160   long truncate_double(double x) { return (long)x; }
161
162   struct do_truncate_float_t
163   {
164     do_truncate_float_t()
165     {
166       ++live_objects;
167     }
168
169     do_truncate_float_t(const do_truncate_float_t&)
170     {
171       ++live_objects;
172     }
173
174     ~do_truncate_float_t()
175     {
176       --live_objects;
177     }
178
179     int operator()(float x) { return (int)x; }
180
181     static int live_objects;
182   };
183
184   int do_truncate_float_t::live_objects = 0;
185
186   struct do_truncate_double_t
187   {
188     do_truncate_double_t()
189     {
190      ++live_objects;
191     }
192
193     do_truncate_double_t(const do_truncate_double_t&)
194     {
195       ++live_objects;
196     }
197
198     ~do_truncate_double_t()
199     {
200       --live_objects;
201     }
202
203     long operator()(double x) { return (long)x; }
204
205     static int live_objects;
206   };
207
208   int do_truncate_double_t::live_objects = 0;
209
210   struct X
211   {
212     int bar;
213
214     int foo()                   { return 1; }
215     int foo_c() const           { return 2; }
216     int foo_v()  volatile       { return 3; }
217     int foo_cv() const volatile { return 4; }
218   };
219
220   // For use in 8_c_compatibility.
221   template<typename R, typename T>
222     typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value, 
223                                     bool>::__type
224     check_ret_type(T)
225     { return true; }
226
227 } // namespace __gnu_test
228
229 #endif // _GLIBCXX_TESTSUITE_TR1_H