]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/util/testsuite_tr1.h
util: New directory.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / testsuite_tr1.h
1 // -*- C++ -*-
2 // Testing utilities for the tr1 testsuite.
3 //
4 // Copyright (C) 2004, 2005, 2006 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 2, 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 COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21 //
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 #ifndef _GLIBCXX_TESTSUITE_TR1_H
32 #define _GLIBCXX_TESTSUITE_TR1_H
33
34 #include <bits/cpp_type_traits.h>
35
36 namespace __gnu_test
37 {
38 // For tr1/type_traits.
39 template<template<typename> class Category,
40 typename Type>
41 bool
42 test_category(bool value)
43 {
44 bool ret = true;
45 ret &= Category<Type>::value == value;
46 ret &= Category<const Type>::value == value;
47 ret &= Category<volatile Type>::value == value;
48 ret &= Category<const volatile Type>::value == value;
49 ret &= Category<Type>::type::value == value;
50 ret &= Category<const Type>::type::value == value;
51 ret &= Category<volatile Type>::type::value == value;
52 ret &= Category<const volatile Type>::type::value == value;
53 return ret;
54 }
55
56 template<template<typename> class Property,
57 typename Type>
58 bool
59 test_property(typename Property<Type>::value_type value)
60 {
61 bool ret = true;
62 ret &= Property<Type>::value == value;
63 ret &= Property<Type>::type::value == value;
64 return ret;
65 }
66
67 // For testing tr1/type_traits/extent, which has a second template
68 // parameter.
69 template<template<typename, unsigned> class Property,
70 typename Type,
71 unsigned Uint>
72 bool
73 test_property(typename Property<Type, Uint>::value_type value)
74 {
75 bool ret = true;
76 ret &= Property<Type, Uint>::value == value;
77 ret &= Property<Type, Uint>::type::value == value;
78 return ret;
79 }
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 { };
101
102 struct ConvType
103 { operator int() const; };
104
105 class AbstractClass
106 {
107 virtual void rotate(int) = 0;
108 virtual ~AbstractClass();
109 };
110
111 class PolymorphicClass
112 {
113 virtual void rotate(int);
114 virtual ~PolymorphicClass();
115 };
116
117 class DerivedPolymorphic : public PolymorphicClass { };
118
119 union UnionType { };
120
121 class IncompleteClass;
122
123 int truncate_float(float x) { return (int)x; }
124 long truncate_double(double x) { return (long)x; }
125
126 struct do_truncate_float_t
127 {
128 do_truncate_float_t()
129 {
130 ++live_objects;
131 }
132
133 do_truncate_float_t(const do_truncate_float_t&)
134 {
135 ++live_objects;
136 }
137
138 ~do_truncate_float_t()
139 {
140 --live_objects;
141 }
142
143 int operator()(float x) { return (int)x; }
144
145 static int live_objects;
146 };
147
148 int do_truncate_float_t::live_objects = 0;
149
150 struct do_truncate_double_t
151 {
152 do_truncate_double_t()
153 {
154 ++live_objects;
155 }
156
157 do_truncate_double_t(const do_truncate_double_t&)
158 {
159 ++live_objects;
160 }
161
162 ~do_truncate_double_t()
163 {
164 --live_objects;
165 }
166
167 long operator()(double x) { return (long)x; }
168
169 static int live_objects;
170 };
171
172 int do_truncate_double_t::live_objects = 0;
173
174 struct X
175 {
176 int bar;
177
178 int foo() { return 1; }
179 int foo_c() const { return 2; }
180 int foo_v() volatile { return 3; }
181 int foo_cv() const volatile { return 4; }
182 };
183
184 // For use in 8_c_compatibility.
185 template<typename R, typename T>
186 typename std::__enable_if<bool, std::__are_same<R, T>::__value>::__type
187 check_ret_type(T)
188 { return true; }
189
190 } // namespace __gnu_test
191
192 #endif // _GLIBCXX_TESTSUITE_TR1_H