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.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 "=", "<=", ">=".
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".
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.
56 -- 06 Dec 94 SAIC ACVC 2.0
61 with Ada
.Strings
.Maps
;
62 with Ada
.Strings
.Unbounded
;
67 Report
.Test
("CXA4010", "Check that the subprograms defined in " &
68 "package Ada.Strings.Unbounded are available, " &
69 "and that they produce correct results");
74 package ASUnb
renames Ada
.Strings
.Unbounded
;
75 use type ASUnb
.Unbounded_String
;
78 Pamphlet_Paragraph_Count
: constant := 2;
79 Lines
: constant := 4;
80 Line_Length
: constant := 40;
82 type Document_Type
is array (Positive range <>)
83 of ASUnb
.Unbounded_String
;
85 type Camera_Ready_Copy_Type
is array (1..Lines
)
86 of String (1..Line_Length
);
88 Pamphlet
: Document_Type
(1..Pamphlet_Paragraph_Count
);
90 Camera_Ready_Copy
: Camera_Ready_Copy_Type
:=
91 (others => (others => Ada
.Strings
.Space
));
93 TC_Finished_Product
: Camera_Ready_Copy_Type
:=
94 ( 1 => "Ada is a programming language designed ",
95 2 => "to support long-lived, reliable software",
97 4 => "Go with Ada! ");
102 procedure Enter_Text_Into_Document
(Document
: in out Document_Type
) is
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
111 Document
(1) := ASUnb
.To_Unbounded_String
("Ada is a language");
113 -- Insert the word "programming" prior to "language".
115 ASUnb
.Insert
(Document
(1),
116 ASUnb
.Index
(Document
(1),
118 ASUnb
.To_String
("progra" & -- Str &
119 ASUnb
."*"(2,'m') & -- Unbd &
123 -- Overwrite the word "language" with "language" + additional text.
125 ASUnb
.Overwrite
(Document
(1),
126 ASUnb
.Index
(Document
(1),
128 ASUnb
.Tail
(Document
(1), 8, ' ')),
129 Ada
.Strings
.Backward
),
130 "language designed to support long-lifed");
133 -- Replace the word "lifed" with "lived".
135 ASUnb
.Replace_Slice
(Document
(1),
136 ASUnb
.Index
(Document
(1), "lifed"),
137 ASUnb
.Length
(Document
(1)),
141 -- Overwrite the word "lived" with "lived" + additional text.
143 ASUnb
.Overwrite
(Document
(1),
144 ASUnb
.Index
(Document
(1),
146 ASUnb
.Tail
(Document
(1), 5, ' ')),
147 Ada
.Strings
.Backward
),
148 "lived, reliable software systems.");
151 -- Use several of the overloaded versions of "&" to form this
155 ASUnb
.To_Unbounded_String
("o ") &
156 ASUnb
.To_Unbounded_String
("with") &
160 end Enter_Text_Into_Document
;
166 procedure Create_Camera_Ready_Copy
167 (Document
: in Document_Type
;
168 Camera_Copy
: out Camera_Ready_Copy_Type
) is
170 -- Break the unbounded strings into fixed lengths.
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.
176 Camera_Copy
(1) := -- Take characters 1-39,
177 ASUnb
.Slice
(Document
(1), -- and append a blank space.
179 ASUnb
.Index
(ASUnb
.To_Unbounded_String
(
180 ASUnb
.Slice
(Document
(1),
183 Ada
.Strings
.Maps
.To_Set
(' '),
185 Ada
.Strings
.Backward
)) & ' ';
187 Camera_Copy
(2) := -- Take characters 40-79.
188 ASUnb
.Slice
(Document
(1),
190 (ASUnb
.Index_Non_Blank
-- Should return 79
191 (ASUnb
.To_Unbounded_String
192 (ASUnb
.Slice
(Document
(1), -- Slice (40..79)
195 Ada
.Strings
.Backward
) + 39)); -- Increment since
199 Camera_Copy
(3)(1..9) := ASUnb
.Slice
(Document
(1), -- Characters 80-88
201 ASUnb
.Length
(Document
(1)));
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.
208 Camera_Copy
(4)(1..ASUnb
.Length
(Document
(2))) :=
209 ASUnb
.To_String
(ASUnb
.Head
(Document
(2),
210 ASUnb
.Length
(Document
(2))));
212 end Create_Camera_Ready_Copy
;
218 function Valid_Proofread
(Draft
, Master
: Camera_Ready_Copy_Type
)
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".
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))
248 -- Enter text into the unbounded string paragraphs of the document.
250 Enter_Text_Into_Document
(Pamphlet
);
253 -- Reformat the unbounded strings into fixed string format.
255 Create_Camera_Ready_Copy
(Document
=> Pamphlet
,
256 Camera_Copy
=> Camera_Ready_Copy
);
259 -- Verify the conversion process.
261 if not Valid_Proofread
(Draft
=> Camera_Ready_Copy
,
262 Master
=> TC_Finished_Product
)
264 Report
.Failed
("Incorrect string processing result");
269 when others => Report
.Failed
("Exception raised in Test_Block");