From 9a3075cf1398fe95d7ca345546af40c7bcd4a89e Mon Sep 17 00:00:00 2001 From: andynoack Date: Thu, 9 Feb 2017 11:40:20 +0100 Subject: [PATCH] hurray first test! --- src/urh/ui/SimulatorScene.py | 13 +++++++++---- tests/test_simulator.py | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 tests/test_simulator.py diff --git a/src/urh/ui/SimulatorScene.py b/src/urh/ui/SimulatorScene.py index cb8ec8ed0a..13740dd476 100644 --- a/src/urh/ui/SimulatorScene.py +++ b/src/urh/ui/SimulatorScene.py @@ -347,6 +347,15 @@ def dropEvent(self, event: QDropEvent): nodes_to_add.extend([file_node for file_node in file_nodes if file_node not in nodes_to_add]) protocols_to_add = [node.protocol for node in nodes_to_add] + + self.add_protocols(protocols_to_add) + + self.update_view() + + super().dropEvent(event) + + + def add_protocols(self, protocols_to_add: list): for protocol in protocols_to_add: for message in protocol.messages: source, destination = self.__detect_source_destination(message) @@ -356,10 +365,6 @@ def dropEvent(self, event: QDropEvent): self.items.append(simulator_message) self.addItem(simulator_message) - self.update_view() - - super().dropEvent(event) - def __detect_source_destination(self, message: Message): # TODO: use SRC_ADDRESS and DST_ADDRESS labels participants = self.controller.project_manager.participants diff --git a/tests/test_simulator.py b/tests/test_simulator.py new file mode 100644 index 0000000000..d116acdc86 --- /dev/null +++ b/tests/test_simulator.py @@ -0,0 +1,27 @@ +import unittest +import tests.utils_testing +from urh import constants +from urh.controller.MainController import MainController + +from tests.utils_testing import get_path_for_data_file + +app = tests.utils_testing.app + + +class TestSimulator(unittest.TestCase): + def setUp(self): + self.old_sym_len = constants.SETTINGS.value('rel_symbol_length', type=int) + constants.SETTINGS.setValue('rel_symbol_length', 0) # Disable Symbols for this Test + + self.form = MainController() + self.form.add_signalfile(get_path_for_data_file("esaver.complex")) + self.sframe = self.form.signal_tab_controller.signal_frames[0] + self.sim_frame = self.form.simulator_tab_controller + self.form.ui.tabWidget.setCurrentIndex(3) + + def tearDown(self): + constants.SETTINGS.setValue('rel_symbol_length', self.old_sym_len) # Restore Symbol Length + + def test_add_signal(self): + self.sim_frame.ui.gvSimulator.scene().add_protocols([self.sframe.proto_analyzer]) + self.assertEqual(len(self.sim_frame.ui.gvSimulator.scene().items), len(self.sframe.proto_analyzer.messages))