1 |
149 |
jeremybenn |
-- CXA4010.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 subprograms defined in package Ada.Strings.Unbounded
|
28 |
|
|
-- are available, and that they produce correct results. Specifically,
|
29 |
|
|
-- check the subprograms To_String, To_Unbounded_String, Insert, "&",
|
30 |
|
|
-- "*", Length, Slice, Replace_Slice, Overwrite, Index, Index_Non_Blank,
|
31 |
|
|
-- Head, Tail, and "=", "<=", ">=".
|
32 |
|
|
--
|
33 |
|
|
-- TEST DESCRIPTION:
|
34 |
|
|
-- This test demonstrates the uses of many of the subprograms defined
|
35 |
|
|
-- in package Ada.Strings.Unbounded for use with unbounded strings.
|
36 |
|
|
-- The test simulates how unbounded strings could be used
|
37 |
|
|
-- to simulate paragraphs of text. Modifications could be easily be
|
38 |
|
|
-- performed using the provided subprograms (although in this test, the
|
39 |
|
|
-- main modification performed was the addition of more text to the
|
40 |
|
|
-- string). One would not have to worry about the formatting of the
|
41 |
|
|
-- paragraph until it was finished and correct in content. Then, once
|
42 |
|
|
-- all required editing is complete, the unbounded strings can be divided
|
43 |
|
|
-- up into the appropriate lengths based on particular formatting
|
44 |
|
|
-- requirements. The test then compares the formatted text product
|
45 |
|
|
-- with a predefined "finished product".
|
46 |
|
|
--
|
47 |
|
|
-- This test uses a large number of the subprograms provided
|
48 |
|
|
-- by package Ada.Strings.Unbounded. Often, the processing involved
|
49 |
|
|
-- could have been performed more efficiently using a minimum number
|
50 |
|
|
-- of the subprograms, in conjunction with loops, etc. However, for
|
51 |
|
|
-- testing purposes, and in the interest of minimizing the number of
|
52 |
|
|
-- tests developed, subprogram variety and feature mixing was stressed.
|
53 |
|
|
--
|
54 |
|
|
--
|
55 |
|
|
-- CHANGE HISTORY:
|
56 |
|
|
-- 06 Dec 94 SAIC ACVC 2.0
|
57 |
|
|
--
|
58 |
|
|
--!
|
59 |
|
|
|
60 |
|
|
with Report;
|
61 |
|
|
with Ada.Strings.Maps;
|
62 |
|
|
with Ada.Strings.Unbounded;
|
63 |
|
|
|
64 |
|
|
procedure CXA4010 is
|
65 |
|
|
begin
|
66 |
|
|
|
67 |
|
|
Report.Test ("CXA4010", "Check that the subprograms defined in " &
|
68 |
|
|
"package Ada.Strings.Unbounded are available, " &
|
69 |
|
|
"and that they produce correct results");
|
70 |
|
|
|
71 |
|
|
Test_Block:
|
72 |
|
|
declare
|
73 |
|
|
|
74 |
|
|
package ASUnb renames Ada.Strings.Unbounded;
|
75 |
|
|
use type ASUnb.Unbounded_String;
|
76 |
|
|
use Ada.Strings;
|
77 |
|
|
|
78 |
|
|
Pamphlet_Paragraph_Count : constant := 2;
|
79 |
|
|
Lines : constant := 4;
|
80 |
|
|
Line_Length : constant := 40;
|
81 |
|
|
|
82 |
|
|
type Document_Type is array (Positive range <>)
|
83 |
|
|
of ASUnb.Unbounded_String;
|
84 |
|
|
|
85 |
|
|
type Camera_Ready_Copy_Type is array (1..Lines)
|
86 |
|
|
of String (1..Line_Length);
|
87 |
|
|
|
88 |
|
|
Pamphlet : Document_Type (1..Pamphlet_Paragraph_Count);
|
89 |
|
|
|
90 |
|
|
Camera_Ready_Copy : Camera_Ready_Copy_Type :=
|
91 |
|
|
(others => (others => Ada.Strings.Space));
|
92 |
|
|
|
93 |
|
|
TC_Finished_Product : Camera_Ready_Copy_Type :=
|
94 |
|
|
( 1 => "Ada is a programming language designed ",
|
95 |
|
|
2 => "to support long-lived, reliable software",
|
96 |
|
|
3 => " systems. ",
|
97 |
|
|
4 => "Go with Ada! ");
|
98 |
|
|
|
99 |
|
|
-----
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
procedure Enter_Text_Into_Document (Document : in out Document_Type) is
|
103 |
|
|
begin
|
104 |
|
|
|
105 |
|
|
-- Fill in both "paragraphs" of the document. Each unbounded string
|
106 |
|
|
-- functions as an individual paragraph, containing an unspecified
|
107 |
|
|
-- number of characters.
|
108 |
|
|
-- Use a variety of different unbounded string subprograms to load
|
109 |
|
|
-- the data.
|
110 |
|
|
|
111 |
|
|
Document(1) := ASUnb.To_Unbounded_String("Ada is a language");
|
112 |
|
|
|
113 |
|
|
-- Insert the word "programming" prior to "language".
|
114 |
|
|
Document(1) :=
|
115 |
|
|
ASUnb.Insert(Document(1),
|
116 |
|
|
ASUnb.Index(Document(1),
|
117 |
|
|
"language"),
|
118 |
|
|
ASUnb.To_String("progra" & -- Str &
|
119 |
|
|
ASUnb."*"(2,'m') & -- Unbd &
|
120 |
|
|
"ing ")); -- Str
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
-- Overwrite the word "language" with "language" + additional text.
|
124 |
|
|
Document(1) :=
|
125 |
|
|
ASUnb.Overwrite(Document(1),
|
126 |
|
|
ASUnb.Index(Document(1),
|
127 |
|
|
ASUnb.To_String(
|
128 |
|
|
ASUnb.Tail(Document(1), 8, ' ')),
|
129 |
|
|
Ada.Strings.Backward),
|
130 |
|
|
"language designed to support long-lifed");
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
-- Replace the word "lifed" with "lived".
|
134 |
|
|
Document(1) :=
|
135 |
|
|
ASUnb.Replace_Slice(Document(1),
|
136 |
|
|
ASUnb.Index(Document(1), "lifed"),
|
137 |
|
|
ASUnb.Length(Document(1)),
|
138 |
|
|
"lived");
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
-- Overwrite the word "lived" with "lived" + additional text.
|
142 |
|
|
Document(1) :=
|
143 |
|
|
ASUnb.Overwrite(Document(1),
|
144 |
|
|
ASUnb.Index(Document(1),
|
145 |
|
|
ASUnb.To_String(
|
146 |
|
|
ASUnb.Tail(Document(1), 5, ' ')),
|
147 |
|
|
Ada.Strings.Backward),
|
148 |
|
|
"lived, reliable software systems.");
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
-- Use several of the overloaded versions of "&" to form this
|
152 |
|
|
-- unbounded string.
|
153 |
|
|
|
154 |
|
|
Document(2) := 'G' &
|
155 |
|
|
ASUnb.To_Unbounded_String("o ") &
|
156 |
|
|
ASUnb.To_Unbounded_String("with") &
|
157 |
|
|
' ' &
|
158 |
|
|
"Ada!";
|
159 |
|
|
|
160 |
|
|
end Enter_Text_Into_Document;
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
-----
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
procedure Create_Camera_Ready_Copy
|
167 |
|
|
(Document : in Document_Type;
|
168 |
|
|
Camera_Copy : out Camera_Ready_Copy_Type) is
|
169 |
|
|
begin
|
170 |
|
|
-- Break the unbounded strings into fixed lengths.
|
171 |
|
|
|
172 |
|
|
-- Search the first unbounded string for portions of text that
|
173 |
|
|
-- are less than or equal to the length of a string in the
|
174 |
|
|
-- Camera_Ready_Copy_Type object.
|
175 |
|
|
|
176 |
|
|
Camera_Copy(1) := -- Take characters 1-39,
|
177 |
|
|
ASUnb.Slice(Document(1), -- and append a blank space.
|
178 |
|
|
1,
|
179 |
|
|
ASUnb.Index(ASUnb.To_Unbounded_String(
|
180 |
|
|
ASUnb.Slice(Document(1),
|
181 |
|
|
1,
|
182 |
|
|
Line_Length)),
|
183 |
|
|
Ada.Strings.Maps.To_Set(' '),
|
184 |
|
|
Ada.Strings.Inside,
|
185 |
|
|
Ada.Strings.Backward)) & ' ';
|
186 |
|
|
|
187 |
|
|
Camera_Copy(2) := -- Take characters 40-79.
|
188 |
|
|
ASUnb.Slice(Document(1),
|
189 |
|
|
40,
|
190 |
|
|
(ASUnb.Index_Non_Blank -- Should return 79
|
191 |
|
|
(ASUnb.To_Unbounded_String
|
192 |
|
|
(ASUnb.Slice(Document(1), -- Slice (40..79)
|
193 |
|
|
40,
|
194 |
|
|
79)),
|
195 |
|
|
Ada.Strings.Backward) + 39)); -- Increment since
|
196 |
|
|
-- this slice starts
|
197 |
|
|
-- at 40.
|
198 |
|
|
|
199 |
|
|
Camera_Copy(3)(1..9) := ASUnb.Slice(Document(1), -- Characters 80-88
|
200 |
|
|
80,
|
201 |
|
|
ASUnb.Length(Document(1)));
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
-- Break the second unbounded string into the appropriate length.
|
205 |
|
|
-- It is only twelve characters in length, so the entire unbounded
|
206 |
|
|
-- string will be placed on one string of the output object.
|
207 |
|
|
|
208 |
|
|
Camera_Copy(4)(1..ASUnb.Length(Document(2))) :=
|
209 |
|
|
ASUnb.To_String(ASUnb.Head(Document(2),
|
210 |
|
|
ASUnb.Length(Document(2))));
|
211 |
|
|
|
212 |
|
|
end Create_Camera_Ready_Copy;
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
-----
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
function Valid_Proofread (Draft, Master : Camera_Ready_Copy_Type)
|
219 |
|
|
return Boolean is
|
220 |
|
|
begin
|
221 |
|
|
|
222 |
|
|
-- Evaluate strings for equality, using the operators defined in
|
223 |
|
|
-- package Ada.Strings.Unbounded. The less than/greater than or
|
224 |
|
|
-- equal comparisons should evaluate to "equals => True".
|
225 |
|
|
|
226 |
|
|
if ASUnb.To_Unbounded_String(Draft(1)) = -- "="(Unb,Unb)
|
227 |
|
|
ASUnb.To_Unbounded_String(Master(1)) and
|
228 |
|
|
ASUnb.To_Unbounded_String(Draft(2)) <= -- "<="(Unb,Unb)
|
229 |
|
|
ASUnb.To_Unbounded_String(Master(2)) and
|
230 |
|
|
ASUnb.To_Unbounded_String(Draft(3)) >= -- ">="(Unb,Unb)
|
231 |
|
|
ASUnb.To_Unbounded_String(Master(3)) and
|
232 |
|
|
ASUnb.To_Unbounded_String(Draft(4)) = -- "="(Unb,Unb)
|
233 |
|
|
ASUnb.To_Unbounded_String(Master(4))
|
234 |
|
|
then
|
235 |
|
|
return True;
|
236 |
|
|
else
|
237 |
|
|
return False;
|
238 |
|
|
end if;
|
239 |
|
|
|
240 |
|
|
end Valid_Proofread;
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
-----
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
begin
|
247 |
|
|
|
248 |
|
|
-- Enter text into the unbounded string paragraphs of the document.
|
249 |
|
|
|
250 |
|
|
Enter_Text_Into_Document (Pamphlet);
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
-- Reformat the unbounded strings into fixed string format.
|
254 |
|
|
|
255 |
|
|
Create_Camera_Ready_Copy (Document => Pamphlet,
|
256 |
|
|
Camera_Copy => Camera_Ready_Copy);
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
-- Verify the conversion process.
|
260 |
|
|
|
261 |
|
|
if not Valid_Proofread (Draft => Camera_Ready_Copy,
|
262 |
|
|
Master => TC_Finished_Product)
|
263 |
|
|
then
|
264 |
|
|
Report.Failed ("Incorrect string processing result");
|
265 |
|
|
end if;
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
exception
|
269 |
|
|
when others => Report.Failed ("Exception raised in Test_Block");
|
270 |
|
|
end Test_Block;
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
Report.Result;
|
274 |
|
|
|
275 |
|
|
end CXA4010;
|