aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats-4/tests/c6/c641002.a
blob: 71edbda1761bab300994e59dae5408d645a929fa (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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
-- C641002.A
--
--                             Grant of Unlimited Rights
--
--     The Ada Conformity Assessment Authority (ACAA) holds unlimited
--     rights in the software and documentation contained herein. Unlimited
--     rights are the same as those granted by the U.S. Government for older
--     parts of the Ada Conformity Assessment Test Suite, and are defined
--     in DFAR 252.227-7013(a)(19). By making this public release, the ACAA
--     intends to confer upon all recipients unlimited rights equal to those
--     held by the ACAA. 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 ACAA 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.
--
--                                     Notice
--
--     The ACAA has created and maintains the Ada Conformity Assessment Test
--     Suite for the purpose of conformity assessments conducted in accordance
--     with the International Standard ISO/IEC 18009 - Ada: Conformity
--     assessment of a language processor. This test suite should not be used
--     to make claims of conformance unless used in accordance with
--     ISO/IEC 18009 and any applicable ACAA procedures.
--*
-- OBJECTIVES:
--     Check that, for an out parameter of a scalar type with a specified
--     Default_Value, the value of the actual parameter is passed in without
--     any constraint check.
--
-- TEST DESCRIPTION:
--     Ada has a general principle that an out parameter (which is logically
--     uninitialized) will as much as practical not raise any exception when
--     making a call. (Of course, an exception could be raised inside the
--     called subprogram, and for by-copy types, the copy back might raise
--     an exception if the value is changed by the called subprogram.)
--
--     This test checks 6.4.1(13.1/3). The purpose of this rule is that an
--     actual object for an out parameter which initially has a valid value
--     will remain valid without raising an exception before the call. This
--     should be true even if the out parameter is not written in the 
--     subprogram even if the Default_Value of the type does not belong to
--     the subtype of the parameter.
--
--     So we test calls on a procedure which may or may not write the out
--     parameters. This procedure models a subprogram which returns multiple
--     results -- here, which parameters are used for results depends
--     upon the result returned in other parameters. (This is a fairly common
--     usage pattern; it's often used as a function can return only a single
--     result.)
--
-- CHANGE HISTORY:
--     30 Mar 21   RLB     Created test for RRS, donated to ACATS.
--
--!
package C641002_0 is

   type Status is (Raw, Bound, Solved, Unknown)
      with Default_Value => Unknown;
   subtype Good_Status is Status range Raw .. Solved;
      
   Unused : constant := -16#6789#;
   type Small_Integer is range -16#8000#..16#7FFF#
      with Default_Value => Unused;
   subtype Small_Natural is Small_Integer range 0 .. Small_Integer'Last;
      
   type Word_16 is mod 2**16
      with Default_Value => 16#DEAD#;
   subtype Half_Word is Word_16 range 0 .. 16#0FFF#;

   Flt_Value : constant := -2.25;

   type Small_Float is digits 3
      with Default_Value => Flt_Value;
   subtype Float_Natural is Small_Float range 0.0 .. Small_Float'Last;
    
   Fix_Value : constant := 3.75;

   type Small_Fixed is delta 0.125 range -4.0 .. 4.0
      with Small => 0.125, Default_Value => Fix_Value;
   subtype Smaller_Fixed is Small_Fixed range -2.0 .. 2.0;
    

   subtype Cases is Character range 'A' .. 'F';
    
   procedure Get_Info (Usable    : out Boolean;
                       Kind      : out Good_Status;
                       Count     : out Small_Natural;
                       Flags     : out Half_Word;
                       Data      : out Float_Natural;
                       Magnitude : out Smaller_Fixed;
                       Test_Case : in Cases);
      -- Returns a different result for each test case.
      -- If Usable is False, none of the other values contains data.
      -- If Usable is True, then the Kind determines which other
      -- parameters contain data. If Kind = Raw, Flags only has data.
      -- If Kind = Bound, then the Count and Flags have data.
      -- If Kind = Solved, then all of the parameters have data.

end C641002_0;


package body C641002_0 is

   procedure Get_Info (Usable    : out Boolean;
                       Kind      : out Good_Status;
                       Count     : out Small_Natural;
                       Flags     : out Half_Word;
                       Data      : out Float_Natural;
                       Magnitude : out Smaller_Fixed;
                       Test_Case : in Cases) is
      -- Returns a different result for each test case. (See spec for
      -- details).
   begin
      -- Note: We cannot read any of the out parameters lest they be
      -- invalid for the declared subtype.
      case Test_Case is
         when 'A' =>
            Usable := True;
            Kind   := Raw;
            Flags  := 16#0010#;
         when 'B' =>
            Usable := True;
            Kind   := Solved;
            Count  := 12;
            Flags  := 16#0012#;
            Data   := 1.75;
            Magnitude := 0.625;
         when 'C' =>
            Usable := False;
         when 'D' =>
            Usable := True;
            Kind   := Bound;
            Flags  := 16#000C#;
            Count  := 4;
         when 'E' =>
            Usable := True;
            Kind   := Solved;
            Count  := 7;
            Flags  := 16#0028#;
            Data   := 1.25;
            Magnitude := -0.25;
         when 'F' =>
            Usable := True;
            Kind   := Bound;
            Flags  := 16#000A#;
            Count  := 3;
      end case;
   end Get_Info;
       
end C641002_0;


with Report;
with C641002_0; use C641002_0;
procedure C641002 is

begin

   Report.Test
     ("C641002",
      "Check that, for a parameter of a scalar type with a specified " &
      "Default_Value, the value of the actual parameter is passed in " &
      "without any constraint check");

   -- First, try initialized objects:
   declare
      Is_Usable     : Boolean := False;
      The_Kind      : Good_Status := Bound;
      The_Count     : Small_Integer := 0;
      The_Flags     : Half_Word := 0;
      The_Data      : Float_Natural := 0.0;
      The_Magnitude : Smaller_Fixed := 0.0;
   begin
      if Is_Usable then
          Report.Failed ("Bad initial value - A1");
      end if;         
      if The_Kind /= Bound then
          Report.Failed ("Bad initial value - A2");
      end if;         
      if The_Count /= 0 then
          Report.Failed ("Bad initial value - A3");
      end if;         
      if The_Flags /= 0 then
          Report.Failed ("Bad initial value - A4");
      end if;         
      if The_Data /= 0.0 then
          Report.Failed ("Bad initial value - A5");
      end if;         
      if The_Magnitude /= 0.0 then
          Report.Failed ("Bad initial value - A6");
      end if;         
      C641002_0.Get_Info (Is_Usable, The_Kind, The_Count, The_Flags, 
                          The_Data, The_Magnitude, Test_Case => 'A');
          -- Should not raise an exception even if buggy, all parameter values
          -- in range.
      if not Is_Usable then
          Report.Failed ("Bad result value - A1");
      end if;         
      if The_Kind /= Raw then
          Report.Failed ("Bad result value - A2");
      end if;         
      if The_Count /= 0 then
          Report.Failed ("Bad result value - A3");
      end if;         
      if The_Flags /= 16#0010# then
          Report.Failed ("Bad result value - A4");
      end if;         
      if The_Data /= 0.0 then
          Report.Failed ("Bad result value - A5");
      end if;         
      if The_Magnitude /= 0.0 then
          Report.Failed ("Bad result value - A6");
      end if;
   end;        

   -- Next, try default initialized objects with the results set:
   declare
      Is_Usable     : Boolean;
      The_Kind      : Status;
      The_Count     : Small_Integer;
      The_Flags     : Word_16;
      The_Data      : Small_Float;
      The_Magnitude : Small_Fixed;
   begin
      -- Is_Usable is not initialized at all, can't pre-test it.
      if The_Kind /= Unknown then
          Report.Failed ("Bad initial value - B2");
      end if;         
      if The_Count /= Unused then
          Report.Failed ("Bad initial value - B3");
      end if;         
      if The_Flags /= 16#DEAD# then
          Report.Failed ("Bad initial value - B4");
      end if;         
      if The_Data /= Flt_Value then
          Report.Failed ("Bad initial value - B5");
      end if;         
      if The_Magnitude /= Fix_Value then
          Report.Failed ("Bad initial value - B6");
      end if;         
      C641002_0.Get_Info (Is_Usable, The_Kind, The_Count, The_Flags, 
                          The_Data, The_Magnitude, Test_Case => 'B');
      if not Is_Usable then
          Report.Failed ("Bad result value - B1");
      end if;         
      if The_Kind /= Solved then
          Report.Failed ("Bad result value - B2");
      end if;         
      if The_Count /= 12 then
          Report.Failed ("Bad result value - B3");
      end if;         
      if The_Flags /= 16#0012# then
          Report.Failed ("Bad result value - B4");
      end if;         
      if The_Data /= 1.75 then
          Report.Failed ("Bad result value - B5");
      end if;         
      if The_Magnitude /= 0.625 then
          Report.Failed ("Bad result value - B6");
      end if;
   end;        

   -- Now, try default initialized objects with the results unchanged:
   -- Note: The defaults are outside of the parameter range, but no
   -- exception should be raised upon the call nor on the copy-back.
   declare
      Is_Usable     : Boolean;
      The_Kind      : Status;
      The_Count     : Small_Integer;
      The_Flags     : Word_16;
      The_Data      : Small_Float;
      The_Magnitude : Small_Fixed;
   begin
      -- Is_Usable is not initialized at all, can't pre-test it.
      if The_Kind /= Unknown then
          Report.Failed ("Bad initial value - C2");
      end if;         
      if The_Count /= Unused then
          Report.Failed ("Bad initial value - C3");
      end if;         
      if The_Flags /= 16#DEAD# then
          Report.Failed ("Bad initial value - C4");
      end if;         
      if The_Data /= Flt_Value then
          Report.Failed ("Bad initial value - C5");
      end if;         
      if The_Magnitude /= Fix_Value then
          Report.Failed ("Bad initial value - C6");
      end if;         
      C641002_0.Get_Info (Is_Usable, The_Kind, The_Count, The_Flags, 
                          The_Data, The_Magnitude, Test_Case => 'C');
      if Is_Usable then
          Report.Failed ("Bad result value - C1");
      end if;         
      if The_Kind /= Unknown then
          Report.Failed ("Bad result value - C2");
      end if;         
      if The_Count /= Unused then
          Report.Failed ("Bad result value - C3");
      end if;         
      if The_Flags /= 16#DEAD# then
          Report.Failed ("Bad result value - C4");
      end if;         
      if The_Data /= Flt_Value then
          Report.Failed ("Bad result value - C5");
      end if;         
      if The_Magnitude /= Fix_Value then
          Report.Failed ("Bad result value - C6");
      end if;
   end;        

   -- Now, try default initialized objects with some written and some
   -- unchanged by the call:
   -- Note: The defaults are outside of the parameter range, but no
   -- exception should be raised upon the call nor on the copy-back.
   declare
      Is_Usable     : Boolean;
      The_Kind      : Status;
      The_Count     : Small_Integer;
      The_Flags     : Word_16;
      The_Data      : Small_Float;
      The_Magnitude : Small_Fixed;
   begin
      -- Is_Usable is not initialized at all, can't pre-test it.
      if The_Kind /= Unknown then
          Report.Failed ("Bad initial value - D2");
      end if;         
      if The_Count /= Unused then
          Report.Failed ("Bad initial value - D3");
      end if;         
      if The_Flags /= 16#DEAD# then
          Report.Failed ("Bad initial value - D4");
      end if;         
      if The_Data /= Flt_Value then
          Report.Failed ("Bad initial value - D5");
      end if;         
      if The_Magnitude /= Fix_Value then
          Report.Failed ("Bad initial value - D6");
      end if;         
      C641002_0.Get_Info (Is_Usable, The_Kind, The_Count, The_Flags, 
                          The_Data, The_Magnitude, Test_Case => 'D');
      if not Is_Usable then
          Report.Failed ("Bad result value - D1");
      end if;         
      if The_Kind /= Bound then
          Report.Failed ("Bad result value - D2");
      end if;         
      if The_Count /= 4 then
          Report.Failed ("Bad result value - D3");
      end if;         
      if The_Flags /= 16#000C# then
          Report.Failed ("Bad result value - D4");
      end if;         
      if The_Data /= Flt_Value then
          Report.Failed ("Bad result value - D5");
      end if;         
      if The_Magnitude /= Fix_Value then
          Report.Failed ("Bad result value - D6");
      end if;
   end;        

   -- Now, try an object with a narrower range
   -- so that one of the results will not fit (an exception should
   -- be raised on the copy-back).
   declare
      subtype Small_Fixed_Natural is Small_Fixed range 0.0 .. Small_Fixed'Last;
      Is_Usable     : Boolean;
      The_Kind      : Status;
      The_Count     : Small_Integer;
      The_Flags     : Word_16;
      The_Data      : Small_Float;
      The_Magnitude : Small_Fixed_Natural;
   begin
      -- Is_Usable is not initialized at all, can't pre-test it.
      if The_Kind /= Unknown then
          Report.Failed ("Bad initial value - E2");
      end if;         
      if The_Count /= Unused then
          Report.Failed ("Bad initial value - E3");
      end if;         
      if The_Flags /= 16#DEAD# then
          Report.Failed ("Bad initial value - E4");
      end if;         
      if The_Data /= Flt_Value then
          Report.Failed ("Bad initial value - E5");
      end if;         
      if The_Magnitude /= Fix_Value then
          Report.Failed ("Bad initial value - E6");
      end if;         
      C641002_0.Get_Info (Is_Usable, The_Kind, The_Count, The_Flags, 
                          The_Data, The_Magnitude, Test_Case => 'E');
          -- The result for The_Magnitude is out of range, Constraint_Error
          -- should be raised.
      Report.Failed ("Copy-back out of fixed range did not raise " &
                     "Constraint_Error");   
   exception
      when Constraint_Error =>
          null; -- Expected, OK.
   end;
   
   declare
      subtype Small_Very_Positive is Small_Integer 
         range 10 .. Small_Integer'Last;
      Is_Usable     : Boolean;
      The_Kind      : Status;
      The_Count     : Small_Very_Positive := 92;
      The_Flags     : Word_16;
      The_Data      : Small_Float;
      The_Magnitude : Small_Fixed;
   begin
      -- Is_Usable is not initialized at all, can't pre-test it.
      if The_Kind /= Unknown then
          Report.Failed ("Bad initial value - F2");
      end if;         
      if The_Count /= 92 then
          Report.Failed ("Bad initial value - F3");
      end if;         
      if The_Flags /= 16#DEAD# then
          Report.Failed ("Bad initial value - F4");
      end if;         
      if The_Data /= Flt_Value then
          Report.Failed ("Bad initial value - F5");
      end if;         
      if The_Magnitude /= Fix_Value then
          Report.Failed ("Bad initial value - F6");
      end if;         
      C641002_0.Get_Info (Is_Usable, The_Kind, The_Count, The_Flags, 
                          The_Data, The_Magnitude, Test_Case => 'F');
          -- The result for The_Count is out of range, Constraint_Error
          -- should be raised.
      Report.Failed ("Copy-back out of integer range did not raise " &
                     "Constraint_Error");   
   exception
      when Constraint_Error =>
          null; -- Expected, OK.
   end;        

   Report.Result;

end C641002;