aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxf/cxf3001.a
blob: 1b9abca153f820fac0831253c69bff71a8807c89 (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
-- CXF3001.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 edited output string value returned by Function Image
--      is correct.
--
-- TEST DESCRIPTION:
--      This test is structured using tables of data, consisting of
--      numerical values, picture strings, and expected image
--      result strings.  
--
--      Each picture string is checked for validity, and an invalid picture 
--      string will cause immediate test failure on its first pass through
--      the evaluation loop.  Inside the evaluation loop, each decimal data 
--      item is combined with each of the picture strings as parameters to a
--      call to Image, and the result of each call is compared to an 
--      expected edited output result string.
--      
--       
-- CHANGE HISTORY:
--      24 Feb 95   SAIC    Initial prerelease version.
--      23 Jun 95   SAIC    Corrected call to functions Valid and To_Picture.
--      22 Aug 95   SAIC    Test name changed to CXF3001 (from CXF3301) to
--                          conform to naming conventions.
--      24 Feb 97   CTA.PWB Corrected picture strings and expected results.
--!

with Ada.Text_IO.Editing;
with Report;

procedure CXF3001 is
begin

   Report.Test ("CXF3001", "Check that the string value returned by " &
                           "Function Image is correct");

   Test_Block:
   declare

      use Ada.Text_IO;

      Number_Of_Decimal_Items    : constant := 5;
      Number_Of_Picture_Strings  : constant := 4;
      Number_Of_Expected_Results : constant := Number_Of_Decimal_Items *
                                               Number_Of_Picture_Strings;

      type String_Pointer_Type is access String;

      -- Define a decimal data type, and instantiate the Decimal_Output 
      -- generic package for the data type.

      type Decimal_Data_Type is delta 0.01 digits 16;
      package Ed_Out is new Editing.Decimal_Output (Decimal_Data_Type);

      -- Define types for the arrays of data that will hold the decimal data 
      -- values, picture strings, and expected edited output results.

      type Decimal_Data_Array_Type is 
        array (Integer range <>) of Decimal_Data_Type;

      type Picture_String_Array_Type is 
        array (Integer range <>) of String_Pointer_Type;

      type Edited_Output_Results_Array_Type is 
        array (Integer range <>) of String_Pointer_Type;

      -- Define the data arrays for this test.

      Decimal_Data : 
        Decimal_Data_Array_Type(1..Number_Of_Decimal_Items) :=
          ( 1 =>  5678.90,
            2 => -6789.01,
            3 =>     0.00,
            4 =>     0.20,
            5 =>     3.45
          );

      Picture_Strings : 
        Picture_String_Array_Type(1..Number_Of_Picture_Strings) :=
          ( 1 => new String'("-$$_$$9.99"),
            2 => new String'("-$$_$$$.$$"),
            3 => new String'("-ZZZZ.ZZ"),
            4 => new String'("-$$$_999.99")
          );

      Edited_Output :
        Edited_Output_Results_Array_Type(1..Number_Of_Expected_Results) := 
          ( 1 => new String'(" $5,678.90"),    
            2 => new String'(" $5,678.90"),
            3 => new String'(" 5678.90"),     
            4 => new String'("  $5,678.90"),  

            5 => new String'("-$6,789.01"),
            6 => new String'("-$6,789.01"),
            7 => new String'("-6789.01"),
            8 => new String'("- $6,789.01"),

            9 => new String'("     $0.00"),
           10 => new String'("          "),    
           11 => new String'("        "),     
           12 => new String'("   $ 000.00"),  

           13 => new String'("     $0.20"),
           14 => new String'("      $.20"),    
           15 => new String'("     .20"),     
           16 => new String'("   $ 000.20"),

           17 => new String'("     $3.45"),
           18 => new String'("     $3.45"),
           19 => new String'("    3.45"),
           20 => new String'("   $ 003.45")
          );

      TC_Picture    : Editing.Picture;
      TC_Loop_Count : Natural := 0;

   begin

      -- Compare string result of Image with expected edited output string.  

      Evaluate_Edited_Output:
      for i in 1..Number_Of_Decimal_Items loop
         for j in 1..Number_Of_Picture_Strings loop

            TC_Loop_Count := TC_Loop_Count + 1;

            -- Check on the validity of the picture strings prior to
            -- processing.

            if Editing.Valid(Picture_Strings(j).all) then

               -- Create the picture object from the picture string.
               TC_Picture := Editing.To_Picture(Picture_Strings(j).all);

               -- Compare actual edited output result of Function Image with
               -- the expected result.

               if Ed_Out.Image(Decimal_Data(i), TC_Picture) /=
                  Edited_Output(TC_Loop_Count).all
               then
                  Report.Failed("Incorrect result from Function Image, " &
                                "when used with decimal data item # "    &
                                Integer'Image(i)                         &
                                " and picture string # "                  &
                                Integer'Image(j));
               end if;

            else
               Report.Failed("Picture String # " & Integer'Image(j) &
                             "reported as being invalid");
               -- Immediate test failure if a string is invalid.
               exit Evaluate_Edited_Output;
            end if;

         end loop;
      end loop Evaluate_Edited_Output;

   exception
      when Editing.Picture_Error =>
         Report.Failed ("Picture_Error raised in Test_Block");
      when Layout_Error          =>
         Report.Failed ("Layout_Error raised in Test_Block");
      when others                => 
         Report.Failed ("Exception raised in Test_Block");
   end Test_Block;

   Report.Result;

end CXF3001;