3 -- Grant of Unlimited Rights
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
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.
27 -- Check that the subprograms defined in package Ada.Strings.Wide_Bounded
28 -- are available, and that they produce correct results. Specifically,
29 -- check the subprograms Append, Delete, Index, Insert , Length,
30 -- Overwrite, Replace_Slice, Slice, "&", To_Bounded_Wide_String,
31 -- To_Wide_String, Translate, and Trim.
34 -- This test demonstrates the uses of a variety of the Wide_String
35 -- functions found in the package Ada.Strings.Wide_Bounded, simulating
36 -- the operations found in a text processing environment.
37 -- With bounded wide strings, the length of each "line" of text can vary
38 -- up to the instantiated maximum, allowing one to view a page of text as
39 -- a series of expandable lines. This provides flexibility in text
40 -- formatting of individual lines (wide strings).
41 -- Several subprograms are defined, all of which attempt to take
42 -- advantage of as many different bounded wide string utilities as
43 -- possible. Often, an operation that is being performed in a subprogram
44 -- using a certain bounded wide string utility could more efficiently be
45 -- performed using a different utility. However, in the interest of
46 -- including as broad coverage as possible, a mixture of utilities is
47 -- invoked in this test.
48 -- A simulated page of text is provided as a parameter to the test
49 -- defined subprograms, and the appropriate processing performed. The
50 -- processed page of text is then compared to a predefined "finished"
51 -- page, and test passage/failure is based on the results of this
56 -- 06 Dec 94 SAIC ACVC 2.0
57 -- 06 Nov 95 SAIC Corrected initialization error for ACVC 2.0.1.
62 with Ada
.Strings
.Wide_Bounded
;
63 with Ada
.Strings
.Wide_Maps
;
70 Report
.Test
("CXA4017", "Check that the subprograms defined in package " &
71 "Ada.Strings.Wide_Bounded are available, and " &
72 "that they produce correct results");
77 Characters_Per_Line
: constant Positive := 40;
78 Lines_Per_Page
: constant Natural := 4;
82 Ada
.Strings
.Wide_Bounded
.Generic_Bounded_Length
(Characters_Per_Line
);
84 use type BS_40
.Bounded_Wide_String
;
86 type Page_Type
is array (1..Lines_Per_Page
) of
87 BS_40
.Bounded_Wide_String
;
89 -- Note: Misspellings below are intentional.
91 Line1
: BS_40
.Bounded_Wide_String
:=
92 BS_40
.To_Bounded_Wide_String
93 ("ada is a progrraming language designed");
94 Line2
: BS_40
.Bounded_Wide_String
:=
95 BS_40
.To_Bounded_Wide_String
("to support the construction of long-");
96 Line3
: BS_40
.Bounded_Wide_String
:=
97 BS_40
.To_Bounded_Wide_String
("lived, highly reliabel software ");
98 Line4
: BS_40
.Bounded_Wide_String
:=
99 BS_40
.To_Bounded_Wide_String
("systems");
101 Page
: Page_Type
:= (1 => Line1
, 2 => Line2
, 3 => Line3
, 4 => Line4
);
103 Finished_Page
: Page_Type
:=
104 (BS_40
.To_Bounded_Wide_String
105 ("Ada is a programming language designed"),
106 BS_40
.To_Bounded_Wide_String
("to support the construction of long-"),
107 BS_40
.To_Bounded_Wide_String
108 ("lived, HIGHLY RELIABLE software systems."),
109 BS_40
.To_Bounded_Wide_String
(""));
113 procedure Compress
(Page
: in out Page_Type
) is
114 Clear_Line
: Natural := Lines_Per_Page
;
116 -- If two consecutive lines on the page are together less than the
117 -- maximum line length, then append those two lines, move up all
118 -- lower lines on the page, and blank out the last line.
119 -- This algorithm works one time through the page, does not perform
120 -- repetitive compression, and is designed for use with this test
122 for i
in 1..Lines_Per_Page
- 1 loop
123 if BS_40
.Length
(Page
(i
)) + BS_40
.Length
(Page
(i
+1)) <=
126 Page
(i
) := BS_40
."&"(Page
(i
),
127 Page
(i
+1)); -- "&" (wd bnd, wd bnd)
129 for j
in i
+1..Lines_Per_Page
- 1 loop
131 BS_40
.To_Bounded_Wide_String
132 (BS_40
.Slice
(Page
(j
+1),
134 BS_40
.Length
(Page
(j
+1))));
137 Page
(Clear_Line
) := BS_40
.Null_Bounded_Wide_String
;
144 procedure Format
(Page
: in out Page_Type
) is
145 Sm_Ada
: BS_40
.Bounded_Wide_String
:=
146 BS_40
.To_Bounded_Wide_String
("ada");
147 Cap_Ada
: constant Wide_String := "Ada";
148 Char_Pos
: Natural := 0;
149 Finished
: Boolean := False;
150 Line
: Natural := Page_Type
'Last;
153 -- Add a period to the end of the last line.
154 while Line
>= Page_Type
'First and not Finished
loop
155 if Page
(Line
) /= BS_40
.Null_Bounded_Wide_String
and
156 BS_40
.Length
(Page
(Line
)) <= BS_40
.Max_Length
158 Page
(Line
) := BS_40
.Append
(Page
(Line
), '.');
164 -- Replace all occurrences of "ada" with "Ada".
165 for Line
in Page_Type
'First .. Page_Type
'Last loop
167 while not Finished
loop
169 BS_40
.Index
(Source
=> Page
(Line
),
170 Pattern
=> BS_40
.To_Wide_String
(Sm_Ada
),
171 Going
=> Ada
.Strings
.Backward
);
172 -- A zero is returned by function Index if no occurrences of
173 -- the pattern wide string are found.
174 Finished
:= (Char_Pos
= 0);
177 (Source
=> Page
(Line
),
179 High
=> Char_Pos
+ BS_40
.Length
(Sm_Ada
) - 1,
182 end loop; -- while loop
183 end loop; -- for loop
189 procedure Spell_Check
(Page
: in out Page_Type
) is
190 type Spelling_Type
is (Incorrect
, Correct
);
191 type Word_Array_Type
is array (Spelling_Type
)
192 of BS_40
.Bounded_Wide_String
;
193 type Dictionary_Type
is array (1..2) of Word_Array_Type
;
195 -- Note that the "words" in the dictionary will require various
196 -- amounts of Trimming prior to their use in the bounded wide string
198 Dictionary
: Dictionary_Type
:=
199 (1 => (BS_40
.To_Bounded_Wide_String
(" reliabel "),
200 BS_40
.To_Bounded_Wide_String
(" reliable ")),
201 2 => (BS_40
.To_Bounded_Wide_String
(" progrraming "),
202 BS_40
.To_Bounded_Wide_String
(" programming ")));
204 Pos
: Natural := Natural'First;
205 Finished
: Boolean := False;
209 for Line
in Page_Type
'Range loop
211 -- Search for the first incorrectly spelled word in the
212 -- Dictionary, if it is found, replace it with the correctly
213 -- spelled word, using the Overwrite function.
215 while not Finished
loop
217 BS_40
.Index
(Page
(Line
),
219 (BS_40
.Trim
(Dictionary
(1)(Incorrect
),
221 Ada
.Strings
.Forward
);
222 Finished
:= (Pos
= 0);
225 BS_40
.Overwrite
(Page
(Line
),
228 (BS_40
.Trim
(Dictionary
(1)(Correct
),
235 -- Search for the second incorrectly spelled word in the
236 -- Dictionary, if it is found, replace it with the correctly
237 -- spelled word, using the Delete procedure and Insert function.
239 while not Finished
loop
241 BS_40
.Index
(Page
(Line
),
242 BS_40
.To_Wide_String
(
243 BS_40
.Trim
(Dictionary
(2)(Incorrect
),
245 Ada
.Strings
.Forward
);
247 Finished
:= (Pos
= 0);
253 Pos
+ BS_40
.To_Wide_String
254 (BS_40
.Trim
(Dictionary
(2)(Incorrect
),
255 Ada
.Strings
.Both
))'Length-1);
257 BS_40
.Insert
(Page
(Line
),
260 (BS_40
.Trim
(Dictionary
(2)(Correct
),
272 procedure Bold
(Page
: in out Page_Type
) is
273 Key_Word
: constant Wide_String := "highly reliable";
274 Bold_Mapping
: constant
275 Ada
.Strings
.Wide_Maps
.Wide_Character_Mapping
:=
276 Ada
.Strings
.Wide_Maps
.To_Mapping
277 (From
=> " abcdefghijklmnopqrstuvwxyz",
278 To
=> " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
279 Pos
: Natural := Natural'First;
280 Finished
: Boolean := False;
282 -- This procedure is designed to change the case of the phrase
283 -- "highly reliable" into upper case (a type of "Bolding").
284 -- All instances of the phrase on all lines of the page will be
287 for Line
in Page_Type
'First .. Page_Type
'Last loop
288 while not Finished
loop
289 Pos
:= BS_40
.Index
(Page
(Line
), Key_Word
);
290 Finished
:= (Pos
= 0);
298 (BS_40
.To_Bounded_Wide_String
299 (BS_40
.Slice
(Page
(Line
),
301 Pos
+ Key_Word
'Length - 1)),
318 for i
in 1..Lines_Per_Page
loop
319 if BS_40
.To_Wide_String
(Page
(i
)) /=
320 BS_40
.To_Wide_String
(Finished_Page
(i
)) or
321 BS_40
.Length
(Page
(i
)) /=
322 BS_40
.Length
(Finished_Page
(i
))
324 Report
.Failed
("Incorrect modification of Page, Line " &
331 when others => Report
.Failed
("Exception raised in Test_Block");