| 1 |
-- CXA4012.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 |
-- |
| 26 |
-- OBJECTIVE: |
| 27 |
-- Check that the types, operations, and other entities defined within |
| 28 |
-- the package Ada.Strings.Wide_Maps are available and produce correct |
| 29 |
-- results. |
| 30 |
-- |
| 31 |
-- TEST DESCRIPTION: |
| 32 |
-- This test demonstrates the availability and function of the types and |
| 33 |
-- operations defined in package Ada.Strings.Wide_Maps. It demonstrates |
| 34 |
-- the use of these types and functions as they would be used in common |
| 35 |
-- programming practice. |
| 36 |
-- Wide_Character set creation, assignment, and comparison are evaluated |
| 37 |
-- in this test. Each of the functions provided in package |
| 38 |
-- Ada.Strings.Wide_Maps is utilized in creating or manipulating set |
| 39 |
-- objects, and the function results are evaluated for correctness. |
| 40 |
-- Wide_Character sequences are examined using the functions provided for |
| 41 |
-- manipulating objects of this type. Likewise, Wide_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 |
| 50 |
-- 01 Nov 95 SAIC Update and repair for ACVC 2.0.1. |
| 51 |
-- |
| 52 |
--! |
| 53 |
|
| 54 |
with Ada.Characters.Handling; |
| 55 |
with Ada.Strings.Wide_Maps; |
| 56 |
|
| 57 |
package CXA40120 is |
| 58 |
|
| 59 |
function Equiv (Ch : Character) return Wide_Character; |
| 60 |
function Equiv (Str : String) |
| 61 |
return Ada.Strings.Wide_Maps.Wide_Character_Sequence; |
| 62 |
function X_Map(From : Wide_Character) return Wide_Character; |
| 63 |
|
| 64 |
end CXA40120; |
| 65 |
|
| 66 |
package body CXA40120 is |
| 67 |
|
| 68 |
-- The following two functions are used to translate character and string |
| 69 |
-- values to "Wide" values. They will be applied to certain Wide_Map |
| 70 |
-- subprogram parameters to simulate the use of Wide_Characters and |
| 71 |
-- Wide_Character_Sequences in actual practice. |
| 72 |
-- Note: These functions do not actually return "equivalent" wide |
| 73 |
-- characters to their character inputs, just "non-character" |
| 74 |
-- wide characters. |
| 75 |
|
| 76 |
function Equiv (Ch : Character) return Wide_Character is |
| 77 |
C : Character := Ch; |
| 78 |
begin |
| 79 |
if Ch = ' ' then |
| 80 |
return Ada.Characters.Handling.To_Wide_Character(C); |
| 81 |
else |
| 82 |
return Wide_Character'Val(Character'Pos(Ch) + |
| 83 |
Character'Pos(Character'Last) + 1); |
| 84 |
end if; |
| 85 |
end Equiv; |
| 86 |
|
| 87 |
function Equiv (Str : String) |
| 88 |
return Ada.Strings.Wide_Maps.Wide_Character_Sequence is |
| 89 |
use Ada.Strings; |
| 90 |
WS : Wide_Maps.Wide_Character_Sequence(Str'First..Str'Last); |
| 91 |
begin |
| 92 |
for i in Str'First..Str'Last loop |
| 93 |
WS(i) := Equiv(Str(i)); |
| 94 |
end loop; |
| 95 |
return WS; |
| 96 |
end Equiv; |
| 97 |
|
| 98 |
function X_Map(From : Wide_Character) return Wide_Character is |
| 99 |
begin |
| 100 |
return Equiv('X'); |
| 101 |
end X_Map; |
| 102 |
|
| 103 |
end CXA40120; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
with CXA40120; |
| 108 |
with Ada.Characters.Handling; |
| 109 |
with Ada.Strings.Wide_Maps; |
| 110 |
with Report; |
| 111 |
|
| 112 |
procedure CXA4012 is |
| 113 |
|
| 114 |
use CXA40120; |
| 115 |
use Ada.Strings; |
| 116 |
|
| 117 |
begin |
| 118 |
|
| 119 |
Report.Test ("CXA4012", "Check that the types, operations, and other " & |
| 120 |
"entities defined within the package " & |
| 121 |
"Ada.Strings.Wide_Maps are available and " & |
| 122 |
"produce correct results"); |
| 123 |
|
| 124 |
Test_Block: |
| 125 |
declare |
| 126 |
|
| 127 |
use type Wide_Maps.Wide_Character_Set; |
| 128 |
|
| 129 |
MidPoint_Letter : constant := 13; |
| 130 |
Last_Letter : constant := 26; |
| 131 |
|
| 132 |
Vowels : constant Wide_Maps.Wide_Character_Sequence := |
| 133 |
Equiv("aeiou"); |
| 134 |
Quasi_Vowel : constant Wide_Character := Equiv('y'); |
| 135 |
|
| 136 |
Alphabet : Wide_Maps.Wide_Character_Sequence(1..Last_Letter); |
| 137 |
Half_Alphabet : Wide_Maps.Wide_Character_Sequence(1..MidPoint_Letter); |
| 138 |
Inverse_Alphabet : Wide_Maps.Wide_Character_Sequence(1..Last_Letter); |
| 139 |
|
| 140 |
Alphabet_Set, |
| 141 |
Consonant_Set, |
| 142 |
Vowel_Set, |
| 143 |
Full_Vowel_Set, |
| 144 |
First_Half_Set, |
| 145 |
Second_Half_Set : Wide_Maps.Wide_Character_Set := Wide_Maps.Null_Set; |
| 146 |
|
| 147 |
begin |
| 148 |
|
| 149 |
-- Load the alphabet string for use in creating sets. |
| 150 |
|
| 151 |
for i in 0..MidPoint_Letter-1 loop |
| 152 |
Half_Alphabet(i+1) := |
| 153 |
Wide_Character'Val(Wide_Character'Pos(Equiv('a')) + i); |
| 154 |
end loop; |
| 155 |
|
| 156 |
for i in 0..Last_Letter-1 loop |
| 157 |
Alphabet(i+1) := |
| 158 |
Wide_Character'Val(Wide_Character'Pos(Equiv('a')) + i); |
| 159 |
end loop; |
| 160 |
|
| 161 |
|
| 162 |
-- Initialize a series of Wide_Character_Set objects. |
| 163 |
|
| 164 |
Alphabet_Set := Wide_Maps.To_Set(Alphabet); |
| 165 |
Vowel_Set := Wide_Maps.To_Set(Vowels); |
| 166 |
Full_Vowel_Set := Vowel_Set OR Wide_Maps.To_Set(Quasi_Vowel); |
| 167 |
Consonant_Set := Vowel_Set XOR Alphabet_Set; |
| 168 |
|
| 169 |
First_Half_Set := Wide_Maps.To_Set(Half_Alphabet); |
| 170 |
Second_Half_Set := Alphabet_Set XOR First_Half_Set; |
| 171 |
|
| 172 |
|
| 173 |
-- Evaluation of Set objects, operators, and functions. |
| 174 |
|
| 175 |
if Alphabet_Set /= (Vowel_Set OR Consonant_Set) then |
| 176 |
Report.Failed("Incorrect set combinations using OR operator"); |
| 177 |
end if; |
| 178 |
|
| 179 |
|
| 180 |
for i in Vowels'First .. Vowels'Last loop |
| 181 |
if not Wide_Maps.Is_In(Vowels(i), Vowel_Set) or |
| 182 |
not Wide_Maps.Is_In(Vowels(i), Alphabet_Set) or |
| 183 |
Wide_Maps.Is_In(Vowels(i), Consonant_Set) |
| 184 |
then |
| 185 |
Report.Failed("Incorrect function Is_In use with set " & |
| 186 |
"combinations - " & Integer'Image(i)); |
| 187 |
end if; |
| 188 |
end loop; |
| 189 |
|
| 190 |
|
| 191 |
if Wide_Maps.Is_Subset(Vowel_Set, First_Half_Set) or |
| 192 |
Wide_Maps."<="(Vowel_Set, Second_Half_Set) or |
| 193 |
not Wide_Maps.Is_Subset(Vowel_Set, Alphabet_Set) |
| 194 |
then |
| 195 |
Report.Failed |
| 196 |
("Incorrect set evaluation using Is_Subset function"); |
| 197 |
end if; |
| 198 |
|
| 199 |
|
| 200 |
if not (Full_Vowel_Set = Wide_Maps.To_Set(Equiv("aeiouy"))) then |
| 201 |
Report.Failed("Incorrect result for ""="" set operator"); |
| 202 |
end if; |
| 203 |
|
| 204 |
|
| 205 |
if not ((Vowel_Set AND First_Half_Set) OR |
| 206 |
(Full_Vowel_Set AND Second_Half_Set)) = Full_Vowel_Set then |
| 207 |
Report.Failed |
| 208 |
("Incorrect result for AND, OR, or ""="" set operators"); |
| 209 |
end if; |
| 210 |
|
| 211 |
|
| 212 |
if (Alphabet_Set AND Wide_Maps.Null_Set) /= Wide_Maps.Null_Set or |
| 213 |
(Alphabet_Set OR Wide_Maps.Null_Set) /= Alphabet_Set |
| 214 |
then |
| 215 |
Report.Failed("Incorrect result for AND or OR set operators"); |
| 216 |
end if; |
| 217 |
|
| 218 |
|
| 219 |
Vowel_Set := Full_Vowel_Set; |
| 220 |
Vowel_Set := Vowel_Set AND (NOT Wide_Maps.To_Set(Quasi_Vowel)); |
| 221 |
|
| 222 |
if not (Vowels = Wide_Maps.To_Sequence(Vowel_Set)) then |
| 223 |
Report.Failed("Incorrect Set to Sequence translation"); |
| 224 |
end if; |
| 225 |
|
| 226 |
|
| 227 |
for i in 0..Last_Letter-1 loop |
| 228 |
Inverse_Alphabet(i+1) := Alphabet(Last_Letter-i); |
| 229 |
end loop; |
| 230 |
|
| 231 |
|
| 232 |
-- Wide_Character_Mapping |
| 233 |
|
| 234 |
declare |
| 235 |
Inverse_Map : Wide_Maps.Wide_Character_Mapping := |
| 236 |
Wide_Maps.To_Mapping(Alphabet, Inverse_Alphabet); |
| 237 |
begin |
| 238 |
if Wide_Maps.Value(Wide_Maps.Identity, Equiv('b')) /= |
| 239 |
Wide_Maps.Value(Inverse_Map, Equiv('y')) |
| 240 |
then |
| 241 |
Report.Failed("Incorrect Inverse mapping"); |
| 242 |
end if; |
| 243 |
end; |
| 244 |
|
| 245 |
|
| 246 |
-- Check that Translation_Error is raised when a character is |
| 247 |
-- repeated in the parameter "From" string. |
| 248 |
declare |
| 249 |
Bad_Map : Wide_Maps.Wide_Character_Mapping; |
| 250 |
begin |
| 251 |
Bad_Map := Wide_Maps.To_Mapping(From => Equiv("aa"), |
| 252 |
To => Equiv("yz")); |
| 253 |
Report.Failed("Exception not raised with repeated character"); |
| 254 |
exception |
| 255 |
when Translation_Error => null; -- OK |
| 256 |
when others => |
| 257 |
Report.Failed("Incorrect exception raised in To_Mapping with " & |
| 258 |
"a repeated character"); |
| 259 |
end; |
| 260 |
|
| 261 |
|
| 262 |
-- Check that Translation_Error is raised when the parameters of the |
| 263 |
-- function To_Mapping are of unequal lengths. |
| 264 |
declare |
| 265 |
Bad_Map : Wide_Maps.Wide_Character_Mapping; |
| 266 |
begin |
| 267 |
Bad_Map := Wide_Maps.To_Mapping(Equiv("abc"), Equiv("yz")); |
| 268 |
Report.Failed |
| 269 |
("Exception not raised with unequal parameter lengths"); |
| 270 |
exception |
| 271 |
when Translation_Error => null; -- OK |
| 272 |
when others => |
| 273 |
Report.Failed("Incorrect exception raised in To_Mapping with " & |
| 274 |
"unequal parameter lengths"); |
| 275 |
end; |
| 276 |
|
| 277 |
|
| 278 |
-- Check that the access-to-subprogram type is defined and available. |
| 279 |
-- This provides for one Wide_Character mapping capability only. |
| 280 |
-- The actual mapping functionality will be tested in conjunction with |
| 281 |
-- the tests of subprograms defined for Wide_String handling. |
| 282 |
|
| 283 |
declare |
| 284 |
|
| 285 |
X_Map_Ptr : Wide_Maps.Wide_Character_Mapping_Function := |
| 286 |
X_Map'Access; |
| 287 |
|
| 288 |
begin |
| 289 |
if X_Map_Ptr(Equiv('A')) /= -- both return 'X' |
| 290 |
X_Map_Ptr.all(Equiv('Q')) |
| 291 |
then |
| 292 |
Report.Failed |
| 293 |
("Incorrect result using access-to-subprogram values"); |
| 294 |
end if; |
| 295 |
end; |
| 296 |
|
| 297 |
|
| 298 |
exception |
| 299 |
when others => Report.Failed ("Exception raised in Test_Block"); |
| 300 |
end Test_Block; |
| 301 |
|
| 302 |
|
| 303 |
Report.Result; |
| 304 |
|
| 305 |
end CXA4012; |