Add unit-test for dpl journal log provider 14/314014/11
authortran.tung <tran.tung@samsung.com>
Thu, 4 Jul 2024 04:04:11 +0000 (11:04 +0700)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 15 Jul 2024 08:29:51 +0000 (08:29 +0000)
Change-Id: I10ba4639ca26fecdd1179168da3e2276ceb54b91
Signed-off-by: tran.tung <tran.tung@samsung.com>
unit-tests/CMakeLists.txt
unit-tests/test_dpl_journal_log_provider.cpp [new file with mode: 0644]

index cb7fd1313b1dd2dec4704574868470042684ad00..e98d594d7369139cd1825e2f5ebfee1d0d09826b 100644 (file)
@@ -73,6 +73,7 @@ SET(UNIT_TESTS_SOURCES
     test_vcore_signature_reader.cpp
     test_cert_server_db.cpp
     test_cert_server_logic.cpp
+    test_dpl_journal_log_provider.cpp
     colour_log_formatter.cpp
     ${PROJECT_SOURCE_DIR}/src/server/src/cert-server-logic.c
     ${PROJECT_SOURCE_DIR}/src/server/src/cert-server-db.c
diff --git a/unit-tests/test_dpl_journal_log_provider.cpp b/unit-tests/test_dpl_journal_log_provider.cpp
new file mode 100644 (file)
index 0000000..7eb35f5
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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/journal_log_provider.h"
+#include <systemd/sd-journal.h>
+
+using namespace VcoreDPL;
+using namespace Log;
+
+#define LEVEL AbstractLogProvider::LogLevel
+
+BOOST_AUTO_TEST_SUITE(DPL_JOURNAL_LOG_PROVIDER_TEST)
+
+POSITIVE_TEST_CASE(T_journal_log_provider_log)
+{
+       JournalLogProvider *journalLogProvider = new JournalLogProvider();
+       const char *str1 = "abc@samsung.com";
+
+       BOOST_CHECK_NO_THROW(journalLogProvider->Log(LEVEL::Error, str1, __FILE__, __LINE__, __FUNCTION__));
+
+       BOOST_CHECK_NO_THROW(journalLogProvider->Log(LEVEL::Warning, NULL, __FILE__, __LINE__, __FUNCTION__));
+
+       BOOST_CHECK_NO_THROW(journalLogProvider->Log(LEVEL::Info, str1, NULL, __LINE__, __FUNCTION__));
+
+       BOOST_CHECK_NO_THROW(journalLogProvider->Log(LEVEL::Debug, str1, __FILE__, -100, __FUNCTION__));
+
+       BOOST_CHECK_NO_THROW(journalLogProvider->Log(LEVEL::Pedantic, str1, __FILE__, __LINE__, NULL));
+
+       delete journalLogProvider;
+}
+
+BOOST_AUTO_TEST_SUITE_END()