PluginManager tests part 5 (SharedLibrary class) (#344)
authorIvan Vagin/AI Tools Lab /SRR/Engineer/삼성전자 <ivan.vagin@samsung.com>
Thu, 21 Jun 2018 07:29:05 +0000 (10:29 +0300)
committerSergey Vostokov/AI Tools Lab /SRR/Staff Engineer/삼성전자 <s.vostokov@samsung.com>
Thu, 21 Jun 2018 07:29:05 +0000 (10:29 +0300)
SharedLibrary class tests

This commit introduced test for SharedLibrary class and appropriate
CMakeLists

Signed-off-by: Ivan Vagin <ivan.vagin@samsung.com>
contrib/nnc/CMakeLists.txt
contrib/nnc/examples/plugin_example/samplePlugin.cpp [moved from contrib/nnc/examples/plugin_example/main.cpp with 98% similarity]
contrib/nnc/src/module/plugin/shared_library.test.cpp [new file with mode: 0644]

index b6d9693..30b11f7 100644 (file)
@@ -22,5 +22,9 @@ add_nncc_test(nnc_module_test ${TESTS} ${HEADERS})
 nncc_target_link_libraries(nnc_module_test nnc_module nncc_core nncc_foundation nnc_plugin_core)
 target_include_directories(nnc_module_test PUBLIC include)
 
+# Set macro in nnc_module_test with some_parser absolute path
+target_compile_definitions(nnc_module_test PRIVATE
+    CMAKE_SAMPLE_PLUGIN_ABS_PATH=$<TARGET_FILE:some_parser>)
+
 add_subdirectory(libs)
 add_subdirectory(examples)
@@ -98,3 +98,8 @@ extern "C" AbstractPluginInstance *get_instance()
   std::cout << std::endl << "!!! plugin (" << pluginName << ") " << __func__ << std::endl;
   return &SamplePluginInstance::getInstance();
 }
+
+extern "C" int getSomeBeef()
+{
+  return 0xBEEF;
+}
diff --git a/contrib/nnc/src/module/plugin/shared_library.test.cpp b/contrib/nnc/src/module/plugin/shared_library.test.cpp
new file mode 100644 (file)
index 0000000..17660e8
--- /dev/null
@@ -0,0 +1,31 @@
+#include "module/plugin/shared_library.h"
+
+#include "gtest/gtest.h"
+
+#define STRING(s) _STRING(s)
+#define _STRING(s) #s
+
+using namespace nncc::contrib::module::plugin;
+
+TEST(CONTRIB_NNC, SharedLibrary)
+{
+  // missing so - missing function
+  SharedLibrary slMissing("/");
+  ASSERT_EQ(slMissing.findFunc("missing_func_name"), nullptr);
+
+  // existing so - missing function
+  SharedLibrary sl(STRING(CMAKE_SAMPLE_PLUGIN_ABS_PATH));
+  ASSERT_EQ(sl.findFunc("missing_func_name"), nullptr);
+
+  // existing so - existing function
+  typedef int (*fp_t)();
+  fp_t getSomeBeef = (fp_t)sl.findFunc("getSomeBeef");
+  ASSERT_NE(getSomeBeef, nullptr);
+  ASSERT_EQ(getSomeBeef(), 0xBEEF);
+
+  // Operator '<<'
+  std::ostringstream os;
+  os << sl;
+  ASSERT_EQ(os.str(), STRING(CMAKE_SAMPLE_PLUGIN_ABS_PATH));
+
+}