Test src/common/log/ module 24/238024/14
authorMateusz Cegielka <m.cegielka@samsung.com>
Tue, 7 Jul 2020 13:16:58 +0000 (15:16 +0200)
committerMateusz Cegielka <m.cegielka@samsung.com>
Mon, 20 Jul 2020 11:42:47 +0000 (13:42 +0200)
Change-Id: Ie0d96e84d8f2de246415e614a37e33c89b256191

test/unit-tests/CMakeLists.txt
test/unit-tests/test_common_log.cpp [new file with mode: 0644]

index b1de433..7f733db 100644 (file)
@@ -30,6 +30,7 @@ SET(TESTS_SOURCES
     ${ASKUSER_TESTS_PATH}/colour_log_formatter.cpp
     ${ASKUSER_TESTS_PATH}/main.cpp
     ${ASKUSER_TESTS_PATH}/test_common_exception.cpp
+    ${ASKUSER_TESTS_PATH}/test_common_log.cpp
     ${ASKUSER_TESTS_PATH}/test_common_policy.cpp
     )
 
diff --git a/test/unit-tests/test_common_log.cpp b/test/unit-tests/test_common_log.cpp
new file mode 100644 (file)
index 0000000..b85524c
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#include <boost/test/results_reporter.hpp>
+
+#include <log/alog.h>
+
+#include "macros.h"
+
+namespace {
+
+void requireConfigurableLevel(int level, const char* name) {
+    setenv("ASKUSER_LOG_LEVEL", name, true);
+    init_agent_log();
+    BOOST_REQUIRE(__alog_level == level);
+}
+
+}
+
+BOOST_AUTO_TEST_SUITE(TESTS_ASKUSER_COMMON_LOG)
+
+POSITIVE_TEST_CASE(askuser_common_log_config)
+{
+    requireConfigurableLevel(LOG_EMERG,   "LOG_EMERG");
+    requireConfigurableLevel(LOG_ALERT,   "LOG_ALERT");
+    requireConfigurableLevel(LOG_CRIT,    "LOG_CRIT");
+    requireConfigurableLevel(LOG_ERR,     "LOG_ERR");
+    requireConfigurableLevel(LOG_WARNING, "LOG_WARNING");
+    requireConfigurableLevel(LOG_NOTICE,  "LOG_NOTICE");
+    requireConfigurableLevel(LOG_INFO,    "LOG_INFO");
+    requireConfigurableLevel(LOG_DEBUG,   "LOG_DEBUG");
+}
+
+NEGATIVE_TEST_CASE(askuser_common_log_config_invalid)
+{
+    requireConfigurableLevel(LOG_ERR, "SOME_INVALID_VALUE");
+}
+
+NEGATIVE_TEST_CASE(askuser_common_log_config_missing)
+{
+    unsetenv("ASKUSER_LOG_LEVEL");
+    init_agent_log();
+    BOOST_REQUIRE(__alog_level == LOG_ERR);
+}
+
+BOOST_AUTO_TEST_SUITE_END()