summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/ca/ca11d013.am
blob: 6cbd3bbccdc202387930fb7edfa9efdb63d10a5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
-- CA11D013.AM
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
--      Check that a child unit can raise an exception that is declared in 
--      parent.                
--
-- TEST DESCRIPTION:
--      Declare a package which defines complex number abstraction with
--      user-defined exceptions (foundation code).
--
--      Add a public child package to the above package. Declare two 
--      subprograms for the parent type.  Each of the subprograms raises a 
--      different exception, based on the value of an input parameter.
--
--      Add a public child procedure to the foundation package.  This
--      procedure raises an exception based on the value of an input 
--      parameter.
--
--      Add a public child function to the foundation package.  This
--      function raises an exception based on the value of an input 
--      parameter.
--
--      In the main program, "with" the child packages, then check that
--      the exceptions are raised and handled as expected.  Ensure that
--      exceptions are:
--         1) raised in the public child package and handled/reraised to
--            be handled by the main program.
--         2) raised and handled locally in the public child package.
--         3) raised and handled locally by "others" in the public child 
--            procedure.
--         4) raised in the public child function and propagated to the
--            main program.
--
-- TEST FILES:
--      The following files comprise this test:
--
--         FA11D00.A
--         CA11D010.A
--         CA11D011.A
--         CA11D012.A
--      => CA11D013.AM
--
--
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--
--!

with FA11D00.CA11D010;               -- Add_Subtract_Complex
with FA11D00.CA11D011;               -- Multiply_Complex
with FA11D00.CA11D012;               -- Divide_Complex

with Report;


procedure CA11D013 is

   package Complex_Pkg renames FA11D00;
   package Add_Subtract_Complex_Pkg renames FA11D00.CA11D010;
   use Complex_Pkg;

begin

   Report.Test ("CA11D013", "Check that a child unit can raise an " &
                "exception that is declared in parent");


   Add_Complex_Subtest:
   declare
      First       : Complex_Type := Complex (Int_Type (Report.Ident_Int (3)), 
                                    Int_Type (Report.Ident_Int (7)));  
      Second      : Complex_Type := Complex (Int_Type (Report.Ident_Int (5)), 
                                    Int_Type (Report.Ident_Int (3)));  
      Add_Result  : Complex_Type := Complex (Int_Type (Report.Ident_Int (8)), 
                                    Int_Type (Report.Ident_Int (10)));  
      Third       : Complex_Type := Complex (Int_Type(Report.Ident_Int(-100)), 
                                    Int_Type (Report.Ident_Int (100)));  
      Complex_Num : Complex_Type := Zero;  

   begin
      Add_Subtract_Complex_Pkg.Add (First, Second, Complex_Num);

      if (Complex_Num /= Add_Result) then
         Report.Failed ("Incorrect results from addition");
      end if;
  
      -- Error is raised in child package and exception 
      -- will be handled/reraised to caller.

      Add_Subtract_Complex_Pkg.Add (First, Third, Complex_Num);

      -- Error was not raised in child package.
      Report.Failed ("Exception was not reraised in addition");

   exception
      when Add_Error     => 
         if not TC_Handled_In_Child_Pkg_Proc then
            Report.Failed ("Exception was not raised in addition");
         else
            TC_Handled_In_Caller := true;  -- Exception is reraised from
                                           -- child package.
         end if;

      when others => 
         Report.Failed ("Unexpected exception in addition subtest"); 
         TC_Handled_In_Caller := false;  -- Improper exception handling
                                         -- in caller.

   end Add_Complex_Subtest;


   Subtract_Complex_Subtest:
   declare
      First       : Complex_Type := Complex (Int_Type (Report.Ident_Int (3)), 
                                    Int_Type (Report.Ident_Int (6)));  
      Second      : Complex_Type := Complex (Int_Type (Report.Ident_Int (5)), 
                                    Int_Type (Report.Ident_Int (7)));  
      Sub_Result  : Complex_Type := Complex (Int_Type (Report.Ident_Int (2)), 
                                    Int_Type (Report.Ident_Int (1)));  
      Third       : Complex_Type := Complex (Int_Type(Report.Ident_Int(-200)), 
                                    Int_Type (Report.Ident_Int (1)));  
      Complex_Num : Complex_Type;

   begin
      Complex_Num := Add_Subtract_Complex_Pkg.Subtract (Second, First);

      if (Complex_Num /= Sub_Result) then
         Report.Failed ("Incorrect results from subtraction");
      end if;
  
      -- Error is raised and exception will be handled in child package.
      Complex_Num := Add_Subtract_Complex_Pkg.Subtract (Second, Third);

   exception
      when Subtract_Error => 
         Report.Failed ("Exception raised in subtraction and " &
                        "propagated to caller");
         TC_Handled_In_Child_Pkg_Func := false; -- Improper exception handling
                                                -- in caller.

      when others => 
         Report.Failed ("Unexpected exception in subtraction subtest"); 
         TC_Handled_In_Child_Pkg_Func := false; -- Improper exception handling
                                                -- in caller.

   end Subtract_Complex_Subtest;


   Multiply_Complex_Subtest:
   declare
      First       : Complex_Type := Complex (Int_Type(Report.Ident_Int(3)), 
                                    Int_Type (Report.Ident_Int (4)));  
      Second      : Complex_Type := Complex (Int_Type(Report.Ident_Int(5)), 
                                    Int_Type (Report.Ident_Int (3)));  
      Mult_Result : Complex_Type := Complex(Int_Type(Report.Ident_Int(15)), 
                                    Int_Type(Report.Ident_Int (12)));  
      Third       : Complex_Type := Complex(Int_Type(Report.Ident_Int(10)), 
                                    Int_Type(Report.Ident_Int (-10)));  
      Complex_Num : Complex_Type;

   begin
      CA11D011 (First, Second, Complex_Num);

      if (Complex_Num /= Mult_Result) then
         Report.Failed ("Incorrect results from multiplication");
      end if;
  
      -- Error is raised and exception will be handled in child package.
     CA11D011 (First, Third, Complex_Num);

   exception
      when Multiply_Error => 
         Report.Failed ("Exception raised in multiplication and " &
                        "propagated to caller");
         TC_Handled_In_Child_Sub := false;     -- Improper exception handling
                                               -- in caller.

      when others => 
         Report.Failed ("Unexpected exception in multiplication subtest"); 
         TC_Handled_In_Child_Sub := false;     -- Improper exception handling
                                               -- in caller.
   end Multiply_Complex_Subtest;


   Divide_Complex_Subtest:
   declare
      First       : Complex_Type := Complex (Int_Type (Report.Ident_Int(10)), 
                                    Int_Type (Report.Ident_Int (15)));  
      Second      : Complex_Type := Complex (Int_Type(Report.Ident_Int(5)), 
                                    Int_Type (Report.Ident_Int (3)));  
      Div_Result  : Complex_Type := Complex (Int_Type(Report.Ident_Int(2)), 
                                    Int_Type (Report.Ident_Int (5)));  
      Third       : Complex_Type := Complex (Int_Type(Report.Ident_Int(-10)), 
                                    Int_Type (Report.Ident_Int (0)));  
      Complex_Num : Complex_Type := Zero;

   begin
      Complex_Num := CA11D012 (First, Second);

      if (Complex_Num /= Div_Result) then
         Report.Failed ("Incorrect results from division");
      end if;
  
      -- Error is raised in child package; exception will be
      -- propagated to caller.
      Complex_Num := CA11D012 (Second, Third);

      -- Error was not raised in child package.
      Report.Failed ("Exception was not raised in division subtest ");

   exception
      when Divide_Error => 
         TC_Propagated_To_Caller := true;  -- Exception is propagated.

      when others => 
         Report.Failed ("Unexpected exception in division subtest"); 
         TC_Propagated_To_Caller := false;  -- Improper exception handling
                                            -- in caller.
   end Divide_Complex_Subtest;


   if not (TC_Handled_In_Caller         and     -- Check to see that all 
           TC_Handled_In_Child_Pkg_Proc and     -- exceptions were handled in
           TC_Handled_In_Child_Pkg_Func and     -- the proper locations.
           TC_Handled_In_Child_Sub      and     
           TC_Propagated_To_Caller)
   then
      Report.Failed ("Exceptions handled in incorrect locations");
   end if;

   Report.Result;

end CA11D013;