Cheking Plugin Handle in case it has not been initialized 74/316774/13
authorLe <xuan.tien@samsung.com>
Wed, 28 Aug 2024 03:54:50 +0000 (10:54 +0700)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 9 Sep 2024 09:14:25 +0000 (09:14 +0000)
Change-Id: Ie5af8d346462fd4cdfb158e8d75033ecfc4b377b
Signed-off-by: Le <xuan.tien@samsung.com>
unit-tests/CMakeLists.txt
unit-tests/test_vcore_plugin_handle.cpp [new file with mode: 0644]

index af8ba78dbda00fa0cab7b8697347d2122548c3a7..f07038b5d61daf497735dc39cc386ae76caaf5e3 100644 (file)
@@ -80,6 +80,7 @@ SET(UNIT_TESTS_SOURCES
     test_vcore_certificate.cpp
     test_vcore_saxreader.cpp
     test_vcore_exception.cpp
+    test_vcore_plugin_handle.cpp
     test_cert_server_db.cpp
     test_cert_server_logic.cpp
     colour_log_formatter.cpp
diff --git a/unit-tests/test_vcore_plugin_handle.cpp b/unit-tests/test_vcore_plugin_handle.cpp
new file mode 100644 (file)
index 0000000..85b0c9b
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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_constant.h"
+#include "test_common.h"
+#include "test_macros.h"
+#include "vcore/PluginHandler.h"
+#include <string>
+#include <iostream>
+#include <stdio.h>
+#include <stdlib.h>
+
+using namespace ValidationCore;
+
+BOOST_AUTO_TEST_SUITE(T_VCORE_PLUGIN_HANDLE)
+
+POSITIVE_TEST_CASE(T_plugin_handle_errorToString)
+{
+       PluginHandler plugin;
+       std::string code = plugin.errorToString(E_SIG_NONE);
+       BOOST_CHECK_EQUAL(code, "Plugin errorstring code : 0");
+}
+
+struct RenameFileFixture {
+       std::string INVALID_PLUGIN_PATH = LIB_DIR + std::string("/libcert-svc-validator-plugin.sobin");
+
+       RenameFileFixture() {
+               if (std::rename(PLUGIN_PATH.c_str(), INVALID_PLUGIN_PATH.c_str()) != 0) {
+                       BOOST_FAIL("This file cannot be renamed before running the test!");
+               }
+       }
+
+       ~RenameFileFixture() {
+               if (std::rename(INVALID_PLUGIN_PATH.c_str(), PLUGIN_PATH.c_str()) != 0) {
+                       BOOST_FAIL("This file cannot be renamed after running the test!");
+               }
+       }
+};
+
+BOOST_FIXTURE_TEST_CASE(T_plugin_not_init, RenameFileFixture)
+{
+       PluginHandler plugin;
+       VCerr vcerrCode;
+       std::string stringCode;
+
+       SignatureData signatureData;
+       vcerrCode = plugin.step(E_SIG_PLUGIN, signatureData);
+       BOOST_CHECK_EQUAL(vcerrCode, E_SIG_PLUGIN);
+
+       stringCode = plugin.errorToString(E_SIG_NONE);
+       BOOST_CHECK_EQUAL(stringCode, "Plugin is not initialized");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file