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.

urExportScenarioToFileTest.cpp 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include <vector>
  2. #include <tuple>
  3. #include <ovp_global_defines.h>
  4. #include "ovtAssert.h"
  5. #include "ovtTestFixtureCommon.h"
  6. int urImportScenarioFromFileTest(int argc, char* argv[]);
  7. #define OVP_ClassId_BoxAlgorithm_ClockStimulator CIdentifier(0x4F756D3F, 0x29FF0B96)
  8. #define OVP_ClassId_BoxAlgorithm_ClockStimulatorDesc CIdentifier(0x4FD067E9, 0x740D2AF0)
  9. #define OVP_ClassId_BoxAlgorithm_StimulationListener CIdentifier(0x65731E1D, 0x47DE5276)
  10. #include "urSimpleTestScenarioDefinition.h"
  11. int urExportScenarioToFileTest(const int argc, char* argv[])
  12. {
  13. const char* configFile = argv[1];
  14. const char* temporaryDirectory = argv[2];
  15. {
  16. Test::ScopedTest<Test::SKernelFixture> fixture(configFile);
  17. auto& context = fixture->context;
  18. #if defined TARGET_OS_Windows
  19. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/openvibe-plugins-sdk-file-io*dll");
  20. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/openvibe-plugins-sdk-stimulation*dll");
  21. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/openvibe-plugins-sdk-tools*dll");
  22. #elif defined TARGET_OS_Linux
  23. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-file-io*so");
  24. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-stimulation*so");
  25. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-tools*so");
  26. #elif defined TARGET_OS_MacOS
  27. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-file-io*dylib");
  28. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-stimulation*dylib");
  29. context->getPluginManager().addPluginsFromFiles(Directories::getLibDir() + "/libopenvibe-plugins-sdk-tools*dylib");
  30. #endif
  31. CIdentifier emptyScenarioIdentifier;
  32. context->getScenarioManager().createScenario(emptyScenarioIdentifier);
  33. CMemoryBuffer memoryBuffer;
  34. OVT_ASSERT(context->getScenarioManager().exportScenario(memoryBuffer, emptyScenarioIdentifier, OVP_GD_ClassId_Algorithm_XMLScenarioExporter),
  35. "Failed to export an empty scenario");
  36. OVT_ASSERT(
  37. context->getScenarioManager().exportScenarioToFile((std::string(temporaryDirectory) + "/test-scenario-empty.mxs").c_str(), emptyScenarioIdentifier,
  38. OVP_GD_ClassId_Algorithm_XMLScenarioExporter), "Failed to export an empty scenario to a file");
  39. CIdentifier importedEmptyScenarioIdentifier;
  40. OVT_ASSERT(context->getScenarioManager().importScenario(importedEmptyScenarioIdentifier, memoryBuffer, OVP_GD_ClassId_Algorithm_XMLScenarioImporter),
  41. "Failed to import an empty exported buffer");
  42. // Create a scenario to be imported by the importer test
  43. CIdentifier simpleScenarioIdentifier;
  44. context->getScenarioManager().createScenario(simpleScenarioIdentifier);
  45. Kernel::IScenario& scenario = context->getScenarioManager().getScenario(simpleScenarioIdentifier);
  46. // Test scenario attributes
  47. for (auto& attribute : simpleScenarioAttributes) { scenario.addAttribute(std::get<0>(attribute), std::get<1>(attribute).c_str()); }
  48. size_t settingIndex = 0;
  49. for (auto& setting : simpleScenarioSettings)
  50. {
  51. scenario.addSetting(std::get<1>(setting).c_str(), std::get<0>(setting), std::get<2>(setting).c_str());
  52. scenario.setSettingValue(settingIndex, std::get<3>(setting).c_str());
  53. settingIndex += 1;
  54. }
  55. CIdentifier actualClockStimulatorBoxId;
  56. scenario.addBox(actualClockStimulatorBoxId, OVP_ClassId_BoxAlgorithm_ClockStimulator, s_ClockStimulatorBoxId);
  57. CIdentifier actualStimulationListenerBoxId;
  58. scenario.addBox(actualStimulationListenerBoxId, OVP_ClassId_BoxAlgorithm_StimulationListener, s_StimulationListenerBoxId);
  59. Kernel::IBox* stimulatorListenerBox = scenario.getBoxDetails(s_StimulationListenerBoxId);
  60. stimulatorListenerBox->addInput("Stimulation stream 2", OV_TypeId_Stimulations);
  61. int scenarioInputIdx = 0;
  62. for (auto& scenarioInput : simpleScenarioInputs)
  63. {
  64. scenario.addInput(std::get<1>(scenarioInput).c_str(), std::get<0>(scenarioInput));
  65. if (std::get<2>(scenarioInput) != CIdentifier::undefined())
  66. {
  67. scenario.setScenarioInputLink(scenarioInputIdx, std::get<2>(scenarioInput), std::get<3>(scenarioInput));
  68. }
  69. scenarioInputIdx += 1;
  70. }
  71. int scenarioOutputIdx = 0;
  72. for (auto& scenarioOutput : simpleScenarioOutputs)
  73. {
  74. scenario.addOutput(std::get<1>(scenarioOutput).c_str(), std::get<0>(scenarioOutput));
  75. if (std::get<2>(scenarioOutput) != CIdentifier::undefined())
  76. {
  77. scenario.setScenarioOutputLink(scenarioOutputIdx, std::get<2>(scenarioOutput), std::get<3>(scenarioOutput));
  78. }
  79. scenarioOutputIdx += 1;
  80. }
  81. CIdentifier actualClockStimulatorToStimulationListenerLinkId;
  82. scenario.connect(actualClockStimulatorToStimulationListenerLinkId, s_ClockStimulatorBoxId, 0, s_StimulationListenerBoxId, 1,
  83. s_ClockStimulatorToStimulationListenerLinkId);
  84. CIdentifier actualSimpleCommentIdentifier;
  85. scenario.addComment(actualSimpleCommentIdentifier, s_SimpleCommentId);
  86. Kernel::IComment* simpleComment = scenario.getCommentDetails(s_SimpleCommentId);
  87. simpleComment->setText("Content of a comment");
  88. CIdentifier actualUnicodeCommentIdentifier;
  89. scenario.addComment(actualUnicodeCommentIdentifier, s_UnicodeCommentId);
  90. Kernel::IComment* unicodeComment = scenario.getCommentDetails(s_UnicodeCommentId);
  91. unicodeComment->setText("This comment contains a newline\nand unicode characters 日本語");
  92. OVT_ASSERT(
  93. context->getScenarioManager().exportScenarioToFile((std::string(temporaryDirectory) + "/" + s_SimpleScenarioFileName).c_str(),
  94. simpleScenarioIdentifier, OVP_GD_ClassId_Algorithm_XMLScenarioExporter), "Failed to export a simple scenario");
  95. }
  96. return urImportScenarioFromFileTest(argc, argv);
  97. }