--- /dev/null
+/*
+ * 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/old_style_log_provider.h"
+#include <string>
+#include <iostream>
+#include <unistd.h>
+#include <fcntl.h>
+
+using namespace VcoreDPL;
+using namespace Log;
+using namespace std;
+
+#define LEVEL AbstractLogProvider::LogLevel
+
+string getLogFromCmd(
+ LEVEL level,
+ const char *message,
+ int line,
+ const char *function)
+{
+ OldStyleLogProvider *oldStyleLogProvider = new OldStyleLogProvider();
+
+ int pipefd[2];
+
+ int ret = pipe(pipefd);
+ if (ret == -1)
+ return "";
+
+ int saved_stdout = dup(STDOUT_FILENO);
+
+ dup2(pipefd[1], STDOUT_FILENO);
+ close(pipefd[1]);
+
+ oldStyleLogProvider->Log(level, message, __FILE__, line, function);
+
+ dup2(saved_stdout, STDOUT_FILENO);
+ close(saved_stdout);
+
+ char buffer[1 << 10];
+ ssize_t count = read(pipefd[0], buffer, sizeof(buffer) - 1);
+ buffer[count] = '\0';
+
+ close(pipefd[0]);
+
+ string output(buffer);
+
+ delete oldStyleLogProvider;
+
+ return output;
+}
+
+BOOST_AUTO_TEST_SUITE(DPL_OLD_STYLE_LOG_PROVIDER_TEST)
+
+POSITIVE_TEST_CASE(T_old_style_log_provider_log)
+{
+ const char *str = "ABCDEF";
+ string message = getLogFromCmd(LEVEL::Error, str, 1, "Log");
+
+ BOOST_CHECK(message.find(str) != string::npos);
+
+ const char *str1 = "FUNCTION_TEST_AAA";
+ message = getLogFromCmd(LEVEL::Warning, NULL, 1, str1);
+
+ BOOST_CHECK(message.find(str1) != string::npos);
+
+ const char *str2 = "454sfscx";
+ message = getLogFromCmd(LEVEL::Info, str2, 1, "Log");
+
+ BOOST_CHECK(message.find(str2) != string::npos);
+
+ const char *str3 = "789dfrs";
+ message = getLogFromCmd(LEVEL::Debug, str3, -1, "Log");
+
+ BOOST_CHECK(message.find(str3) != string::npos);
+
+ const char *str4 = "798fdsg";
+ message = getLogFromCmd(LEVEL::Pedantic, str4, 1, "Log");
+
+ BOOST_CHECK(message.find(str4) != string::npos);
+}
+
+NEGATIVE_TEST_CASE(T_old_style_log_provider_log_out_of_range_level)
+{
+ string message = getLogFromCmd(LEVEL::None, "This is a type none log", 1, "Log");
+
+ BOOST_CHECK(message.find("Unsupported log level: 0") != string::npos);
+
+ LEVEL Level = static_cast<LEVEL>(1 << 3);
+ message = getLogFromCmd(Level, "This is a type error log", 1, "Log");
+
+ BOOST_CHECK(message.find("Unsupported log level: 8") != string::npos);
+}
+
+BOOST_AUTO_TEST_SUITE_END()