xref: /minix3/external/bsd/kyua-cli/dist/utils/logging/operations_test.cpp (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc // Copyright 2011 Google Inc.
2*11be35a1SLionel Sambuc // All rights reserved.
3*11be35a1SLionel Sambuc //
4*11be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
5*11be35a1SLionel Sambuc // modification, are permitted provided that the following conditions are
6*11be35a1SLionel Sambuc // met:
7*11be35a1SLionel Sambuc //
8*11be35a1SLionel Sambuc // * Redistributions of source code must retain the above copyright
9*11be35a1SLionel Sambuc //   notice, this list of conditions and the following disclaimer.
10*11be35a1SLionel Sambuc // * Redistributions in binary form must reproduce the above copyright
11*11be35a1SLionel Sambuc //   notice, this list of conditions and the following disclaimer in the
12*11be35a1SLionel Sambuc //   documentation and/or other materials provided with the distribution.
13*11be35a1SLionel Sambuc // * Neither the name of Google Inc. nor the names of its contributors
14*11be35a1SLionel Sambuc //   may be used to endorse or promote products derived from this software
15*11be35a1SLionel Sambuc //   without specific prior written permission.
16*11be35a1SLionel Sambuc //
17*11be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*11be35a1SLionel Sambuc // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*11be35a1SLionel Sambuc // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*11be35a1SLionel Sambuc // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*11be35a1SLionel Sambuc // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*11be35a1SLionel Sambuc // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*11be35a1SLionel Sambuc // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*11be35a1SLionel Sambuc // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*11be35a1SLionel Sambuc // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*11be35a1SLionel Sambuc // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*11be35a1SLionel Sambuc // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*11be35a1SLionel Sambuc 
29*11be35a1SLionel Sambuc #include "utils/logging/operations.hpp"
30*11be35a1SLionel Sambuc 
31*11be35a1SLionel Sambuc extern "C" {
32*11be35a1SLionel Sambuc #include <unistd.h>
33*11be35a1SLionel Sambuc }
34*11be35a1SLionel Sambuc 
35*11be35a1SLionel Sambuc #include <fstream>
36*11be35a1SLionel Sambuc #include <string>
37*11be35a1SLionel Sambuc 
38*11be35a1SLionel Sambuc #include <atf-c++.hpp>
39*11be35a1SLionel Sambuc 
40*11be35a1SLionel Sambuc #include "utils/datetime.hpp"
41*11be35a1SLionel Sambuc #include "utils/format/macros.hpp"
42*11be35a1SLionel Sambuc #include "utils/fs/operations.hpp"
43*11be35a1SLionel Sambuc #include "utils/fs/path.hpp"
44*11be35a1SLionel Sambuc 
45*11be35a1SLionel Sambuc namespace datetime = utils::datetime;
46*11be35a1SLionel Sambuc namespace fs = utils::fs;
47*11be35a1SLionel Sambuc namespace logging = utils::logging;
48*11be35a1SLionel Sambuc 
49*11be35a1SLionel Sambuc 
50*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(generate_log_name__before_log);
ATF_TEST_CASE_BODY(generate_log_name__before_log)51*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(generate_log_name__before_log)
52*11be35a1SLionel Sambuc {
53*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 10, 0, 0);
54*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(fs::path("/some/dir/foobar.20110221-181000.log"),
55*11be35a1SLionel Sambuc                    logging::generate_log_name(fs::path("/some/dir"), "foobar"));
56*11be35a1SLionel Sambuc 
57*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 10, 1, 987654);
58*11be35a1SLionel Sambuc     logging::log(logging::level_info, "file", 123, "A message");
59*11be35a1SLionel Sambuc 
60*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 10, 2, 123);
61*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(fs::path("/some/dir/foobar.20110221-181000.log"),
62*11be35a1SLionel Sambuc                    logging::generate_log_name(fs::path("/some/dir"), "foobar"));
63*11be35a1SLionel Sambuc }
64*11be35a1SLionel Sambuc 
65*11be35a1SLionel Sambuc 
66*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(generate_log_name__after_log);
ATF_TEST_CASE_BODY(generate_log_name__after_log)67*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(generate_log_name__after_log)
68*11be35a1SLionel Sambuc {
69*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 15, 0, 0);
70*11be35a1SLionel Sambuc     logging::log(logging::level_info, "file", 123, "A message");
71*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 15, 1, 987654);
72*11be35a1SLionel Sambuc     logging::log(logging::level_info, "file", 123, "A message");
73*11be35a1SLionel Sambuc 
74*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 15, 2, 123);
75*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(fs::path("/some/dir/foobar.20110221-181500.log"),
76*11be35a1SLionel Sambuc                    logging::generate_log_name(fs::path("/some/dir"), "foobar"));
77*11be35a1SLionel Sambuc 
78*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 15, 3, 1);
79*11be35a1SLionel Sambuc     logging::log(logging::level_info, "file", 123, "A message");
80*11be35a1SLionel Sambuc 
81*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 15, 4, 91);
82*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(fs::path("/some/dir/foobar.20110221-181500.log"),
83*11be35a1SLionel Sambuc                    logging::generate_log_name(fs::path("/some/dir"), "foobar"));
84*11be35a1SLionel Sambuc }
85*11be35a1SLionel Sambuc 
86*11be35a1SLionel Sambuc 
87*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(log);
ATF_TEST_CASE_BODY(log)88*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(log)
89*11be35a1SLionel Sambuc {
90*11be35a1SLionel Sambuc     logging::set_inmemory();
91*11be35a1SLionel Sambuc 
92*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 10, 0, 0);
93*11be35a1SLionel Sambuc     logging::log(logging::level_debug, "f1", 1, "Debug message");
94*11be35a1SLionel Sambuc 
95*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 10, 1, 987654);
96*11be35a1SLionel Sambuc     logging::log(logging::level_error, "f2", 2, "Error message");
97*11be35a1SLionel Sambuc 
98*11be35a1SLionel Sambuc     logging::set_persistency("debug", fs::path("test.log"));
99*11be35a1SLionel Sambuc 
100*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 10, 2, 123);
101*11be35a1SLionel Sambuc     logging::log(logging::level_info, "f3", 3, "Info message");
102*11be35a1SLionel Sambuc 
103*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 10, 3, 456);
104*11be35a1SLionel Sambuc     logging::log(logging::level_warning, "f4", 4, "Warning message");
105*11be35a1SLionel Sambuc 
106*11be35a1SLionel Sambuc     std::ifstream input("test.log");
107*11be35a1SLionel Sambuc     ATF_REQUIRE(input);
108*11be35a1SLionel Sambuc 
109*11be35a1SLionel Sambuc     const pid_t pid = ::getpid();
110*11be35a1SLionel Sambuc 
111*11be35a1SLionel Sambuc     std::string line;
112*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
113*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
114*11be35a1SLionel Sambuc         (F("20110221-181000 D %s f1:1: Debug message") % pid).str(), line);
115*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
116*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
117*11be35a1SLionel Sambuc         (F("20110221-181001 E %s f2:2: Error message") % pid).str(), line);
118*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
119*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
120*11be35a1SLionel Sambuc         (F("20110221-181002 I %s f3:3: Info message") % pid).str(), line);
121*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
122*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
123*11be35a1SLionel Sambuc         (F("20110221-181003 W %s f4:4: Warning message") % pid).str(), line);
124*11be35a1SLionel Sambuc }
125*11be35a1SLionel Sambuc 
126*11be35a1SLionel Sambuc 
127*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(set_persistency__no_backlog);
ATF_TEST_CASE_BODY(set_persistency__no_backlog)128*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(set_persistency__no_backlog)
129*11be35a1SLionel Sambuc {
130*11be35a1SLionel Sambuc     logging::set_persistency("debug", fs::path("test.log"));
131*11be35a1SLionel Sambuc 
132*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 2, 21, 18, 20, 0, 654321);
133*11be35a1SLionel Sambuc     logging::log(logging::level_debug, "file", 123, "Debug message");
134*11be35a1SLionel Sambuc 
135*11be35a1SLionel Sambuc     std::ifstream input("test.log");
136*11be35a1SLionel Sambuc     ATF_REQUIRE(input);
137*11be35a1SLionel Sambuc 
138*11be35a1SLionel Sambuc     const pid_t pid = ::getpid();
139*11be35a1SLionel Sambuc 
140*11be35a1SLionel Sambuc     std::string line;
141*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
142*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
143*11be35a1SLionel Sambuc         (F("20110221-182000 D %s file:123: Debug message") % pid).str(), line);
144*11be35a1SLionel Sambuc }
145*11be35a1SLionel Sambuc 
146*11be35a1SLionel Sambuc 
147*11be35a1SLionel Sambuc /// Creates a log for testing purposes, buffering messages on start.
148*11be35a1SLionel Sambuc ///
149*11be35a1SLionel Sambuc /// \param level The level of the desired log.
150*11be35a1SLionel Sambuc /// \param path The output file.
151*11be35a1SLionel Sambuc static void
create_log(const std::string & level,const std::string & path)152*11be35a1SLionel Sambuc create_log(const std::string& level, const std::string& path)
153*11be35a1SLionel Sambuc {
154*11be35a1SLionel Sambuc     logging::set_inmemory();
155*11be35a1SLionel Sambuc 
156*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 3, 19, 11, 40, 0, 100);
157*11be35a1SLionel Sambuc     logging::log(logging::level_debug, "file1", 11, "Debug 1");
158*11be35a1SLionel Sambuc 
159*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 3, 19, 11, 40, 1, 200);
160*11be35a1SLionel Sambuc     logging::log(logging::level_error, "file2", 22, "Error 1");
161*11be35a1SLionel Sambuc 
162*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 3, 19, 11, 40, 2, 300);
163*11be35a1SLionel Sambuc     logging::log(logging::level_info, "file3", 33, "Info 1");
164*11be35a1SLionel Sambuc 
165*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 3, 19, 11, 40, 3, 400);
166*11be35a1SLionel Sambuc     logging::log(logging::level_warning, "file4", 44, "Warning 1");
167*11be35a1SLionel Sambuc 
168*11be35a1SLionel Sambuc     logging::set_persistency(level, fs::path(path));
169*11be35a1SLionel Sambuc 
170*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 3, 19, 11, 40, 4, 500);
171*11be35a1SLionel Sambuc     logging::log(logging::level_debug, "file1", 11, "Debug 2");
172*11be35a1SLionel Sambuc 
173*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 3, 19, 11, 40, 5, 600);
174*11be35a1SLionel Sambuc     logging::log(logging::level_error, "file2", 22, "Error 2");
175*11be35a1SLionel Sambuc 
176*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 3, 19, 11, 40, 6, 700);
177*11be35a1SLionel Sambuc     logging::log(logging::level_info, "file3", 33, "Info 2");
178*11be35a1SLionel Sambuc 
179*11be35a1SLionel Sambuc     datetime::set_mock_now(2011, 3, 19, 11, 40, 7, 800);
180*11be35a1SLionel Sambuc     logging::log(logging::level_warning, "file4", 44, "Warning 2");
181*11be35a1SLionel Sambuc }
182*11be35a1SLionel Sambuc 
183*11be35a1SLionel Sambuc 
184*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(set_persistency__some_backlog__debug);
ATF_TEST_CASE_BODY(set_persistency__some_backlog__debug)185*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(set_persistency__some_backlog__debug)
186*11be35a1SLionel Sambuc {
187*11be35a1SLionel Sambuc     create_log("debug", "test.log");
188*11be35a1SLionel Sambuc 
189*11be35a1SLionel Sambuc     std::ifstream input("test.log");
190*11be35a1SLionel Sambuc     ATF_REQUIRE(input);
191*11be35a1SLionel Sambuc 
192*11be35a1SLionel Sambuc     const pid_t pid = ::getpid();
193*11be35a1SLionel Sambuc 
194*11be35a1SLionel Sambuc     std::string line;
195*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
196*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
197*11be35a1SLionel Sambuc         (F("20110319-114000 D %s file1:11: Debug 1") % pid).str(), line);
198*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
199*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
200*11be35a1SLionel Sambuc         (F("20110319-114001 E %s file2:22: Error 1") % pid).str(), line);
201*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
202*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
203*11be35a1SLionel Sambuc         (F("20110319-114002 I %s file3:33: Info 1") % pid).str(), line);
204*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
205*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
206*11be35a1SLionel Sambuc         (F("20110319-114003 W %s file4:44: Warning 1") % pid).str(), line);
207*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
208*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
209*11be35a1SLionel Sambuc         (F("20110319-114004 D %s file1:11: Debug 2") % pid).str(), line);
210*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
211*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
212*11be35a1SLionel Sambuc         (F("20110319-114005 E %s file2:22: Error 2") % pid).str(), line);
213*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
214*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
215*11be35a1SLionel Sambuc         (F("20110319-114006 I %s file3:33: Info 2") % pid).str(), line);
216*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
217*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
218*11be35a1SLionel Sambuc         (F("20110319-114007 W %s file4:44: Warning 2") % pid).str(), line);
219*11be35a1SLionel Sambuc }
220*11be35a1SLionel Sambuc 
221*11be35a1SLionel Sambuc 
222*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(set_persistency__some_backlog__error);
ATF_TEST_CASE_BODY(set_persistency__some_backlog__error)223*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(set_persistency__some_backlog__error)
224*11be35a1SLionel Sambuc {
225*11be35a1SLionel Sambuc     create_log("error", "test.log");
226*11be35a1SLionel Sambuc 
227*11be35a1SLionel Sambuc     std::ifstream input("test.log");
228*11be35a1SLionel Sambuc     ATF_REQUIRE(input);
229*11be35a1SLionel Sambuc 
230*11be35a1SLionel Sambuc     const pid_t pid = ::getpid();
231*11be35a1SLionel Sambuc 
232*11be35a1SLionel Sambuc     std::string line;
233*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
234*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
235*11be35a1SLionel Sambuc         (F("20110319-114001 E %s file2:22: Error 1") % pid).str(), line);
236*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
237*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
238*11be35a1SLionel Sambuc         (F("20110319-114005 E %s file2:22: Error 2") % pid).str(), line);
239*11be35a1SLionel Sambuc }
240*11be35a1SLionel Sambuc 
241*11be35a1SLionel Sambuc 
242*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(set_persistency__some_backlog__info);
ATF_TEST_CASE_BODY(set_persistency__some_backlog__info)243*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(set_persistency__some_backlog__info)
244*11be35a1SLionel Sambuc {
245*11be35a1SLionel Sambuc     create_log("info", "test.log");
246*11be35a1SLionel Sambuc 
247*11be35a1SLionel Sambuc     std::ifstream input("test.log");
248*11be35a1SLionel Sambuc     ATF_REQUIRE(input);
249*11be35a1SLionel Sambuc 
250*11be35a1SLionel Sambuc     const pid_t pid = ::getpid();
251*11be35a1SLionel Sambuc 
252*11be35a1SLionel Sambuc     std::string line;
253*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
254*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
255*11be35a1SLionel Sambuc         (F("20110319-114001 E %s file2:22: Error 1") % pid).str(), line);
256*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
257*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
258*11be35a1SLionel Sambuc         (F("20110319-114002 I %s file3:33: Info 1") % pid).str(), line);
259*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
260*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
261*11be35a1SLionel Sambuc         (F("20110319-114003 W %s file4:44: Warning 1") % pid).str(), line);
262*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
263*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
264*11be35a1SLionel Sambuc         (F("20110319-114005 E %s file2:22: Error 2") % pid).str(), line);
265*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
266*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
267*11be35a1SLionel Sambuc         (F("20110319-114006 I %s file3:33: Info 2") % pid).str(), line);
268*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
269*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
270*11be35a1SLionel Sambuc         (F("20110319-114007 W %s file4:44: Warning 2") % pid).str(), line);
271*11be35a1SLionel Sambuc }
272*11be35a1SLionel Sambuc 
273*11be35a1SLionel Sambuc 
274*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(set_persistency__some_backlog__warning);
ATF_TEST_CASE_BODY(set_persistency__some_backlog__warning)275*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(set_persistency__some_backlog__warning)
276*11be35a1SLionel Sambuc {
277*11be35a1SLionel Sambuc     create_log("warning", "test.log");
278*11be35a1SLionel Sambuc 
279*11be35a1SLionel Sambuc     std::ifstream input("test.log");
280*11be35a1SLionel Sambuc     ATF_REQUIRE(input);
281*11be35a1SLionel Sambuc 
282*11be35a1SLionel Sambuc     const pid_t pid = ::getpid();
283*11be35a1SLionel Sambuc 
284*11be35a1SLionel Sambuc     std::string line;
285*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
286*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
287*11be35a1SLionel Sambuc         (F("20110319-114001 E %s file2:22: Error 1") % pid).str(), line);
288*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
289*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
290*11be35a1SLionel Sambuc         (F("20110319-114003 W %s file4:44: Warning 1") % pid).str(), line);
291*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
292*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
293*11be35a1SLionel Sambuc         (F("20110319-114005 E %s file2:22: Error 2") % pid).str(), line);
294*11be35a1SLionel Sambuc     ATF_REQUIRE(std::getline(input, line).good());
295*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
296*11be35a1SLionel Sambuc         (F("20110319-114007 W %s file4:44: Warning 2") % pid).str(), line);
297*11be35a1SLionel Sambuc }
298*11be35a1SLionel Sambuc 
299*11be35a1SLionel Sambuc 
300*11be35a1SLionel Sambuc ATF_TEST_CASE(set_persistency__fail);
ATF_TEST_CASE_HEAD(set_persistency__fail)301*11be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(set_persistency__fail)
302*11be35a1SLionel Sambuc {
303*11be35a1SLionel Sambuc     set_md_var("require.user", "unprivileged");
304*11be35a1SLionel Sambuc }
ATF_TEST_CASE_BODY(set_persistency__fail)305*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(set_persistency__fail)
306*11be35a1SLionel Sambuc {
307*11be35a1SLionel Sambuc     ATF_REQUIRE_THROW_RE(std::range_error, "'foobar'",
308*11be35a1SLionel Sambuc                          logging::set_persistency("foobar", fs::path("log")));
309*11be35a1SLionel Sambuc 
310*11be35a1SLionel Sambuc     fs::mkdir(fs::path("dir"), 0644);
311*11be35a1SLionel Sambuc     ATF_REQUIRE_THROW_RE(std::runtime_error, "dir/fail.log",
312*11be35a1SLionel Sambuc                          logging::set_persistency("debug",
313*11be35a1SLionel Sambuc                                                   fs::path("dir/fail.log")));
314*11be35a1SLionel Sambuc }
315*11be35a1SLionel Sambuc 
316*11be35a1SLionel Sambuc 
ATF_INIT_TEST_CASES(tcs)317*11be35a1SLionel Sambuc ATF_INIT_TEST_CASES(tcs)
318*11be35a1SLionel Sambuc {
319*11be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, generate_log_name__before_log);
320*11be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, generate_log_name__after_log);
321*11be35a1SLionel Sambuc 
322*11be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, log);
323*11be35a1SLionel Sambuc 
324*11be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, set_persistency__no_backlog);
325*11be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, set_persistency__some_backlog__debug);
326*11be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, set_persistency__some_backlog__error);
327*11be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, set_persistency__some_backlog__info);
328*11be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, set_persistency__some_backlog__warning);
329*11be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, set_persistency__fail);
330*11be35a1SLionel Sambuc }
331