summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxa/cxa4031.a
blob: 91bc68ce6e719667cec4767036678271ce018fa0 (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
-- CXA4031.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 functions To_Unbounded_String (version with Length
--      parameter), "=", "<", "<=", ">", ">=" (all with String-Unbounded
--      String parameter mix), as well as three versions of Procedure Append.
--      
-- 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 processed in a
--      user environment, using the subprograms provided in this package.
--
--      This test, when taken in conjunction with tests CXA4010, CXA4011,
--      CXA4030, and CXA4032 will constitute a test of all the functionality 
--      contained in package Ada.Strings.Unbounded.  This test uses a variety 
--      of the subprograms defined in the unbounded string package in ways 
--      typical of common usage.
--      
--       
-- CHANGE HISTORY:
--      27 Feb 95   SAIC    Initial prerelease version.
--      18 Apr 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--
--!

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

procedure CXA4031 is
begin

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

   Test_Block:
   declare

      package Unb renames Ada.Strings.Unbounded;
      use Unb;
      use Ada.Exceptions;
 
      subtype LC_Characters is Character range 'a'..'z';

      Null_String       : constant String := "";
      TC_String         : constant String := "A Standard String";

      TC_Unb_String,
      TC_New_Unb_String : Unb.Unbounded_String := Unb.Null_Unbounded_String;

   begin

      -- Function To_Unbounded_String (version with Length parameter)
      -- returns an unbounded string that represents an uninitialized String
      -- whose length is Length.
      -- Note: Unbounded_String length can vary conceptually between 0 and
      --       Natural'Last.

      if Unb.Length(Unb.To_Unbounded_String(Length => 10)) /= 10 or
         Unb.Length(Unb.To_Unbounded_String(1))            /=  1 or
         Unb.Length(Unb.To_Unbounded_String(0))            /=  0 or
         Unb.Length(Unb."&"(Unb.To_Unbounded_String(Length => 10),
                    Unb."&"(Unb.To_Unbounded_String(1),
                            Unb.To_Unbounded_String(0) ))) /= 10+1+0
      then
         Report.Failed
           ("Incorrect results from Function To_Unbounded_String with " &
            "Length parameter");
      end if;


      -- Procedure Append (Unbounded - Unbounded)
      -- Note: For each of the Append procedures, the resulting string 
      --       represented by the Source parameter is given by the 
      --       concatenation of the original value of Source and the value 
      --       of New_Item.

      TC_Unb_String := Unb.To_Unbounded_String("Sample string of length L");
      TC_New_Unb_String := Unb.To_Unbounded_String(" and then some");

      Unb.Append(Source => TC_Unb_String, New_Item => TC_New_Unb_String);
      
      if TC_Unb_String /= 
         Unb.To_Unbounded_String("Sample string of length L and then some")
      then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "unbounded string parameters - 1");
      end if;


      TC_Unb_String := Unb.To_Unbounded_String("Sample string of length L");
      TC_New_Unb_String := Unb.Null_Unbounded_String;

      Unb.Append(TC_Unb_String, TC_New_Unb_String);
      
      if TC_Unb_String /= 
         Unb.To_Unbounded_String("Sample string of length L")
      then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "unbounded string parameters - 2");
      end if;


      TC_Unb_String := Unb.Null_Unbounded_String;

      Unb.Append(TC_Unb_String,
                 Unb.To_Unbounded_String("New Unbounded String"));
      
      if TC_Unb_String /= 
         Unb.To_Unbounded_String("New Unbounded String")
      then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "unbounded string parameters - 3");
      end if;

      
      -- Procedure Append (Unbounded - String)

      TC_Unb_String := Unb.To_Unbounded_String("An Unbounded String and ");

      Unb.Append(Source => TC_Unb_String, New_Item => TC_String);
      
      if TC_Unb_String /= 
         Unb.To_Unbounded_String("An Unbounded String and A Standard String")
      then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "an unbounded string parameter and a string "   &
                       "parameter - 1");
      end if;


      TC_Unb_String := Unb.To_Unbounded_String("An Unbounded String");

      Unb.Append(TC_Unb_String, New_Item => Null_String);
      
      if TC_Unb_String /= 
         Unb.To_Unbounded_String("An Unbounded String")
      then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "an unbounded string parameter and a string "   &
                       "parameter - 2");
      end if;


      TC_Unb_String := Unb.Null_Unbounded_String;

      Unb.Append(TC_Unb_String, TC_String);
      
      if TC_Unb_String /= Unb.To_Unbounded_String("A Standard String") then
         Report.Failed("Incorrect results from Procedure Append with " &
                       "an unbounded string parameter and a string "   &
                       "parameter - 3");
      end if;


      -- Procedure Append (Unbounded - Character)

      TC_Unb_String := Unb.To_Unbounded_String("Lower Case = ");

      for i in LC_Characters'Range loop
         Unb.Append(Source => TC_Unb_String, New_Item => LC_Characters(i));
      end loop;

      if TC_Unb_String /= 
         Unb.To_Unbounded_String("Lower Case = abcdefghijklmnopqrstuvwxyz")
      then
         Report.Failed("Incorrect results from Procedure Append with "  &
                       "an unbounded string parameter and a character " &
                       "parameter - 1");
      end if;        

      
      TC_Unb_String := Unb.Null_Unbounded_String;

      Unb.Append(TC_Unb_String, New_Item => 'a');
      
      if TC_Unb_String /= Unb.To_Unbounded_String("a") then
         Report.Failed("Incorrect results from Procedure Append with "  &
                       "an unbounded string parameter and a character " &
                       "parameter - 2");
      end if;        


      -- Function "="

      TC_Unb_String := Unb.To_Unbounded_String(TC_String);

      if not (TC_Unb_String = TC_String)                 or  -- (Unb_Str, Str)
         not Unb."="("A Standard String", TC_Unb_String) or  -- (Str, Unb_Str)
         not ((Unb.Null_Unbounded_String = "") and           -- (Unb_Str, Str)
              ("Test String" =                               -- (Str, Unb_Str)
               Unb.To_Unbounded_String("Test String")))
      then
         Report.Failed("Incorrect results from function ""="" with " &
                       "string - unbounded string parameter combinations");
      end if;


      -- Function "<"

      if not ("Extra Space" < Unb.To_Unbounded_String("Extra Space ") and
              Unb.To_Unbounded_String("tess") < "test"                and
              Unb.To_Unbounded_String("best") < "test")                or
         Unb.Null_Unbounded_String            < Null_String            or
         " leading blank"  < Unb.To_Unbounded_String(" leading blank") or
         "ending blank "   < Unb.To_Unbounded_String("ending blank ")  
      then
         Report.Failed("Incorrect results from function ""<"" with " &
                       "string - unbounded string parameter combinations");
      end if;


      -- Function "<="

      TC_Unb_String := Unb.To_Unbounded_String("Sample string");

      if TC_Unb_String                 <= "Sample strin" or  -- (Unb_Str, Str)
         "sample string"               <= TC_Unb_String  or  -- (Str, Unb_Str)
         not(Unb.Null_Unbounded_String <= "")            or  -- (Unb_Str, Str)
         not("Sample string"           <= TC_Unb_String)     -- (Str, Unb_Str)
      then
         Report.Failed("Incorrect results from function ""<="" with " &
                       "string - unbounded string parameter combinations");
      end if;


      -- Function ">"

      TC_Unb_String := Unb.To_Unbounded_String("A MUCH LONGER STRING");

      if not ("A much longer string" > TC_Unb_String                  and 
              Unb.To_Unbounded_String(TC_String) > "A Standard Strin" and
              "abcdefgh" > Unb.To_Unbounded_String("ABCDEFGH"))        or
         Unb.Null_Unbounded_String > Null_String    
      then
         Report.Failed("Incorrect results from function "">"" with " &
                       "string - unbounded string parameter combinations");
      end if;


      -- Function ">=" 

      TC_Unb_String := Unb.To_Unbounded_String(TC_String);

      if not (TC_Unb_String >= TC_String                       and 
              Null_String   >= Unb.Null_Unbounded_String       and
              "test"        >= Unb.To_Unbounded_String("tess") and  
              Unb.To_Unbounded_String("Programming") >= "PROGRAMMING")
      then
         Report.Failed("Incorrect results from function "">="" with " &
                       "string - unbounded string parameter combinations");
      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 CXA4031;