Debian Codegraph @

gcc/testsuite/ada/acats/tests/c6/c620002.a

raw
1 -- C620001.A
2
3 -- Grant of Unlimited Rights
4 --
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
14 -- to do so.
15 --
16 -- DISCLAIMER
17 --
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
24 --*
25 -- OBJECTIVE:
26 -- Check that elementary parameters are passed by copy.
27 --
28 -- Part 2: Integer, float, and access types, task and protected entries.
29 --
30 -- TEST DESCRIPTION:
31 -- Subtests are:
32 -- (A) Scalar parameters to task entries.
33 -- (B) Scalar parameters to protected entries.
34 -- (C) Access parameters to task entries.
35 -- (D) Access parameters to protected entries.
36 --
37 -- For all of these examples, we pass array elements indexed by dynamically
38 -- determined indexes. Doing this side-steps the check of 6.4.1(6.15/3) and
39 -- makes the test more realistic.
40 --
41 -- Note: This is based on legacy test C95072A.ADA (which was withdrawn).
42 --
43 -- CHANGE HISTORY:
44 -- 22 Jul 1985 DAS Created test.
45 -- 12 May 2020 RLB Revised so test cases are legal for Ada 2012, modernized
46 -- objective, converted to modern format, added float
47 -- and protected cases.
48
49 with Report;
50 procedure C620002 is
51
52 use Report;
53
54 begin
55 Test ("C620002", "Check that elementary parameters are passed by copy," &
56 " part 2 - task and protected entries");
57
58 --------------------------------------------------
59
60 declare -- (A)
61
62 I,J,K : Natural := Report.Ident_Int (1); -- Index values.
63 Arr : array (1 .. 4) of Integer;
64 E : exception;
65
66 task TA is
67 entry EA (EI : in Integer;
68 EO : out Integer;
69 EIO : in out Integer);
70 end TA;
71
72 task body TA is
73
74 Tmp : Integer;
75
76 begin
77
78 accept EA (EI : in Integer;
79 EO : out Integer;
80 EIO : in out Integer) do
81
82 Tmp := EI; -- Save value of EI at accept.
83
84 EO := 10;
85 if EI /= Tmp then
86 Failed ("Assignement to scalar out " &
87 "parameter changes the value of " &
88 "input parameter - A");
89 Tmp := EI; -- Reset Tmp for next case.
90 end if;
91
92 EIO := EIO + 100;
93 if EI /= Tmp then
94 Failed ("Assignment to scalar in out " &
95 "parameter changes the value of " &
96 "input parameter - A");
97 Tmp := EI; -- Reset Tmp for next case.
98 end if;
99
100 Arr(I) := Arr(I) + 1;
101 if EI /= Tmp then
102 Failed ("Assignment to scalar actual " &
103 "parameter changes the value of " &
104 "input parameter - A");
105 end if;
106
107 raise E; -- Check exception handling.
108 end EA;
109
110 exception
111 when others => null;
112 end TA;
113
114 begin -- (A)
115 Arr := (others => 0);
116 TA.EA (Arr(I), Arr(J), Arr(K));
117 Failed ("Exception not raised - A");
118 exception
119 when E =>
120 if Arr(I) /= 1 then
121 case Arr(I) is
122 when 11 =>
123 Failed ("Out actual scalar parameter " &
124 "changed global value - A");
125 when 101 =>
126 Failed ("In out actual scalar " &
127 "parameter changed global value - A");
128 when 111 =>
129 Failed ("Out and in out actual scalar " &
130 "parameters changed global " &
131 "value - A");
132 when others =>
133 Failed ("Undetermined change to global " &
134 "value - A");
135 end case;
136 end if;
137 when others =>
138 Failed ("Wrong exception raised - A");
139 end; -- (A)
140
141 --------------------------------------------------
142
143 declare -- (B)
144
145 I,J,K : Natural := Report.Ident_Int (3); -- Index values.
146 Arr : array (1 .. 5) of Integer;
147 E : exception;
148
149 protected PA is
150 entry EA (EI : in Integer;
151 EO : out Integer;
152 EIO : in out Integer);
153 end PA;
154
155 protected body PA is
156
157 entry EA (EI : in Integer;
158 EO : out Integer;
159 EIO : in out Integer) when True is
160
161 Tmp : Integer;
162
163 begin
164
165 Tmp := EI; -- Save value of EI at entry.
166
167 EO := 10;
168 if EI /= Tmp then
169 Failed ("Assignement to scalar out " &
170 "parameter changes the value of " &
171 "input parameter - B");
172 Tmp := EI; -- Reset Tmp for next case.
173 end if;
174
175 EIO := EIO + 100;
176 if EI /= Tmp then
177 Failed ("Assignment to scalar in out " &
178 "parameter changes the value of " &
179 "input parameter - B");
180 Tmp := EI; -- Reset Tmp for next case.
181 end if;
182
183 Arr(I) := Arr(I) + 1;
184 if EI /= Tmp then
185 Failed ("Assignment to scalar actual " &
186 "parameter changes the value of " &
187 "input parameter - B");
188 end if;
189
190 raise E; -- Check exception handling.
191 end EA;
192
193 end PA;
194
195 begin -- (B)
196 Arr := (others => 0);
197 PA.EA (Arr(I), Arr(J), Arr(K));
198 Failed ("Exception not raised - B");
199 exception
200 when E =>
201 if Arr(I) /= 1 then
202 case Arr(I) is
203 when 11 =>
204 Failed ("Out actual scalar parameter " &
205 "changed global value - B");
206 when 101 =>
207 Failed ("In out actual scalar " &
208 "parameter changed global value - B");
209 when 111 =>
210 Failed ("Out and in out actual scalar " &
211 "parameters changed global " &
212 "value - B");
213 when others =>
214 Failed ("Undetermined change to global " &
215 "value - B");
216 end case;
217 end if;
218 when others =>
219 Failed ("Wrong exception raised - B");
220 end; -- (B)
221
222 --------------------------------------------------
223
224 declare -- (C)
225
226 type Acctype is access Integer;
227
228 I,J,K : Natural := Report.Ident_Int (2); -- Index values.
229 Arr : array (1 .. 5) of Acctype;
230 E : exception;
231
232 task TB is
233 entry EB (EI : in Acctype;
234 EO : out Acctype;
235 EIO : in out Acctype);
236 end TB;
237
238 task body TB is
239
240 Tmp : Acctype;
241
242 begin
243
244 accept EB (EI : in Acctype;
245 EO : out Acctype;
246 EIO : in out Acctype) do
247
248 Tmp := EI; -- Save value of EI at accept.
249
250 Arr(I) := new Integer'(101);
251 if EI /= Tmp then
252 Failed ("Assignment to access actual " &
253 "parameter changes the value of " &
254 "input parameter - C");
255 Tmp := EI; -- Reset Tmp for next case.
256 end if;
257
258 EO := new Integer'(1);
259 if EI /= Tmp then
260 Failed ("Assignment to access out " &
261 "parameter changes the value of " &
262 "input parameter - C");
263 Tmp := EI; -- Reset Tmp for next case.
264 end if;
265
266 EIO := new Integer'(10);
267 if EI /= Tmp then
268 Failed ("Assignment to access in out " &
269 "parameter changes the value of " &
270 "input parameter - C");
271 end if;
272
273 raise E; -- Check exception handling.
274 end EB;
275
276 exception
277 when others => null;
278 end TB;
279
280 begin -- (C)
281 Arr(I) := new Integer'(100);
282 TB.EB (Arr(I), Arr(J), Arr(K));
283 Failed ("Exception not raised - C");
284 exception
285 when E =>
286 if (Arr(I).all /= 101) then
287 Failed ("Out or in out actual " &
288 "parameter value changed despite " &
289 "raised exception - C");
290 end if;
291 when others =>
292 Failed ("Wrong exception raised - C");
293 end; -- (C)
294
295 --------------------------------------------------
296
297 declare -- (D)
298
299 type Acctype is access Integer;
300
301 I,J,K : Natural := Report.Ident_Int (4); -- Index values.
302 Arr : array (1 .. 6) of Acctype;
303 E : exception;
304
305 protected PB is
306 entry EB (EI : in Acctype;
307 EO : out Acctype;
308 EIO : in out Acctype);
309 end PB;
310
311 protected body PB is
312
313 entry EB (EI : in Acctype;
314 EO : out Acctype;
315 EIO : in out Acctype) when True is
316
317 Tmp : Acctype;
318
319 begin
320 Tmp := EI; -- Save value of EI at entry.
321
322 Arr(I) := new Integer'(101);
323 if EI /= Tmp then
324 Failed ("Assignment to access actual " &
325 "parameter changes the value of " &
326 "input parameter - D");
327 Tmp := EI; -- Reset Tmp for next case.
328 end if;
329
330 EO := new Integer'(1);
331 if EI /= Tmp then
332 Failed ("Assignment to access out " &
333 "parameter changes the value of " &
334 "input parameter - D");
335 Tmp := EI; -- Reset Tmp for next case.
336 end if;
337
338 EIO := new Integer'(10);
339 if EI /= Tmp then
340 Failed ("Assignment to access in out " &
341 "parameter changes the value of " &
342 "input parameter - D");
343 end if;
344
345 raise E; -- Check exception handling.
346 end EB;
347
348 end PB;
349
350 begin -- (D)
351 Arr(I) := new Integer'(100);
352 PB.EB (Arr(I), Arr(J), Arr(K));
353 Failed ("Exception not raised - D");
354 exception
355 when E =>
356 if (Arr(I).all /= 101) then
357 Failed ("Out or in out actual " &
358 "parameter value changed despite " &
359 "raised exception - D");
360 end if;
361 when others =>
362 Failed ("Wrong exception raised - D");
363 end; -- (D)
364
365 --------------------------------------------------
366
367 declare -- (E)
368
369 I,J,K : Natural := Report.Ident_Int (3); -- Index values.
370 Arr : array (1 .. 3) of Float;
371 E : exception;
372
373 task TC is
374 entry EC (EI : in Float;
375 EO : out Float;
376 EIO : in out Float);
377 end TC;
378
379 task body TC is
380
381 Tmp : Float;
382
383 begin
384
385 accept EC (EI : in Float;
386 EO : out Float;
387 EIO : in out Float) do
388
389 Tmp := EI; -- Save value of EI at accept.
390
391 EO := 0.5;
392 if EI /= Tmp then
393 Failed ("Assignement to float out " &
394 "parameter changes the value of " &
395 "input parameter - E");
396 Tmp := EI; -- Reset Tmp for next case.
397 end if;
398
399 EIO := EIO + 0.25;
400 if EI /= Tmp then
401 Failed ("Assignment to float in out " &
402 "parameter changes the value of " &
403 "input parameter - E");
404 Tmp := EI; -- Reset Tmp for next case.
405 end if;
406
407 Arr(I) := Arr(I) + 1.0;
408 if EI /= Tmp then
409 Failed ("Assignment to float actual " &
410 "parameter changes the value of " &
411 "input parameter - E");
412 end if;
413
414 raise E; -- Check exception handling.
415 end EC;
416
417 exception
418 when others => null;
419 end TC;
420
421 begin -- (E)
422 Arr := (others => 0.0);
423 TC.EC (Arr(I), Arr(J), Arr(K));
424 Failed ("Exception not raised - E");
425 exception
426 when E =>
427 if (Arr(I) /= 1.0) then
428 Failed ("Out or in out actual procedure " &
429 "parameter value changed despite " &
430 "raised exception - E");
431 end if;
432 when others =>
433 Failed ("Wrong exception raised - E");
434 end; -- (E)
435
436 --------------------------------------------------
437
438 declare -- (F)
439
440 I,J,K : Natural := Report.Ident_Int (6); -- Index values.
441 Arr : array (1 .. 7) of Float;
442 E : exception;
443
444 protected PC is
445 entry EC (EI : in Float;
446 EO : out Float;
447 EIO : in out Float);
448 end PC;
449
450 protected body PC is
451
452 entry EC (EI : in Float;
453 EO : out Float;
454 EIO : in out Float) when True is
455
456 Tmp : Float;
457
458 begin
459
460 Tmp := EI; -- Save value of EI at entry.
461
462 EO := 0.5;
463 if EI /= Tmp then
464 Failed ("Assignement to float out " &
465 "parameter changes the value of " &
466 "input parameter - F");
467 Tmp := EI; -- Reset Tmp for next case.
468 end if;
469
470 EIO := EIO + 0.25;
471 if EI /= Tmp then
472 Failed ("Assignment to float in out " &
473 "parameter changes the value of " &
474 "input parameter - F");
475 Tmp := EI; -- Reset Tmp for next case.
476 end if;
477
478 Arr(I) := Arr(I) + 1.0;
479 if EI /= Tmp then
480 Failed ("Assignment to float actual " &
481 "parameter changes the value of " &
482 "input parameter - F");
483 end if;
484
485 raise E; -- Check exception handling.
486 end EC;
487
488 end PC;
489
490 begin -- (F)
491 Arr := (others => 0.0);
492 PC.EC (Arr(I), Arr(J), Arr(K));
493 Failed ("Exception not raised - F");
494 exception
495 when E =>
496 if (Arr(I) /= 1.0) then
497 Failed ("Out or in out actual procedure " &
498 "parameter value changed despite " &
499 "raised exception - F");
500 end if;
501 when others =>
502 Failed ("Wrong exception raised - F");
503 end; -- (F)
504
505 --------------------------------------------------
506
507 Result;
508
509 end C620002;