1 // Copyright 2011 Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "utils/logging/macros.hpp"
34 #include <atf-c++.hpp>
36 #include "utils/datetime.hpp"
37 #include "utils/fs/path.hpp"
38 #include "utils/logging/operations.hpp"
40 namespace datetime
= utils::datetime
;
41 namespace fs
= utils::fs
;
42 namespace logging
= utils::logging
;
45 ATF_TEST_CASE_WITHOUT_HEAD(ld
);
46 ATF_TEST_CASE_BODY(ld
)
48 logging::set_persistency("debug", fs::path("test.log"));
49 datetime::set_mock_now(2011, 2, 21, 18, 30, 0, 0);
52 std::ifstream
input("test.log");
56 ATF_REQUIRE(std::getline(input
, line
).good());
57 ATF_REQUIRE_MATCH("20110221-183000 D .*: Debug message", line
);
61 ATF_TEST_CASE_WITHOUT_HEAD(le
);
62 ATF_TEST_CASE_BODY(le
)
64 logging::set_persistency("debug", fs::path("test.log"));
65 datetime::set_mock_now(2011, 2, 21, 18, 30, 0, 0);
68 std::ifstream
input("test.log");
72 ATF_REQUIRE(std::getline(input
, line
).good());
73 ATF_REQUIRE_MATCH("20110221-183000 E .*: Error message", line
);
77 ATF_TEST_CASE_WITHOUT_HEAD(li
);
78 ATF_TEST_CASE_BODY(li
)
80 logging::set_persistency("debug", fs::path("test.log"));
81 datetime::set_mock_now(2011, 2, 21, 18, 30, 0, 0);
84 std::ifstream
input("test.log");
88 ATF_REQUIRE(std::getline(input
, line
).good());
89 ATF_REQUIRE_MATCH("20110221-183000 I .*: Info message", line
);
93 ATF_TEST_CASE_WITHOUT_HEAD(lw
);
94 ATF_TEST_CASE_BODY(lw
)
96 logging::set_persistency("debug", fs::path("test.log"));
97 datetime::set_mock_now(2011, 2, 21, 18, 30, 0, 0);
98 LW("Warning message");
100 std::ifstream
input("test.log");
104 ATF_REQUIRE(std::getline(input
, line
).good());
105 ATF_REQUIRE_MATCH("20110221-183000 W .*: Warning message", line
);
109 ATF_INIT_TEST_CASES(tcs
)
111 ATF_ADD_TEST_CASE(tcs
, ld
);
112 ATF_ADD_TEST_CASE(tcs
, le
);
113 ATF_ADD_TEST_CASE(tcs
, li
);
114 ATF_ADD_TEST_CASE(tcs
, lw
);