File: facility_tests-pgsql.adb

package info (click to toggle)
libalog 0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,056 kB
  • ctags: 465
  • sloc: ada: 5,203; makefile: 166; sql: 9; sh: 2
file content (243 lines) | stat: -rw-r--r-- 8,782 bytes parent folder | download
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
--
--  Copyright (c) 2008-2009,
--  Reto Buerki, Adrian-Ken Rueegsegger
--  secunet SwissIT AG
--
--  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 Ahven; use Ahven;

with Alog.Log_Request;
with Alog.Facilities.Pgsql;

package body Facility_Tests.PGSQL is

   use Alog;
   use Alog.Log_Request;
   use Alog.Facilities;

   -------------------------------------------------------------------------

   procedure Disable_Write_Loglevel is
      F     : Alog.Facilities.Pgsql.Instance;
      State : constant Boolean := False;
   begin
      F.Toggle_Write_Loglevel (State => State);
      Assert (Condition => (F.Is_Write_Loglevel = State),
              Message   => "unable to set to " & Boolean'Image (State));
      F.Toggle_Write_Loglevel (State => not State);
      Assert (Condition => (F.Is_Write_Loglevel = not State),
              Message   => "unable to set to " & Boolean'Image (not State));
   end Disable_Write_Loglevel;

   -------------------------------------------------------------------------

   procedure Disable_Write_Timestamp is
      F     : Alog.Facilities.Pgsql.Instance;
      State : constant Boolean := False;
   begin
      F.Toggle_Write_Timestamp (State => State);
      Assert (Condition => (F.Is_Write_Timestamp = State),
              Message   => "unable to set to " & Boolean'Image (State));
      F.Toggle_Write_Timestamp (State => not State);
      Assert (Condition => (F.Is_Write_Timestamp = not State),
              Message   => "unable to set to " & Boolean'Image (not State));
   end Disable_Write_Timestamp;

   -------------------------------------------------------------------------

   procedure Enable_SQL_Trace is
      F     : Alog.Facilities.Pgsql.Instance;
      State : constant Boolean := True;
   begin
      F.Toggle_SQL_Trace (State => State);
      Assert (Condition => (F.Is_SQL_Trace = State),
              Message   => "unable to set to " & Boolean'Image (State));
      F.Toggle_SQL_Trace (State => not State);
      Assert (Condition => (F.Is_SQL_Trace = not State),
              Message   => "unable to set to " & Boolean'Image (not State));
   end Enable_SQL_Trace;

   -------------------------------------------------------------------------

   procedure Initialize (T : in out Testcase) is
   begin
      T.Set_Name (Name => "Tests for PGSQL Facility");
      T.Add_Test_Routine
        (Routine => Set_Host_Name'Access,
         Name    => "set hostname");
      T.Add_Test_Routine
        (Routine => Set_Host_Address'Access,
         Name    => "set host address");
      T.Add_Test_Routine
        (Routine => Set_Host_Port'Access,
         Name    => "set host port");
      T.Add_Test_Routine
        (Routine => Set_DB_Name'Access,
         Name    => "set database name");
      T.Add_Test_Routine
        (Routine => Set_Table_Name'Access,
         Name    => "set table name");
      T.Add_Test_Routine
        (Routine => Set_Level_Column_Name'Access,
         Name    => "set level column name");
      T.Add_Test_Routine
        (Routine => Set_Timestamp_Column_Name'Access,
         Name    => "set timestamp column name");
      T.Add_Test_Routine
        (Routine => Set_Message_Column_Name'Access,
         Name    => "set message column name");
      T.Add_Test_Routine
        (Routine => Set_Credentials'Access,
         Name    => "set credentials");
      T.Add_Test_Routine
        (Routine => Enable_SQL_Trace'Access,
         Name    => "toggle sql trace");
      T.Add_Test_Routine
        (Routine => Disable_Write_Timestamp'Access,
         Name    => "toggle timestamp");
      T.Add_Test_Routine
        (Routine => Disable_Write_Loglevel'Access,
         Name    => "toggle loglevel");
--        T.Add_Test_Routine
--          (Routine => Write_Message'Access,
--           Name    => "log a message to PGSQL database");
   end Initialize;

   -------------------------------------------------------------------------

   procedure Set_Credentials is
      F : Alog.Facilities.Pgsql.Instance;
      Username : constant String := "foo";
      Password : constant String := "bar";
   begin
      F.Set_Credentials (Username => Username,
                         Password => Password);
      Assert (Condition => (F.Get_Credentials = Username),
              Message   => "non matching username");
   end Set_Credentials;

   -------------------------------------------------------------------------

   procedure Set_DB_Name is
      F : Alog.Facilities.Pgsql.Instance;
      DB_Name : constant String := "FOODB";
   begin
      F.Set_DB_Name (DB_Name);
      Assert (Condition => (F.Get_DB_Name = DB_Name),
              Message   => "non matching database name");
   end Set_DB_Name;

   -------------------------------------------------------------------------

   procedure Set_Host_Address is
      F : Alog.Facilities.Pgsql.Instance;
      Host_Address : constant String := "127.0.0.1";
   begin
      F.Set_Host_Address (Host_Address);
   end Set_Host_Address;

   -------------------------------------------------------------------------

   procedure Set_Host_Name is
      F : Alog.Facilities.Pgsql.Instance;
      Hostname : constant String := "foohost";
   begin
      F.Set_Host_Name (Hostname);
      Assert (Condition => (F.Get_Host_Name = Hostname),
              Message   => "non matching hostname");
   end Set_Host_Name;

   -------------------------------------------------------------------------

   procedure Set_Host_Port is
      F : Alog.Facilities.Pgsql.Instance;
      Host_Port : constant Natural := 1024;
   begin
      F.Set_Host_Port (Host_Port);
      Assert (Condition => (F.Get_Host_Port = Host_Port),
              Message   => "non matching host port");
   end Set_Host_Port;

   -------------------------------------------------------------------------

   procedure Set_Level_Column_Name is
      F : Alog.Facilities.Pgsql.Instance;
      Level_Column_Name : constant String := "foocolumn";
   begin
      F.Set_Level_Column_Name (Level_Column_Name);
      Assert (Condition => (F.Get_Level_Column_Name = Level_Column_Name),
              Message   => "non matching level column name");
   end Set_Level_Column_Name;

   -------------------------------------------------------------------------

   procedure Set_Message_Column_Name is
      F : Alog.Facilities.Pgsql.Instance;
      Message_Column_Name : constant String := "foobarcolumn";
   begin
      F.Set_Message_Column_Name (Message_Column_Name);
      Assert (Condition =>
                (F.Get_Message_Column_Name = Message_Column_Name),
              Message   => "non matching message column name");
   end Set_Message_Column_Name;

   -------------------------------------------------------------------------

   procedure Set_Table_Name is
      F : Alog.Facilities.Pgsql.Instance;
      Table_Name : constant String := "footable";
   begin
      F.Set_Table_Name (Table_Name);
      Assert (Condition => (F.Get_Table_Name = Table_Name),
              Message   => "non matching table name");
   end Set_Table_Name;

   -------------------------------------------------------------------------

   procedure Set_Timestamp_Column_Name is
      F : Alog.Facilities.Pgsql.Instance;
      Timestamp_Column_Name : constant String := "barcolumn";
   begin
      F.Set_Timestamp_Column_Name (Timestamp_Column_Name);
      Assert (Condition =>
                (F.Get_Timestamp_Column_Name = Timestamp_Column_Name),
              Message   => "non matching timestamp column name");
   end Set_Timestamp_Column_Name;

   -------------------------------------------------------------------------

   procedure Write_Message is
      F : Alog.Facilities.Pgsql.Instance;
   begin
      F.Toggle_Write_Timestamp (State => False);

      F.Set_DB_Name (DB_Name => "alog");
      F.Set_Credentials (Username => "alog",
                         Password => "foobar");

      --  Setup facility (open db connection, etc)
      F.Setup;

      F.Process (Request => Create (Message => "Test message"));

      F.Teardown;
   end Write_Message;

end Facility_Tests.PGSQL;