2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / ada / acats / tests / cxa / cxa4001.a
blobd850acd4a7238e622f1ae69d4ddceec4005560b2
1 -- CXA4001.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.
16 -- DISCLAIMER
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 --*
26 -- OBJECTIVE:
27 -- Check that the types, operations, and other entities defined within
28 -- the package Ada.Strings.Maps are available and/or produce correct
29 -- results.
31 -- TEST DESCRIPTION:
32 -- This test demonstrates the availability and function of the types and
33 -- operations defined in package Ada.Strings.Maps. It demonstrates the
34 -- use of these types and functions as they would be used in common
35 -- programming practice.
36 -- Character set creation, assignment, and comparison are evaluated
37 -- in this test. Each of the functions provided in package
38 -- Ada.Strings.Maps is utilized in creating or manipulating set objects,
39 -- and the function results are evaluated for correctness.
40 -- Character sequences are examined using the functions provided for
41 -- manipulating objects of this type. Likewise, character maps are
42 -- created, and their contents evaluated. Exception raising conditions
43 -- from the function To_Mapping are also created.
44 -- Note: Throughout this test, the set logical operators are printed in
45 -- capital letters to enhance their visibility.
46 --
47 --
48 -- CHANGE HISTORY:
49 -- 06 Dec 94 SAIC ACVC 2.0
51 --!
53 with Ada.Strings.Maps;
54 with Report;
56 procedure CXA4001 is
58 use Ada.Strings;
59 use type Maps.Character_Set;
61 begin
63 Report.Test ("CXA4001", "Check that the types, operations, and other " &
64 "entities defined within the package " &
65 "Ada.Strings.Maps are available and/or produce " &
66 "correct results");
68 Test_Block:
69 declare
71 MidPoint_Letter : constant := 13;
72 Last_Letter : constant := 26;
74 Vowels : constant Maps.Character_Sequence := "aeiou";
75 Quasi_Vowel : constant Character := 'y';
77 Alphabet : Maps.Character_Sequence (1..Last_Letter);
78 Half_Alphabet : Maps.Character_Sequence (1..MidPoint_Letter);
79 Inverse_Alphabet : Maps.Character_Sequence (1..Last_Letter);
81 Alphabet_Set,
82 Consonant_Set,
83 Vowel_Set,
84 Full_Vowel_Set,
85 First_Half_Set,
86 Second_Half_Set : Maps.Character_Set;
88 begin
90 -- Load the alphabet string for use in creating sets.
93 for i in 0..12 loop
94 Half_Alphabet(i+1) := Character'Val(Character'Pos('a') + i);
95 end loop;
97 for i in 0..25 loop
98 Alphabet(i+1) := Character'Val(Character'Pos('a') + i);
99 end loop;
102 -- Initialize a series of Character_Set objects.
104 Alphabet_Set := Maps.To_Set(Alphabet);
105 Vowel_Set := Maps.To_Set(Vowels);
106 Full_Vowel_Set := Vowel_Set OR Maps.To_Set(Quasi_Vowel);
107 Consonant_Set := Vowel_Set XOR Alphabet_Set;
109 First_Half_Set := Maps.To_Set(Half_Alphabet);
110 Second_Half_Set := Alphabet_Set XOR First_Half_Set;
113 -- Evaluation of Set objects, operators, and functions.
115 if Alphabet_Set /= (Vowel_Set OR Consonant_Set) then
116 Report.Failed("Incorrect set combinations using OR operator");
117 end if;
120 for i in 1..5 loop
121 if not Maps.Is_In(Vowels(i), Vowel_Set) or
122 not Maps.Is_In(Vowels(i), Alphabet_Set) or
123 Maps.Is_In(Vowels(i), Consonant_Set)
124 then
125 Report.Failed("Incorrect function Is_In use with set " &
126 "combinations - " & Integer'Image(i));
127 end if;
128 end loop;
131 if Maps.Is_Subset(Vowel_Set, First_Half_Set) or
132 Maps."<="(Vowel_Set, Second_Half_Set) or
133 not Maps.Is_Subset(Vowel_Set, Alphabet_Set)
134 then
135 Report.Failed("Incorrect set evaluation using Is_Subset function");
136 end if;
139 if not (Full_Vowel_Set = Maps.To_Set("aeiouy")) then
140 Report.Failed("Incorrect result for ""="" set operator");
141 end if;
144 if not ((Vowel_Set AND First_Half_Set) OR
145 (Full_Vowel_Set AND Second_Half_Set)) = Full_Vowel_Set then
146 Report.Failed
147 ("Incorrect result for AND, OR, or ""="" set operators");
148 end if;
151 if (Alphabet_Set AND Maps.Null_Set) /= Maps.Null_Set or
152 (Alphabet_Set OR Maps.Null_Set) /= Alphabet_Set
153 then
154 Report.Failed("Incorrect result for AND or OR set operators");
155 end if;
158 Vowel_Set := Full_Vowel_Set;
159 Vowel_Set := Vowel_Set AND (NOT Maps.To_Set(Quasi_Vowel));
161 if not (Vowels = Maps.To_Sequence(Vowel_Set)) then
162 Report.Failed("Incorrect Set to Sequence translation");
163 end if;
166 for i in 1..26 loop
167 Inverse_Alphabet(i) := Alphabet(27-i);
168 end loop;
170 declare
171 Inverse_Map : Maps.Character_Mapping :=
172 Maps.To_Mapping(Alphabet, Inverse_Alphabet);
173 begin
174 if Maps.Value(Maps.Identity, 'b') /= Maps.Value(Inverse_Map,'y')
175 then
176 Report.Failed("Incorrect Inverse mapping");
177 end if;
178 end;
181 -- Check that Translation_Error is raised when a character is
182 -- repeated in the parameter "From" string.
183 declare
184 Bad_Map : Maps.Character_Mapping;
185 begin
186 Bad_Map := Maps.To_Mapping(From => "aa", To => "yz");
187 Report.Failed("Exception not raised with repeated character");
188 exception
189 when Translation_Error => null; -- OK
190 when others =>
191 Report.Failed("Incorrect exception raised in To_Mapping with " &
192 "a repeated character");
193 end;
196 -- Check that Translation_Error is raised when the parameters of the
197 -- function To_Mapping are of unequal lengths.
198 declare
199 Bad_Map : Maps.Character_Mapping;
200 begin
201 Bad_Map := Maps.To_Mapping("abc", "yz");
202 Report.Failed("Exception not raised with unequal parameter lengths");
203 exception
204 when Translation_Error => null; -- OK
205 when others =>
206 Report.Failed("Incorrect exception raised in To_Mapping with " &
207 "unequal parameter lengths");
208 end;
211 exception
212 when others => Report.Failed ("Exception raised in Test_Block");
213 end Test_Block;
216 Report.Result;
218 end CXA4001;