summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxa/cxa4024.a
blob: 1b0af9ce9785b520ab0c774e65776c7e4037302e (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
-- CXA4024.A
--
--                             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 the function "-", To_Ranges, To_Domain, and To_Range are
--      available in the package Ada.Strings.Maps, and that they produce
--      correct results based on the Character_Set/Character_Mapping input
--      provided.
--
-- TEST DESCRIPTION:
--      This test examines the operation of four functions from within the
--      Ada.Strings.Maps package.  A variety of Character_Sequence, 
--      Character_Set, and Character_Mapping objects are created and 
--      initialized for use with these functions.  In each subtest of
--      function operation, specific inputs are provided to the functions as
--      input parameters, and the results are evaluated against expected
--      values.  Wherever appropriate, additional characteristics of the
--      function results are verified against the prescribed result
--      characteristics.
--
--       
-- CHANGE HISTORY:
--      03 Feb 95   SAIC    Initial prerelease version
--      10 Mar 95   SAIC    Incorporated reviewer comments.
--      15 Apr 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--      05 Oct 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--
--!

with Ada.Strings.Maps;
with Ada.Strings.Maps.Constants;
with Ada.Characters.Latin_1;
with Report;

procedure CXA4024 is

begin

   Report.Test ("CXA4024", "Check that the function ""-"", To_Ranges, " &
                           "To_Domain, and To_Range are available in "  &
                           "the package Ada.Strings.Maps, and that "    &
                           "they produce correct results");

   Test_Block:
   declare

      use Ada.Strings, Ada.Strings.Maps;
      use type Maps.Character_Set;  -- To allow logical set operator 
                                    -- infix notation.
      package ACL1 renames Ada.Characters.Latin_1;
  
      MidPoint_Letter  : constant := 13;
      Last_Letter      : constant := 26;

      Vowels           : constant Maps.Character_Sequence := "aeiou";
      Quasi_Vowel      : constant Character := 'y';

      Alphabet         : Maps.Character_Sequence (1..Last_Letter);
      Half_Alphabet    : Maps.Character_Sequence (1..MidPoint_Letter);

      Alphabet_Set,
      Consonant_Set,
      Vowel_Set,
      First_Half_Set,
      Second_Half_Set  : Maps.Character_Set;


   begin

      -- Load the alphabet strings for use in creating sets.
      for i in 0..12 loop
         Half_Alphabet(i+1) := Character'Val(Character'Pos('a') + i);
      end loop;

      for i in 0..25 loop
         Alphabet(i+1) := Character'Val(Character'Pos('a') + i);
      end loop;

      -- Initialize a series of Character_Set objects.
      
      Alphabet_Set    := Maps.To_Set(Alphabet);
      Vowel_Set       := Maps.To_Set(Vowels);
      Consonant_Set   := Vowel_Set  XOR  Alphabet_Set;
      First_Half_Set  := Maps.To_Set(Half_Alphabet);
      Second_Half_Set := Alphabet_Set  XOR  First_Half_Set;



      -- Evaluation of Set operator "-".

      if Consonant_Set  /= "-"(Alphabet_Set, Vowel_Set)       or
         Vowel_Set      /= (Alphabet_Set - Consonant_Set)     or
         Alphabet_Set   /= Alphabet_Set - Maps.Null_Set       or
         First_Half_Set /= "-"(Alphabet_Set, Second_Half_Set) or
         (Alphabet_Set - Vowel_Set) /= "AND"(Alphabet_Set, "NOT"(Vowel_Set)) 
      then
         Report.Failed("Incorrect result from ""-"" operator for sets");
      end if;



      -- Evaluation of Function "To_Ranges".

      declare

         use type Maps.Character_Range;
         use type Maps.Character_Ranges;

         Set_A_to_C   : Maps.Character_Set   := Maps.To_Set("ABC");
         Set_J        : Maps.Character_Set   := Maps.To_Set("J");
         Set_M_to_P   : Maps.Character_Set   := Maps.To_Set("MNOP");
         Set_X_to_Z   : Maps.Character_Set   := Maps.To_Set("XYZ");
         Set_Of_Five  : Maps.Character_Set   := Set_A_to_C OR  -- Union of the
                                                Set_M_to_P OR  -- five sets.
                                                Set_X_to_Z OR
                                                Set_J      OR
                                                Maps.Null_Set;

         TC_Range_A_to_C : Maps.Character_Range := (Low => 'A', High => 'C');
         TC_Range_J      : Maps.Character_Range := ('J', 'J');
         TC_Range_M_to_P : Maps.Character_Range := ('M', 'P');
         TC_Range_X_to_Z : Maps.Character_Range := (Low => 'X', High => 'Z');

         TC_Ranges       : Maps.Character_Ranges (1..4) :=
                             (1 => TC_Range_A_to_C, 
                              2 => TC_Range_J,
                              3 => TC_Range_M_to_P, 
                              4 => TC_Range_X_to_Z);

      begin

         -- Based on input of a set containing four separate "spans" of
         -- character sequences, Function To_Ranges is required to produce
         -- the shortest array of contiguous ranges of Character values in
         -- the input set, in increasing order of Low.

         declare

            -- This Character_Ranges constant should consist of array
            -- components, each component being a Character_Range from Low
            -- to High containing the appropriate characters.

            Ranges_Result   : constant Maps.Character_Ranges :=
                                Maps.To_Ranges(Set => Set_Of_Five);
         begin

            -- Check the structure and components of the Character_Ranges 
            -- constant.

            if Ranges_Result(1)      /= TC_Range_A_to_C   or
               Ranges_Result(1).Low  /= TC_Ranges(1).Low  or
               Ranges_Result(2)      /= TC_Range_J        or
               Ranges_Result(2).High /= TC_Ranges(2).High or
               Ranges_Result(3)      /= TC_Range_M_to_P   or
               Ranges_Result(3).Low  /= TC_Ranges(3).Low  or   
               Ranges_Result(3).High /= TC_Ranges(3).High or  
               Ranges_Result(4)      /= TC_Range_X_To_Z   or
               Ranges_Result(4).Low  /= TC_Ranges(4).Low  or   
               Ranges_Result(4).High /= TC_Ranges(4).High
            then
               Report.Failed ("Incorrect structure or components in " &
                              "Character_Ranges constant");
            end if;
            
         exception
            when others => 
              Report.Failed("Exception raised using the Function To_Ranges " &
                            "to initialize a Character_Ranges constant");
         end;
      end;



      -- Evaluation of Functions To_Domain and To_Range.

      declare

         Null_Sequence          : constant Maps.Character_Sequence := "";

         TC_Upper_Case_Sequence : constant Maps.Character_Sequence :=
                                    "ZYXWVUTSRQPONMABCDEFGHIJKL";
         TC_Lower_Case_Sequence : constant Maps.Character_Sequence :=
                                    "zyxwvutsrqponmabcdefghijkl";
         TC_Unordered_Sequence  : Maps.Character_Sequence(1..6) := 
                                    "BxACzy";

         TC_Upper_to_Lower_Map  : Maps.Character_Mapping :=
                                    Maps.To_Mapping(TC_Upper_Case_Sequence,
                                                    TC_Lower_Case_Sequence);

         TC_Lower_to_Upper_Map  : Maps.Character_Mapping :=
                                    Maps.To_Mapping(TC_Lower_Case_Sequence,
                                                    TC_Upper_Case_Sequence);

         TC_Unordered_Map       : Maps.Character_Mapping :=
                                    Maps.To_Mapping(TC_Unordered_Sequence, 
                                                    "ikglja");
      begin

         declare

            TC_Domain_1 : constant Maps.Character_Sequence := 
                              Maps.To_Domain(TC_Upper_to_Lower_Map);
                              
            TC_Domain_2 : constant Maps.Character_Sequence := 
                              Maps.To_Domain(TC_Lower_to_Upper_Map);

            TC_Domain_3 : Maps.Character_Sequence(1..6);

            TC_Range_1  : constant Maps.Character_Sequence :=
                              Maps.To_Range(TC_Upper_to_Lower_Map);

            TC_Range_2  : constant Maps.Character_Sequence :=
                              Maps.To_Range(TC_Lower_to_Upper_Map);

            TC_Range_3  : Maps.Character_Sequence(1..6);

         begin

            -- Function To_Domain returns the shortest Character_Sequence
            -- value such that each character not in the result maps to
            -- itself, and all characters in the result are in ascending 
            -- order.

            TC_Domain_3 := Maps.To_Domain(TC_Unordered_Map);

            -- Check contents of result of To_Domain, must be in ascending
            -- order.

            if TC_Domain_1 /= "ABCDEFGHIJKLMNOPQRSTUVWXYZ" then
               Report.Failed("Incorrect result from To_Domain with " &
                             "TC_Upper_to_Lower_Map as input");
            end if;

            if TC_Domain_2 /= "abcdefghijklmnopqrstuvwxyz" then
               Report.Failed("Incorrect result from To_Domain with " &
                             "TC_Lower_to_Upper_Map as input");
            end if;

            if TC_Domain_3 /= "ABCxyz" then        
               Report.Failed("Incorrect result from To_Domain with " &
                             "an unordered mapping as input");
            end if;


            -- The lower bound on the returned Character_Sequence value
            -- from To_Domain must be 1.

            if TC_Domain_1'First /= 1 or 
               TC_Domain_2'First /= 1 or
               TC_Domain_3'First /= 1
            then
               Report.Failed("Incorrect lower bound returned from To_Domain");
            end if;


            -- Check contents of result of To_Range.

            TC_Range_3 := Maps.To_Range(TC_Unordered_Map);

            if TC_Range_1 /= "abcdefghijklmnopqrstuvwxyz" then
               Report.Failed("Incorrect result from To_Range with " &
                             "TC_Upper_to_Lower_Map as input");
            end if;

            if TC_Range_2 /= "ABCDEFGHIJKLMNOPQRSTUVWXYZ" then
               Report.Failed("Incorrect result from To_Range with " &
                             "TC_Lower_to_Upper_Map as input");
            end if;

            if TC_Range_3 /= "gilkaj" then          
               Report.Failed("Incorrect result from To_Range with " &
                             "an unordered mapping as input");
            end if;


            -- The lower bound on the returned Character_Sequence value
            -- must be 1.

            if TC_Range_1'First /= 1 or 
               TC_Range_2'First /= 1 or
               TC_Range_3'First /= 1
            then
               Report.Failed("Incorrect lower bound returned from To_Range");
            end if;


            -- The upper bound on the returned Character_Sequence value
            -- must be Map'Length.

            if TC_Range_1'Last /= TC_Lower_Case_Sequence'Length or
               TC_Range_2'Last /= TC_Upper_Case_Sequence'Length or
               TC_Range_3'Last /= TC_Unordered_Sequence'Length 
            then
               Report.Failed("Incorrect upper bound returned from To_Range");
            end if;

         end;

         -- Both function To_Domain and To_Range return the null string 
         -- when provided the Identity character map as an input parameter.

         if Maps.To_Domain(Maps.Identity) /= Null_Sequence then
            Report.Failed("Function To_Domain did not return the null " &
                          "string when provided the Identity map as "   &
                          "input");
         end if;

         if Maps.To_Range(Maps.Identity) /= Null_Sequence then
            Report.Failed("Function To_Range did not return the null " &
                          "string when provided the Identity map as "  &
                          "input");
         end if;

      exception
         when others => 
           Report.Failed("Exception raised during the evaluation of " &
                         "Function To_Domain and To_Range");
      end;

   exception
      when others => Report.Failed ("Exception raised in Test_Block");
   end Test_Block;


   Report.Result;

end CXA4024;