Commit | Line | Data |
---|---|---|
9bba8c8f MC |
1 | // 2002-05-27 |
2 | ||
3 | #include <exception> | |
4 | #include <stdexcept> | |
5 | #include <string> | |
6 | ||
76565097 | 7 | enum region { oriental, egyptian, greek, etruscan, roman }; |
9bba8c8f | 8 | |
76565097 DC |
9 | // Test one. |
10 | class gnu_obj_1 | |
11 | { | |
12 | public: | |
13 | typedef region antiquities; | |
14 | const bool test; | |
15 | const int key1; | |
16 | long key2; | |
9bba8c8f | 17 | |
76565097 | 18 | antiquities value; |
9bba8c8f | 19 | |
76565097 DC |
20 | gnu_obj_1(antiquities a, long l): test(true), key1(5), key2(l), value(a) {} |
21 | }; | |
9bba8c8f | 22 | |
76565097 DC |
23 | // Test two. |
24 | template<typename T> | |
25 | class gnu_obj_2: public virtual gnu_obj_1 | |
26 | { | |
27 | public: | |
28 | antiquities value_derived; | |
29 | ||
30 | gnu_obj_2(antiquities b): gnu_obj_1(oriental, 7), value_derived(b) { } | |
31 | }; | |
9bba8c8f | 32 | |
76565097 DC |
33 | // Test three. |
34 | template<typename T> | |
35 | class gnu_obj_3 | |
36 | { | |
37 | public: | |
38 | typedef region antiquities; | |
39 | gnu_obj_2<int> data; | |
9bba8c8f | 40 | |
76565097 DC |
41 | gnu_obj_3(antiquities b): data(etruscan) { } |
42 | }; | |
9bba8c8f MC |
43 | |
44 | int main() | |
45 | { | |
9bba8c8f MC |
46 | bool test = true; |
47 | const int i = 5; | |
48 | int j = i; | |
49 | gnu_obj_2<long> test2(roman); | |
50 | gnu_obj_3<long> test3(greek); | |
51 | ||
52 | // 1 | |
53 | try | |
54 | { | |
55 | ++j; | |
76565097 | 56 | throw gnu_obj_1(egyptian, 4589); // marker 1-throw |
9bba8c8f MC |
57 | } |
58 | catch (gnu_obj_1& obj) | |
59 | { | |
60 | ++j; | |
76565097 | 61 | if (obj.value != egyptian) // marker 1-catch |
9bba8c8f MC |
62 | test &= false; |
63 | if (obj.key2 != 4589) | |
64 | test &= false; | |
65 | } | |
66 | catch (...) | |
67 | { | |
68 | j = 0; | |
69 | test &= false; | |
70 | } | |
71 | ||
72 | // 2 | |
73 | try | |
74 | { | |
76565097 | 75 | ++j; // marker 2-start |
9bba8c8f MC |
76 | try |
77 | { | |
76565097 | 78 | ++j; // marker 2-next |
9bba8c8f MC |
79 | try |
80 | { | |
81 | ++j; | |
76565097 | 82 | throw gnu_obj_1(egyptian, 4589); // marker 2-throw |
9bba8c8f MC |
83 | } |
84 | catch (gnu_obj_1& obj) | |
85 | { | |
86 | ++j; | |
76565097 | 87 | if (obj.value != egyptian) // marker 2-catch |
9bba8c8f MC |
88 | test &= false; |
89 | if (obj.key2 != 4589) | |
90 | test &= false; | |
91 | } | |
92 | } | |
93 | catch (gnu_obj_1& obj) | |
94 | { | |
95 | ++j; | |
96 | if (obj.value != egyptian) | |
97 | test &= false; | |
98 | if (obj.key2 != 4589) | |
99 | test &= false; | |
100 | } | |
101 | } | |
102 | catch (...) | |
103 | { | |
104 | j = 0; | |
105 | test &= false; | |
106 | } | |
107 | ||
108 | // 3 use standard library | |
109 | using namespace std; | |
110 | try | |
111 | { | |
112 | if (j < 100) | |
76565097 | 113 | throw invalid_argument("gdb.1"); // marker 3-throw |
9bba8c8f MC |
114 | } |
115 | catch (exception& obj) | |
116 | { | |
76565097 | 117 | if (obj.what() != "gdb.1") // marker 3-catch |
9bba8c8f MC |
118 | test &= false; |
119 | } | |
120 | return 0; | |
121 | } |