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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 294 jeremybenn
-- CXA4006.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 Ada.Strings.Bounded are
28
--      available, and that they produce correct results. Specifically, check
29
--      the subprograms Length, Slice, "&", To_Bounded_String, Append, Index,
30
--      To_String, Replace_Slice, Trim, Overwrite, Delete, Insert, and
31
--      Translate.
32
--
33
-- TEST DESCRIPTION:
34
--      This test demonstrates the uses of a variety of the string functions
35
--      found in the package Ada.Strings.Bounded, simulating the operations
36
--      found in a text processing package.
37
--      With bounded strings, the length of each "line" of text can vary up
38
--      to the instantiated maximum, allowing one to view a page of text as
39
--      a series of expandable lines.  This provides flexibility in text
40
--      formatting of individual lines (strings).
41
--      Several subprograms are defined, all of which attempt to take advantage
42
--      of as many different bounded string utilities as possible.  Often,
43
--      an operation that is being performed in a subprogram using a certain
44
--      bounded string utility could more efficiently be performed using a
45
--      a different utility.  However, in the interest of including as broad
46
--      coverage as possible, a mixture of utilities is invoked in this test.
47
--      A simulated page of text is provided as a parameter to the test
48
--      defined subprograms, and the appropriate processing performed.  The
49
--      processed page of text is then compared to a predefined "finished"
50
--      page, and test passage/failure is based on the results of this
51
--      comparison.
52
--
53
--
54
-- CHANGE HISTORY:
55
--      06 Dec 94   SAIC    ACVC 2.0
56
--
57
--!
58
 
59
with Ada.Strings;
60
with Ada.Strings.Bounded;
61
with Ada.Strings.Maps;
62
with Report;
63
 
64
procedure CXA4006 is
65
 
66
begin
67
 
68
   Report.Test ("CXA4006", "Check that the subprograms defined in package "  &
69
                           "Ada.Strings.Bounded are available, and that "    &
70
                           "they produce correct results");
71
 
72
   Test_Block:
73
   declare
74
 
75
      Characters_Per_Line : constant Positive := 40;
76
      Lines_Per_Page      : constant Natural  :=  4;
77
 
78
      package BS_40 is new
79
        Ada.Strings.Bounded.Generic_Bounded_Length(Characters_Per_Line);
80
      use type BS_40.Bounded_String;
81
 
82
      type Page_Type is array (1..Lines_Per_Page) of BS_40.Bounded_String;
83
 
84
      -- Note: Misspellings below are intentional.
85
 
86
      Line1 : BS_40.Bounded_String :=
87
        BS_40.To_Bounded_String("ada is a progrraming language designed");
88
      Line2 : BS_40.Bounded_String :=
89
        BS_40.To_Bounded_String("to support the construction of long-");
90
      Line3 : BS_40.Bounded_String :=
91
        BS_40.To_Bounded_String("lived, highly reliabel software ");
92
      Line4 : BS_40.Bounded_String :=
93
        BS_40.To_Bounded_String("systems");
94
 
95
      Page  : Page_Type := (1 => Line1, 2 => Line2, 3 => Line3, 4 => Line4);
96
 
97
      Finished_Page : Page_Type :=
98
        (BS_40.To_Bounded_String("Ada is a programming language designed"),
99
         BS_40.To_Bounded_String("to support the construction of long-"),
100
         BS_40.To_Bounded_String("lived, HIGHLY RELIABLE software systems."),
101
         BS_40.To_Bounded_String(""));
102
 
103
      ---
104
 
105
      procedure Compress (Page : in out Page_Type) is
106
         Clear_Line : Natural := Lines_Per_Page;
107
      begin
108
         -- If two consecutive lines on the page are together less than the
109
         -- maximum line length, then append those two lines, move up all
110
         -- lower lines on the page, and blank out the last line.
111
         for i in 1..Lines_Per_Page - 1 loop
112
            if BS_40.Length(Page(i)) + BS_40.Length(Page(i+1)) <=
113
               BS_40.Max_Length
114
            then
115
               Page(i) := BS_40."&"(Page(i),
116
                                    Page(i+1));       -- "&" (bounded, bounded)
117
 
118
               for j in i+1..Lines_Per_Page - 1 loop
119
                  Page(j) :=
120
                    BS_40.To_Bounded_String
121
                      (BS_40.Slice(Page(j+1),
122
                                   1,
123
                                   BS_40.Length(Page(j+1))));
124
                  Clear_Line := j + 1;
125
               end loop;
126
               Page(Clear_Line) := BS_40.Null_Bounded_String;
127
            end if;
128
         end loop;
129
      end Compress;
130
 
131
      ---
132
 
133
      procedure Format (Page : in out Page_Type) is
134
         Sm_Ada   : BS_40.Bounded_String := BS_40.To_Bounded_String("ada");
135
         Cap_Ada  : constant String      := "Ada";
136
         Char_Pos : Natural := 0;
137
         Finished : Boolean := False;
138
         Line     : Natural := Page_Type'Last;
139
      begin
140
 
141
         -- Add a period to the end of the last line.
142
         while Line >= Page_Type'First and not Finished loop
143
            if Page(Line) /= BS_40.Null_Bounded_String      and
144
               BS_40.Length(Page(Line)) <= BS_40.Max_Length
145
            then
146
               Page(Line) := BS_40.Append(Page(Line), '.');
147
               Finished := True;
148
            end if;
149
            Line := Line - 1;
150
         end loop;
151
 
152
         -- Replace all occurrences of "ada" with "Ada".
153
         for Line in Page_Type'First .. Page_Type'Last loop
154
            Finished := False;
155
            while not Finished loop
156
               Char_Pos := BS_40.Index(Source  => Page(Line),
157
                                       Pattern => BS_40.To_String(Sm_Ada),
158
                                       Going   => Ada.Strings.Backward);
159
               -- A zero is returned by function Index if no occurrences of
160
               -- the pattern string are found.
161
               Finished := (Char_Pos = 0);
162
               if not Finished then
163
                  BS_40.Replace_Slice
164
                    (Source => Page(Line),
165
                     Low    => Char_Pos,
166
                     High   => Char_Pos + BS_40.Length(Sm_Ada) - 1,
167
                     By     => Cap_Ada);
168
               end if;
169
            end loop;   -- while loop
170
         end loop;      -- for loop
171
 
172
      end Format;
173
 
174
      ---
175
 
176
      procedure Spell_Check (Page : in out Page_Type) is
177
         type Spelling_Type is (Incorrect, Correct);
178
         type Word_Array_Type is array (Spelling_Type)
179
           of BS_40.Bounded_String;
180
         type Dictionary_Type is array (1..2) of Word_Array_Type;
181
 
182
         -- Note that the "words" in the dictionary will require various
183
         -- amounts of Trimming prior to their use in the string functions.
184
         Dictionary : Dictionary_Type :=
185
                      (1 => (BS_40.To_Bounded_String("  reliabel          "),
186
                             BS_40.To_Bounded_String("       reliable   ")),
187
                       2 => (BS_40.To_Bounded_String("  progrraming  "),
188
                             BS_40.To_Bounded_String(" programming ")));
189
 
190
         Pos      : Natural := Natural'First;
191
         Finished : Boolean := False;
192
 
193
      begin
194
 
195
         for Line in Page_Type'Range loop
196
 
197
            -- Search for the first incorrectly spelled word in the Dictionary,
198
            -- if it is found, replace it with the correctly spelled word,
199
            -- using the Overwrite function.
200
 
201
            while not Finished loop
202
               Pos :=
203
                 BS_40.Index(Page(Line),
204
                             BS_40.To_String(
205
                               BS_40.Trim(Dictionary(1)(Incorrect),
206
                                          Ada.Strings.Both)),
207
                             Ada.Strings.Forward);
208
               Finished := (Pos = 0);
209
               if not Finished then
210
                  Page(Line) :=
211
                    BS_40.Overwrite(Page(Line),
212
                                    Pos,
213
                                    BS_40.To_String
214
                                      (BS_40.Trim(Dictionary(1)(Correct),
215
                                                  Ada.Strings.Both)));
216
               end if;
217
            end loop;
218
 
219
            Finished := False;
220
 
221
            -- Search for the second incorrectly spelled word in the
222
            -- Dictionary, if it is found, replace it with the correctly
223
            -- spelled word, using the Delete procedure and Insert function.
224
 
225
            while not Finished loop
226
               Pos :=
227
                 BS_40.Index(Page(Line),
228
                             BS_40.To_String(
229
                               BS_40.Trim(Dictionary(2)(Incorrect),
230
                                          Ada.Strings.Both)),
231
                             Ada.Strings.Forward);
232
 
233
               Finished := (Pos = 0);
234
 
235
               if not Finished then
236
                  BS_40.Delete
237
                    (Page(Line),
238
                     Pos,
239
                     Pos + BS_40.To_String
240
                             (BS_40.Trim(Dictionary(2)(Incorrect),
241
                                         Ada.Strings.Both))'Length-1);
242
                  Page(Line) :=
243
                    BS_40.Insert(Page(Line),
244
                                 Pos,
245
                                 BS_40.To_String
246
                                      (BS_40.Trim(Dictionary(2)(Correct),
247
                                                  Ada.Strings.Both)));
248
               end if;
249
            end loop;
250
 
251
            Finished := False;
252
 
253
         end loop;
254
      end Spell_Check;
255
 
256
      ---
257
 
258
      procedure Bold (Page : in out Page_Type) is
259
         Key_Word     : constant String := "highly reliable";
260
         Bold_Mapping : constant Ada.Strings.Maps.Character_Mapping :=
261
           Ada.Strings.Maps.To_Mapping(From => " abcdefghijklmnopqrstuvwxyz",
262
                                       To   => " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
263
         Pos      : Natural := Natural'First;
264
         Finished : Boolean := False;
265
      begin
266
         -- This procedure is designed to change the case of the phrase
267
         -- "highly reliable" into upper case (a type of "Bolding").
268
         -- All instances of the phrase on all lines of the page will be
269
         -- modified.
270
 
271
         for Line in Page_Type'First .. Page_Type'Last loop
272
            while not Finished loop
273
               Pos := BS_40.Index(Page(Line), Key_Word);
274
               Finished := (Pos = 0);
275
               if not Finished then
276
 
277
                  BS_40.Overwrite
278
                         (Page(Line),
279
                          Pos,
280
                          BS_40.To_String
281
                            (BS_40.Translate
282
                               (BS_40.To_Bounded_String
283
                                   (BS_40.Slice(Page(Line),
284
                                                Pos,
285
                                                Pos + Key_Word'Length - 1)),
286
                                Bold_Mapping)));
287
 
288
               end if;
289
            end loop;
290
            Finished := False;
291
         end loop;
292
      end Bold;
293
 
294
 
295
   begin
296
 
297
      Compress(Page);
298
      Format(Page);
299
      Spell_Check(Page);
300
      Bold(Page);
301
 
302
      for i in 1..Lines_Per_Page loop
303
         if BS_40.To_String(Page(i)) /= BS_40.To_String(Finished_Page(i)) or
304
            BS_40.Length(Page(i))    /= BS_40.Length(Finished_Page(i))
305
         then
306
            Report.Failed("Incorrect modification of Page, Line " &
307
                           Integer'Image(i));
308
         end if;
309
      end loop;
310
 
311
 
312
   exception
313
      when others => Report.Failed ("Exception raised in Test_Block");
314
   end Test_Block;
315
 
316
 
317
   Report.Result;
318
 
319
end CXA4006;

powered by: WebSVN 2.1.0

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