------------------------------------------------------------------------------
--
-- procedure Test_International_Standard_Book_Numbers (body)
--
-- For testing package International_Standard_Book_Numbers.
--
-- Source: "Find fem fejl", Kjeld Bagger Laursen, in Hovedområdet 1/1998,
-- Københavns Universitets Naturvidenskabelige Fakultet.
--
------------------------------------------------------------------------------
-- Update information:
--
-- 1998.02.06 (Jacob Sparre Andersen)
-- Written.
--
-- (Insert additional update information above this line.)
------------------------------------------------------------------------------
with Ada.Text_IO;
with International_Standard_Book_Numbers;
with UStrings;
procedure Test_International_Standard_Book_Numbers is
---------------------------------------------------------------------------
-- As strings:
Book_Images : array (1 .. 4) of String (1 .. 13) :=
("87-502-0440-8", "0-201-82753-4",
"0-19-859665-0", "0-201-86253-4");
---------------------------------------------------------------------------
-- As ISBN objects:
type ISBN_Data is
record
Country, Publisher, Book : Natural;
Country_Length, Publisher_Length : Positive;
end record;
Book_Codes : array (1 .. 4) of ISBN_Data :=
((87, 502, 0440, 2, 3), ( 0, 201, 82753, 1, 3),
( 0, 19, 859665, 1, 2), ( 0, 201, 86253, 1, 3));
---------------------------------------------------------------------------
use Ada.Text_IO;
use International_Standard_Book_Numbers;
Data : ISBN;
ISBN_As_String : UStrings.UString;
begin -- Test_International_Standard_Book_Numbers
if Valid (Data) then
Put_Line (Image (Data) & " (valid)");
else
Put_Line ("(invalid ISBN)");
end if;
New_Line;
for Index in Book_Images'Range loop
begin
Put (Index'Img & ": """);
Put (Book_Images (Index) & """ ");
Data := Value (Book_Images (Index));
Put ("""" & Image (Data) & """ ");
if Valid (Data) then
Put_Line ("(valid) ");
else
Put_Line ("(invalid) ");
end if;
New_Line;
exception
when Constraint_Error =>
Put_Line ("A Constraint_Error was raised.");
when others =>
Put_Line ("Some exception occurred.");
end;
end loop;
New_Line;
for Index in Book_Images'Range loop
begin
Put (Index'Img & ": ");
Data :=
To_ISBN (Country => Book_Codes (Index).Country,
Publisher => Book_Codes (Index).Publisher,
Book => Book_Codes (Index).Book,
Country_Length => Book_Codes (Index).Country_Length,
Publisher_Length => Book_Codes (Index).Publisher_Length);
Put ("""");
Put (Image (Data) & """ ");
if Valid (Data) then
Put_Line ("(valid) ");
else
Put_Line ("(invalid) ");
end if;
exception
when Constraint_Error =>
Put_Line ("A Constraint_Error was raised.");
when others =>
Put_Line ("Some exception occurred.");
end;
end loop;
New_Line;
loop
Put ("ISBN ");
UStrings.Get_Line (ISBN_As_String);
begin
Data := Value (UStrings.S (ISBN_As_String));
Put_Line (" ISBN " & Image (Data) & " - OK!");
exception
when Constraint_Error =>
Put_Line (" ISBN " & UStrings.S (ISBN_As_String) & " - Bad!");
exit;
when others =>
raise;
end;
end loop;
end Test_International_Standard_Book_Numbers;
Typeset with Ada_To_HTML (Jacob and Jesper)