PluginManager tests part 2 (#332)
authorIvan Vagin/AI Tools Lab /SRR/Engineer/삼성전자 <ivan.vagin@samsung.com>
Wed, 20 Jun 2018 14:35:18 +0000 (17:35 +0300)
committerSergey Vostokov/AI Tools Lab /SRR/Staff Engineer/삼성전자 <s.vostokov@samsung.com>
Wed, 20 Jun 2018 14:35:18 +0000 (17:35 +0300)
PluginManager tests part 2

This commit introduced tests for classes:
 * ConfigException
 * PluginException

Signed-off-by: Ivan Vagin <ivan.vagin@samsung.com>
contrib/nnc/libs/plugin/CMakeLists.txt
contrib/nnc/libs/plugin/src/ConfigException.test.cpp [new file with mode: 0644]
contrib/nnc/libs/plugin/src/PluginException.test.cpp [new file with mode: 0644]

index 559a575..51553b2 100644 (file)
@@ -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 (file)
index 0000000..bb44703
--- /dev/null
@@ -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<std::string> 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 (file)
index 0000000..8b8c13f
--- /dev/null
@@ -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<std::string> 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);
+}