summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxa/cxa4034.a
blob: a1ed53de0f7ebe1058515d7df558c8e89482ce98 (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
-- CXA4034.A
--
--                             Grant of Unlimited Rights
--
--     The Ada Conformity Assessment Authority (ACAA) holds unlimited
--     rights in the software and documentation contained herein. Unlimited
--     rights are the same as those granted by the U.S. Government for older
--     parts of the Ada Conformity Assessment Test Suite, and are defined
--     in DFAR 252.227-7013(a)(19). By making this public release, the ACAA
--     intends to confer upon all recipients unlimited rights equal to those
--     held by the ACAA. 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.Slice raises Index_Error if
--    High > Length (Source) or Low > Length (Source) + 1.
--    (Defect Report 8652/0049).
--
--    Check that Ada.Strings.Wide_Bounded.Slice raises Index_Error if
--    High > Length (Source) or Low > Length (Source) + 1.
--
-- CHANGE HISTORY:
--    12 FEB 2001   PHL   Initial version
--    14 MAR 2001   RLB   Added Wide_Bounded subtest.
--
--!
with Ada.Exceptions;
use Ada.Exceptions;
with Ada.Strings.Bounded;
with Ada.Strings.Wide_Bounded;
use Ada.Strings;
with Report;
use Report;
procedure CXA4034 is

    package Bs is new Ada.Strings.Bounded.Generic_Bounded_Length (40);

    package WBs is new Ada.Strings.Wide_Bounded.Generic_Bounded_Length (32);

    Source : String (Ident_Int (1) .. Ident_Int (30));

    Wide_Source : Wide_String (Ident_Int (1) .. Ident_Int (24));

    X : Bs.Bounded_String;

    WX : WBs.Bounded_Wide_String;

begin
    Test ("CXA4034",
          "Check that Slice raises Index_Error if either Low or High is " &
             "greater than the Length(Source) for Ada.Strings.Bounded and " &
             "Ada.Strings.Wide_Bounded");

    -- Fill Source with "ABC..."
    for I in Source'Range loop
        Source (I) := Ident_Char (Character'Val (I +
                        Character'Pos ('A') - Source'First));
    end loop;
    -- and W with "ABC..."
    for I in Wide_Source'Range loop
        Wide_Source (I) := Ident_Wide_Char (Wide_Character'Val (I +
                         Wide_Character'Pos ('A') - Wide_Source'First));
    end loop;

    X := Bs.To_Bounded_String (Source);

    begin
        declare
            S : constant String :=
               Bs.Slice (X, Low => Ident_Int (28), High => Ident_Int (41));
        begin
            Failed ("No exception raised by Slice - 1");
            if S = Source then
                Comment ("Don't optimize S");
            end if;
        end;
    exception
        when Index_Error =>
            null; -- Expected exception.
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 1");
    end;

    begin
        declare
            S : constant String :=
               Bs.Slice (X, Low => Ident_Int (8), High => Ident_Int (31));
        begin
            Failed ("No exception raised by Slice - 2");
            if S = Source then
                Comment ("Don't optimize S");
            end if;
        end;
    exception
        when Index_Error =>
            null; -- Expected exception.
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 2");
    end;

    begin
        declare
            S : constant String :=
               Bs.Slice (X, Low => Ident_Int (15), High => Ident_Int (30));
        begin
            if S /= Source(15..30) then
                Failed ("Wrong result - 3");
            end if;
        end;
    exception
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 3");
    end;

    begin
        declare
            S : constant String :=
               Bs.Slice (X, Low => Ident_Int (42), High => Ident_Int (28));
        begin
            Failed ("No exception raised by Slice - 4");
            if S = Source then
                Comment ("Don't optimize S");
            end if;
        end;
    exception
        when Index_Error =>
            null; -- Expected exception.
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 4");
    end;

    begin
        declare
            S : constant String :=
               Bs.Slice (X, Low => Ident_Int (31), High => Ident_Int (28));
        begin
            if S /= "" then
                Failed ("Wrong result - 5");
            end if;
        end;
    exception
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 5");
    end;

    begin
        declare
            S : constant String :=
               Bs.Slice (X, Low => Ident_Int (30), High => Ident_Int (30));
        begin
            if S /= Source(30..30) then
                Failed ("Wrong result - 6");
            end if;
        end;
    exception
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 6");
    end;

    WX := WBs.To_Bounded_Wide_String (Wide_Source);

    begin
        declare
            W : constant Wide_String :=
               WBs.Slice (WX, Low => Ident_Int (21), High => Ident_Int (33));
        begin
            Failed ("No exception raised by Slice - 7");
            if W = Wide_Source then
                Comment ("Don't optimize W");
            end if;
        end;
    exception
        when Index_Error =>
            null; -- Expected exception.
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 7");
    end;

    begin
        declare
            W : constant Wide_String :=
               WBs.Slice (WX, Low => Ident_Int (8), High => Ident_Int (25));
        begin
            Failed ("No exception raised by Slice - 8");
            if W = Wide_Source then
                Comment ("Don't optimize W");
            end if;
        end;
    exception
        when Index_Error =>
            null; -- Expected exception.
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 8");
    end;

    begin
        declare
            W : constant Wide_String :=
               WBs.Slice (WX, Low => Ident_Int (15), High => Ident_Int (24));
        begin
            if W /= Wide_Source(15..24) then
                Failed ("Wrong result - 8");
            end if;
        end;
    exception
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 9");
    end;

    begin
        declare
            W : constant Wide_String :=
               WBs.Slice (WX, Low => Ident_Int (36), High => Ident_Int (20));
        begin
            Failed ("No exception raised by Slice - 10");
            if W = Wide_Source then
                Comment ("Don't optimize W");
            end if;
        end;
    exception
        when Index_Error =>
            null; -- Expected exception.
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 10");
    end;

    begin
        declare
            W : constant Wide_String :=
               WBs.Slice (WX, Low => Ident_Int (25), High => Ident_Int (21));
        begin
            if W /= "" then
                Failed ("Wrong result - 11");
            end if;
        end;
    exception
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 11");
    end;

    begin
        declare
            W : constant Wide_String :=
               WBs.Slice (WX, Low => Ident_Int (24), High => Ident_Int (24));
        begin
            if W /= Wide_Source(24..24) then
                Failed ("Wrong result - 12");
            end if;
        end;
    exception
        when E: others =>
            Failed ("Exception raised - " & Exception_Name (E) &
                    " - " & Exception_Message (E) & " - 12");
    end;

    Result;
end CXA4034;