aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats-4/tests/c5/c552001.a
blob: 7a1c4fe8b686c66fe53742d373f28ec82529305f (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
--  C552001.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.
--*
--
--  OBJECTIVE:
--    Check correct operation of array component iterators:
--       (A) Check that the loop parameter of an array component
--           iterator can be assigned if the array object is a variable view.
--       (B) Check that the execution of an array component iterator is
--           immediately complete if the array is a null array.
--       (C) Check that a forward array component iterator visits each
--           component of a one-dimensional array exactly once, in the order of
--           index values (first to last).
--       (D) Check that a forward array component iterator for a
--           two-dimensional array visits each component in canonical order,
--           with the last dimension varying fastest.
--       (E) Check that a forward array component iterator for a
--           three-dimensional array visits each component in canonical order,
--           with the last dimension varying fastest, and the middle dimension
--           varying the next fastest.
--       (F) Check that a reverse array component iterator visits each
--           component of a one-dimensional array exactly once, in the reverse
--           order of index values (last to first).
--       (G) Check that a reverse array component iterator for a
--           two-dimensional array visits each component in canonical order,
--           with the last dimension varying fastest.
--       (H) Check that the iterable_name of an array component iterator is
--           evaluated exactly once at the start of the loop.
--
--  CHANGE HISTORY:
--    10 Feb 2015  BJM  Created ACATS test.
--    18 Mar 2015  RLB  Readied test for issuance; Fortran subtests split into
--                      a separate file. Added dynamic and parameter cases to
--                      increase coverage.

--!

with Report;

procedure C552001 is

   type One_D_Array is array (Positive range <>) of Integer;

   subtype Ten_Integer_Array is One_D_Array (1 .. 10);

   A : Ten_Integer_Array :=
     (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

   Backwards_A : constant Ten_Integer_Array :=
     (10, 9, 8, 7, 6, 5, 4, 3, 2, 1);

   type Two_D_Array is array (Positive range <>,
                              Positive range <>) of Integer;

   Null_Array : array (1 .. 0) of Integer := (others => 0);

   Null_2D_Array : Two_D_Array
      (Report.Ident_Int(1) .. 4, 2 .. Report.Ident_Int(1)) :=
      (others => (others => 0));

   C : Ten_Integer_Array := (others => 0);

   Two_D : constant Two_D_Array (1 .. 5, 1 .. 3) := (1 => (1, 2, 3),
                                                     2 => (4, 5, 6),
                                                     3 => (7, 8, 9),
                                                     4 => (10, 11, 12),
                                                     5 => (13, 14, 15));

   Dyn_Two_D : constant Two_D_Array (1 .. Report.Ident_Int(4),
                                     1 .. Report.Ident_Int(2))
        := (1 => (1, 2),
            2 => (3, 4),
            3 => (5, 6),
            4 => (7, 8));

   Three_D_E : constant array (1 .. 2, 1 .. 3, 1 .. 4) of Integer :=
     (1 => (1 => (1, 2, 3, 4),
            2 => (5, 6, 7, 8),
            3 => (9, 10, 11, 12)),
      2 => (1 => (13, 14, 15, 16),
            2 => (17, 18, 19, 20),
            3 => (21, 22, 23, 24)));

   type Result_Array is array
     (1 .. Two_D'Length (1) * Two_D'Length (2)) of Integer;

   Result : Result_Array := (others => 0);
   Expected_Result : constant Result_Array :=
     (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);

   Expected_Reverse_Result : constant Result_Array :=
     (15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1);

   type Three_D_Result_Array is array
     (1 .. Three_D_E'Length (1) *
          Three_D_E'Length (2) *
          Three_D_E'Length (3)) of Integer;

   Three_D_Result : Three_D_Result_Array := (others => 0);

   Expected_3D_Result : constant Three_D_Result_Array :=
     (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
      21, 22, 23, 24);

   Count : Natural := 0;
   Evaluation_Count : Natural := 0;

   function Get_Array return Ten_Integer_Array is
      Local_Result : constant Ten_Integer_Array :=
        (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
   begin
      Evaluation_Count := Evaluation_Count + 1;
      return Local_Result;
   end Get_Array;

   procedure Test_One_D (Arr : in One_D_Array; In_Reverse : in Boolean) is
   begin
      Count := 0;
      C := (others => 0);
      if In_Reverse then
         for E of reverse Arr loop
            Count := Count + 1;
            C (Count) := E;
         end loop;
      else
         for E of Arr loop
            Count := Count + 1;
            C (Count) := E;
         end loop;
      end if;
   end Test_One_D;

   procedure Test_Two_D (Arr : in Two_D_Array; In_Reverse : in Boolean) is
   begin
      Count := 0;
      Result := (others => 0);
      if In_Reverse then
         for E of reverse Arr loop
            Count := Count + 1;
            Result (Count) := E;
         end loop;
      else
         for E of Arr loop
            Count := Count + 1;
            Result (Count) := E;
         end loop;
      end if;
   end Test_Two_D;

   procedure Mod_1D (Arr : in out Ten_Integer_Array) is
   begin
      for E of reverse Arr loop
         E := E + 2;
      end loop;
   end Mod_1D;

begin

   Report.Test ("C552001",
                "Check correct operation of array component iterators");

   --  Loop parameter can be assigned for variable array. Objective (A)
   for E of A loop
      E := E + 1;
   end loop;

   if (for all I in A'Range => A (I) /= I + 1) then
      Report.Failed
        (Descr => "1A) array component iterator should have been modified");
   end if;

   Mod_1D (A);

   if (for all I in A'Range => A (I) /= I + 3) then
      Report.Failed
        (Descr => "1B) array component iterator should have been modified");
   end if;

   --  A null array does not iterate. Objective (B)
   for E of Null_Array loop
      Report.Failed
        (Descr => "2A) null array should not have iterations");
      E := E + 1;
   end loop;

   Test_One_D (One_D_Array(Null_Array), In_Reverse => True);

   if Count /= 0 then
      Report.Failed
        (Descr => "2B) null array should not have iterations");
   end if;

   for E of Null_2D_Array loop
      Report.Failed
        (Descr => "2C) null array should not have iterations");
      E := E + 1;
   end loop;

   Test_Two_D (Null_2D_Array, In_Reverse => False);

   if Count /= 0 then
      Report.Failed
        (Descr => "2D) null array should not have iterations");
   end if;

   --  A forward iterator visits each component of a one-dimensional array
   --  exactly once, in the order of index values (first to last).
   --  Objective (C)
   for E of A loop
      Count := Count + 1;
      C (Count) := E;
   end loop;

   if Count /= 10 or else C /= A then
      Report.Failed
        (Descr =>
           "3A) Each component wasn't visited exactly once in forward order");
   end if;

   Test_One_D (A, In_Reverse => False);

   if Count /= 10 or else C /= A then
      Report.Failed
        (Descr =>
           "3B) Each component wasn't visited exactly once in forward order");
   end if;


   --  Check that a forward array component iterator for a two-dimensional
   --  array visits each component in canonical order, with the last dimension
   --  varying fastest.  Objective (D)
   Count := 0;
   for E of Two_D loop
      Count := Count + 1;
      Result (Count) := E;
   end loop;

   if Count /= Result_Array'Length or else Result /= Expected_Result then
      Report.Failed
        (Descr =>
           "4A) Each component wasn't visited exactly once " &
           "in forward canonical order");
   end if;

   Count := 0;
   for E of Dyn_Two_D loop
      Count := Count + 1;
      Result (Count) := E;
   end loop;

   if Count /= 8 or else Result(1..8) /= Expected_Result(1..8) then
      Report.Failed
        (Descr =>
           "4B) Each component of dynamic array wasn't visited exactly once " &
           "in forward canonical order");
   end if;

   Test_Two_D (Two_D, In_Reverse => False);

   if Count /= Result_Array'Length or else Result /= Expected_Result then
      Report.Failed
        (Descr =>
           "4C) Each component wasn't visited exactly once " &
           "in forward canonical order - subprogram case");
   end if;

   --  Check that a forward array component iterator for a three-dimensional
   --  array visits each component in canonical order, with the last dimension
   --  varying fastest, and the middle dimension varying the next fastest.
   --  Objective (E)
   Count := 0;
   for E of Three_D_E loop
      Count := Count + 1;
      Three_D_Result (Count) := E;
   end loop;

   if Count /= Three_D_Result'Length or else
     Three_D_Result /= Expected_3D_Result
   then
      Report.Failed
        (Descr =>
           "5) Each component wasn't visited exactly once " &
           "in forward canonical order");
   end if;

   Count := 0;
   C := (others => 0);

   A := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

   --  Check that a reverse array component iterator visits each component of a
   --  one-dimensional array exactly once, in the reverse order of index values
   --  (last to first). Objective (F)
   for E of reverse A loop
      Count := Count + 1;
      C (Count) := E;
   end loop;

   if Count /= 10 or else C /= Backwards_A then
      Report.Failed
        (Descr =>
           "6A) Each component wasn't visited exactly once in reverse order");
   end if;

   Test_One_D (A, In_Reverse => True);

   if Count /= 10 or else C /= Backwards_A then
      Report.Failed
        (Descr =>
           "6B) Each component wasn't visited exactly once in reverse order");
   end if;

   --  Check that a reverse array component iterator for a two-dimensional
   --  array visits each component in canonical order, with the last dimension
   --  varying fastest. Objective (G)
   Count := 0;
   Result := (others => 0);

   for E of reverse Two_D loop
      Count := Count + 1;
      Result (Count) := E;
   end loop;

   if Count /= Result_Array'Length or else Result /= Expected_Reverse_Result
   then
      Report.Failed
        (Descr =>
           "7A) Each component wasn't visited exactly once " &
           "in reverse canonical order");
   end if;

   Test_Two_D (Two_D, In_Reverse => True);

   if Count /= Result_Array'Length or else Result /= Expected_Reverse_Result
   then
      Report.Failed
        (Descr =>
           "7B) Each component wasn't visited exactly once " &
           "in reverse canonical order");
   end if;

   --  Check that the iterable_name of an array component iterator is evaluated
   --  exactly once at the start of the loop. Objective (H)
   Count := 0;
   for E of Get_Array loop
      Count := Count + 1;
   end loop;

   if Evaluation_Count /= 1 then
      Report.Failed
        (Descr =>
           "8) Iterable_Name was not evaluated only once");
   elsif Count /= Ten_Integer_Array'Length then
      Report.Failed
        (Descr =>
           "8) Wrong number of iterators for array returned from function");
   end if;

   Report.Result;

end C552001;