1-- CXF3A08.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 version of Ada.Text_IO.Editing.Put with an out 28-- String parameter propagates Layout_Error if the edited output string 29-- result of Put exceeds the length of the out String parameter. 30-- 31-- TEST DESCRIPTION: 32-- This test is structured using tables of data, consisting of 33-- numerical values, picture strings, and expected image 34-- result strings. These data tables are found in package FXF3A00. 35-- 36-- This test examines the case of the out string parameter to Procedure 37-- Put being insufficiently long to hold the entire edited output 38-- string result of the procedure. In this case, Layout_Error is to be 39-- raised. Test failure results if Layout_Error is not raised, or if an 40-- exception other than Layout_Error is raised. 41-- 42-- A number of data combinations are examined, using instantiations 43-- of Package Decimal_Output with different decimal data types and 44-- both default and non-default parameters as generic actual parameters. 45-- In addition, calls to Procedure Put are performed using default 46-- parameters, non-default parameters, and non-default parameters that 47-- override the generic actual parameters provided at the time of 48-- instantiation of Decimal_Output. 49-- 50-- TEST FILES: 51-- The following files comprise this test: 52-- 53-- FXF3A00.A (foundation code) 54-- => CXF3A08.A 55-- 56-- 57-- CHANGE HISTORY: 58-- 31 JAN 95 SAIC Initial prerelease version. 59-- 60--! 61 62with FXF3A00; 63with Ada.Text_IO.Editing; 64with Report; 65 66procedure CXF3A08 is 67begin 68 69 Report.Test ("CXF3A08", "Check that the version of " & 70 "Ada.Text_IO.Editing.Put with an out " & 71 "String parameter propagates Layout_Error " & 72 "if the output string exceeds the length " & 73 "of the out String parameter"); 74 75 Test_Block: 76 declare 77 78 use Ada.Text_IO; 79 80 -- Instantiate the Decimal_Output generic package for two 81 -- different decimal data types. 82 -- Uses decimal type with delta 0.01 and 83 package Pack_2DP is -- non-default generic actual parameters. 84 new Editing.Decimal_Output(Num => FXF3A00.Decimal_Type_2DP, 85 Default_Currency => "$", 86 Default_Fill => '*', 87 Default_Separator => ',', 88 Default_Radix_Mark => '.'); 89 90 package Pack_NDP is -- Uses decimal type with delta 1.0. 91 new Editing.Decimal_Output(FXF3A00.Decimal_Type_NDP); 92 93 TC_Picture : Editing.Picture; 94 TC_Start_Loop : Integer := 0; 95 TC_End_Loop : Integer := 0; 96 TC_Offset : Integer := 0; 97 98 TC_Short_String : String(1..4); -- Shorter than the shortest edited 99 -- output string result. 100 101 begin 102 103 -- Examine cases where the out string parameter is shorter than 104 -- the length of the edited output result. Use the instantiation of 105 -- Decimal_Output specific to data with two decimal places. 106 107 TC_Start_Loop := 1; 108 TC_End_Loop := FXF3A00.Number_of_2DP_Items - -- 10 109 FXF3A00.Number_Of_Foreign_Strings; 110 111 for i in TC_Start_Loop..TC_End_Loop loop -- 1..10 112 113 -- Create the picture object from the picture string. 114 115 TC_Picture := 116 Editing.To_Picture(Pic_String => FXF3A00.Valid_Strings(i).all, 117 Blank_When_Zero => False); 118 119 -- The out parameter string provided in the call to Put is 120 -- shorter than the edited output result of the procedure. 121 -- This will result in a Layout_Error being raised and handled. 122 -- Test failure results from no exception being raised, or from 123 -- the wrong exception being raised. 124 125 begin 126 127 -- Use the instantiation of Decimal_Output specific to decimal 128 -- data with two decimal places, as well as non-default 129 -- parameters and named parameter association. 130 131 Pack_2DP.Put(To => TC_Short_String, 132 Item => FXF3A00.Data_With_2DP(i), 133 Pic => TC_Picture, 134 Currency => "$", 135 Fill => '*', 136 Separator => ',', 137 Radix_Mark => '.'); 138 139 -- Test failure if exception not raised. 140 141 Report.Failed 142 ("Layout_Error not raised, decimal data with two decimal " & 143 "places, loop #" & Integer'Image(i)); 144 145 exception 146 when Layout_Error => null; -- OK, expected exception. 147 when others => 148 Report.Failed 149 ("Incorrect exception raised, Layout_Error expected, " & 150 "decimal data with two decimal places, loop #" & 151 Integer'Image(i)); 152 end; 153 end loop; 154 155 156 -- Perform similar evaluations as above, but use the instantiation 157 -- of Decimal_Output specific to decimal data with no decimal places. 158 159 TC_Start_Loop := TC_End_Loop + 1; -- 11 160 TC_End_Loop := TC_Start_Loop + -- 22 161 FXF3A00.Number_of_NDP_Items - 1; 162 TC_Offset := FXF3A00.Number_of_Foreign_Strings; -- 10 163 -- This offset is required due to the arrangement of data within the 164 -- tables found in FXF3A00. 165 166 for i in TC_Start_Loop..TC_End_Loop loop -- 11..22 167 168 -- Create the picture object from the picture string. 169 170 TC_Picture := Editing.To_Picture(FXF3A00.Valid_Strings(i).all); 171 172 begin 173 174 -- Use the instantiation of Decimal_Output specific to decimal 175 -- data with no decimal places, as well as default parameters 176 -- and positional parameter association. 177 178 Pack_NDP.Put(TC_Short_String, 179 FXF3A00.Data_With_NDP(i-TC_Offset), 180 TC_Picture); 181 182 -- Test failure if exception not raised. 183 184 Report.Failed 185 ("Layout_Error not raised, decimal data with no decimal " & 186 "places, loop #" & Integer'Image(i)); 187 188 exception 189 when Layout_Error => null; -- OK, expected exception. 190 when others => 191 Report.Failed 192 ("Incorrect exception raised, Layout_Error expected, " & 193 "decimal data with no decimal places, loop #" & 194 Integer'Image(i)); 195 end; 196 197 end loop; 198 199 200 -- Check that Layout_Error is raised by Put resulting from an 201 -- instantiation of Decimal_Output specific to foreign currency 202 -- representations. 203 -- Note: Both of the following evaluation sets use decimal data with 204 -- two decimal places. 205 206 declare 207 208 package Pack_FF is 209 new Editing.Decimal_Output(Num => FXF3A00.Decimal_Type_2DP, 210 Default_Currency => "FF", 211 Default_Fill => '*', 212 Default_Separator => '.', 213 Default_Radix_Mark => ','); 214 215 begin 216 217 TC_Offset := FXF3A00.Number_Of_2DP_Items - -- 10 218 FXF3A00.Number_Of_Foreign_Strings; 219 220 for i in 1..FXF3A00.Number_Of_FF_Strings loop -- 1..4 221 begin 222 223 -- Create the picture object from the picture string. 224 TC_Picture := 225 Editing.To_Picture(FXF3A00.Foreign_Strings(i).all); 226 227 Pack_FF.Put(To => TC_Short_String, 228 Item => FXF3A00.Data_With_2DP(i+TC_Offset), 229 Pic => TC_Picture); 230 231 Report.Failed("Layout_Error was not raised by Put from " & 232 "an instantiation of Decimal_Output using " & 233 "non-default parameters specific to FF " & 234 "currency, loop #" & Integer'Image(i)); 235 236 exception 237 when Layout_Error => null; -- OK, expected exception. 238 when others => 239 Report.Failed("Incorrect exception raised by Put from " & 240 "an instantiation of Decimal_Output using " & 241 "non-default parameters specific to FF " & 242 "currency, loop #" & Integer'Image(i)); 243 end; 244 end loop; 245 246 247 -- These evaluations use a version of Put resulting from a 248 -- non-default instantiation of Decimal_Output, but which has 249 -- specific foreign currency parameters provided in the call that 250 -- override the generic actual parameters provided at instantiation. 251 252 TC_Offset := TC_Offset + FXF3A00.Number_Of_FF_Strings; -- 14 253 254 for i in 1..FXF3A00.Number_Of_DM_Strings loop -- 1..5 255 begin 256 TC_Picture := 257 Editing.To_Picture(FXF3A00.Foreign_Strings 258 (i+FXF3A00.Number_Of_FF_Strings).all); 259 260 Pack_2DP.Put(To => TC_Short_String, 261 Item => FXF3A00.Data_With_2DP(i+TC_Offset), 262 Pic => TC_Picture, 263 Currency => "DM", 264 Fill => '*', 265 Separator => ',', 266 Radix_Mark => '.'); 267 268 Report.Failed("Layout_Error was not raised by Put using " & 269 "non-default parameters specific to DM " & 270 "currency, loop #" & Integer'Image(i)); 271 272 exception 273 when Layout_Error => null; -- OK, expected exception. 274 when others => 275 Report.Failed("Incorrect exception raised by Put using " & 276 "non-default parameters specific to DM " & 277 "currency, loop #" & Integer'Image(i)); 278 end; 279 end loop; 280 281 end; 282 283 exception 284 when others => Report.Failed("Exception raised in Test_Block"); 285 end Test_Block; 286 287 Report.Result; 288 289end CXF3A08; 290