From 43f64de29db5217cdb13d1c0b069c2f904d6ac65 Mon Sep 17 00:00:00 2001 From: Mateusz Cegielka Date: Tue, 7 Jul 2020 15:16:58 +0200 Subject: [PATCH] Test src/common/log/ module Change-Id: Ie0d96e84d8f2de246415e614a37e33c89b256191 --- test/unit-tests/CMakeLists.txt | 1 + test/unit-tests/test_common_log.cpp | 59 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 test/unit-tests/test_common_log.cpp diff --git a/test/unit-tests/CMakeLists.txt b/test/unit-tests/CMakeLists.txt index b1de433..7f733db 100644 --- a/test/unit-tests/CMakeLists.txt +++ b/test/unit-tests/CMakeLists.txt @@ -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 index 0000000..b85524c --- /dev/null +++ b/test/unit-tests/test_common_log.cpp @@ -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 + +#include + +#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() -- 2.34.1