综合平台编程器项目的远程存储
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

144 строки
4.9 KiB

  1. #include "domain/virtual_register_repository.h"
  2. #include "services/alarm_service.h"
  3. #include "services/hmi_editor_service.h"
  4. #include "services/hmi_navigation_service.h"
  5. #include "services/hmi_runtime_service.h"
  6. #include "services/logic_editor_service.h"
  7. #include "services/offline_simulation_service.h"
  8. #include "services/project_service.h"
  9. #include "services/register_monitor_service.h"
  10. #include "services/runtime_mode_service.h"
  11. #include "support/test_support.h"
  12. #include "ui/hmi_editor_widget.h"
  13. #include "ui/logic_editor_widget.h"
  14. #include "ui/runtime_panel_controller.h"
  15. #include <QApplication>
  16. #include <QCoreApplication>
  17. #include <QEventLoop>
  18. #include <QLabel>
  19. #include <QWidget>
  20. #include <iostream>
  21. #include <stdexcept>
  22. #include <string>
  23. namespace {
  24. using TestProjectStorage = TestSupport::InMemoryProjectStorage;
  25. using TestSupport::require;
  26. ControlLogic makeAlwaysOnLogic()
  27. {
  28. ControlLogic logic;
  29. logic.id = "queued-trace-logic";
  30. logic.name = "Queued trace logic";
  31. LadderRung rung;
  32. rung.id = "always-on-rung";
  33. rung.name = "Always on";
  34. rung.condition = ConditionExpression::fromWire("always-on-wire", 10);
  35. LogicNode output;
  36. output.id = "always-on-output";
  37. output.config = CoilNodeConfig{
  38. RegisterAddress{RegisterArea::M, 1}, CoilMode::Normal};
  39. rung.output = output;
  40. logic.rungs.push_back(rung);
  41. return logic;
  42. }
  43. void testQueuedOfflineTraceIsIgnoredAfterReturningToEditing()
  44. {
  45. TestProjectStorage storage;
  46. ProjectService project_service(storage);
  47. VirtualRegisterRepository virtual_repository;
  48. OfflineSimulationService simulation_service(virtual_repository);
  49. RuntimeModeService runtime_mode_service(project_service, simulation_service);
  50. HmiEditorService hmi_editor_service(project_service);
  51. HmiRuntimeService hmi_runtime_service(virtual_repository);
  52. LogicEditorService logic_editor_service(project_service);
  53. HmiNavigationService hmi_navigation_service(project_service);
  54. AlarmService alarm_service(project_service, virtual_repository);
  55. RegisterMonitorService register_monitor_service(virtual_repository);
  56. const ControlLogic logic = makeAlwaysOnLogic();
  57. project_service.editProject().controlLogics.push_back(logic);
  58. QWidget parent;
  59. HmiEditorWidget hmi_editor_widget(
  60. hmi_editor_service, hmi_runtime_service, alarm_service, &parent);
  61. LogicEditorWidget logic_editor_widget(logic_editor_service, &parent);
  62. QLabel executor_status_label(&parent);
  63. std::string current_logic_id = logic.id;
  64. logic_editor_widget.setLogicId(current_logic_id);
  65. RuntimePanelController controller(
  66. parent,
  67. runtime_mode_service,
  68. project_service,
  69. hmi_editor_service,
  70. hmi_runtime_service,
  71. logic_editor_service,
  72. hmi_navigation_service,
  73. alarm_service,
  74. register_monitor_service,
  75. hmi_editor_widget,
  76. logic_editor_widget,
  77. executor_status_label,
  78. [&current_logic_id] { return current_logic_id; },
  79. [&current_logic_id](const std::string &logic_id)
  80. {
  81. current_logic_id = logic_id;
  82. },
  83. [](const std::string &) {},
  84. [](const QString &, int) {},
  85. [](const QString &) {},
  86. [] {});
  87. controller.configure();
  88. require(runtime_mode_service.enterOfflineRunning().succeeded,
  89. "offline simulation must start for queued trace regression");
  90. controller.enterRuntime(
  91. {}, logic.id, runtime_mode_service.mode(),
  92. runtime_mode_service.plcConnectionState());
  93. require(simulation_service.executeOnce().succeeded,
  94. "offline simulation must produce a trace before editing");
  95. require(simulation_service.traceSnapshot()
  96. .forLogic(logic.id).rungValues.at("always-on-rung"),
  97. "the queued trace must contain an energized rung");
  98. require(runtime_mode_service.enterEditing().succeeded,
  99. "offline simulation must return to editing before queued delivery");
  100. controller.leaveRuntime(
  101. runtime_mode_service.mode(), runtime_mode_service.plcConnectionState());
  102. logic_editor_widget.clearRuntimeTrace();
  103. require(!logic_editor_widget.runtimeTraceEnabled(),
  104. "editing transition must initially clear the runtime trace");
  105. QCoreApplication::processEvents(QEventLoop::AllEvents);
  106. require(!logic_editor_widget.runtimeTraceEnabled(),
  107. "a queued offline scan must not restore the trace after returning to editing");
  108. }
  109. } // namespace
  110. int main(int argc, char *argv[])
  111. {
  112. qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("offscreen"));
  113. QApplication application(argc, argv);
  114. try
  115. {
  116. testQueuedOfflineTraceIsIgnoredAfterReturningToEditing();
  117. }
  118. catch (const std::exception &error)
  119. {
  120. std::cerr << "runtime panel controller tests failed: "
  121. << error.what() << '\n';
  122. return 1;
  123. }
  124. std::cout << "runtime panel controller tests passed\n";
  125. return 0;
  126. }