aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxa/cxa4010.a
blob: 8646b12b5e48755331ec2b8c009a67bee3d03b0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
-- CXA4010.A
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
--      Check that the subprograms defined in package Ada.Strings.Unbounded
--      are available, and that they produce correct results. Specifically, 
--      check the subprograms To_String, To_Unbounded_String, Insert, "&", 
--      "*", Length, Slice, Replace_Slice, Overwrite, Index, Index_Non_Blank,
--      Head, Tail, and "=", "<=", ">=".
--      
-- TEST DESCRIPTION:
--      This test demonstrates the uses of many of the subprograms defined
--      in package Ada.Strings.Unbounded for use with unbounded strings.
--      The test simulates how unbounded strings could be used
--      to simulate paragraphs of text.  Modifications could be easily be
--      performed using the provided subprograms (although in this test, the
--      main modification performed was the addition of more text to the
--      string).  One would not have to worry about the formatting of the 
--      paragraph until it was finished and correct in content.  Then, once
--      all required editing is complete, the unbounded strings can be divided
--      up into the appropriate lengths based on particular formatting
--      requirements.  The test then compares the formatted text product
--      with a predefined "finished product".  
--      
--      This test uses a large number of the subprograms provided
--      by package Ada.Strings.Unbounded.  Often, the processing involved
--      could have been performed more efficiently using a minimum number
--      of the subprograms, in conjunction with loops, etc.  However, for
--      testing purposes, and in the interest of minimizing the number of
--      tests developed, subprogram variety and feature mixing was stressed.
--
--       
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--
--!

with Report;
with Ada.Strings.Maps;
with Ada.Strings.Unbounded;

procedure CXA4010 is
begin

   Report.Test ("CXA4010", "Check that the subprograms defined in "        &
                           "package Ada.Strings.Unbounded are available, " &
                           "and that they produce correct results");

   Test_Block:
   declare

      package ASUnb renames Ada.Strings.Unbounded;
      use type ASUnb.Unbounded_String;
      use Ada.Strings;

      Pamphlet_Paragraph_Count : constant :=  2;
      Lines                    : constant :=  4;
      Line_Length              : constant := 40;

      type Document_Type is array (Positive range <>) 
        of ASUnb.Unbounded_String;

      type Camera_Ready_Copy_Type is array (1..Lines) 
        of String (1..Line_Length);

      Pamphlet            : Document_Type (1..Pamphlet_Paragraph_Count);

      Camera_Ready_Copy   : Camera_Ready_Copy_Type := 
                              (others => (others => Ada.Strings.Space));

      TC_Finished_Product : Camera_Ready_Copy_Type :=
                          ( 1 => "Ada is a programming language designed  ",
                            2 => "to support long-lived, reliable software",
                            3 => " systems.                               ",
                            4 => "Go with Ada!                            ");

      -----


      procedure Enter_Text_Into_Document (Document : in out Document_Type) is
      begin

         -- Fill in both "paragraphs" of the document.  Each unbounded string
         -- functions as an individual paragraph, containing an unspecified
         -- number of characters.
         -- Use a variety of different unbounded string subprograms to load 
         -- the data.

         Document(1) := ASUnb.To_Unbounded_String("Ada is a language");

         -- Insert the word "programming" prior to "language".
         Document(1) := 
           ASUnb.Insert(Document(1), 
                        ASUnb.Index(Document(1),
                                    "language"),
                        ASUnb.To_String("progra" &           -- Str &
                                        ASUnb."*"(2,'m') &   -- Unbd & 
                                        "ing "));            -- Str


         -- Overwrite the word "language" with "language" + additional text.
         Document(1) :=
           ASUnb.Overwrite(Document(1),
                           ASUnb.Index(Document(1),
                                       ASUnb.To_String(
                                         ASUnb.Tail(Document(1), 8, ' ')),
                                       Ada.Strings.Backward),
                           "language designed to support long-lifed");


         -- Replace the word "lifed" with "lived".
         Document(1) :=
           ASUnb.Replace_Slice(Document(1),
                               ASUnb.Index(Document(1), "lifed"),
                               ASUnb.Length(Document(1)),
                               "lived");


         -- Overwrite the word "lived" with "lived" + additional text.
         Document(1) :=
           ASUnb.Overwrite(Document(1),
                           ASUnb.Index(Document(1),
                                       ASUnb.To_String(
                                         ASUnb.Tail(Document(1), 5, ' ')),
                                       Ada.Strings.Backward),
                               "lived, reliable software systems.");
                              
                              
         -- Use several of the overloaded versions of "&" to form this
         -- unbounded string.

         Document(2) := 'G' &                               
                        ASUnb.To_Unbounded_String("o ") & 
                        ASUnb.To_Unbounded_String("with") &
                        ' ' & 
                        "Ada!";

      end Enter_Text_Into_Document;


      -----


      procedure Create_Camera_Ready_Copy 
                  (Document    : in     Document_Type;
                   Camera_Copy :    out Camera_Ready_Copy_Type) is
      begin
         -- Break the unbounded strings into fixed lengths.

         -- Search the first unbounded string for portions of text that
         -- are less than or equal to the length of a string in the 
         -- Camera_Ready_Copy_Type object.  

         Camera_Copy(1) :=                 -- Take characters 1-39,
           ASUnb.Slice(Document(1),        -- and append a blank space.
                       1,
                       ASUnb.Index(ASUnb.To_Unbounded_String(
                                      ASUnb.Slice(Document(1),
                                                  1,
                                                  Line_Length)),
                                   Ada.Strings.Maps.To_Set(' '),
                                   Ada.Strings.Inside,
                                   Ada.Strings.Backward)) & ' ';

         Camera_Copy(2) :=                 -- Take characters 40-79.
           ASUnb.Slice(Document(1),
                       40,
                       (ASUnb.Index_Non_Blank          -- Should return 79
                          (ASUnb.To_Unbounded_String
                             (ASUnb.Slice(Document(1), -- Slice (40..79)
                                         40,
                                         79)),
                           Ada.Strings.Backward) + 39)); -- Increment since
                                                         -- this slice starts
                                                         -- at 40.

         Camera_Copy(3)(1..9) := ASUnb.Slice(Document(1), -- Characters 80-88
                                             80,
                                             ASUnb.Length(Document(1))); 
                                

         -- Break the second unbounded string into the appropriate length.
         -- It is only twelve characters in length, so the entire unbounded
         -- string will be placed on one string of the output object.

         Camera_Copy(4)(1..ASUnb.Length(Document(2))) :=
           ASUnb.To_String(ASUnb.Head(Document(2),
                                      ASUnb.Length(Document(2))));

      end Create_Camera_Ready_Copy;


      -----


      function Valid_Proofread (Draft, Master : Camera_Ready_Copy_Type) 
        return Boolean is
      begin

         -- Evaluate strings for equality, using the operators defined in
         -- package Ada.Strings.Unbounded.  The less than/greater than or
         -- equal comparisons should evaluate to "equals => True".

         if ASUnb.To_Unbounded_String(Draft(1))   =       -- "="(Unb,Unb)
            ASUnb.To_Unbounded_String(Master(1))   and    
            ASUnb.To_Unbounded_String(Draft(2))  <=       -- "<="(Unb,Unb)
            ASUnb.To_Unbounded_String(Master(2))   and
            ASUnb.To_Unbounded_String(Draft(3))  >=       -- ">="(Unb,Unb)
            ASUnb.To_Unbounded_String(Master(3))   and
            ASUnb.To_Unbounded_String(Draft(4))   =       -- "="(Unb,Unb)
            ASUnb.To_Unbounded_String(Master(4))
         then
            return True;
         else
            return False;
         end if;

      end Valid_Proofread;


      -----


   begin

      -- Enter text into the unbounded string paragraphs of the document.

      Enter_Text_Into_Document (Pamphlet);


      -- Reformat the unbounded strings into fixed string format.

      Create_Camera_Ready_Copy (Document    => Pamphlet,
                                Camera_Copy => Camera_Ready_Copy);


      -- Verify the conversion process.

      if not Valid_Proofread (Draft  => Camera_Ready_Copy,
                              Master => TC_Finished_Product)
      then
         Report.Failed ("Incorrect string processing result");
      end if;


   exception
      when others => Report.Failed ("Exception raised in Test_Block");
   end Test_Block;


   Report.Result;

end CXA4010;