Add unit-test for dpl log.cpp 82/314282/7
authortranthanhtung2001 <tran.tung@samsung.com>
Wed, 10 Jul 2024 01:23:35 +0000 (08:23 +0700)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 15 Jul 2024 10:42:07 +0000 (10:42 +0000)
Change-Id: I8792e0263409b514d93468f35a627343c05375d6
Signed-off-by: tranthanhtung2001 <tran.tung@samsung.com>
unit-tests/CMakeLists.txt
unit-tests/test_dpl_log.cpp [new file with mode: 0644]

index 65a1efc..8ba8c02 100644 (file)
@@ -62,6 +62,7 @@ SET(UNIT_TESTS_SOURCES
     test_constant.cpp
     test_common.cpp
     test_dpl_journal_log_provider.cpp
+    test_dpl_log.cpp
     test_dpl_old_style_log_provider.cpp
     test_vcore_base64.cpp
     test_vcore_cert_store_type.cpp
diff --git a/unit-tests/test_dpl_log.cpp b/unit-tests/test_dpl_log.cpp
new file mode 100644 (file)
index 0000000..bd9cd6f
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2024 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 "test_macros.h"
+#include "dpl/log/log.h"
+
+using namespace VcoreDPL;
+using namespace Log;
+using namespace std;
+
+enum LOG_LEVEL {
+       None,
+       Error,
+       Warning,
+       Info,
+       Debug,
+       Pedantic
+};
+
+BOOST_AUTO_TEST_SUITE(DPL_LOG_TEST)
+
+POSITIVE_TEST_CASE(T__select_provider)
+{
+       LogSystem *logSystem = new LogSystem();
+
+       BOOST_CHECK_NO_THROW(logSystem->SelectProvider("JOURNALD"));
+
+       BOOST_CHECK_NO_THROW(logSystem->SelectProvider("DLOG"));
+
+       BOOST_CHECK_NO_THROW(logSystem->SelectProvider("CONSOLE"));
+
+       delete logSystem;
+}
+
+NEGATIVE_TEST_CASE(T__select_provider_exception_out_of_range_name)
+{
+       LogSystem *logSystem = new LogSystem();
+
+       BOOST_CHECK_THROW(logSystem->SelectProvider("ABCD"), std::out_of_range);
+
+       delete logSystem;
+}
+
+POSITIVE_TEST_CASE(T__set_log_level)
+{
+       LogSystem *logSystem = new LogSystem();
+
+       logSystem->SetLogLevel("0");
+       BOOST_CHECK_EQUAL(LOG_LEVEL::None, (int)logSystem->GetLogLevel());
+
+       logSystem->SetLogLevel("1");
+       BOOST_CHECK_EQUAL(LOG_LEVEL::Error, (int)logSystem->GetLogLevel());
+
+       logSystem->SetLogLevel("2");
+       BOOST_CHECK_EQUAL(LOG_LEVEL::Warning, (int)logSystem->GetLogLevel());
+
+       logSystem->SetLogLevel("3");
+       BOOST_CHECK_EQUAL(LOG_LEVEL::Info, (int)logSystem->GetLogLevel());
+
+       logSystem->SetLogLevel("4");
+       BOOST_CHECK_EQUAL(LOG_LEVEL::Debug, (int)logSystem->GetLogLevel());
+
+       logSystem->SetLogLevel("5");
+       BOOST_CHECK_EQUAL(LOG_LEVEL::Pedantic, (int)logSystem->GetLogLevel());
+
+       delete logSystem;
+}
+
+NEGATIVE_TEST_CASE(T__set_log_level_wrong_args)
+{
+       LogSystem *logSystem = new LogSystem();
+
+       logSystem->SetLogLevel("-1");
+       BOOST_CHECK_EQUAL(LOG_LEVEL::None, (int)logSystem->GetLogLevel());
+
+       logSystem->SetLogLevel("10");
+       BOOST_CHECK_EQUAL(LOG_LEVEL::Pedantic, (int)logSystem->GetLogLevel());
+
+       logSystem->SetLogLevel("absf");
+       BOOST_CHECK_EQUAL(LOG_LEVEL::Debug, (int)logSystem->GetLogLevel());
+
+       delete logSystem;
+}
+
+BOOST_AUTO_TEST_SUITE_END()