| 1 |
-- CXF3A03.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 function Length in the generic package Decimal_Output |
| 28 |
-- returns the number of characters in the edited output string |
| 29 |
-- produced by function Image, for a particular decimal type, |
| 30 |
-- currency string, and radix mark. |
| 31 |
-- Check that function Valid in the generic package Decimal_Output |
| 32 |
-- returns correct results based on the particular decimal value, |
| 33 |
-- and the Picture and Currency string parameters. |
| 34 |
-- |
| 35 |
-- TEST DESCRIPTION: |
| 36 |
-- This test uses two instantiations of package Decimal_Output, one |
| 37 |
-- for decimal data with delta 0.01, the other for decimal data with |
| 38 |
-- delta 1.0. The functions Length and Valid found in this generic |
| 39 |
-- package are evaluated for each instantiation. |
| 40 |
-- Function Length is examined with picture and currency string input |
| 41 |
-- parameters of different sizes. |
| 42 |
-- Function Valid is examined with a decimal type data item, picture |
| 43 |
-- object, and currency string, for cases that are both valid and |
| 44 |
-- invalid (Layout_Error would result from the particular items as |
| 45 |
-- input parameters to function Image). |
| 46 |
-- |
| 47 |
-- TEST FILES: |
| 48 |
-- The following files comprise this test: |
| 49 |
-- |
| 50 |
-- FXF3A00.A (foundation code) |
| 51 |
-- => CXF3A03.A |
| 52 |
-- |
| 53 |
-- |
| 54 |
-- CHANGE HISTORY: |
| 55 |
-- 06 Dec 94 SAIC ACVC 2.0 |
| 56 |
-- |
| 57 |
--! |
| 58 |
|
| 59 |
with FXF3A00; |
| 60 |
with Ada.Text_IO.Editing; |
| 61 |
with Report; |
| 62 |
|
| 63 |
procedure CXF3A03 is |
| 64 |
begin |
| 65 |
|
| 66 |
Report.Test ("CXF3A03", "Check that function Length returns the " & |
| 67 |
"number of characters in the edited output " & |
| 68 |
"string produced by function Image, for a " & |
| 69 |
"particular decimal type, currency string, " & |
| 70 |
"and radix mark. Check that function Valid " & |
| 71 |
"returns correct results based on the " & |
| 72 |
"particular decimal value, and the Picture " & |
| 73 |
"and Currency string parameters"); |
| 74 |
|
| 75 |
Test_Block: |
| 76 |
declare |
| 77 |
|
| 78 |
use Ada.Text_IO; |
| 79 |
use FXF3A00; |
| 80 |
|
| 81 |
type Instantiation_Type is (NDP, TwoDP); |
| 82 |
|
| 83 |
-- Defaults used for all other generic parameters in these |
| 84 |
-- instantiations. |
| 85 |
package Pack_NDP is new Editing.Decimal_Output (Decimal_Type_NDP); |
| 86 |
package Pack_2DP is new Editing.Decimal_Output (Decimal_Type_2DP); |
| 87 |
|
| 88 |
TC_Lower_Bound, |
| 89 |
TC_Higher_Bound : Integer := 0; |
| 90 |
|
| 91 |
TC_Picture : Editing.Picture; |
| 92 |
TC_US_String : constant String := "$"; |
| 93 |
TC_FF_String : constant String := "FF"; |
| 94 |
TC_DM_String : constant String := "DM"; |
| 95 |
TC_CHF_String : constant String := "CHF"; |
| 96 |
|
| 97 |
|
| 98 |
function Dollar_Sign_Present (Str : String) return Boolean is |
| 99 |
begin |
| 100 |
for i in 1..Str'Length loop |
| 101 |
if Str(i) = '$' then |
| 102 |
return True; |
| 103 |
end if; |
| 104 |
end loop; |
| 105 |
return False; |
| 106 |
end Dollar_Sign_Present; |
| 107 |
|
| 108 |
function V_Present (Str : String) return Boolean is |
| 109 |
begin |
| 110 |
for i in 1..Str'Length loop |
| 111 |
if Str(i) = 'V' or Str(i) = 'v' then |
| 112 |
return True; |
| 113 |
end if; |
| 114 |
end loop; |
| 115 |
return False; |
| 116 |
end V_Present; |
| 117 |
|
| 118 |
|
| 119 |
function Accurate_Length (Pict_Str : String; |
| 120 |
Inst : Instantiation_Type; |
| 121 |
Currency_String : String) |
| 122 |
return Boolean is |
| 123 |
|
| 124 |
TC_Length : Natural := 0; |
| 125 |
TC_Currency_Length_Adjustment : Natural := 0; |
| 126 |
TC_Radix_Adjustment : Natural := 0; |
| 127 |
begin |
| 128 |
|
| 129 |
-- Create the picture object from the picture string. |
| 130 |
TC_Picture := Editing.To_Picture(Pict_Str); |
| 131 |
|
| 132 |
-- Calculate the currency length adjustment. |
| 133 |
if Dollar_Sign_Present (Editing.Pic_String(TC_Picture)) then |
| 134 |
TC_Currency_Length_Adjustment := Currency_String'Length - 1; |
| 135 |
end if; |
| 136 |
|
| 137 |
-- Calculate the Radix adjustment. |
| 138 |
if V_Present (Editing.Pic_String(TC_Picture)) then |
| 139 |
TC_Radix_Adjustment := 1; |
| 140 |
end if; |
| 141 |
|
| 142 |
-- Calculate the length, using the version of Length that comes |
| 143 |
-- from the appropriate instantiation of Decimal_Output, based |
| 144 |
-- on the decimal type used in the instantiation. |
| 145 |
if Inst = NDP then |
| 146 |
TC_Length := Pack_NDP.Length(TC_Picture, |
| 147 |
Currency_String); |
| 148 |
else |
| 149 |
TC_Length := Pack_2DP.Length(TC_Picture, |
| 150 |
Currency_String); |
| 151 |
end if; |
| 152 |
|
| 153 |
return TC_Length = Editing.Pic_String(TC_Picture)'Length + |
| 154 |
TC_Currency_Length_Adjustment - |
| 155 |
TC_Radix_Adjustment; |
| 156 |
end Accurate_Length; |
| 157 |
|
| 158 |
|
| 159 |
begin |
| 160 |
|
| 161 |
Length_Block: |
| 162 |
begin |
| 163 |
|
| 164 |
-- The first 10 picture strings in the Valid_Strings array correspond |
| 165 |
-- to data values of a decimal type with delta 0.01. |
| 166 |
-- Note: The appropriate instantiation of the Decimal_Output package |
| 167 |
-- (and therefore function Length) is used by function |
| 168 |
-- Accurate_Length to calculate length. |
| 169 |
|
| 170 |
for i in 1..10 loop |
| 171 |
if not Accurate_Length (FXF3A00.Valid_Strings(i).all, |
| 172 |
TwoDP, |
| 173 |
TC_US_String) |
| 174 |
then |
| 175 |
Report.Failed("Incorrect result from function Length, " & |
| 176 |
"when used with a decimal type with delta .01 " & |
| 177 |
"and with the currency string " & TC_US_String & |
| 178 |
" in evaluating picture string " & |
| 179 |
FXF3A00.Valid_Strings(i).all ); |
| 180 |
end if; |
| 181 |
end loop; |
| 182 |
|
| 183 |
|
| 184 |
-- Picture strings 17-20 in the Valid_Strings array correspond |
| 185 |
-- to data values of a decimal type with delta 1.0. Again, the |
| 186 |
-- instantiation of Decimal_Output used is based on this particular |
| 187 |
-- decimal type. |
| 188 |
|
| 189 |
for i in 17..20 loop |
| 190 |
if not Accurate_Length (FXF3A00.Valid_Strings(i).all, |
| 191 |
NDP, |
| 192 |
TC_US_String) |
| 193 |
then |
| 194 |
Report.Failed("Incorrect result from function Length, " & |
| 195 |
"when used with a decimal type with delta 1.0 " & |
| 196 |
"and with the currency string " & TC_US_String & |
| 197 |
" in evaluating picture string " & |
| 198 |
FXF3A00.Valid_Strings(i).all ); |
| 199 |
end if; |
| 200 |
end loop; |
| 201 |
|
| 202 |
|
| 203 |
-- The first 4 picture strings in the Foreign_Strings array |
| 204 |
-- correspond to data values of a decimal type with delta 0.01, |
| 205 |
-- and to the currency string "FF" (two characters). |
| 206 |
|
| 207 |
for i in 1..FXF3A00.Number_of_FF_Strings loop |
| 208 |
if not Accurate_Length (FXF3A00.Foreign_Strings(i).all, |
| 209 |
TwoDP, |
| 210 |
TC_FF_String) |
| 211 |
then |
| 212 |
Report.Failed("Incorrect result from function Length, " & |
| 213 |
"when used with a decimal type with delta .01 " & |
| 214 |
"and with the currency string " & TC_FF_String & |
| 215 |
" in evaluating picture string " & |
| 216 |
FXF3A00.Foreign_Strings(i).all ); |
| 217 |
end if; |
| 218 |
end loop; |
| 219 |
|
| 220 |
|
| 221 |
-- Picture strings 5-9 in the Foreign_Strings array correspond |
| 222 |
-- to data values of a decimal type with delta 0.01, and to the |
| 223 |
-- currency string "DM" (two characters). |
| 224 |
|
| 225 |
TC_Lower_Bound := FXF3A00.Number_of_FF_Strings + 1; |
| 226 |
TC_Higher_Bound := FXF3A00.Number_of_FF_Strings + |
| 227 |
FXF3A00.Number_of_DM_Strings; |
| 228 |
|
| 229 |
for i in TC_Lower_Bound..TC_Higher_Bound loop |
| 230 |
if not Accurate_Length (FXF3A00.Foreign_Strings(i).all, |
| 231 |
TwoDP, |
| 232 |
TC_DM_String) |
| 233 |
then |
| 234 |
Report.Failed("Incorrect result from function Length, " & |
| 235 |
"when used with a decimal type with delta .01 " & |
| 236 |
"and with the currency string " & TC_DM_String & |
| 237 |
" in evaluating picture string " & |
| 238 |
FXF3A00.Foreign_Strings(i).all ); |
| 239 |
end if; |
| 240 |
end loop; |
| 241 |
|
| 242 |
|
| 243 |
-- Picture string #10 in the Foreign_Strings array corresponds |
| 244 |
-- to a data value of a decimal type with delta 0.01, and to the |
| 245 |
-- currency string "CHF" (three characters). |
| 246 |
|
| 247 |
if not Accurate_Length (FXF3A00.Foreign_Strings(10).all, |
| 248 |
TwoDP, |
| 249 |
TC_CHF_String) |
| 250 |
then |
| 251 |
Report.Failed("Incorrect result from function Length, " & |
| 252 |
"when used with a decimal type with delta .01 " & |
| 253 |
"and with the currency string " & |
| 254 |
TC_CHF_String); |
| 255 |
end if; |
| 256 |
|
| 257 |
exception |
| 258 |
when others => |
| 259 |
Report.Failed("Unexpected exception raised in Length_Block"); |
| 260 |
end Length_Block; |
| 261 |
|
| 262 |
|
| 263 |
Valid_Block: |
| 264 |
declare |
| 265 |
|
| 266 |
-- This offset value is used to align picture string and decimal |
| 267 |
-- data values from package FXF3A00 for proper correspondence for |
| 268 |
-- the evaluations below. |
| 269 |
|
| 270 |
TC_Offset : constant Natural := 10; |
| 271 |
|
| 272 |
begin |
| 273 |
|
| 274 |
-- The following four For Loops examine cases where the |
| 275 |
-- decimal data/picture string/currency combinations used will |
| 276 |
-- generate valid Edited Output strings. These combinations, when |
| 277 |
-- provided to the Function Valid (from instantiations of |
| 278 |
-- Decimal_Output), should result in a return result of True. |
| 279 |
-- The particular instantiated version of Valid used in these loops |
| 280 |
-- is that for decimal data with delta 0.01. |
| 281 |
|
| 282 |
-- The first 4 picture strings in the Foreign_Strings array |
| 283 |
-- correspond to data values of a decimal type with delta 0.01, |
| 284 |
-- and to the currency string "FF" (two characters). |
| 285 |
|
| 286 |
for i in 1..FXF3A00.Number_of_FF_Strings loop |
| 287 |
-- Create the picture object from the picture string. |
| 288 |
TC_Picture := Editing.To_Picture(FXF3A00.Foreign_Strings(i).all); |
| 289 |
|
| 290 |
if not Pack_2DP.Valid (FXF3A00.Data_With_2DP(TC_Offset + i), |
| 291 |
TC_Picture, |
| 292 |
TC_FF_String) |
| 293 |
then |
| 294 |
Report.Failed("Incorrect result from function Valid, " & |
| 295 |
"when used with a decimal type with delta .01 " & |
| 296 |
"and with the currency string " & TC_FF_String & |
| 297 |
" in evaluating picture string " & |
| 298 |
FXF3A00.Foreign_Strings(i).all ); |
| 299 |
end if; |
| 300 |
end loop; |
| 301 |
|
| 302 |
|
| 303 |
-- Picture strings 5-9 in the Foreign_Strings array correspond |
| 304 |
-- to data values of a decimal type with delta 0.01, and to the |
| 305 |
-- currency string "DM" (two characters). |
| 306 |
|
| 307 |
TC_Lower_Bound := FXF3A00.Number_of_FF_Strings + 1; |
| 308 |
TC_Higher_Bound := FXF3A00.Number_of_FF_Strings + |
| 309 |
FXF3A00.Number_of_DM_Strings; |
| 310 |
|
| 311 |
for i in TC_Lower_Bound..TC_Higher_Bound loop |
| 312 |
-- Create the picture object from the picture string. |
| 313 |
TC_Picture := Editing.To_Picture(FXF3A00.Foreign_Strings(i).all); |
| 314 |
|
| 315 |
if not Pack_2DP.Valid (FXF3A00.Data_With_2DP(TC_Offset + i), |
| 316 |
TC_Picture, |
| 317 |
TC_DM_String) |
| 318 |
then |
| 319 |
Report.Failed("Incorrect result from function Valid, " & |
| 320 |
"when used with a decimal type with delta .01 " & |
| 321 |
"and with the currency string " & TC_DM_String & |
| 322 |
" in evaluating picture string " & |
| 323 |
FXF3A00.Foreign_Strings(i).all ); |
| 324 |
end if; |
| 325 |
end loop; |
| 326 |
|
| 327 |
|
| 328 |
-- Picture string #10 in the Foreign_Strings array corresponds |
| 329 |
-- to a data value of a decimal type with delta 0.01, and to the |
| 330 |
-- currency string "CHF" (three characters). |
| 331 |
|
| 332 |
-- Create the picture object from the picture string. |
| 333 |
TC_Picture := Editing.To_Picture(FXF3A00.Foreign_Strings(10).all); |
| 334 |
|
| 335 |
if not Pack_2DP.Valid (FXF3A00.Data_With_2DP(TC_Offset + 10), |
| 336 |
TC_Picture, |
| 337 |
TC_CHF_String) |
| 338 |
then |
| 339 |
Report.Failed("Incorrect result from function Valid, " & |
| 340 |
"when used with a decimal type with delta .01 " & |
| 341 |
"and with the currency string " & |
| 342 |
TC_CHF_String); |
| 343 |
end if; |
| 344 |
|
| 345 |
|
| 346 |
-- The following For Loop examines cases where the |
| 347 |
-- decimal data/picture string/currency combinations used will |
| 348 |
-- generate valid Edited Output strings. |
| 349 |
-- The particular instantiated version of Valid used in this loop |
| 350 |
-- is that for decimal data with delta 1.0; the others above have |
| 351 |
-- been for decimal data with delta 0.01. |
| 352 |
-- Note: TC_Offset is used here to align picture strings from the |
| 353 |
-- FXF3A00.Valid_Strings table with the appropriate decimal |
| 354 |
-- data in the FXF3A00.Data_With_NDP table. |
| 355 |
|
| 356 |
for i in 1..FXF3A00.Number_Of_NDP_Items loop |
| 357 |
-- Create the picture object from the picture string. |
| 358 |
TC_Picture := |
| 359 |
Editing.To_Picture(FXF3A00.Valid_Strings(TC_Offset + i).all); |
| 360 |
|
| 361 |
if not Pack_NDP.Valid (FXF3A00.Data_With_NDP(i), |
| 362 |
TC_Picture, |
| 363 |
TC_US_String) |
| 364 |
then |
| 365 |
Report.Failed("Incorrect result from function Valid, " & |
| 366 |
"when used with a decimal type with delta .01 " & |
| 367 |
"and with the currency string " & TC_US_String & |
| 368 |
" in evaluating picture string " & |
| 369 |
FXF3A00.Valid_Strings(i).all ); |
| 370 |
end if; |
| 371 |
end loop; |
| 372 |
|
| 373 |
|
| 374 |
-- The following three evaluations of picture strings, used in |
| 375 |
-- conjunction with the specific decimal values provided, will cause |
| 376 |
-- Editing.Image to raise Layout_Error (to be examined in other |
| 377 |
-- tests). Function Valid should return a False result for these |
| 378 |
-- combinations. |
| 379 |
-- The first two evaluations use the instantiation of Decimal_Output |
| 380 |
-- with a decimal type with delta 0.01, while the last evaluation |
| 381 |
-- uses the instantiation with decimal type with delta 1.0. |
| 382 |
|
| 383 |
for i in 1..FXF3A00.Number_of_Erroneous_Conditions loop |
| 384 |
|
| 385 |
-- Create the picture object from the picture string. |
| 386 |
TC_Picture := |
| 387 |
Editing.To_Picture(FXF3A00.Erroneous_Strings(i).all); |
| 388 |
|
| 389 |
if i < 3 then -- Choose the appropriate instantiation. |
| 390 |
if Pack_2DP.Valid(Item => FXF3A00.Erroneous_Data(i), |
| 391 |
Pic => TC_Picture, |
| 392 |
Currency => TC_US_String) |
| 393 |
then |
| 394 |
Report.Failed("Incorrect result from function Valid, " & |
| 395 |
"when used with a decimal type with delta " & |
| 396 |
"0.01 and with the currency string " & |
| 397 |
TC_US_String & |
| 398 |
" in evaluating picture string " & |
| 399 |
FXF3A00.Valid_Strings(i).all ); |
| 400 |
end if; |
| 401 |
else |
| 402 |
if Pack_NDP.Valid(Item => FXF3A00.Decimal_Type_NDP( |
| 403 |
FXF3A00.Erroneous_Data(i)), |
| 404 |
Pic => TC_Picture, |
| 405 |
Currency => TC_US_String) |
| 406 |
then |
| 407 |
Report.Failed("Incorrect result from function Valid, " & |
| 408 |
"when used with a decimal type with delta " & |
| 409 |
"1.0 and with the currency string " & |
| 410 |
TC_US_String & |
| 411 |
" in evaluating picture string " & |
| 412 |
FXF3A00.Valid_Strings(i).all ); |
| 413 |
end if; |
| 414 |
end if; |
| 415 |
end loop; |
| 416 |
|
| 417 |
exception |
| 418 |
when others => |
| 419 |
Report.Failed("Unexpected exception raised in Valid_Block"); |
| 420 |
end Valid_Block; |
| 421 |
|
| 422 |
|
| 423 |
exception |
| 424 |
when others => Report.Failed ("Exception raised in Test_Block"); |
| 425 |
end Test_Block; |
| 426 |
|
| 427 |
Report.Result; |
| 428 |
|
| 429 |
end CXF3A03; |