2 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
16 #include <boost/test/unit_test.hpp>
18 #include <dpl/log/old_style_log_provider.h>
19 #include <dpl/log/journal_log_provider.h>
20 #include <dpl/log/dlog_log_provider.h>
21 #include <dpl/log/log.h>
24 using namespace CKM::Log;
28 std::vector<AbstractLogProvider::LogLevel> levels({
29 AbstractLogProvider::LogLevel::Error,
30 AbstractLogProvider::LogLevel::Warning,
31 AbstractLogProvider::LogLevel::Info,
32 AbstractLogProvider::LogLevel::Debug,
33 AbstractLogProvider::LogLevel::Pedantic,
34 static_cast<AbstractLogProvider::LogLevel>(999)
37 void testProvider(AbstractLogProvider &provider)
39 for (auto level : levels)
40 BOOST_REQUIRE_NO_THROW(provider.Log(
41 level, "message", __FILE__, __LINE__, __func__));
43 BOOST_REQUIRE_NO_THROW(provider.SetTag("tag"));
46 } // namespace anonymous
48 BOOST_AUTO_TEST_SUITE(LOG_PROVIDER_TEST)
50 BOOST_AUTO_TEST_CASE(oldstyle_backend)
52 OldStyleLogProvider provider;
54 testProvider(provider);
57 BOOST_AUTO_TEST_CASE(journal_backend)
59 JournalLogProvider provider;
61 testProvider(provider);
64 BOOST_AUTO_TEST_CASE(dlog_backend)
66 DLOGLogProvider provider;
68 testProvider(provider);
71 BOOST_AUTO_TEST_CASE(log_system)
75 system.AddProvider(new OldStyleLogProvider);
76 system.AddProvider(new JournalLogProvider);
77 system.AddProvider(new DLOGLogProvider);
79 for (auto level : levels)
80 BOOST_REQUIRE_NO_THROW(system.Log(
81 level, "message", __FILE__, __LINE__, __func__));
83 BOOST_REQUIRE_NO_THROW(system.SetTag("Test"));
85 BOOST_REQUIRE_NO_THROW(system.SetLogLevel("5"));
86 BOOST_REQUIRE_NO_THROW(system.SetLogLevel("4"));
87 BOOST_REQUIRE_NO_THROW(system.SetLogLevel("3"));
88 BOOST_REQUIRE_NO_THROW(system.SetLogLevel("2"));
89 BOOST_REQUIRE_NO_THROW(system.SetLogLevel("1"));
90 BOOST_REQUIRE_NO_THROW(system.SetLogLevel("0"));
91 BOOST_REQUIRE(system.GetLogLevel() == AbstractLogProvider::LogLevel::None);
93 BOOST_REQUIRE_NO_THROW(system.SelectProvider("DLOG"));
94 BOOST_REQUIRE_NO_THROW(system.SelectProvider("JOURNALD"));
97 BOOST_AUTO_TEST_SUITE_END()