| 1 |
-- CXAA009.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 capabilities provided in instantiations of the |
| 28 |
-- Ada.Text_IO.Float_IO package operate correctly when the mode of |
| 29 |
-- the file is Append_File. Check that Float_IO procedures Put and Get |
| 30 |
-- properly transfer floating point data to/from data files that are in |
| 31 |
-- Append_File mode. Check that the formatting parameters available in |
| 32 |
-- the package can be used and modified successfully in the appending and |
| 33 |
-- retrieval of data. |
| 34 |
-- |
| 35 |
-- TEST DESCRIPTION: |
| 36 |
-- This test is designed to simulate an environment where a data file |
| 37 |
-- that holds floating point information is created, written to, and |
| 38 |
-- closed. In the future, the file can be reopened in Append_File mode, |
| 39 |
-- additional data can be appended to it, and then closed. This process |
| 40 |
-- of Open/Append/Close can be repeated as necessary. All data written |
| 41 |
-- to the file is verified for accuracy when retrieved from the file. |
| 42 |
-- |
| 43 |
-- This test verifies issues of create in Append_File mode, appending to |
| 44 |
-- a file previously appended to, opening in Append_File mode, resetting |
| 45 |
-- from Append_File mode to In_File mode, as well as a variety of Text_IO |
| 46 |
-- and Float_IO predefined subprograms. |
| 47 |
-- |
| 48 |
-- APPLICABILITY CRITERIA: |
| 49 |
-- This test is applicable only to implementations that support text |
| 50 |
-- files. |
| 51 |
-- |
| 52 |
-- |
| 53 |
-- CHANGE HISTORY: |
| 54 |
-- 06 Dec 94 SAIC ACVC 2.0 |
| 55 |
-- 25 Feb 97 PWB.CTA Allowed for non-support of some IO operations |
| 56 |
--! |
| 57 |
|
| 58 |
with Ada.Text_IO; |
| 59 |
with Report; |
| 60 |
|
| 61 |
procedure CXAA009 is |
| 62 |
|
| 63 |
use Ada; |
| 64 |
Loan_File : Text_IO.File_Type; |
| 65 |
Loan_Filename : constant String := |
| 66 |
Report.Legal_File_Name ( Nam => "CXAA009" ); |
| 67 |
Incomplete : exception; |
| 68 |
|
| 69 |
begin |
| 70 |
|
| 71 |
Report.Test ("CXAA009", "Check that the capabilities of " & |
| 72 |
"Text_IO.Float_IO operate correctly for files " & |
| 73 |
"with mode Append_File"); |
| 74 |
|
| 75 |
Test_for_Text_IO_Support: |
| 76 |
begin |
| 77 |
|
| 78 |
-- An implementation that does not support Text_IO in a particular |
| 79 |
-- environment will raise Use_Error on calls to various |
| 80 |
-- Text_IO operations. This block statement encloses a call to |
| 81 |
-- Create, which should raise the exception in a non-supportive |
| 82 |
-- environment. This exception will be handled to produce a |
| 83 |
-- Not_Applicable result. |
| 84 |
|
| 85 |
Text_IO.Create (File => Loan_File, -- Create in |
| 86 |
Mode => Text_IO.Out_File, -- Out_File mode. |
| 87 |
Name => Loan_Filename); |
| 88 |
|
| 89 |
exception |
| 90 |
|
| 91 |
when Text_IO.Use_Error | Text_IO.Name_Error => |
| 92 |
Report.Not_Applicable |
| 93 |
( "Files not supported - Create as Out_File for Text_IO" ); |
| 94 |
raise Incomplete; |
| 95 |
|
| 96 |
end Test_for_Text_IO_Support; |
| 97 |
|
| 98 |
Operational_Test_Block: |
| 99 |
declare |
| 100 |
Total_Loans_Outstanding : constant Natural := 3; |
| 101 |
Transaction_Status : Boolean := False; |
| 102 |
|
| 103 |
type Account_Balance_Type is digits 6 range 0.0 .. 1.0E6; |
| 104 |
type Loan_Balance_Type is digits 6; |
| 105 |
type Interest_Rate_Type is digits 4 range 0.0 .. 30.00; |
| 106 |
|
| 107 |
type Loan_Info_Type is record |
| 108 |
Account_Balance : Account_Balance_Type := 0.00; |
| 109 |
Loan_Balance : Loan_Balance_Type := 0.00; |
| 110 |
Loan_Interest_Rate : Interest_Rate_Type := 0.00; |
| 111 |
end record; |
| 112 |
|
| 113 |
Home_Refinance_Loan : Loan_Info_Type := |
| 114 |
(14_500.00, 135_000.00, 6.875); |
| 115 |
Line_Of_Credit_Loan : Loan_Info_Type := |
| 116 |
( 5490.00, -3000.00, 13.75); |
| 117 |
Small_Business_Loan : Loan_Info_Type := |
| 118 |
(Account_Balance => 45_000.00, |
| 119 |
Loan_Balance => 10_500.00, |
| 120 |
Loan_Interest_Rate => 5.875); |
| 121 |
|
| 122 |
package Acct_IO is new Text_IO.Float_IO (Account_Balance_Type); |
| 123 |
package Loan_IO is new Text_IO.Float_IO (Loan_Balance_Type); |
| 124 |
package Rate_IO is new Text_IO.Float_IO (Interest_Rate_Type); |
| 125 |
|
| 126 |
|
| 127 |
-- The following procedure performs the addition of loan information |
| 128 |
-- into a data file. Boolean status of True is returned if all of |
| 129 |
-- the data entry was successful, False otherwise. |
| 130 |
-- This demonstrates use of Float_IO using a variety of data formats. |
| 131 |
|
| 132 |
procedure Update_Loan_Info (The_File : in out Text_IO.File_Type; |
| 133 |
The_Loan : in Loan_Info_Type; |
| 134 |
Status : out Boolean ) is |
| 135 |
begin |
| 136 |
Acct_IO.Put (The_File, The_Loan.Account_Balance); |
| 137 |
Loan_IO.Put (The_File, The_Loan.Loan_Balance, 15, 2, 0); |
| 138 |
Rate_IO.Put (File => The_File, |
| 139 |
Item => The_Loan.Loan_Interest_Rate, |
| 140 |
Fore => 6, |
| 141 |
Aft => 3, |
| 142 |
Exp => 0); |
| 143 |
Text_IO.New_Line (The_File); |
| 144 |
Status := True; |
| 145 |
exception |
| 146 |
when others => Status := False; |
| 147 |
end Update_Loan_Info; |
| 148 |
|
| 149 |
|
| 150 |
begin |
| 151 |
|
| 152 |
-- This code section simulates a bank maintaining a data file |
| 153 |
-- containing information on loans that have been made. |
| 154 |
-- The scenario: |
| 155 |
-- The loan file was created in Out_File mode. |
| 156 |
-- Some number of data records are added. |
| 157 |
-- The file is closed. |
| 158 |
-- The file is subsequently reopened in Append_File mode. |
| 159 |
-- Data is appended to the file. |
| 160 |
-- The file is closed. |
| 161 |
-- Repeat the Open/Append/Close process as required. |
| 162 |
-- Verify data in the file. |
| 163 |
-- etc. |
| 164 |
|
| 165 |
Update_Loan_Info(Loan_File, Home_Refinance_Loan, Transaction_Status); |
| 166 |
|
| 167 |
if not Transaction_Status then |
| 168 |
Report.Failed ("Failure in update of first loan data"); |
| 169 |
end if; |
| 170 |
|
| 171 |
Text_IO.Close (Loan_File); |
| 172 |
|
| 173 |
-- When subsequent data items are to be added to the file, the file |
| 174 |
-- is opened in Append_File mode. |
| 175 |
|
| 176 |
Text_IO.Open (Loan_File, -- Open with |
| 177 |
Text_IO.Append_File, -- Append mode. |
| 178 |
Loan_Filename); |
| 179 |
|
| 180 |
Update_Loan_Info(Loan_File, Line_Of_Credit_Loan, Transaction_Status); |
| 181 |
|
| 182 |
if not Transaction_Status then |
| 183 |
Report.Failed("Failure in update of first loan data"); |
| 184 |
end if; |
| 185 |
|
| 186 |
Text_IO.Close(Loan_File); |
| 187 |
|
| 188 |
-- To add additional data to the file, the file |
| 189 |
-- is again opened in Append_File mode (appending to a file |
| 190 |
-- previously appended to). |
| 191 |
|
| 192 |
Text_IO.Open (Loan_File, -- Open with |
| 193 |
Text_IO.Append_File, -- Append mode. |
| 194 |
Loan_Filename); |
| 195 |
|
| 196 |
Update_Loan_Info(Loan_File, Small_Business_Loan, Transaction_Status); |
| 197 |
|
| 198 |
if not Transaction_Status then |
| 199 |
Report.Failed("Failure in update of first loan data"); |
| 200 |
end if; |
| 201 |
|
| 202 |
Test_Verification_Block: |
| 203 |
declare |
| 204 |
type Ledger_Type is |
| 205 |
array (1 .. Total_Loans_Outstanding) of Loan_Info_Type; |
| 206 |
TC_Bank_Ledger : Ledger_Type; |
| 207 |
TC_Item_Count : Natural := 0; |
| 208 |
begin |
| 209 |
|
| 210 |
Reset1: |
| 211 |
begin |
| 212 |
Text_IO.Reset (Loan_File, Text_IO.In_File); -- Reset for |
| 213 |
-- reading. |
| 214 |
exception |
| 215 |
when Text_IO.Use_Error => |
| 216 |
Report.Not_Applicable |
| 217 |
( "Reset to In_File not supported for Text_IO" ); |
| 218 |
raise Incomplete; |
| 219 |
end Reset1; |
| 220 |
|
| 221 |
while not Text_IO.End_Of_File (Loan_File) loop |
| 222 |
TC_Item_Count := TC_Item_Count + 1; |
| 223 |
Acct_IO.Get (Loan_File, |
| 224 |
TC_Bank_Ledger(TC_Item_Count).Account_Balance); |
| 225 |
Loan_IO.Get (Loan_File, |
| 226 |
TC_Bank_Ledger(TC_Item_Count).Loan_Balance, |
| 227 |
0); |
| 228 |
Rate_IO.Get(File => Loan_File, |
| 229 |
Item => |
| 230 |
TC_Bank_Ledger(TC_Item_Count).Loan_Interest_Rate, |
| 231 |
Width => 0); |
| 232 |
Text_IO.Skip_Line(Loan_File); |
| 233 |
|
| 234 |
end loop; |
| 235 |
|
| 236 |
-- Verify all of the data fields read from the file. Compare |
| 237 |
-- with the values that were originally entered into the file. |
| 238 |
|
| 239 |
if (TC_Bank_Ledger(1) /= Home_Refinance_Loan) or |
| 240 |
(TC_Bank_Ledger(2) /= Line_Of_Credit_Loan) or |
| 241 |
(TC_Bank_Ledger(3) /= Small_Business_Loan) then |
| 242 |
Report.Failed("Error in data read from file"); |
| 243 |
end if; |
| 244 |
|
| 245 |
if (TC_Item_Count /= Total_Loans_Outstanding) then |
| 246 |
Report.Failed ("Incorrect number of records read from file"); |
| 247 |
end if; |
| 248 |
|
| 249 |
exception |
| 250 |
when Incomplete => |
| 251 |
raise; |
| 252 |
when others => |
| 253 |
Report.Failed ("Error raised during data verification"); |
| 254 |
end Test_Verification_Block; |
| 255 |
|
| 256 |
exception |
| 257 |
when Incomplete => |
| 258 |
raise; |
| 259 |
when others => |
| 260 |
Report.Failed ("Exception in Text_IO.Float_IO processing"); |
| 261 |
end Operational_Test_Block; |
| 262 |
|
| 263 |
Final_Block: |
| 264 |
begin |
| 265 |
-- Delete the external file. |
| 266 |
if Text_IO.Is_Open(Loan_File) then |
| 267 |
Text_IO.Delete(Loan_File); |
| 268 |
else |
| 269 |
Text_IO.Open(Loan_File, Text_IO.In_File, Loan_Filename); |
| 270 |
Text_IO.Delete(Loan_File); |
| 271 |
end if; |
| 272 |
|
| 273 |
exception |
| 274 |
|
| 275 |
when Text_IO.Use_Error => |
| 276 |
Report.Failed |
| 277 |
( "Delete not properly implemented for Text_IO" ); |
| 278 |
|
| 279 |
end Final_Block; |
| 280 |
|
| 281 |
Report.Result; |
| 282 |
|
| 283 |
exception |
| 284 |
when Incomplete => |
| 285 |
Report.Result; |
| 286 |
when others => |
| 287 |
Report.Failed ( "Unexpected exception" ); |
| 288 |
Report.Result; |
| 289 |
|
| 290 |
end CXAA009; |