Improve the process for GNU tools
[minix3.git] / external / bsd / kyua-cli / dist / utils / logging / macros_test.cpp
blob808d5e1847482d6406e7d4e929f806a17deb9122
1 // Copyright 2011 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
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"
31 #include <fstream>
32 #include <string>
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);
50 LD("Debug message");
52 std::ifstream input("test.log");
53 ATF_REQUIRE(input);
55 std::string line;
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);
66 LE("Error message");
68 std::ifstream input("test.log");
69 ATF_REQUIRE(input);
71 std::string line;
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);
82 LI("Info message");
84 std::ifstream input("test.log");
85 ATF_REQUIRE(input);
87 std::string line;
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");
101 ATF_REQUIRE(input);
103 std::string line;
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);