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