]>
Commit | Line | Data |
---|---|---|
0179f2c6 DG |
1 | // 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu> |
2 | // | |
748086b7 | 3 | // Copyright (C) 2005, 2009 Free Software Foundation, Inc. |
0179f2c6 DG |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
0179f2c6 DG |
9 | // any later version. |
10 | // | |
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
0179f2c6 DG |
19 | |
20 | // 3.7.2 polymorphic function object wrapper | |
21 | #include <tr1/functional> | |
22 | #include <testsuite_hooks.h> | |
23 | #include <testsuite_tr1.h> | |
24 | ||
25 | using namespace __gnu_test; | |
26 | ||
27 | bool test __attribute__((unused)) = true; | |
28 | ||
29 | // Operations on empty function<> objects | |
30 | void test01() | |
31 | { | |
32 | using std::tr1::function; | |
33 | using std::tr1::bad_function_call; | |
34 | ||
35 | // Default-construction | |
36 | function<int(float)> f1; | |
37 | VERIFY( ((bool)f1 == false) ); | |
38 | VERIFY( !f1 ); | |
39 | VERIFY( f1 == 0 ); | |
40 | VERIFY( 0 == f1 ); | |
41 | VERIFY( !(f1 != 0) ); | |
42 | VERIFY( !(0 != f1) ); | |
43 | ||
44 | // Copy-construction | |
45 | function<int(float)> f2(f1); | |
46 | VERIFY( !f2 ); | |
47 | ||
48 | // Construct with NULL pointer | |
49 | function<int(float)> f3(0); | |
50 | VERIFY( !f3 ); | |
51 | ||
52 | // Assignment | |
53 | f1 = f2; | |
54 | VERIFY( !f1); | |
55 | ||
56 | // Assignment to NULL pointer | |
57 | f1 = 0; | |
58 | VERIFY( !f1 ); | |
59 | ||
60 | // Swap | |
61 | swap(f1, f2); | |
62 | VERIFY( !f1 ); | |
63 | VERIFY( !f2 ); | |
64 | ||
65 | // Invocation should throw bad_function_call | |
66 | bool thrown = false; | |
67 | try | |
68 | { | |
69 | f1(3.14159f); | |
70 | VERIFY( false ); | |
71 | } | |
72 | catch (bad_function_call) | |
73 | { | |
74 | thrown = true; | |
75 | } | |
76 | VERIFY( thrown ); | |
77 | ||
78 | // target_type returns typeid(void) | |
79 | VERIFY( f1.target_type() == typeid(void) ); | |
80 | ||
81 | // target() always returns a NULL pointer | |
82 | VERIFY( f1.target<int (*)(float)>() == 0); | |
83 | ||
84 | // Check const version | |
85 | const function<int(float)>& f1c = f1; | |
86 | VERIFY( f1c.target<int (*)(float)>() == 0 ); | |
87 | VERIFY( !f1c ); | |
88 | } | |
89 | ||
90 | int main() | |
91 | { | |
92 | test01(); | |
93 | return 0; | |
94 | } |