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/] [cxa/] [cxa4021.a] - Blame information for rev 294

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 294 jeremybenn
-- CXA4021.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 subprograms defined in package
28
--      Ada.Strings.Wide_Unbounded are available, and that they produce
29
--      correct results. Specifically, check the subprograms Head, Index,
30
--      Index_Non_Blank, Insert, Length, Overwrite, Replace_Slice, Slice,
31
--      Tail, To_Wide_String, To_Unbounded_Wide_String, "*", "&",
32
--      and "=", "<=", ">=".
33
--
34
-- TEST DESCRIPTION:
35
--      This test demonstrates the uses of many of the subprograms defined
36
--      in package Ada.Strings.Wide_Unbounded for use with unbounded wide
37
--      strings.
38
--      The test attempts to simulate how unbounded wide strings could be used
39
--      to simulate paragraphs of text.  Modifications could be easily be
40
--      performed using the provided subprograms (although in this test, the
41
--      main modification performed was the addition of more text to the
42
--      string).  One would not have to worry about the formatting of the
43
--      paragraph until it was finished and correct in content.  Then, once
44
--      all required editing is complete, the unbounded strings can be divided
45
--      up into the appropriate lengths based on particular formatting
46
--      requirements.  The test then compares the formatted text product
47
--      with a predefined "finished product".
48
--
49
--      This test attempts to use a large number of the subprograms provided
50
--      by package Ada.Strings.Wide_Unbounded.  Often, the processing involved
51
--      could have been performed more efficiently using a minimum number
52
--      of the subprograms, in conjunction with loops, etc.  However, for
53
--      testing purposes, and in the interest of minimizing the number of
54
--      tests developed, subprogram variety and feature mixing was stressed.
55
--
56
--
57
-- CHANGE HISTORY:
58
--      06 Dec 94   SAIC    ACVC 2.0
59
--
60
--!
61
 
62
with Report;
63
with Ada.Characters.Handling;
64
with Ada.Strings.Wide_Maps;
65
with Ada.Strings.Wide_Unbounded;
66
 
67
procedure CXA4021 is
68
 
69
   -- The following two functions are used to translate character and string
70
   -- values to "Wide" values.  They will be applied to all the Wide_Bounded
71
   -- subprogram character and string parameters to simulate the use of non-
72
   -- character Wide_Characters and Wide_Strings in actual practice.
73
   -- Note: These functions do not actually return "equivalent" wide
74
   --       characters to their character inputs, just "non-character"
75
   --       wide characters.
76
 
77
   function Equiv (Ch : Character) return Wide_Character is
78
      C : Character := Ch;
79
   begin
80
      if Ch = ' ' then
81
         return Ada.Characters.Handling.To_Wide_Character(C);
82
      else
83
         return Wide_Character'Val(Character'Pos(Ch) +
84
                Character'Pos(Character'Last) + 1);
85
      end if;
86
   end Equiv;
87
 
88
 
89
   function Equiv (Str : String) return Wide_String is
90
      WS : Wide_String(Str'First..Str'Last);
91
   begin
92
      for i in Str'First..Str'Last loop
93
         WS(i) := Equiv(Str(i));
94
      end loop;
95
      return WS;
96
   end Equiv;
97
 
98
begin
99
 
100
   Report.Test ("CXA4021", "Check that the subprograms defined in "     &
101
                           "package Ada.Strings.Wide_Unbounded are "    &
102
                           "available, and that they produce correct "  &
103
                           "results");
104
 
105
   Test_Block:
106
   declare
107
 
108
      package ASW renames Ada.Strings.Wide_Unbounded;
109
      use type ASW.Unbounded_Wide_String;
110
      use Ada.Strings;
111
 
112
      Pamphlet_Paragraph_Count : constant :=  2;
113
      Lines                    : constant :=  4;
114
      Line_Length              : constant := 40;
115
 
116
      type Document_Type is array (Positive range <>)
117
        of ASW.Unbounded_Wide_String;
118
 
119
      type Camera_Ready_Copy_Type is array (1..Lines)
120
        of Wide_String (1..Line_Length);
121
 
122
      Pamphlet            : Document_Type (1..Pamphlet_Paragraph_Count);
123
 
124
      Camera_Ready_Copy   : Camera_Ready_Copy_Type :=
125
                              (others => (others => Ada.Strings.Wide_Space));
126
 
127
      TC_Finished_Product : Camera_Ready_Copy_Type :=
128
                   ( 1 => Equiv("Ada is a programming language designed  "),
129
                     2 => Equiv("to support long-lived, reliable software"),
130
                     3 => Equiv(" systems.                               "),
131
                     4 => Equiv("Go with Ada!                            "));
132
 
133
      -----
134
 
135
 
136
      procedure Enter_Text_Into_Document (Document : in out Document_Type) is
137
      begin
138
 
139
         -- Fill in both "paragraphs" of the document.  Each unbounded wide
140
         -- string functions as an individual paragraph, containing an
141
         -- unspecified number of characters.
142
         -- Use a variety of different unbounded wide string subprograms to
143
         -- load the data.
144
 
145
         Document(1) :=
146
           ASW.To_Unbounded_Wide_String(Equiv("Ada is a language"));
147
 
148
         -- Insert the word "programming" prior to "language".
149
         Document(1) :=
150
           ASW.Insert(Document(1),
151
                      ASW.Index(Document(1),
152
                                Equiv("language")),
153
                      ASW.To_Wide_String(Equiv("progra") &       -- Wd Str &
154
                                         ASW."*"(2,Equiv('m')) & -- Wd Unbd &
155
                                         Equiv("ing ")));        -- Wd Str
156
 
157
 
158
         -- Overwrite the word "language" with "language" + additional text.
159
         Document(1) :=
160
           ASW.Overwrite(Document(1),
161
                         ASW.Index(Document(1),
162
                                   ASW.To_Wide_String(
163
                                     ASW.Tail(Document(1), 8, Equiv(' '))),
164
                                   Ada.Strings.Backward),
165
                         Equiv("language designed to support long-lifed"));
166
 
167
 
168
         -- Replace the word "lifed" with "lived".
169
         Document(1) :=
170
           ASW.Replace_Slice(Document(1),
171
                             ASW.Index(Document(1), Equiv("lifed")),
172
                             ASW.Length(Document(1)),
173
                             Equiv("lived"));
174
 
175
 
176
         -- Overwrite the word "lived" with "lived" + additional text.
177
         Document(1) :=
178
           ASW.Overwrite(Document(1),
179
                         ASW.Index(Document(1),
180
                                   ASW.To_Wide_String
181
                                     (ASW.Tail(Document(1), 5, Equiv(' '))),
182
                                   Ada.Strings.Backward),
183
                         Equiv("lived, reliable software systems."));
184
 
185
 
186
         -- Use several of the overloaded versions of "&" to form this
187
         -- unbounded wide string.
188
 
189
         Document(2) := Equiv('G')                                  &
190
                        ASW.To_Unbounded_Wide_String(Equiv("o "))   &
191
                        ASW.To_Unbounded_Wide_String(Equiv("with")) &
192
                        Equiv(' ')                                  &
193
                        Equiv("Ada!");
194
 
195
      end Enter_Text_Into_Document;
196
 
197
 
198
      -----
199
 
200
 
201
      procedure Create_Camera_Ready_Copy
202
                  (Document    : in     Document_Type;
203
                   Camera_Copy :    out Camera_Ready_Copy_Type) is
204
      begin
205
         -- Break the unbounded wide strings into fixed lengths.
206
 
207
         -- Search the first unbounded wide string for portions of text that
208
         -- are less than or equal to the length of a wide string in the
209
         -- Camera_Ready_Copy_Type object.
210
 
211
         Camera_Copy(1) :=               -- Take characters 1-39,
212
           ASW.Slice(Document(1),        -- and append a blank space.
213
                     1,
214
                     ASW.Index(ASW.To_Unbounded_Wide_String
215
                                 (ASW.Slice(Document(1),
216
                                            1,
217
                                            Line_Length)),
218
                               Ada.Strings.Wide_Maps.To_Set(Equiv(' ')),
219
                               Ada.Strings.Inside,
220
                               Ada.Strings.Backward)) & Equiv(' ');
221
 
222
         Camera_Copy(2) :=                 -- Take characters 40-79.
223
           ASW.Slice(Document(1),
224
                     40,
225
                     (ASW.Index_Non_Blank              -- Should return 79
226
                        (ASW.To_Unbounded_Wide_String
227
                           (ASW.Slice(Document(1),     -- Slice (40..79)
228
                                      40,
229
                                      79)),
230
                         Ada.Strings.Backward) + 39)); -- Increment since
231
                                                       -- this slice starts
232
                                                       -- at 40.
233
 
234
         Camera_Copy(3)(1..9) := ASW.Slice(Document(1), -- Characters 80-88
235
                                           80,
236
                                           ASW.Length(Document(1)));
237
 
238
 
239
         -- Break the second unbounded wide string into the appropriate
240
         -- length.  It is only twelve characters in length, so the entire
241
         -- unbounded wide string will be placed on one string of the output
242
         -- object.
243
 
244
         Camera_Copy(4)(1..ASW.Length(Document(2))) :=
245
           ASW.To_Wide_String(ASW.Head(Document(2),
246
                                       ASW.Length(Document(2))));
247
 
248
      end Create_Camera_Ready_Copy;
249
 
250
 
251
      -----
252
 
253
 
254
      function Valid_Proofread (Draft, Master : Camera_Ready_Copy_Type)
255
        return Boolean is
256
      begin
257
 
258
         -- Evaluate wide strings for equality, using the operators defined
259
         -- in package Ada.Strings.Wide_Unbounded.  The less than/greater
260
         -- than or equal comparisons should evaluate to "equals => True".
261
 
262
         if ASW.To_Unbounded_Wide_String(Draft(1))   =     -- "="(WUnb,WUnb)
263
            ASW.To_Unbounded_Wide_String(Master(1))   and
264
            ASW.To_Unbounded_Wide_String(Draft(2))  <=     -- "<="(WUnb,WUnb)
265
            ASW.To_Unbounded_Wide_String(Master(2))   and
266
            ASW.To_Unbounded_Wide_String(Draft(3))  >=     -- ">="(WUnb,WUnb)
267
            ASW.To_Unbounded_Wide_String(Master(3))   and
268
            ASW.To_Unbounded_Wide_String(Draft(4))   =     -- "="(WUnb,WUnb)
269
            ASW.To_Unbounded_Wide_String(Master(4))
270
         then
271
            return True;
272
         else
273
            return False;
274
         end if;
275
 
276
      end Valid_Proofread;
277
 
278
 
279
      -----
280
 
281
 
282
   begin
283
 
284
      -- Enter text into the unbounded wide string paragraphs of the document.
285
 
286
      Enter_Text_Into_Document (Pamphlet);
287
 
288
 
289
      -- Reformat the unbounded wide strings into fixed wide string format.
290
 
291
      Create_Camera_Ready_Copy (Document    => Pamphlet,
292
                                Camera_Copy => Camera_Ready_Copy);
293
 
294
 
295
      -- Verify the conversion process.
296
 
297
      if not Valid_Proofread (Draft  => Camera_Ready_Copy,
298
                              Master => TC_Finished_Product)
299
      then
300
         Report.Failed ("Incorrect unbounded wide string processing result");
301
      end if;
302
 
303
 
304
   exception
305
      when others => Report.Failed ("Exception raised in Test_Block");
306
   end Test_Block;
307
 
308
 
309
   Report.Result;
310
 
311
end CXA4021;

powered by: WebSVN 2.1.0

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