summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxa/cxa4028.a
blob: bc6cac14c5e74bf00c8028f279e711e8a896a387 (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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
-- CXA4028.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 Ada.Strings.Bounded procedures Append, Head, Tail, and 
--      Trim, and relational operator functions "=", ">", ">=", "<", "<=" 
--      with parameter combinations of type String and Bounded_String, 
--      produce correct results.
--
-- TEST DESCRIPTION:
--      This test examines the operation of several subprograms from within 
--      the Ada.Strings.Bounded package.  Four different instantiations of
--      Ada.Strings.Bounded.Generic_Bounded_Length provide packages defined
--      to manipulate bounded strings of lengths 1, 20, 40, and 80.
--      Examples of the above mentioned procedures and relational operators
--      from each of these instantiations are tested, with results compared
--      against expected output.
--      
--      Testing of the function versions of many of the subprograms tested
--      here is performed in tests CXA4006-CXA4009.
--      
--       
-- CHANGE HISTORY:
--      16 Feb 95   SAIC    Initial prerelease version
--      10 Mar 95   SAIC    Incorporated reviewer comments.
--      15 Apr 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--
--!

with Ada.Exceptions;
with Ada.Strings.Bounded;
with Report;

procedure CXA4028 is

begin

   Report.Test ("CXA4028", "Check that Ada.Strings.Bounded procedures "    &
                           "Append, Head, Tail, and Trim, and relational " &
                           "operator functions =, >, >=, <, <= with "      &
                           "parameter combinations of type String and "    &
                           "Bounded_String, produce correct results");

   Test_Block:
   declare

      use Ada.Exceptions;
      use Ada.Strings;

      -- Instantiations of Bounded String generic package.

      package BS1  is new Ada.Strings.Bounded.Generic_Bounded_Length(1);
      package BS20 is new Ada.Strings.Bounded.Generic_Bounded_Length(20);
      package BS40 is new Ada.Strings.Bounded.Generic_Bounded_Length(40);
      package BS80 is new Ada.Strings.Bounded.Generic_Bounded_Length(80);

      use type BS1.Bounded_String,  BS20.Bounded_String, 
               BS40.Bounded_String, BS80.Bounded_String;

      String_1   : String(1..1)  := "A";
      String_20  : String(1..20) := "ABCDEFGHIJKLMNOPQRST";
      String_40  : String(1..40) := "abcdefghijklmnopqrst" & String_20;
      String_80  : String(1..80) := String_40 & String_40;

      BString_1  : BS1.Bounded_String  := BS1.Null_Bounded_String;
      BString_20 : BS20.Bounded_String := BS20.Null_Bounded_String;
      BString_40 : BS40.Bounded_String := BS40.Null_Bounded_String;
      BString_80 : BS80.Bounded_String := BS80.Null_Bounded_String;

   begin

      -- Procedure Append.

      declare
         use BS1, BS20;
      begin
         Append(Source => BString_1, New_Item => To_Bounded_String("A"));
         Append(BString_1, "B", Ada.Strings.Left);
         Append(BString_1, 'C', Drop => Ada.Strings.Right); -- Drop appended
                                                            -- character.
         if BString_1 /= To_Bounded_String("B") then
            Report.Failed("Incorrect results from BS1 versions of " &
                          "procedure Append");
         end if;

         Append(BString_20, 'T');                      -- Character.
         Append(BString_20, "his string");             -- String.
         Append(BString_20, 
                To_Bounded_String(" is complete."),    -- Bounded string.
                Drop => Ada.Strings.Right);            -- Drop 4 characters.

         if BString_20 /= To_Bounded_String("This string is compl") then
            Report.Failed("Incorrect results from BS20 versions of " &
                          "procedure Append");
         end if;
      end;


      -- Operator "=".

      BString_40 := BS40.To_Bounded_String(String_40);
      BString_80 := BS80.To_Bounded_String(
                           BS40.To_String(BString_40) &
                           BS40.To_String(BString_40));

      if not (BString_40 = String_40 and         -- (Bounded_String, String)
              BS80."="(String_80, BString_80))   -- (String, Bounded_String)
      then
         Report.Failed("Incorrect results from function ""="" with " &
                       "string - bounded string parameter combinations");
      end if;


      -- Operator "<". 

      BString_1  := BS1.To_Bounded_String("cat",         -- string "c" only.
                                          Drop => Ada.Strings.Right);
      BString_20 := BS20.To_Bounded_String("Santa Claus");

      if BString_1 < "C"        or               -- (Bounded_String, String)
         BS1."<"(BString_1,"c") or               -- (Bounded_String, String)
         "x"  < BString_1       or               -- (String, Bounded_String)
         BString_20 < "Santa "  or               -- (Bounded_String, String)
         "Santa and his Elves" < BString_20      -- (String, Bounded_String)
      then
         Report.Failed("Incorrect results from function ""<"" with " &
                       "string - bounded string parameter combinations");
      end if;


      -- Operator "<=". 

      BString_20 := BS20.To_Bounded_String("Sample string");

      if BString_20          <= "Sample strin"  or -- (Bounded_String, String)
         "sample string"     <= BString_20      or -- (String, Bounded_String)
         not("Sample string" <= BString_20)        -- (String, Bounded_String)
      then
         Report.Failed("Incorrect results from function ""<="" with " &
                       "string - bounded string parameter combinations");
      end if;


      -- Operator ">". 

      BString_40 := BS40.To_Bounded_String("A MUCH LONGER SAMPLE STRING.");

      if BString_40 > "A much longer sample string"     or  -- (Bnd_Str, Str)
         String_20  > BS40.To_Bounded_String(String_40) or  -- (Str, Bnd_Str)
         BS40.To_Bounded_String("ABCDEFGH") > "abcdefgh"    -- (Str, Bnd_Str)
      then
         Report.Failed("Incorrect results from function "">"" with " &
                       "string - bounded string parameter combinations");
      end if;


      -- Operator ">=". 

      BString_80 := BS80.To_Bounded_String(String_80);

      if not (BString_80 >= String_80  and 
              BS80.To_Bounded_String("Programming") >= "PROGRAMMING" and
              "test" >= BS80.To_Bounded_String("tess"))
      then
         Report.Failed("Incorrect results from function "">="" with " &
                       "string - bounded string parameter combinations");
      end if;


      -- Procedure Trim

      BString_20 := BS20.To_Bounded_String("      Left Spaces  ");
      BS20.Trim(Source => BString_20, 
                Side   => Ada.Strings.Left);

      if "Left Spaces  " /= BString_20 then
         Report.Failed("Incorrect results from Procedure Trim with " &
                       "Side = Left");
      end if;

      BString_40 := BS40.To_Bounded_String("    Right Spaces    ");
      BS40.Trim(BString_40, Side => Ada.Strings.Right);

      if BString_40 /= "    Right Spaces" then
         Report.Failed("Incorrect results from Procedure Trim with " &
                       "Side = Right");
      end if;

      BString_20 := BS20.To_Bounded_String("   Both Sides      ");
      BS20.Trim(BString_20, Ada.Strings.Both);

      if BString_20 /= BS20.To_Bounded_String("Both Sides") then
         Report.Failed("Incorrect results from Procedure Trim with " &
                       "Side = Both");
      end if;

      BString_80 := BS80.To_Bounded_String("Centered    Spaces");
      BS80.Trim(BString_80, Ada.Strings.Both);

      if BString_80 /= BS80.To_Bounded_String("Centered    Spaces") then
         Report.Failed("Incorrect results from Procedure Trim with " &
                       "no blank spaces on the ends of the string");
      end if;


      -- Procedure Head

      BString_40 := BS40.To_Bounded_String("Test String");
      BS40.Head(Source => BString_40,
                Count  => 4);                       -- Count < Source'Length

      if BString_40 /= BS40.To_Bounded_String("Test") then
         Report.Failed("Incorrect results from Procedure Head with " &
                       "the Count parameter less than Source'Length");
      end if;

      BString_1 := BS1.To_Bounded_String("X");
      BS1.Head(BString_1, BS1.Length(BString_1));   -- Count = Source'Length

      if BString_1 /= "X" then
         Report.Failed("Incorrect results from Procedure Head with " &
                       "the Count parameter equal to Source'Length");
      end if;

      BString_20 := BS20.To_Bounded_String("Sample string");
      BS20.Head(BString_20, 
                Count => BS20.Max_Length,           -- Count > Source'Length
                Pad => '*');

      if BString_20 /= BS20.To_Bounded_String("Sample string*******") then
         Report.Failed("Incorrect results from Procedure Head with "    &
                       "the Count parameter greater than Source'Length");
      end if;

      BString_20 := BS20.To_Bounded_String("Twenty Characters 20");
      BS20.Head(BString_20, 22, Pad => '*', Drop => Ada.Strings.Left);

      if BString_20 /= "enty Characters 20**" then
         Report.Failed("Incorrect results from Procedure Head with "      &
                       "the Count parameter greater than Source'Length, " &
                       "and the Drop parameter = Left");
      end if;

      BString_20 := BS20.To_Bounded_String("Short String");
      BS20.Head(BString_20, 23, '-', Ada.Strings.Right);

      if ("Short String--------") /= BString_20 then
         Report.Failed("Incorrect results from Procedure Head with " &
                       "the Count parameter greater than Source'Length, " &
                       "and the Drop parameter = Right");
      end if;


      -- Procedure Tail

      BString_40 := BS40.To_Bounded_String("Test String");
      BS40.Tail(Source => BString_40,
                Count  => 6);                       -- Count < Source'Length

      if BString_40 /= BS40.To_Bounded_String("String") then
         Report.Failed("Incorrect results from Procedure Tail with " &
                       "the Count parameter less than Source'Length");
      end if;

      BString_1 := BS1.To_Bounded_String("X");
      BS1.Tail(BString_1, BS1.Length(BString_1));   -- Count = Source'Length

      if BString_1 /= "X" then
         Report.Failed("Incorrect results from Procedure Tail with " &
                       "the Count parameter equal to Source'Length");
      end if;

      BString_20 := BS20.To_Bounded_String("Sample string");
      BS20.Tail(BString_20, 
                Count => BS20.Max_Length,           -- Count > Source'Length
                Pad => '*');

      if BString_20 /= BS20.To_Bounded_String("*******Sample string") then
         Report.Failed("Incorrect results from Procedure Tail with "    &
                       "the Count parameter greater than Source'Length");
      end if;

      BString_20 := BS20.To_Bounded_String("Twenty Characters");  -- Len = 17
      BS20.Tail(BString_20, 22, Pad => '*', Drop => Ada.Strings.Left);

      if BString_20 /= "***Twenty Characters" then
         Report.Failed("Incorrect results from Procedure Tail with "      &
                       "the Count parameter greater than Source'Length, " &
                       "and the Drop parameter = Left");
      end if;

      BString_20 := BS20.To_Bounded_String("Maximum Length Chars");
      BS20.Tail(BString_20, 23, '-', Ada.Strings.Right);

      if ("---Maximum Length Ch") /= BString_20 then
         Report.Failed("Incorrect results from Procedure Tail with " &
                       "the Count parameter greater than Source'Length, " &
                       "and the Drop parameter = Right");
      end if;

   exception
      when The_Error : others => 
         Report.Failed ("The following exception was raised in the " &
                        "Test_Block: " & Exception_Name(The_Error));
   end Test_Block;

   Report.Result;

end CXA4028;