3 -- Grant of Unlimited Rights
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
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.
27 -- Check that statically identifiable picture strings can be used to
28 -- produce correctly formatted edited output.
31 -- This test defines several picture strings that are statically
32 -- identifiable, (i.e., Pic : Picture := To_Picture("..."); ).
33 -- These picture strings are used in conjunction with decimal data
34 -- as parameters in calls to functions Valid and Image. These
35 -- functions are created by an instantiation of the generic package
36 -- Ada.Text_IO.Editing.Decimal_Output.
40 -- 04 Apr 96 SAIC Initial release for 2.1.
41 -- 13 Feb 97 PWB.CTA corrected incorrect picture strings.
45 with Ada
.Text_IO
.Editing
;
51 Report
.Test
("CXF3003", "Check that statically identifiable " &
52 "picture strings can be used to produce " &
53 "correctly formatted edited output");
59 use Ada
.Text_IO
.Editing
;
61 Def_Cur
: constant String := "$";
62 Def_Fill
: constant Character := '*';
63 Def_Sep
: constant Character := Default_Separator
;
64 Def_Radix
: constant Character :=
65 Ada
.Text_IO
.Editing
.Default_Radix_Mark
;
67 type Str_Ptr
is access String;
68 type Edited_Output_Array_Type
is array (Integer range <>) of Str_Ptr
;
70 -- Define a decimal data type, and instantiate the Decimal_Output
71 -- generic package for the data type.
73 type Decimal_Data_Type
is delta 0.01 digits 16;
76 new Decimal_Output
(Num
=> Decimal_Data_Type
,
77 Default_Currency
=> Def_Cur
,
79 Default_Separator
=> Default_Separator
,
80 Default_Radix_Mark
=> Def_Radix
);
83 type Decimal_Data_Array_Type
is
84 array (Integer range <>) of Decimal_Data_Type
;
86 Decimal_Data
: Decimal_Data_Array_Type
(1..5) :=
93 -- Statically identifiable picture strings.
95 Picture_1
: Picture
:= To_Picture
("-$$_$$9.99");
96 Picture_2
: Picture
:= To_Picture
("-$$_$$$.$$");
97 Picture_3
: Picture
:= To_Picture
("-ZZZZ.ZZ");
98 Picture_5
: Picture
:= To_Picture
("-$$$_999.99");
99 Picture_6
: Picture
:= To_Picture
("-###**_***_**9.99");
100 Picture_7
: Picture
:= To_Picture
("-$**_***_**9.99");
101 Picture_8
: Picture
:= To_Picture
("-$$$$$$.$$");
102 Picture_9
: Picture
:= To_Picture
("-$$$$$$.$$");
103 Picture_10
: Picture
:= To_Picture
("+BBBZZ_ZZZ_ZZZ.ZZ");
104 Picture_11
: Picture
:= To_Picture
("--_---_---_--9");
105 Picture_12
: Picture
:= To_Picture
("-$_$$$_$$$_$$9.99");
106 Picture_14
: Picture
:= To_Picture
("$_$$9.99");
107 Picture_15
: Picture
:= To_Picture
("$$9.99");
110 Picture_1_Output
: Edited_Output_Array_Type
(1..5) :=
111 ( 1 => new String'(" $1,357.99"),
112 2 => new String'("-$9,029.01"),
113 3 => new String'(" $0.00"),
114 4 => new String'(" $0.20"),
115 5 => new String'(" $3.45"));
117 Picture_2_Output : Edited_Output_Array_Type(1..5) :=
118 (1 => new String'(" $1,357.99"),
119 2 => new String'("-$9,029.01"),
120 3 => new String'(" "),
121 4 => new String'(" $.20"),
122 5 => new String'(" $3.45"));
124 Picture_3_Output
: Edited_Output_Array_Type
(1..5) :=
125 (1 => new String'(" 1357.99"),
126 2 => new String'("-9029.01"),
127 3 => new String'(" "),
128 4 => new String'(" .20"),
129 5 => new String'(" 3.45"));
131 Picture_5_Output : Edited_Output_Array_Type(1..5) :=
132 (1 => new String'(" $1,357.99"),
133 2 => new String'("- $9,029.01"),
134 3 => new String'(" $ 000.00"),
135 4 => new String'(" $ 000.20"),
136 5 => new String'(" $ 003.45"));
140 -- Check the results of function Valid, using the first five decimal
141 -- data items and picture strings.
143 if not Image_IO
.Valid
(Decimal_Data
(1), Picture_1
) then
144 Report
.Failed
("Picture string 1 not valid");
145 elsif not Image_IO
.Valid
(Decimal_Data
(2), Picture_2
) then
146 Report
.Failed
("Picture string 2 not valid");
147 elsif not Image_IO
.Valid
(Decimal_Data
(3), Picture_3
) then
148 Report
.Failed
("Picture string 3 not valid");
149 elsif not Image_IO
.Valid
(Decimal_Data
(5), Picture_5
) then
150 Report
.Failed
("Picture string 5 not valid");
154 -- Check the results of function Image, using the picture strings
155 -- constructed above, with a variety of named vs. positional
156 -- parameter notation and defaulted parameters.
159 if Image_IO
.Image
(Item
=> Decimal_Data
(i
), Pic
=> Picture_1
) /=
160 Picture_1_Output
(i
).all
162 Report
.Failed
("Incorrect result from function Image with " &
163 "decimal data item #" & Integer'Image(i
) & ", " &
164 "combined with Picture_1 picture string." &
165 "Expected: " & Picture_1_Output
(i
).all & ", " &
167 Image_IO
.Image
(Decimal_Data
(i
),Picture_1
));
170 if Image_IO
.Image
(Decimal_Data
(i
), Pic
=> Picture_2
) /=
171 Picture_2_Output
(i
).all
173 Report
.Failed
("Incorrect result from function Image with " &
174 "decimal data item #" & Integer'Image(i
) & ", " &
175 "combined with Picture_2 picture string." &
176 "Expected: " & Picture_2_Output
(i
).all & ", " &
178 Image_IO
.Image
(Decimal_Data
(i
),Picture_2
));
181 if Image_IO
.Image
(Decimal_Data
(i
), Picture_3
) /=
182 Picture_3_Output
(i
).all
184 Report
.Failed
("Incorrect result from function Image with " &
185 "decimal data item #" & Integer'Image(i
) & ", " &
186 "combined with Picture_3 picture string." &
187 "Expected: " & Picture_3_Output
(i
).all & ", " &
189 Image_IO
.Image
(Decimal_Data
(i
),Picture_3
));
192 if Image_IO
.Image
(Decimal_Data
(i
), Picture_5
) /=
193 Picture_5_Output
(i
).all
195 Report
.Failed
("Incorrect result from function Image with " &
196 "decimal data item #" & Integer'Image(i
) & ", " &
197 "combined with Picture_5 picture string." &
198 "Expected: " & Picture_5_Output
(i
).all & ", " &
200 Image_IO
.Image
(Decimal_Data
(i
),Picture_5
));
205 if Image_IO
.Image
(Item
=> 123456.78,
209 Separator
=> Def_Sep
,
210 Radix_Mark
=> Def_Radix
) /= " $***123,456.78"
212 Report
.Failed
("Incorrect result from Fn. Image using Picture_6");
215 if Image_IO
.Image
(123456.78,
219 Separator
=> Def_Sep
,
220 Radix_Mark
=> Def_Radix
) /= " $***123,456.78"
222 Report
.Failed
("Incorrect result from Fn. Image using Picture_7");
225 if Image_IO
.Image
(0.0,
229 Separator
=> Def_Sep
,
230 Radix_Mark
=> Def_Radix
) /= " "
232 Report
.Failed
("Incorrect result from Fn. Image using Picture_8");
235 if Image_IO
.Image
(0.20,
239 Separator
=> Default_Separator
,
240 Radix_Mark
=> Default_Radix_Mark
) /= " $.20"
242 Report
.Failed
("Incorrect result from Fn. Image using Picture_9");
245 if Image_IO
.Image
(123456.00,
249 Separator
=> Def_Sep
,
250 Radix_Mark
=> Def_Radix
) /= "+ 123,456.00"
252 Report
.Failed
("Incorrect result from Fn. Image using Picture_10");
255 if Image_IO
.Image
(-123456.78,
260 Radix_Mark
=> Def_Radix
) /= " -123,457"
262 Report
.Failed
("Incorrect result from Fn. Image using Picture_11");
265 if Image_IO
.Image
(123456.78, Picture_12
, "$", '*', ',', '.') /=
268 Report
.Failed
("Incorrect result from Fn. Image using Picture_12");
271 if Image_IO
.Image
(1.23,
274 Fill
=> Def_Fill
) /= " $1.23"
276 Report
.Failed
("Incorrect result from Fn. Image using Picture_14");
279 if Image_IO
.Image
(12.34, Pic
=> Picture_15
) /= "$12.34"
281 Report
.Failed
("Incorrect result from Fn. Image using Picture_15");
285 when The_Error
: others =>
286 Report
.Failed
("The following exception was raised in the " &
287 "Test_Block: " & Exception_Name
(The_Error
));