You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

urValidateScenarioTest.cpp 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #include <iostream>
  2. #include <string>
  3. #include "gtest/gtest.h"
  4. #include "ovtAssert.h"
  5. #include "ovtTestFixtureCommon.h"
  6. #include <ovp_global_defines.h>
  7. #include <array>
  8. // DO NOT USE a global Test::ScopedTest<Test::SKernelFixture> variable here
  9. // because it causes a bug due to plugins global descriptors beeing destroyed before
  10. // the kernel context.
  11. OpenViBE::Kernel::IKernelContext* context = nullptr;
  12. std::string g_dataDirectory;
  13. bool importScenarioFromFile(const char* filename)
  14. {
  15. const std::string scenarioFilePath = std::string(g_dataDirectory) + "/" + filename;
  16. context->getErrorManager().releaseErrors();
  17. OpenViBE::CIdentifier scenarioID;
  18. if (context->getScenarioManager().importScenarioFromFile(scenarioID, scenarioFilePath.c_str(), OVP_GD_ClassId_Algorithm_XMLScenarioImporter))
  19. {
  20. context->getScenarioManager().releaseScenario(scenarioID);
  21. return true;
  22. }
  23. return false;
  24. }
  25. // should be called after importScenarioFromFile
  26. bool checkForSchemaValidationError()
  27. {
  28. auto& errorManager = context->getErrorManager();
  29. auto error = errorManager.getLastError();
  30. while (error)
  31. {
  32. if (error->getErrorType() == OpenViBE::Kernel::ErrorType::BadXMLSchemaValidation) { return true; }
  33. error = error->getNestedError();
  34. }
  35. return false;
  36. }
  37. TEST(validate_scenario_test_case, test_no_false_positive)
  38. {
  39. const std::array<const char*, 3> files = { "test-scenario-false-positive1.mxs", "test-scenario-false-positive2.mxs", "test-scenario-false-positive3.mxs" };
  40. // here we use assert because we want to fail directly
  41. // in order to avoid a segfault
  42. ASSERT_TRUE(context != nullptr);
  43. for (size_t i = 0; i < 3; ++i) { EXPECT_TRUE(importScenarioFromFile(files[i])); }
  44. }
  45. TEST(validate_scenario_test_case, test_root)
  46. {
  47. const std::array<const char*, 9> files = {
  48. "test-root-dup-attributes.mxs",
  49. "test-root-dup-boxes.mxs",
  50. "test-root-dup-comments.mxs",
  51. "test-root-dup-creator.mxs",
  52. "test-root-dup-inputs.mxs",
  53. "test-root-dup-links.mxs",
  54. "test-root-dup-outputs.mxs",
  55. "test-root-dup-settings.mxs",
  56. "test-root-dup-version.mxs"
  57. };
  58. // here we use assert because we want to fail directly
  59. // in order to avoid a segfault
  60. ASSERT_TRUE(context != nullptr);
  61. for (size_t i = 0; i < 9; ++i)
  62. {
  63. EXPECT_FALSE(importScenarioFromFile(files[i]));
  64. EXPECT_TRUE(checkForSchemaValidationError());
  65. }
  66. }
  67. TEST(validate_scenario_test_case, test_attribute)
  68. {
  69. const std::array<const char*, 4> files = {
  70. "test-attribute-dup-id.mxs",
  71. "test-attribute-dup-value.mxs",
  72. "test-attribute-missing-id.mxs",
  73. "test-attribute-missing-value.mxs"
  74. };
  75. // here we use assert because we want to fail directly
  76. // in order to avoid a segfault
  77. ASSERT_TRUE(context != nullptr);
  78. for (size_t i = 0; i < 4; ++i)
  79. {
  80. EXPECT_FALSE(importScenarioFromFile(files[i]));
  81. EXPECT_TRUE(checkForSchemaValidationError());
  82. }
  83. }
  84. TEST(validate_scenario_test_case, test_box)
  85. {
  86. const std::array<const char*, 10> files = {
  87. "test-box-dup-algo.mxs",
  88. "test-box-dup-attributes.mxs",
  89. "test-box-dup-id.mxs",
  90. "test-box-dup-inputs.mxs",
  91. "test-box-dup-name.mxs",
  92. "test-box-dup-outputs.mxs",
  93. "test-box-dup-settings.mxs",
  94. "test-box-missing-algo.mxs",
  95. "test-box-missing-id.mxs",
  96. "test-box-missing-name.mxs"
  97. };
  98. // here we use assert because we want to fail directly
  99. // in order to avoid a segfault
  100. ASSERT_TRUE(context != nullptr);
  101. for (size_t i = 0; i < 10; ++i)
  102. {
  103. EXPECT_FALSE(importScenarioFromFile(files[i]));
  104. EXPECT_TRUE(checkForSchemaValidationError());
  105. }
  106. }
  107. TEST(validate_scenario_test_case, test_comment)
  108. {
  109. const std::array<const char*, 5> files = {
  110. "test-comment-dup-attributes.mxs",
  111. "test-comment-dup-id.mxs",
  112. "test-comment-dup-text.mxs",
  113. "test-comment-missing-id.mxs",
  114. "test-comment-missing-text.mxs"
  115. };
  116. // here we use assert because we want to fail directly
  117. // in order to avoid a segfault
  118. ASSERT_TRUE(context != nullptr);
  119. for (size_t i = 0; i < 5; ++i)
  120. {
  121. EXPECT_FALSE(importScenarioFromFile(files[i]));
  122. EXPECT_TRUE(checkForSchemaValidationError());
  123. }
  124. }
  125. TEST(validate_scenario_test_case, test_input)
  126. {
  127. const std::array<const char*, 4> files = {
  128. "test-input-dup-id.mxs",
  129. "test-input-dup-name.mxs",
  130. "test-input-missing-id.mxs",
  131. "test-input-missing-name.mxs"
  132. };
  133. // here we use assert because we want to fail directly
  134. // in order to avoid a segfault
  135. ASSERT_TRUE(context != nullptr);
  136. for (size_t i = 0; i < 4; ++i)
  137. {
  138. EXPECT_FALSE(importScenarioFromFile(files[i]));
  139. EXPECT_TRUE(checkForSchemaValidationError());
  140. }
  141. }
  142. TEST(validate_scenario_test_case, test_link)
  143. {
  144. const std::array<const char*, 7> files = {
  145. "test-link-dup-attributes.mxs",
  146. "test-link-dup-id.mxs",
  147. "test-link-dup-source.mxs",
  148. "test-link-dup-target.mxs",
  149. "test-link-missing-id.mxs",
  150. "test-link-missing-source.mxs",
  151. "test-link-missing-target.mxs"
  152. };
  153. // here we use assert because we want to fail directly
  154. // in order to avoid a segfault
  155. ASSERT_TRUE(context != nullptr);
  156. for (size_t i = 0; i < 7; ++i)
  157. {
  158. EXPECT_FALSE(importScenarioFromFile(files[i]));
  159. EXPECT_TRUE(checkForSchemaValidationError());
  160. }
  161. }
  162. TEST(validate_scenario_test_case, test_output)
  163. {
  164. const std::array<const char*, 4> files = {
  165. "test-output-dup-id.mxs",
  166. "test-output-dup-name.mxs",
  167. "test-output-missing-id.mxs",
  168. "test-output-missing-name.mxs"
  169. };
  170. // here we use assert because we want to fail directly
  171. // in order to avoid a segfault
  172. ASSERT_TRUE(context != nullptr);
  173. for (size_t i = 0; i < 4; ++i)
  174. {
  175. EXPECT_FALSE(importScenarioFromFile(files[i]));
  176. EXPECT_TRUE(checkForSchemaValidationError());
  177. }
  178. }
  179. TEST(validate_scenario_test_case, test_setting)
  180. {
  181. const std::array<const char*, 9> files = {
  182. "test-setting-bad-modif.mxs",
  183. "test-setting-dup-default.mxs",
  184. "test-setting-dup-id.mxs",
  185. "test-setting-dup-modif.mxs",
  186. "test-setting-dup-name.mxs",
  187. "test-setting-dup-value.mxs",
  188. "test-setting-missing-default.mxs",
  189. "test-setting-missing-id.mxs",
  190. "test-setting-missing-name.mxs"
  191. };
  192. // here we use assert because we want to fail directly
  193. // in order to avoid a segfault
  194. ASSERT_TRUE(context != nullptr);
  195. for (size_t i = 0; i < 9; ++i)
  196. {
  197. EXPECT_FALSE(importScenarioFromFile(files[i]));
  198. EXPECT_TRUE(checkForSchemaValidationError());
  199. }
  200. }
  201. TEST(validate_scenario_test_case, test_source)
  202. {
  203. const std::array<const char*, 5> files = {
  204. "test-source-bad-index.mxs",
  205. "test-source-dup-id.mxs",
  206. "test-source-dup-index.mxs",
  207. "test-source-missing-id.mxs",
  208. "test-source-missing-index.mxs"
  209. };
  210. // here we use assert because we want to fail directly
  211. // in order to avoid a segfault
  212. ASSERT_TRUE(context != nullptr);
  213. for (size_t i = 0; i < 5; ++i)
  214. {
  215. EXPECT_FALSE(importScenarioFromFile(files[i]));
  216. EXPECT_TRUE(checkForSchemaValidationError());
  217. }
  218. }
  219. TEST(validate_scenario_test_case, test_target)
  220. {
  221. const std::array<const char*, 5> files = {
  222. "test-target-bad-index.mxs",
  223. "test-target-dup-id.mxs",
  224. "test-target-dup-index.mxs",
  225. "test-target-missing-id.mxs",
  226. "test-target-missing-index.mxs"
  227. };
  228. // here we use assert because we want to fail directly
  229. // in order to avoid a segfault
  230. ASSERT_TRUE(context != nullptr);
  231. for (size_t i = 0; i < 5; ++i)
  232. {
  233. EXPECT_FALSE(importScenarioFromFile(files[i]));
  234. EXPECT_TRUE(checkForSchemaValidationError());
  235. }
  236. }
  237. int urValidateScenarioTest(int argc, char* argv[])
  238. {
  239. OVT_ASSERT(argc >= 3, "Failure retrieve test parameters");
  240. OpenViBE::Test::ScopedTest<OpenViBE::Test::SKernelFixture> fixture;
  241. fixture->setConfigFile(argv[1]);
  242. g_dataDirectory = argv[2];
  243. context = fixture->context;
  244. #if defined TARGET_OS_Windows
  245. context->getPluginManager().addPluginsFromFiles(OpenViBE::Directories::getLibDir() + "/openvibe-plugins-sdk-file-io*dll");
  246. context->getPluginManager().addPluginsFromFiles(OpenViBE::Directories::getLibDir() + "/openvibe-plugins-sdk-stimulation*dll");
  247. context->getPluginManager().addPluginsFromFiles(OpenViBE::Directories::getLibDir() + "/openvibe-plugins-sdk-tools*dll");
  248. #elif defined TARGET_OS_Linux
  249. context->getPluginManager().addPluginsFromFiles(OpenViBE::Directories::getLibDir() + "/libopenvibe-plugins-sdk-file-io*so");
  250. context->getPluginManager().addPluginsFromFiles(OpenViBE::Directories::getLibDir() + "/libopenvibe-plugins-sdk-stimulation*so");
  251. context->getPluginManager().addPluginsFromFiles(OpenViBE::Directories::getLibDir() + "/libopenvibe-plugins-sdk-tools*so");
  252. #elif defined TARGET_OS_MacOS
  253. context->getPluginManager().addPluginsFromFiles(OpenViBE::Directories::getLibDir() + "/libopenvibe-plugins-sdk-file-io*dylib");
  254. context->getPluginManager().addPluginsFromFiles(OpenViBE::Directories::getLibDir() + "/libopenvibe-plugins-sdk-stimulation*dylib");
  255. context->getPluginManager().addPluginsFromFiles(OpenViBE::Directories::getLibDir() + "/libopenvibe-plugins-sdk-tools*dylib");
  256. #endif
  257. testing::InitGoogleTest(&argc, argv);
  258. ::testing::GTEST_FLAG(filter) = "validate_scenario_test_case.*";
  259. return RUN_ALL_TESTS();
  260. }