From 1f021ee664bc5ce4344bc7af30469dfdd0245836 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ivan=20Vagin/AI=20Tools=20Lab=20/SRR/Engineer/=EC=82=BC?= =?utf8?q?=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 20 Jun 2018 17:35:18 +0300 Subject: [PATCH] PluginManager tests part 2 (#332) PluginManager tests part 2 This commit introduced tests for classes: * ConfigException * PluginException Signed-off-by: Ivan Vagin --- contrib/nnc/libs/plugin/CMakeLists.txt | 6 ++++ .../nnc/libs/plugin/src/ConfigException.test.cpp | 40 ++++++++++++++++++++++ .../nnc/libs/plugin/src/PluginException.test.cpp | 40 ++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 contrib/nnc/libs/plugin/src/ConfigException.test.cpp create mode 100644 contrib/nnc/libs/plugin/src/PluginException.test.cpp diff --git a/contrib/nnc/libs/plugin/CMakeLists.txt b/contrib/nnc/libs/plugin/CMakeLists.txt index 559a575..51553b2 100644 --- a/contrib/nnc/libs/plugin/CMakeLists.txt +++ b/contrib/nnc/libs/plugin/CMakeLists.txt @@ -1,7 +1,13 @@ file(GLOB_RECURSE HEADERS "include/*.h") file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE TESTS "src/*.test.cpp") +list(REMOVE_ITEM SOURCES ${TESTS}) add_nncc_library(nnc_plugin_core SHARED ${HEADERS} ${SOURCES}) set_target_properties(nnc_plugin_core PROPERTIES LINKER_LANGUAGE CXX) target_link_libraries(nnc_plugin_core PRIVATE nncc_foundation) target_include_directories(nnc_plugin_core PUBLIC include) + +add_nncc_test(nnc_plugin_core_test ${TESTS} ${HEADERS}) +nncc_target_link_libraries(nnc_plugin_core_test nnc_plugin_core) +nncc_target_link_libraries(nnc_plugin_core_test nncc_foundation) diff --git a/contrib/nnc/libs/plugin/src/ConfigException.test.cpp b/contrib/nnc/libs/plugin/src/ConfigException.test.cpp new file mode 100644 index 0000000..bb44703 --- /dev/null +++ b/contrib/nnc/libs/plugin/src/ConfigException.test.cpp @@ -0,0 +1,40 @@ +#include "ConfigException.h" + +#include "gtest/gtest.h" + +using namespace nncc::contrib; + +std::string configErrorMsg1 = "error constructor"; +std::string configErrorMsg2 = "error second constructor"; + +std::vector configErrorMsgs = {configErrorMsg1, configErrorMsg2}; + +void configErr1() { throw ConfigException(configErrorMsg1); } + +void configErr2() +{ + try + { + configErr1(); + } + catch (ConfigException &e) + { + throw ConfigException(e, configErrorMsg2); + } +} + +TEST(CONTRIB_PLUGIN, ConfigException) +{ + try + { + configErr2(); + } + catch (ConfigException &e) + { + ASSERT_TRUE(configErrorMsgs == e.getInfo()); + return; + } + + // should not happen + ASSERT_TRUE(false); +} diff --git a/contrib/nnc/libs/plugin/src/PluginException.test.cpp b/contrib/nnc/libs/plugin/src/PluginException.test.cpp new file mode 100644 index 0000000..8b8c13f --- /dev/null +++ b/contrib/nnc/libs/plugin/src/PluginException.test.cpp @@ -0,0 +1,40 @@ +#include "PluginException.h" + +#include "gtest/gtest.h" + +using namespace nncc::contrib; + +std::string pluginErrorMsg1 = "error constructor"; +std::string pluginErrorMsg2 = "error second constructor"; + +std::vector pluginErrorMsgs = {pluginErrorMsg1, pluginErrorMsg2}; + +void pluginErr1() { throw PluginException(pluginErrorMsg1); } + +void pluginErr2() +{ + try + { + pluginErr1(); + } + catch (PluginException &e) + { + throw PluginException(e, pluginErrorMsg2); + } +} + +TEST(CONTRIB_PLUGIN, PluginException) +{ + try + { + pluginErr2(); + } + catch (PluginException &e) + { + ASSERT_TRUE(pluginErrorMsgs == e.getInfo()); + return; + } + + // should not happen + ASSERT_TRUE(false); +} -- 2.7.4