OSDN Git Service

2009-12-30 Daniel Frey <d.frey@gmx.de>
[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,
60            unsigned Uint>
61     bool
62     test_property(typename Property<Type, Uint>::value_type value)
63     {
64       bool ret = true;
65       ret &= Property<Type, Uint>::value == value;
66       ret &= Property<Type, Uint>::type::value == value;
67       return ret;
68     }
69
70 #ifdef __GXX_EXPERIMENTAL_CXX0X__
71   template<template<typename...> class Relationship,
72            typename... Types>
73     bool
74     test_relationship(bool value)
75     {
76       bool ret = true;
77       ret &= Relationship<Types...>::value == value;
78       ret &= Relationship<Types...>::type::value == value;
79       return ret;
80     }
81 #else
82   template<template<typename, typename> class Relationship,
83            typename Type1, typename Type2>
84     bool
85     test_relationship(bool value)
86     {
87       bool ret = true;
88       ret &= Relationship<Type1, Type2>::value == value;
89       ret &= Relationship<Type1, Type2>::type::value == value;
90       return ret;
91     }
92 #endif
93
94   // Test types.
95   class ClassType { };
96   typedef const ClassType           cClassType;
97   typedef volatile ClassType        vClassType;
98   typedef const volatile ClassType  cvClassType;
99
100   class DerivedType : public ClassType { };
101
102   enum EnumType { e0 };
103
104   struct ConvType
105   { operator int() const; };
106
107   class AbstractClass
108   {
109     virtual void rotate(int) = 0;
110   };
111
112   class PolymorphicClass
113   {
114     virtual void rotate(int);
115   };
116
117   class DerivedPolymorphic : public PolymorphicClass { };
118
119   class VirtualDestructorClass
120   {
121     virtual ~VirtualDestructorClass();
122   };
123
124   union UnionType { };
125
126   class IncompleteClass;
127
128   struct ExplicitClass
129   {
130     ExplicitClass(double&);
131     explicit ExplicitClass(int&);
132   };
133
134   int truncate_float(float x) { return (int)x; }
135   long truncate_double(double x) { return (long)x; }
136
137   struct do_truncate_float_t
138   {
139     do_truncate_float_t()
140     {
141       ++live_objects;
142     }
143
144     do_truncate_float_t(const do_truncate_float_t&)
145     {
146       ++live_objects;
147     }
148
149     ~do_truncate_float_t()
150     {
151       --live_objects;
152     }
153
154     int operator()(float x) { return (int)x; }
155
156     static int live_objects;
157   };
158
159   int do_truncate_float_t::live_objects = 0;
160
161   struct do_truncate_double_t
162   {
163     do_truncate_double_t()
164     {
165      ++live_objects;
166     }
167
168     do_truncate_double_t(const do_truncate_double_t&)
169     {
170       ++live_objects;
171     }
172
173     ~do_truncate_double_t()
174     {
175       --live_objects;
176     }
177
178     long operator()(double x) { return (long)x; }
179
180     static int live_objects;
181   };
182
183   int do_truncate_double_t::live_objects = 0;
184
185   struct X
186   {
187     int bar;
188
189     int foo()                   { return 1; }
190     int foo_c() const           { return 2; }
191     int foo_v()  volatile       { return 3; }
192     int foo_cv() const volatile { return 4; }
193   };
194
195   // For use in 8_c_compatibility.
196   template<typename R, typename T>
197     typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value, 
198                                     bool>::__type
199     check_ret_type(T)
200     { return true; }
201
202 } // namespace __gnu_test
203
204 #endif // _GLIBCXX_TESTSUITE_TR1_H