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.

urImportScenarioFromFileTest.cpp 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #include <string>
  2. #include <vector>
  3. #include <ovp_global_defines.h>
  4. #include "ovtAssert.h"
  5. #include "ovtTestFixtureCommon.h"
  6. #include "urSimpleTestScenarioDefinition.h"
  7. #define to_cppstring(str) std::string(str.toASCIIString())
  8. int urImportScenarioFromFileTest(int /*argc*/, char* argv[])
  9. {
  10. const char* configFile = argv[1];
  11. const char* dataDirectory = argv[2];
  12. {
  13. Test::ScopedTest<Test::SKernelFixture> fixture(configFile);
  14. auto& context = fixture->context;
  15. #if defined TARGET_OS_Windows
  16. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/openvibe-plugins-sdk-file-io*dll");
  17. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/openvibe-plugins-sdk-stimulation*dll");
  18. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/openvibe-plugins-sdk-tools*dll");
  19. #elif defined TARGET_OS_Linux
  20. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-file-io*so");
  21. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-stimulation*so");
  22. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-tools*so");
  23. #elif defined TARGET_OS_MacOS
  24. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-file-io*dylib");
  25. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-stimulation*dylib");
  26. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-tools*dylib");
  27. #endif
  28. const std::string scenarioFilePath = std::string(dataDirectory) + "/" + s_SimpleScenarioFileName;
  29. CIdentifier scenarioID;
  30. OVT_ASSERT(context->getScenarioManager().importScenarioFromFile(scenarioID, scenarioFilePath.c_str(), OVP_GD_ClassId_Algorithm_XMLScenarioImporter),
  31. "Failed to import the scenario file");
  32. OVT_ASSERT(scenarioID != CIdentifier::undefined(), "Scenario importer failed to import the scenario but failed to report an error");
  33. auto& scenario = context->getScenarioManager().getScenario(scenarioID);
  34. // Test scenario attributes
  35. for (auto& attribute : simpleScenarioAttributes)
  36. {
  37. OVT_ASSERT_STREQ(to_cppstring(scenario.getAttributeValue(std::get<0>(attribute))), std::get<1>(attribute), "Badly imported scenario attribute");
  38. }
  39. // Test settings
  40. OVT_ASSERT(scenario.getSettingCount() == simpleScenarioSettings.size(), "Imported scenario does not have the correct number of settings");
  41. for (size_t settingIndex = 0; settingIndex < simpleScenarioSettings.size(); settingIndex += 1)
  42. {
  43. CIdentifier settingTypeId;
  44. OVT_ASSERT(scenario.getSettingType(settingIndex, settingTypeId), "Cannot get setting type");
  45. OVT_ASSERT(settingTypeId == std::get<0>(simpleScenarioSettings[settingIndex]), "Setting has wrong type");
  46. CString settingName;
  47. OVT_ASSERT(scenario.getSettingName(settingIndex, settingName), "Cannot get setting name");
  48. OVT_ASSERT_STREQ(to_cppstring(settingName), std::get<1>(simpleScenarioSettings[settingIndex]), "Setting has wrong name");
  49. CString settingDefaultValue;
  50. OVT_ASSERT(scenario.getSettingDefaultValue(settingIndex, settingDefaultValue), "Cannot get setting default value");
  51. OVT_ASSERT_STREQ(to_cppstring(settingDefaultValue), std::get<2>(simpleScenarioSettings[settingIndex]), "Setting has wrong default value");
  52. CString settingValue;
  53. OVT_ASSERT(scenario.getSettingValue(settingIndex, settingValue), "Cannot get setting value");
  54. OVT_ASSERT_STREQ(to_cppstring(settingValue), std::get<3>(simpleScenarioSettings[settingIndex]), "Setting has wrong value");
  55. }
  56. // Test boxes
  57. OVT_ASSERT(scenario.isBox(s_ClockStimulatorBoxId), "Imported scenario does not contain the Clock Stimulator Box");
  58. OVT_ASSERT(scenario.isBox(s_StimulationListenerBoxId), "Imported scenario does not contain the Stimulation Listener Box");
  59. const Kernel::IBox* clockStimulatorBox = scenario.getBoxDetails(s_ClockStimulatorBoxId);
  60. OVT_ASSERT_STREQ(to_cppstring(clockStimulatorBox->getName()), std::string("Clock stimulator"), "Badly imported Clock Stimulator name");
  61. const Kernel::IBox* stimulationListenerBox = scenario.getBoxDetails(s_StimulationListenerBoxId);
  62. OVT_ASSERT_STREQ(to_cppstring(stimulationListenerBox->getName()), std::string("Stimulation listener"), "Badly imported Stimulation Listener name");
  63. // Test inputs
  64. OVT_ASSERT(scenario.getInputCount() == simpleScenarioInputs.size(), "Imported scenario has wrong number of inputs");
  65. for (size_t index = 0; index < simpleScenarioInputs.size(); index += 1)
  66. {
  67. CIdentifier inputTypeId;
  68. OVT_ASSERT(scenario.getInputType(index, inputTypeId), "Cannot get input type");
  69. OVT_ASSERT(inputTypeId == std::get<0>(simpleScenarioInputs[index]), "Input has wrong type");
  70. CString inputName;
  71. OVT_ASSERT(scenario.getInputName(index, inputName), "Cannot get input name");
  72. OVT_ASSERT_STREQ(to_cppstring(inputName), std::get<1>(simpleScenarioInputs[index]), "Input has wrong name");
  73. CIdentifier dstBoxID;
  74. size_t dstBoxInputIdx;
  75. CIdentifier dstBoxInputID = CIdentifier::undefined();
  76. OVT_ASSERT(scenario.getScenarioInputLink(index, dstBoxID, dstBoxInputIdx), "Cannot get scenario input details by index");
  77. OVT_ASSERT(scenario.getScenarioInputLink(index, dstBoxID, dstBoxInputID), "Cannot get scenario input details by identifier");
  78. OVT_ASSERT(dstBoxID == std::get<2>(simpleScenarioInputs[index]), "Scenario input is not connected to the correct box");
  79. OVT_ASSERT(dstBoxInputIdx == std::get<3>(simpleScenarioInputs[index]), "Scenario input is not connected to the correct box input");
  80. }
  81. // Test outputs
  82. OVT_ASSERT(scenario.getOutputCount() == simpleScenarioOutputs.size(), "Imported scenario has wrong number of outputs");
  83. for (size_t idx = 0; idx < simpleScenarioOutputs.size(); idx += 1)
  84. {
  85. CIdentifier outputTypeId;
  86. OVT_ASSERT(scenario.getOutputType(idx, outputTypeId), "Cannot get output type");
  87. OVT_ASSERT(outputTypeId == std::get<0>(simpleScenarioOutputs[idx]), "Output has wrong type");
  88. CString outputName;
  89. OVT_ASSERT(scenario.getOutputName(idx, outputName), "Cannot get output name");
  90. OVT_ASSERT_STREQ(to_cppstring(outputName), std::get<1>(simpleScenarioOutputs[idx]), "Output has wrong name");
  91. CIdentifier dstBoxID;
  92. size_t dstBoxOutputIndex;
  93. CIdentifier dstBoxOutputIdentifier = CIdentifier::undefined();
  94. OVT_ASSERT(scenario.getScenarioOutputLink(idx, dstBoxID, dstBoxOutputIndex), "Cannot get scenario output details by index");
  95. OVT_ASSERT(scenario.getScenarioOutputLink(idx, dstBoxID, dstBoxOutputIdentifier), "Cannot get scenario output details by identifier");
  96. OVT_ASSERT(dstBoxID == std::get<2>(simpleScenarioOutputs[idx]), "Scenario output is not connected to the correct box");
  97. OVT_ASSERT(dstBoxOutputIndex == std::get<3>(simpleScenarioOutputs[idx]), "Scenario output is not connected to the correct box output");
  98. }
  99. // Test links
  100. OVT_ASSERT(scenario.isLink(s_ClockStimulatorToStimulationListenerLinkId),
  101. "Imported scenario does not contain a link between the Clock Stimulator and Stimulation Listener boxes");
  102. const Kernel::ILink* clockStimulatorToStimulationListenerLink = scenario.getLinkDetails(s_ClockStimulatorToStimulationListenerLinkId);
  103. CIdentifier linkSourceBoxId;
  104. size_t linkSourceOutputIndex;
  105. CIdentifier linkSourceOutputIdentifier;
  106. OVT_ASSERT(clockStimulatorToStimulationListenerLink->getSource(linkSourceBoxId, linkSourceOutputIndex, linkSourceOutputIdentifier),
  107. "Could not get link details");
  108. OVT_ASSERT(linkSourceBoxId == s_ClockStimulatorBoxId,
  109. "The Clock Stimulator to Stimulation Listener link does not have the Clock Stimulator as the source");
  110. OVT_ASSERT(linkSourceOutputIndex == 0,
  111. "The Clock Stimulator to Stimulation Listener link does not have the first output of Clock Stimulator as the output");
  112. CIdentifier linkTargetBoxId;
  113. size_t linkTargetInputIndex;
  114. CIdentifier linkTargetInputIdentifier;
  115. OVT_ASSERT(clockStimulatorToStimulationListenerLink->getTarget(linkTargetBoxId, linkTargetInputIndex, linkTargetInputIdentifier),
  116. "Could not get link details");
  117. OVT_ASSERT(linkTargetBoxId == s_StimulationListenerBoxId,
  118. "The Clock Stimulator to Stimulation Listener link does not have the Stimulation Listener as the target");
  119. OVT_ASSERT(linkTargetInputIndex == 1,
  120. "The Clock Stimulator to Stimulation Listener link does not have the second input of Stimulation Listener as the input");
  121. // Test comments
  122. OVT_ASSERT(scenario.isComment(s_SimpleCommentId), "Imported scenario does not contain the simple comment");
  123. OVT_ASSERT(scenario.isComment(s_UnicodeCommentId), "Imported scenario does not contain the comment containing unicode");
  124. const Kernel::IComment* simpleComment = scenario.getCommentDetails(s_SimpleCommentId);
  125. const CString simpleCommentText = simpleComment->getText();
  126. OVT_ASSERT_STREQ(std::string("Content of a comment"), to_cppstring(simpleCommentText), "The imported scenario comment contains a wrong text");
  127. const Kernel::IComment* unicodeComment = scenario.getCommentDetails(s_UnicodeCommentId);
  128. const CString unicodeCommentText = unicodeComment->getText();
  129. OVT_ASSERT_STREQ(std::string("This comment contains a newline\nand unicode characters 日本語"), to_cppstring(unicodeCommentText),
  130. "The imported scenario comment contains a wrong text");
  131. }
  132. return EXIT_SUCCESS;
  133. }