From: Mateusz Cegielka Date: Tue, 7 Jul 2020 13:16:58 +0000 (+0200) Subject: Test src/common/log/ module X-Git-Tag: accepted/tizen/unified/20200807.141036~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F24%2F238024%2F14;p=platform%2Fcore%2Fsecurity%2Faskuser.git Test src/common/log/ module Change-Id: Ie0d96e84d8f2de246415e614a37e33c89b256191 --- 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()