Unification of import methods in gstore
[platform/core/security/key-manager.git] / tests / test_log-provider.cpp
1 /*
2  *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  */
16 #include <boost/test/unit_test.hpp>
17
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>
22
23 using namespace CKM;
24 using namespace CKM::Log;
25
26 namespace {
27
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)
35 });
36
37 void testProvider(AbstractLogProvider &provider)
38 {
39         for (auto level : levels)
40                 BOOST_REQUIRE_NO_THROW(provider.Log(
41                         level, "message", __FILE__, __LINE__, __func__));
42
43         BOOST_REQUIRE_NO_THROW(provider.SetTag("tag"));
44 }
45
46 } // namespace anonymous
47
48 BOOST_AUTO_TEST_SUITE(LOG_PROVIDER_TEST)
49
50 BOOST_AUTO_TEST_CASE(oldstyle_backend)
51 {
52         OldStyleLogProvider provider;
53
54         testProvider(provider);
55 }
56
57 BOOST_AUTO_TEST_CASE(journal_backend)
58 {
59         JournalLogProvider provider;
60
61         testProvider(provider);
62 }
63
64 BOOST_AUTO_TEST_CASE(dlog_backend)
65 {
66         DLOGLogProvider provider;
67
68         testProvider(provider);
69 }
70
71 BOOST_AUTO_TEST_CASE(log_system)
72 {
73         LogSystem system;
74
75         system.AddProvider(new OldStyleLogProvider);
76         system.AddProvider(new JournalLogProvider);
77         system.AddProvider(new DLOGLogProvider);
78
79         for (auto level : levels)
80                 BOOST_REQUIRE_NO_THROW(system.Log(
81                         level, "message", __FILE__, __LINE__, __func__));
82
83         BOOST_REQUIRE_NO_THROW(system.SetTag("Test"));
84
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);
92
93         BOOST_REQUIRE_NO_THROW(system.SelectProvider("DLOG"));
94         BOOST_REQUIRE_NO_THROW(system.SelectProvider("JOURNALD"));
95 }
96
97 BOOST_AUTO_TEST_SUITE_END()