Commit | Line | Data |
---|---|---|
335928ac MC |
1 | /* This test script is part of GDB, the GNU debugger. |
2 | ||
3 | Copyright 2002, 2004, | |
4 | Free Software Foundation, Inc. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 8 | the Free Software Foundation; either version 3 of the License, or |
335928ac MC |
9 | (at your option) any later version. |
10 | ||
11 | This program 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. | |
a9762ec7 | 15 | |
335928ac | 16 | You should have received a copy of the GNU General Public License |
a9762ec7 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
335928ac | 18 | */ |
9bba8c8f MC |
19 | |
20 | #include <exception> | |
21 | #include <stdexcept> | |
22 | #include <string> | |
23 | ||
76565097 | 24 | enum region { oriental, egyptian, greek, etruscan, roman }; |
9bba8c8f | 25 | |
76565097 DC |
26 | // Test one. |
27 | class gnu_obj_1 | |
28 | { | |
29 | public: | |
30 | typedef region antiquities; | |
31 | const bool test; | |
32 | const int key1; | |
33 | long key2; | |
9bba8c8f | 34 | |
76565097 | 35 | antiquities value; |
9bba8c8f | 36 | |
76565097 DC |
37 | gnu_obj_1(antiquities a, long l): test(true), key1(5), key2(l), value(a) {} |
38 | }; | |
9bba8c8f | 39 | |
76565097 DC |
40 | // Test two. |
41 | template<typename T> | |
42 | class gnu_obj_2: public virtual gnu_obj_1 | |
43 | { | |
44 | public: | |
45 | antiquities value_derived; | |
46 | ||
47 | gnu_obj_2(antiquities b): gnu_obj_1(oriental, 7), value_derived(b) { } | |
48 | }; | |
9bba8c8f | 49 | |
76565097 DC |
50 | // Test three. |
51 | template<typename T> | |
52 | class gnu_obj_3 | |
53 | { | |
54 | public: | |
55 | typedef region antiquities; | |
56 | gnu_obj_2<int> data; | |
9bba8c8f | 57 | |
76565097 DC |
58 | gnu_obj_3(antiquities b): data(etruscan) { } |
59 | }; | |
9bba8c8f MC |
60 | |
61 | int main() | |
62 | { | |
9bba8c8f MC |
63 | bool test = true; |
64 | const int i = 5; | |
65 | int j = i; | |
66 | gnu_obj_2<long> test2(roman); | |
67 | gnu_obj_3<long> test3(greek); | |
68 | ||
69 | // 1 | |
70 | try | |
71 | { | |
72 | ++j; | |
76565097 | 73 | throw gnu_obj_1(egyptian, 4589); // marker 1-throw |
9bba8c8f MC |
74 | } |
75 | catch (gnu_obj_1& obj) | |
76 | { | |
77 | ++j; | |
76565097 | 78 | if (obj.value != egyptian) // marker 1-catch |
9bba8c8f MC |
79 | test &= false; |
80 | if (obj.key2 != 4589) | |
81 | test &= false; | |
82 | } | |
83 | catch (...) | |
84 | { | |
85 | j = 0; | |
86 | test &= false; | |
87 | } | |
88 | ||
89 | // 2 | |
90 | try | |
91 | { | |
76565097 | 92 | ++j; // marker 2-start |
9bba8c8f MC |
93 | try |
94 | { | |
76565097 | 95 | ++j; // marker 2-next |
9bba8c8f MC |
96 | try |
97 | { | |
98 | ++j; | |
76565097 | 99 | throw gnu_obj_1(egyptian, 4589); // marker 2-throw |
9bba8c8f MC |
100 | } |
101 | catch (gnu_obj_1& obj) | |
102 | { | |
103 | ++j; | |
76565097 | 104 | if (obj.value != egyptian) // marker 2-catch |
9bba8c8f MC |
105 | test &= false; |
106 | if (obj.key2 != 4589) | |
107 | test &= false; | |
108 | } | |
109 | } | |
110 | catch (gnu_obj_1& obj) | |
111 | { | |
112 | ++j; | |
113 | if (obj.value != egyptian) | |
114 | test &= false; | |
115 | if (obj.key2 != 4589) | |
116 | test &= false; | |
117 | } | |
118 | } | |
119 | catch (...) | |
120 | { | |
121 | j = 0; | |
122 | test &= false; | |
123 | } | |
124 | ||
125 | // 3 use standard library | |
126 | using namespace std; | |
127 | try | |
128 | { | |
129 | if (j < 100) | |
76565097 | 130 | throw invalid_argument("gdb.1"); // marker 3-throw |
9bba8c8f MC |
131 | } |
132 | catch (exception& obj) | |
133 | { | |
76565097 | 134 | if (obj.what() != "gdb.1") // marker 3-catch |
9bba8c8f MC |
135 | test &= false; |
136 | } | |
137 | return 0; | |
138 | } |