Add logging classes to unit tests 67/234167/14
authorTomasz Swierczek <t.swierczek@samsung.com>
Fri, 22 May 2020 06:02:04 +0000 (08:02 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Wed, 24 Jun 2020 12:18:46 +0000 (14:18 +0200)
Change-Id: Ife01f17db01dc2657c005ab3d8b741826ce6ed17

test/CMakeLists.txt
test/test_log.cpp [new file with mode: 0644]

index 5f98a91b22395cf96f285241dfd112bc2f831feb..d1c645f766c09cd97afc5a501ffea089342395c4 100644 (file)
@@ -51,10 +51,11 @@ SET(TARGET_SM_PERFORMANCE_TESTS "security-manager-performance-tests")
 
 SET(SM_TESTS_SOURCES
     ${SM_TEST_SRC}/colour_log_formatter.cpp
+    ${SM_TEST_SRC}/privilege_db_fixture.cpp
     ${SM_TEST_SRC}/security-manager-tests.cpp
+    ${SM_TEST_SRC}/test_log.cpp
     ${SM_TEST_SRC}/test_filesystem.cpp
     ${SM_TEST_SRC}/test_file-lock.cpp
-    ${SM_TEST_SRC}/privilege_db_fixture.cpp
     ${SM_TEST_SRC}/test_privilege_db_transactions.cpp
     ${SM_TEST_SRC}/test_privilege_db_app_pkg_getters.cpp
     ${SM_TEST_SRC}/test_privilege_db_add_app.cpp
@@ -77,8 +78,10 @@ SET(SM_TESTS_SOURCES
     ${DPL_PATH}/db/src/sql_connection.cpp
     ${DPL_PATH}/db/src/naive_synchronization_object.cpp
     ${DPL_PATH}/log/src/abstract_log_provider.cpp
+    ${DPL_PATH}/log/src/dlog_log_provider.cpp
     ${DPL_PATH}/log/src/log.cpp
     ${DPL_PATH}/log/src/old_style_log_provider.cpp
+    ${DPL_PATH}/log/src/sd_journal_provider.cpp
     ${PROJECT_SOURCE_DIR}/src/common/config-file.cpp
     ${PROJECT_SOURCE_DIR}/src/common/credentials.cpp
     ${PROJECT_SOURCE_DIR}/src/common/filesystem.cpp
diff --git a/test/test_log.cpp b/test/test_log.cpp
new file mode 100644 (file)
index 0000000..5d4c17c
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ *  Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Tomasz Swierczek <t.swierczek@samsung.com>
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ *
+ *
+ * @file        test_log.cpp
+ * @author      Tomasz Ćšwierczek (t.swierczek@samsung.com)
+ * @version     1.0
+ * @brief       Tests of logging classes
+ */
+
+#include <string>
+
+#include <dpl/log/dlog_log_provider.h>
+#include <dpl/log/old_style_log_provider.h>
+#include <dpl/log/sd_journal_provider.h>
+#include <testmacros.h>
+
+using namespace SecurityManager;
+
+BOOST_AUTO_TEST_SUITE(LOG_TEST)
+
+POSITIVE_TEST_CASE(T1111_dlog)
+{
+    Log::DLOGLogProvider logger;
+    BOOST_REQUIRE_NO_THROW(logger.SetTag("UnitTestTag"));
+    BOOST_REQUIRE_NO_THROW(logger.Debug("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Info("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Warning("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Error("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Pedantic("message", "file", 1, "function"));
+}
+
+POSITIVE_TEST_CASE(T1112_sd_journal)
+{
+    Log::SdJournalProvider logger;
+    BOOST_REQUIRE_NO_THROW(logger.SetTag("UnitTestTag"));
+    BOOST_REQUIRE_NO_THROW(logger.Debug("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Info("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Warning("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Error("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Pedantic("message", "file", 1, "function"));
+}
+
+POSITIVE_TEST_CASE(T1113_old_style_with_err)
+{
+    Log::OldStyleLogProvider logger(true, true, true, true, true, true);
+    BOOST_REQUIRE_NO_THROW(logger.Debug("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Info("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Warning("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Error("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Pedantic("message", "file", 1, "function"));
+}
+
+POSITIVE_TEST_CASE(T1113_old_style_no_err)
+{
+    Log::OldStyleLogProvider logger(true, true, true, true, true, false);
+    BOOST_REQUIRE_NO_THROW(logger.Debug("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Info("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Warning("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Error("message", "file", 1, "function"));
+    BOOST_REQUIRE_NO_THROW(logger.Pedantic("message", "file", 1, "function"));
+}
+
+BOOST_AUTO_TEST_SUITE_END()