2005-04-26 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / libstdc++-v3 / testsuite / testsuite_tr1.h
blobea6affb37c1dba96596376621fa229befd4403bf
1 // -*- C++ -*-
2 // Testing utilities for the tr1 testsuite.
3 //
4 // Copyright (C) 2004, 2005 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.
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.
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
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.
31 #ifndef _GLIBCXX_TESTSUITE_TR1_H
32 #define _GLIBCXX_TESTSUITE_TR1_H
34 namespace __gnu_test
36 // For tr1/type_traits.
37 template<template<typename> class Category,
38 typename Type>
39 bool
40 test_category(bool value)
42 bool ret = true;
43 ret &= Category<Type>::value == value;
44 ret &= Category<const Type>::value == value;
45 ret &= Category<volatile Type>::value == value;
46 ret &= Category<const volatile Type>::value == value;
47 ret &= Category<Type>::type::value == value;
48 ret &= Category<const Type>::type::value == value;
49 ret &= Category<volatile Type>::type::value == value;
50 ret &= Category<const volatile Type>::type::value == value;
51 return ret;
54 template<template<typename> class Property,
55 typename Type>
56 bool
57 test_property(typename Property<Type>::value_type value)
59 bool ret = true;
60 ret &= Property<Type>::value == value;
61 ret &= Property<Type>::type::value == value;
62 return ret;
65 template<template<typename> class Property,
66 typename Type>
67 bool
68 test_copy_property(bool value)
70 bool ret = true;
71 ret &= Property<Type>::value == value;
72 ret &= Property<const Type>::value == value;
73 ret &= Property<volatile Type>::value == !value;
74 ret &= Property<const volatile Type>::value == !value;
75 ret &= Property<Type>::type::value == value;
76 ret &= Property<const Type>::type::value == value;
77 ret &= Property<volatile Type>::type::value == !value;
78 ret &= Property<const volatile Type>::type::value == !value;
79 return ret;
82 template<template<typename> class Property,
83 typename Type>
84 bool
85 test_assign_property(bool value)
87 bool ret = true;
88 ret &= Property<Type>::value == value;
89 ret &= Property<const Type>::value == !value;
90 ret &= Property<volatile Type>::value == !value;
91 ret &= Property<const volatile Type>::value == !value;
92 ret &= Property<Type>::type::value == value;
93 ret &= Property<const Type>::type::value == !value;
94 ret &= Property<volatile Type>::type::value == !value;
95 ret &= Property<const volatile Type>::type::value == !value;
96 return ret;
99 template<template<typename, typename> class Relationship,
100 typename Type1, typename Type2>
101 bool
102 test_relationship(bool value)
104 bool ret = true;
105 ret &= Relationship<Type1, Type2>::value == value;
106 ret &= Relationship<Type1, Type2>::type::value == value;
107 return ret;
110 // Test types.
111 class ClassType { };
112 typedef const ClassType cClassType;
113 typedef volatile ClassType vClassType;
114 typedef const volatile ClassType cvClassType;
116 class DerivedType : public ClassType { };
118 enum EnumType { };
120 struct ConvType
121 { operator int() const; };
123 class AbstractClass
125 virtual void rotate(int) = 0;
126 virtual ~AbstractClass();
129 class PolymorphicClass
131 virtual void rotate(int);
132 virtual ~PolymorphicClass();
135 class DerivedPolymorphic : public PolymorphicClass { };
137 union UnionType { };
140 int truncate_float(float x) { return (int)x; }
141 long truncate_double(double x) { return (long)x; }
143 struct do_truncate_float_t
145 do_truncate_float_t()
147 ++live_objects;
150 do_truncate_float_t(const do_truncate_float_t&)
152 ++live_objects;
155 ~do_truncate_float_t()
157 --live_objects;
160 int operator()(float x) { return (int)x; }
162 static int live_objects;
165 int do_truncate_float_t::live_objects = 0;
167 struct do_truncate_double_t
169 do_truncate_double_t()
171 ++live_objects;
174 do_truncate_double_t(const do_truncate_double_t&)
176 ++live_objects;
179 ~do_truncate_double_t()
181 --live_objects;
184 long operator()(double x) { return (long)x; }
186 static int live_objects;
189 int do_truncate_double_t::live_objects = 0;
191 struct X
193 int bar;
195 int foo() { return 1; }
196 int foo_c() const { return 2; }
197 int foo_v() volatile { return 3; }
198 int foo_cv() const volatile { return 4; }
200 } // namespace __gnu_test
202 #endif // _GLIBCXX_TESTSUITE_TR1_H