1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
--
-- Copyright (c) 2008-2009,
-- Reto Buerki, Adrian-Ken Rueegsegger
--
-- This file is part of Alog.
--
-- Alog is free software; you can redistribute it and/or modify
-- it under the terms of the GNU Lesser General Public License as published
-- by the Free Software Foundation; either version 2.1 of the License, or
-- (at your option) any later version.
--
-- Alog is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public License
-- along with Alog; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-- MA 02110-1301 USA
--
with Ada.Calendar.Time_Zones;
with Ahven; use Ahven;
with Alog.Facilities.File_Descriptor;
package body Facility_Tests is
use Alog;
use Alog.Facilities;
-------------------------------------------------------------------------
procedure Initialize (T : in out Testcase) is
begin
T.Set_Name (Name => "Tests for Facilites");
T.Add_Test_Routine
(Routine => Set_Name'Access,
Name => "set facility name");
T.Add_Test_Routine
(Routine => Toggle_Loglevel'Access,
Name => "toggle loglevel");
T.Add_Test_Routine
(Routine => Toggle_Timestamp'Access,
Name => "toggle timestamp");
T.Add_Test_Routine
(Routine => Toggle_UTC_Timestamp'Access,
Name => "toggle UTC timestamp");
T.Add_Test_Routine
(Routine => Toggle_Source'Access,
Name => "toggle source writing");
T.Add_Test_Routine
(Routine => Timestamp_Creation'Access,
Name => "timestamp creation");
T.Add_Test_Routine
(Routine => Timestamp_Format_Setter'Access,
Name => "set timestamp format");
end Initialize;
-------------------------------------------------------------------------
procedure Set_Name is
F : File_Descriptor.Instance;
Expected : constant String := "TEST";
begin
F.Set_Name (Name => Expected);
Assert (Condition => F.Get_Name = Expected,
Message => "name not equal");
end Set_Name;
-------------------------------------------------------------------------
procedure Timestamp_Creation is
use Ada.Calendar;
use Ada.Calendar.Time_Zones;
F : File_Descriptor.Instance;
Ref_Time : constant Time := Time_Of
(Year => 2009,
Month => 10,
Day => 10,
Seconds => 7255.0);
Ref_Stamp : constant String := "Oct 10 2009 02:00:55";
-- Adding the UTC time offset to the reference time should lead to the
-- same timestamp string when UTC timestamps are enabled since UTC time
-- is timezone-dependent time minus the UTC offset at that given time.
Ref_UTC_Time : constant Time := Ref_Time + Duration
(UTC_Time_Offset (Ref_Time)) * 60;
begin
Assert (Condition => Ref_Stamp = F.Get_Timestamp (Time => Ref_Time),
Message => "Timestamp mismatch");
F.Toggle_UTC_Timestamp (State => True);
Assert (Condition => F.Get_Timestamp (Time => Ref_UTC_Time) = Ref_Stamp,
Message => "UTC timestamp mismatch!");
end Timestamp_Creation;
-------------------------------------------------------------------------
procedure Timestamp_Format_Setter
is
use Ada.Calendar;
F : File_Descriptor.Instance;
Ref_Time : constant Time := Time_Of
(Year => 2009,
Month => 10,
Day => 10,
Seconds => 7255.0);
begin
F.Set_Timestamp_Format (Format => "%b %Y");
Assert (Condition => F.Get_Timestamp (Time => Ref_Time) = "Oct 2009",
Message => "Timestamp mismatch");
begin
F.Set_Timestamp_Format (Format => "a b c %");
Fail (Message => "Exception expected");
exception
when Invalid_Timestamp_Format => null;
end;
end Timestamp_Format_Setter;
-------------------------------------------------------------------------
procedure Toggle_Loglevel is
F : File_Descriptor.Instance;
begin
Assert (Condition => not F.Is_Write_Loglevel,
Message => "Loglevel writing is 'True' by default");
F.Toggle_Write_Loglevel (State => True);
Assert (Condition => F.Is_Write_Loglevel,
Message => "Loglevel writing not 'True'");
end Toggle_Loglevel;
-------------------------------------------------------------------------
procedure Toggle_Source is
F : File_Descriptor.Instance;
begin
Assert (Condition => F.Is_Write_Source,
Message => "Source writing is 'False' by default");
F.Toggle_Write_Source (State => False);
Assert (Condition => not F.Is_Write_Source,
Message => "Source writing is still 'True'");
end Toggle_Source;
-------------------------------------------------------------------------
procedure Toggle_Timestamp is
F : File_Descriptor.Instance;
begin
Assert (Condition => F.Is_Write_Timestamp,
Message => "Timestamp writing is 'False' by default");
F.Toggle_Write_Timestamp (State => False);
Assert (Condition => not F.Is_Write_Timestamp,
Message => "Timestamp writing not 'False'");
end Toggle_Timestamp;
-------------------------------------------------------------------------
procedure Toggle_UTC_Timestamp is
F : File_Descriptor.Instance;
begin
Assert (Condition => not F.Is_UTC_Timestamp,
Message => "Default should be 'False'");
F.Toggle_UTC_Timestamp (State => True);
Assert (Condition => F.Is_UTC_Timestamp,
Message => "Expected 'True'");
end Toggle_UTC_Timestamp;
end Facility_Tests;
|