OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [cxb/] [cxb3010.a] - Blame information for rev 294

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 294 jeremybenn
-- CXB3010.A
2
--
3
--                             Grant of Unlimited Rights
4
--
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
14
--     to do so.
15
--
16
--                                    DISCLAIMER
17
--
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.
24
--*
25
--
26
-- OBJECTIVE:
27
--      Check that the Procedure Free resets the parameter Item to
28
--      Null_Ptr.  Check that Free has no effect if Item is Null_Ptr.
29
--
30
--      Check that the version of Function Value with a chars_ptr parameter
31
--      returning a char_array result returns the prefix of an array of
32
--      chars.
33
--
34
--      Check that the version of Function Value with a chars_ptr parameter
35
--      and a size_t parameter returning a char_array result returns
36
--      the shorter of:
37
--        1) the first size_t number of characters, or
38
--        2) the characters up to and including the first nul.
39
--
40
--      Check that both of the above versions of Function Value propagate
41
--      Dereference_Error if the Item parameter is Null_Ptr.
42
--
43
-- TEST DESCRIPTION:
44
--      This test validates the Procedure Free and two versions of Function
45
--      Value.  A variety of char_array and char_ptr values are provided as
46
--      input, and results are compared for both length and content.
47
--
48
--      This test assumes that the following characters are all included
49
--      in the implementation defined type Interfaces.C.char:
50
--      ' ', 'a'..'z', and 'A'..'Z'.
51
--
52
-- APPLICABILITY CRITERIA:
53
--      This test is applicable to all implementations that provide
54
--      package Interfaces.C.Strings.  If an implementation provides
55
--      package Interfaces.C.Strings, this test must compile, execute,
56
--      and report "PASSED".
57
--
58
--
59
-- CHANGE HISTORY:
60
--      27 Sep 95   SAIC    Initial prerelease version.
61
--      13 May 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
62
--      26 Oct 96   SAIC    Incorporated reviewer comments.
63
--      01 DEC 97   EDS     Replicate line 199 at line 256, to ensure that
64
--                          TC_chars_ptr has a valid pointer.
65
--      08 JUL 99   RLB     Added a test case to check that Value raises
66
--                          Constraint_Error when Length = 0. (From Technical
67
--                          Corrigendum 1).
68
--      25 JAN 01   RLB     Repaired previous test case to avoid raising
69
--                          Constraint_Error in test case code.
70
--      26 JAN 01   RLB     Added an Ident_Int to the test case to prevent
71
--                          optimization.
72
 
73
--!
74
 
75
with Report;
76
with Interfaces.C.Strings;                                    -- N/A => ERROR
77
 
78
procedure CXB3010 is
79
begin
80
 
81
   Report.Test ("CXB3010", "Check that Procedure Free and versions of " &
82
                           "Function Value produce correct results");
83
 
84
   Test_Block:
85
   declare
86
 
87
      package IC  renames Interfaces.C;
88
      package ICS renames Interfaces.C.Strings;
89
 
90
      use type IC.char_array;
91
      use type IC.size_t;
92
      use type ICS.chars_ptr;
93
      use type IC.char;
94
 
95
      Null_Char_Array_Access : constant ICS.char_array_access := null;
96
 
97
      TC_String_1            : constant String       := "Nonul";
98
      TC_String_2            : constant String       := "AbCdE";
99
      TC_Blank_String        : constant String(1..5) := (others => ' ');
100
 
101
      -- The initialization of the following char_array objects
102
      -- includes the appending of a terminating nul char, in order to
103
      -- prevent the erroneous execution of Function Value.
104
 
105
      TC_char_array          : IC.char_array :=
106
                                 IC.To_C(TC_Blank_String, True);
107
      TC_char_array_1        : constant IC.char_array :=
108
                                          IC.To_C(TC_String_1, True);
109
      TC_char_array_2        : constant IC.char_array :=
110
                                          IC.To_C(TC_String_2, True);
111
      TC_Blank_char_array    : constant IC.char_array :=
112
                                          IC.To_C(TC_Blank_String, True);
113
 
114
      -- This chars_ptr is initialized via the use of New_Chars_Array to
115
      -- avoid erroneous execution of procedure Free.
116
      TC_chars_ptr           : ICS.chars_ptr :=
117
                                 ICS.New_Char_Array(TC_Blank_char_array);
118
 
119
   begin
120
 
121
      -- Check that the Procedure Free resets the parameter Item
122
      -- to Null_Ptr.
123
 
124
      if TC_chars_ptr = ICS.Null_Ptr then
125
         Report.Failed("TC_chars_ptr is currently null; it should not be " &
126
                       "null since it was given default initialization");
127
      end if;
128
 
129
      ICS.Free(TC_chars_ptr);
130
 
131
      if TC_chars_ptr /= ICS.Null_Ptr then
132
         Report.Failed("TC_chars_ptr was not set to Null_Ptr by " &
133
                       "Procedure Free");
134
      end if;
135
 
136
      -- Check that Free has no effect if Item is Null_Ptr.
137
 
138
      begin
139
         TC_chars_ptr := ICS.Null_Ptr;  -- Ensure pointer is null.
140
         ICS.Free(TC_chars_ptr);
141
         if TC_chars_ptr /= ICS.Null_Ptr then
142
            Report.Failed("TC_chars_ptr was set to a non-Null_Ptr value "  &
143
                          "by Procedure Free.  It was provided as a null " &
144
                          "parameter to Free, and there should have been " &
145
                          "no effect from a call to Procedure Free");
146
         end if;
147
      exception
148
         when others =>
149
           Report.Failed("Unexpected exception raised by Procedure Free " &
150
                         "when parameter Item is Null_Ptr");
151
      end;
152
 
153
 
154
      -- Check that the version of Function Value with a chars_ptr parameter
155
      -- that returns a char_array result returns an array of chars (up to
156
      -- and including the first nul).
157
 
158
      TC_chars_ptr  := ICS.New_Char_Array(TC_char_array_1);
159
      TC_char_array := ICS.Value(Item => TC_chars_ptr);
160
 
161
      if TC_char_array                  /= TC_char_array_1            or
162
         IC.To_Ada(TC_char_array, True) /= IC.To_Ada(TC_char_array_1)
163
      then
164
         Report.Failed("Incorrect result from Function Value - 1");
165
      end if;
166
 
167
      TC_chars_ptr  := ICS.New_Char_Array(TC_char_array_2);
168
      TC_char_array := ICS.Value(Item => TC_chars_ptr);
169
 
170
      if TC_char_array                  /= TC_char_array_2            or
171
         IC.To_Ada(TC_char_array, True) /= IC.To_Ada(TC_char_array_2)
172
      then
173
         Report.Failed("Incorrect result from Function Value - 2");
174
      end if;
175
 
176
      if ICS.Value(Item => ICS.New_String("A little longer string")) /=
177
         IC.To_C("A little longer string")
178
      then
179
         Report.Failed("Incorrect result from Function Value - 3");
180
      end if;
181
 
182
 
183
      -- Check that the version of Function Value with a chars_ptr parameter
184
      -- and a size_t parameter that returns a char_array result returns
185
      -- the shorter of:
186
      --   1) the first size_t number of characters, or
187
      --   2) the characters up to and including the first nul.
188
 
189
      -- Case 1: the first size_t number of characters (less than the
190
      --         total length).
191
 
192
      begin
193
         TC_chars_ptr        := ICS.New_Char_Array(TC_char_array_1);
194
         TC_char_array(0..2) := ICS.Value(Item => TC_chars_ptr, Length => 3);
195
 
196
         if TC_char_array(0..2) /= TC_char_array_1(0..2)
197
         then
198
            Report.Failed
199
              ("Incorrect result from Function Value with Length " &
200
               "parameter - 1");
201
         end if;
202
      exception
203
         when others =>
204
           Report.Failed("Exception raised during Case 1 evaluation");
205
      end;
206
 
207
      -- Case 2: the characters up to and including the first nul.
208
 
209
      TC_chars_ptr  := ICS.New_Char_Array(TC_char_array_2);
210
 
211
      -- The length supplied as a parameter exceeds the total length of
212
      -- TC_char_array_2.  The result should be the entire TC_char_array_2
213
      -- including the terminating nul.
214
 
215
      TC_char_array := ICS.Value(Item => TC_chars_ptr, Length => 7);
216
 
217
      if TC_char_array            /= TC_char_array_2            or
218
         IC.To_Ada(TC_char_array) /= IC.To_Ada(TC_char_array_2) or
219
         not (IC.Is_Nul_Terminated(TC_char_array))
220
      then
221
         Report.Failed("Incorrect result from Function Value with Length " &
222
                       "parameter - 2");
223
      end if;
224
 
225
 
226
      -- Check that both of the above versions of Function Value propagate
227
      -- Dereference_Error if the Item parameter is Null_Ptr.
228
 
229
      declare
230
 
231
         -- Declare a dummy function to demonstrate one way that a chars_ptr
232
         -- variable could inadvertantly be set to Null_Ptr prior to a call
233
         -- to Value (below).
234
         function Freedom (Condition : Boolean := False;
235
                           Ptr       : ICS.chars_ptr) return ICS.chars_ptr is
236
            Pointer : ICS.chars_ptr := Ptr;
237
         begin
238
            if Condition then
239
               ICS.Free(Pointer);
240
            else
241
               null; -- An activity that doesn't set the chars_ptr value to
242
                     -- Null_Ptr.
243
            end if;
244
            return Pointer;
245
         end Freedom;
246
 
247
      begin
248
 
249
         begin
250
            TC_char_array := ICS.Value(Item => Freedom(True, TC_chars_ptr));
251
            Report.Failed
252
              ("Function Value (without Length parameter) did not " &
253
               "raise Dereference_Error when provided a null Item " &
254
               "parameter input value");
255
            if TC_char_array(0) = '6' then   -- Defeat optimization.
256
               Report.Comment("Should never be printed");
257
            end if;
258
         exception
259
            when ICS.Dereference_Error => null;  -- OK, expected exception.
260
            when others                =>
261
              Report.Failed("Incorrect exception raised by Function Value " &
262
                            "with Item parameter, when the Item parameter " &
263
                            "is Null_Ptr");
264
         end;
265
 
266
         TC_chars_ptr  := ICS.New_Char_Array(TC_char_array_2);
267
         begin
268
            TC_char_array := ICS.Value(Item   => Freedom(True, TC_chars_ptr),
269
                                       Length => 4);
270
            Report.Failed
271
              ("Function Value (with Length parameter) did not "    &
272
               "raise Dereference_Error when provided a null Item " &
273
               "parameter input value");
274
            if TC_char_array(0) = '6' then   -- Defeat optimization.
275
               Report.Comment("Should never be printed");
276
            end if;
277
         exception
278
            when ICS.Dereference_Error => null;  -- OK, expected exception.
279
            when others                =>
280
              Report.Failed("Incorrect exception raised by Function Value " &
281
                            "with both Item and Length parameters, when "   &
282
                            "the Item parameter is Null_Ptr");
283
         end;
284
      end;
285
 
286
      -- Check that Function Value with two parameters propagates
287
      -- Constraint_Error if Length is 0.
288
 
289
      begin
290
         TC_chars_ptr        := ICS.New_Char_Array(TC_char_array_1);
291
         declare
292
            TC : IC.char_array := ICS.Value(Item => TC_chars_ptr, Length =>
293
                IC.Size_T(Report.Ident_Int(0)));
294
         begin
295
             Report.Failed
296
                 ("Function Value (with Length parameter) did not "    &
297
                  "raise Constraint_Error when Length = 0");
298
             if TC'Length <= TC_char_array'Length then
299
                TC_char_array(1..TC'Length) := TC; -- Block optimization of TC.
300
             end if;
301
         end;
302
 
303
         Report.Failed
304
              ("Function Value (with Length parameter) did not "    &
305
               "raise Constraint_Error when Length = 0");
306
      exception
307
         when Constraint_Error => null;  -- OK, expected exception.
308
         when others =>
309
            Report.Failed("Incorrect exception raised by Function Value " &
310
                          "with both Item and Length parameters, when "   &
311
                          "Length = 0");
312
      end;
313
 
314
   exception
315
      when others => Report.Failed ("Exception raised in Test_Block");
316
   end Test_Block;
317
 
318
   Report.Result;
319
 
320
end CXB3010;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.