コード例 #1
0
ファイル: QtTestCase.py プロジェクト: proFessorJohns/urh
class QtTestCase(unittest.TestCase):
    CLOSE_TIMEOUT = 10
    WAIT_TIMEOUT_BEFORE_NEW = 10
    SHOW = os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "show_gui"))

    @classmethod
    def setUpClass(cls):
        write_settings()
        cls.app = QApplication(sys.argv)

    @classmethod
    def tearDownClass(cls):
        cls.app.quit()
        sip.delete(cls.app)
        cls.app = None

    def setUp(self):
        self.form = MainController()
        if self.SHOW:
            self.form.show()

    def add_signal_to_form(self, filename: str):
        QApplication.instance().processEvents()
        QTest.qWait(self.WAIT_TIMEOUT_BEFORE_NEW)
        self.form.add_signalfile(get_path_for_data_file(filename))

    def tearDown(self):
        if hasattr(self, "dialog"):
            self.dialog.close()
        if hasattr(self, "form"):
            self.form.close_all()
            if self.SHOW:
                self.form.close()
        QApplication.instance().processEvents()
        QTest.qWait(self.CLOSE_TIMEOUT)
コード例 #2
0
class TestMaincontrollerGUI(unittest.TestCase):
    def setUp(self):
        self.form = MainController()

    def test_open_recent(self):
        self.form.add_signalfile(
            tests.utils_testing.get_path_for_data_file("esaver.complex"))
        app.processEvents()
        self.assertEqual(len(self.form.signal_tab_controller.signal_frames), 1)
        self.form.close_all()
        app.processEvents()
        QTest.qWait(10)
        self.assertEqual(len(self.form.signal_tab_controller.signal_frames), 0)
        self.form.recentFileActionList[0].trigger()
        self.assertEqual(len(self.form.signal_tab_controller.signal_frames), 1)

    def test_update_decodings(self):
        self.form.update_decodings()
        self.assertTrue(True)

    def test_options_changed(self):
        self.form.add_signalfile(
            tests.utils_testing.get_path_for_data_file("esaver.complex"))
        self.form.on_options_changed({
            "rel_symbol_length": 0,
            "show_pause_as_time": True,
            "default_view": 0
        })
        self.assertEqual(
            self.form.signal_tab_controller.signal_frames[0].ui.cbProtoView.
            currentIndex(), 0)
コード例 #3
0
class TestSignalTabGUI(unittest.TestCase):
    def setUp(self):
        self.form = MainController()

    def test_close_all(self):
        # Add a bunch of signals
        NUM_SIGNALS = 10
        for _ in range(NUM_SIGNALS):
            self.form.add_signalfile(get_path_for_data_file("esaver.complex"))

        self.assertEqual(self.form.signal_tab_controller.num_signals, NUM_SIGNALS)

        self.form.close_all()
        QTest.qWait(1)
        self.assertEqual(self.form.signal_tab_controller.num_signals, 0)

        self.form.add_signalfile(get_path_for_data_file("ask.complex"))
        self.assertEqual(self.form.signal_tab_controller.num_signals, 1)

    def test_zoom(self):
        self.form.add_signalfile(get_path_for_data_file("esaver.complex"))
        frame = self.form.signal_tab_controller.signal_frames[0]
        x_zoom = frame.ui.spinBoxXZoom.value()
        self.assertEqual(x_zoom, 100)

        for _ in range(10):
            frame.ui.gvSignal.zoom(1.01)
            self.assertGreater(frame.ui.spinBoxXZoom.value(), x_zoom)
            x_zoom = frame.ui.spinBoxXZoom.value()

        for _ in range(10):
            frame.ui.gvSignal.zoom(0.99)
            self.assertLess(frame.ui.spinBoxXZoom.value(), x_zoom)
            x_zoom = frame.ui.spinBoxXZoom.value()
コード例 #4
0
ファイル: QtTestCase.py プロジェクト: weirdindiankid/urh
class QtTestCase(unittest.TestCase):
    CLOSE_TIMEOUT = 10
    WAIT_TIMEOUT_BEFORE_NEW = 10
    SHOW = os.path.exists(
        os.path.join(os.path.dirname(os.path.realpath(__file__)), "show_gui"))

    @classmethod
    def setUpClass(cls):
        write_settings()
        cls.app = QApplication(sys.argv)

    @classmethod
    def tearDownClass(cls):
        cls.app.quit()
        sip.delete(cls.app)
        cls.app = None

    def setUp(self):
        self.form = MainController()
        if self.SHOW:
            self.form.show()

    def wait_before_new_file(self):
        QApplication.instance().processEvents()
        QTest.qWait(self.WAIT_TIMEOUT_BEFORE_NEW)

    def add_signal_to_form(self, filename: str):
        self.wait_before_new_file()
        self.form.add_signalfile(get_path_for_data_file(filename))

    def get_path_for_filename(self, filename) -> str:
        return get_path_for_data_file(filename)

    def add_signal_to_generator(self, signal_index: int):
        gframe = self.form.generator_tab_controller
        item = gframe.tree_model.rootItem.children[0].children[signal_index]
        index = gframe.tree_model.createIndex(signal_index, 0, item)
        rect = gframe.ui.treeProtocols.visualRect(index)
        QTest.mousePress(gframe.ui.treeProtocols.viewport(),
                         Qt.LeftButton,
                         pos=rect.center())
        self.assertEqual(gframe.ui.treeProtocols.selectedIndexes()[0], index)
        mimedata = gframe.tree_model.mimeData(
            gframe.ui.treeProtocols.selectedIndexes())
        gframe.table_model.dropMimeData(mimedata, 1, -1, -1,
                                        gframe.table_model.createIndex(0, 0))

    def tearDown(self):
        if hasattr(self, "dialog"):
            self.dialog.close()
        if hasattr(self, "form"):
            self.form.close_all()
            if self.SHOW:
                self.form.close()
        QApplication.instance().processEvents()
        QTest.qWait(self.CLOSE_TIMEOUT)
コード例 #5
0
class TestProjectManager(unittest.TestCase):
    def setUp(self):
        self.form = MainController()
        self.form.project_manager.set_project_folder("./data")
        QTest.qWait(100)
        self.cframe = self.form.compare_frame_controller
        self.gframe = self.form.generator_tab_controller

    def test_save_modulations(self):
        self.gframe.modulators[0].name = "Test"
        amplitude = random.random()
        self.gframe.modulators[0].carrier_amplitude = amplitude
        self.gframe.modulators[0].carrier_freq_hz = 1337
        self.gframe.modulators[0].carrier_phase_deg = 42
        self.gframe.modulators[0].modulation_type = 1
        self.gframe.modulators[0].sample_rate = 10**3
        self.gframe.modulators.append(Modulator("test 2"))
        self.gframe.modulators = self.gframe.modulators[:
                                                        2]  # Take only the first two

        self.form.project_manager.saveProject()

        loaded_mods = self.form.project_manager.read_modulators_from_project_file(
        )
        self.assertEqual(len(loaded_mods), 2)

        self.assertEqual(loaded_mods[0].name, "Test")
        self.assertEqual(loaded_mods[1].name, "test 2")
        self.assertEqual(loaded_mods[0].carrier_freq_hz, 1337)
        self.assertEqual(loaded_mods[0].carrier_phase_deg, 42)
        self.assertEqual(loaded_mods[0].modulation_type, 1)
        self.assertEqual(loaded_mods[0].sample_rate, 10**3)

        self.gframe.modulators.clear()
        self.assertEqual(len(self.gframe.modulators), 0)

        self.form.project_manager.set_project_folder(
            self.form.project_manager.project_path)
        self.assertEqual(len(self.gframe.modulators), 2)

    def test_close_all(self):
        self.form.close_all()
        QTest.qWait(10)
        self.form.add_signalfile("./data/ask.complex")
        self.form.add_signalfile("./data/fsk.complex")
        QTest.qWait(10)
        self.assertEqual(self.form.signal_tab_controller.num_signals, 2)
        self.form.close_all()
        QTest.qWait(10)
        self.assertEqual(self.form.signal_tab_controller.num_signals, 0)
        self.assertIsNone(self.form.project_manager.project_file)
コード例 #6
0
ファイル: QtTestCase.py プロジェクト: Cyber-Forensic/urh
class QtTestCase(unittest.TestCase):
    CLOSE_TIMEOUT = 10
    WAIT_TIMEOUT_BEFORE_NEW = 10
    SHOW = os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "show_gui"))

    @classmethod
    def setUpClass(cls):
        write_settings()
        cls.app = QApplication(sys.argv)

    @classmethod
    def tearDownClass(cls):
        cls.app.quit()
        sip.delete(cls.app)
        cls.app = None

    def setUp(self):
        self.form = MainController()
        if self.SHOW:
            self.form.show()

    def wait_before_new_file(self):
        QApplication.instance().processEvents()
        QTest.qWait(self.WAIT_TIMEOUT_BEFORE_NEW)

    def add_signal_to_form(self, filename: str):
        self.wait_before_new_file()
        self.form.add_signalfile(get_path_for_data_file(filename))

    def add_signal_to_generator(self, signal_index: int):
        gframe = self.form.generator_tab_controller
        item = gframe.tree_model.rootItem.children[0].children[signal_index]
        index = gframe.tree_model.createIndex(signal_index, 0, item)
        rect = gframe.ui.treeProtocols.visualRect(index)
        QTest.mousePress(gframe.ui.treeProtocols.viewport(), Qt.LeftButton, pos=rect.center())
        self.assertEqual(gframe.ui.treeProtocols.selectedIndexes()[0], index)
        mimedata = gframe.tree_model.mimeData(gframe.ui.treeProtocols.selectedIndexes())
        gframe.table_model.dropMimeData(mimedata, 1, -1, -1, gframe.table_model.createIndex(0, 0))

    def tearDown(self):
        if hasattr(self, "dialog"):
            self.dialog.close()
        if hasattr(self, "form"):
            self.form.close_all()
            if self.SHOW:
                self.form.close()
        QApplication.instance().processEvents()
        QTest.qWait(self.CLOSE_TIMEOUT)
コード例 #7
0
class TestSignalTabGUI(unittest.TestCase):
    def setUp(self):
        self.form = MainController()

    def test_close_all(self):
        # Add a bunch of signals
        NUM_SIGNALS = 10
        for _ in range(NUM_SIGNALS):
            self.form.add_signalfile("./data/esaver.complex")

        QTest.qWait(10)
        self.assertEqual(self.form.signal_tab_controller.num_signals, NUM_SIGNALS)

        self.form.close_all()
        QTest.qWait(10)
        self.assertEqual(self.form.signal_tab_controller.num_signals, 0)

        self.form.add_signalfile("./data/ask.complex")
        QTest.qWait(10)
        self.assertEqual(self.form.signal_tab_controller.num_signals, 1)
コード例 #8
0
class TestProjectManager(unittest.TestCase):
    def setUp(self):
        self.form = MainController()
        self.form.project_manager.set_project_folder(
            get_path_for_data_file(""), ask_for_new_project=False)
        self.cframe = self.form.compare_frame_controller
        self.gframe = self.form.generator_tab_controller

        self.dialog = ProjectDialogController(
            project_manager=self.form.project_manager, parent=self.form)

    def test_save_modulations(self):
        self.gframe.modulators[0].name = "Test"
        amplitude = random.random()
        self.gframe.modulators[0].carrier_amplitude = amplitude
        self.gframe.modulators[0].carrier_freq_hz = 1337
        self.gframe.modulators[0].carrier_phase_deg = 42
        self.gframe.modulators[0].modulation_type = 1
        self.gframe.modulators[0].sample_rate = 10**3
        self.gframe.modulators.append(Modulator("test 2"))
        self.gframe.modulators = self.gframe.modulators[:
                                                        2]  # Take only the first two

        self.form.project_manager.saveProject()

        loaded_mods = self.form.project_manager.read_modulators_from_project_file(
        )
        self.assertEqual(len(loaded_mods), 2)

        self.assertEqual(loaded_mods[0].name, "Test")
        self.assertEqual(loaded_mods[1].name, "test 2")
        self.assertEqual(loaded_mods[0].carrier_freq_hz, 1337)
        self.assertEqual(loaded_mods[0].carrier_phase_deg, 42)
        self.assertEqual(loaded_mods[0].modulation_type, 1)
        self.assertEqual(loaded_mods[0].sample_rate, 10**3)

        self.gframe.modulators.clear()
        self.assertEqual(len(self.gframe.modulators), 0)

        self.form.project_manager.set_project_folder(
            self.form.project_manager.project_path)
        self.assertEqual(len(self.gframe.modulators), 2)

    def test_close_all(self):
        self.form.close_all()
        QTest.qWait(1500)
        self.assertEqual(self.form.signal_tab_controller.num_signals, 0)
        self.form.add_signalfile(get_path_for_data_file("ask.complex"))
        self.form.add_signalfile(get_path_for_data_file("fsk.complex"))
        self.assertEqual(self.form.signal_tab_controller.num_signals, 2)
        self.form.close_all()
        QTest.qWait(1500)
        self.assertEqual(self.form.signal_tab_controller.num_signals, 0)
        self.assertEqual(self.form.project_manager.project_file, None)

    def test_project_dialog(self):
        frequency = 1e9
        sample_rate = 10e9
        bandwidth = 10
        gain = 42
        descr = "URH rockz."

        self.dialog.ui.spinBoxFreq.setValue(frequency)
        self.assertEqual(self.dialog.freq, frequency)

        self.dialog.ui.spinBoxSampleRate.setValue(sample_rate)
        self.assertEqual(self.dialog.sample_rate, sample_rate)

        self.dialog.ui.spinBoxBandwidth.setValue(bandwidth)
        self.assertEqual(self.dialog.bandwidth, bandwidth)

        self.dialog.ui.spinBoxGain.setValue(gain)
        self.assertEqual(self.dialog.gain, gain)

        self.dialog.ui.txtEdDescription.setPlainText(descr)
        self.assertEqual(self.dialog.description, descr)

        self.dialog.ui.lineEditBroadcastAddress.setText("abcd")
        self.dialog.ui.lineEditBroadcastAddress.textEdited.emit("abcd")
        self.assertEqual(self.dialog.broadcast_address_hex, "abcd")

        if len(self.dialog.participants) == 0:
            self.dialog.ui.btnAddParticipant.click()
            self.assertEqual(len(self.dialog.participants), 1)

        model = self.dialog.participant_table_model
        model.setData(model.index(0, 0), "Testing")
        model.setData(model.index(0, 1), "T")
        model.setData(model.index(0, 2), 5)
        model.setData(model.index(0, 3), 0)
        model.setData(model.index(0, 4), "aaaa")
        participant = self.dialog.participants[0]
        self.assertEqual(participant.name, "Testing")
        self.assertEqual(participant.shortname, "T")
        self.assertEqual(participant.color_index, 5)
        self.assertEqual(participant.relative_rssi, 0)
        self.assertEqual(participant.address_hex, "aaaa")

        num_participants = len(self.dialog.participants)
        self.dialog.ui.btnAddParticipant.click()
        self.dialog.ui.btnAddParticipant.click()
        self.dialog.ui.btnAddParticipant.click()
        self.assertEqual(len(self.dialog.participants), num_participants + 3)

        self.dialog.ui.btnRemoveParticipant.click()
        self.dialog.ui.btnRemoveParticipant.click()
        self.dialog.ui.btnRemoveParticipant.click()
        self.assertEqual(len(self.dialog.participants), num_participants)

        test_path = os.path.join(QDir.tempPath(), "urh_test")

        self.dialog.ui.lineEdit_Path.setText(test_path)
        self.dialog.ui.lineEdit_Path.textEdited.emit(test_path)
        self.assertEqual(self.dialog.path, test_path)
        self.dialog.ui.btnOK.click()

        self.assertTrue(os.path.isdir(test_path))

        self.form.project_manager.from_dialog(self.dialog)

        self.dialog = ProjectDialogController(
            project_manager=self.form.project_manager,
            parent=self.form,
            new_project=False)
        self.assertEqual(self.dialog.ui.spinBoxFreq.value(), frequency)
        self.assertEqual(self.dialog.ui.spinBoxSampleRate.value(), sample_rate)
        self.assertEqual(self.dialog.ui.spinBoxBandwidth.value(), bandwidth)
        self.assertEqual(self.dialog.ui.spinBoxGain.value(), gain)
        self.assertEqual(self.dialog.ui.txtEdDescription.toPlainText(), descr)
        self.assertFalse(self.dialog.ui.lineEdit_Path.isEnabled())
コード例 #9
0
class TestSignalTabGUI(unittest.TestCase):
    def setUp(self):
        constants.SETTINGS.setValue("not_show_save_dialog", True)
        self.form = MainController()
        self.form.add_signalfile(get_path_for_data_file("esaver.complex"))
        self.frame = self.form.signal_tab_controller.signal_frames[0]

    def test_close_all(self):
        self.form.close_all()
        QTest.qWait(250)
        self.assertEqual(self.form.signal_tab_controller.num_signals, 0)

        # Add a bunch of signals
        num_signals = 10
        for _ in range(num_signals):
            self.form.add_signalfile(get_path_for_data_file("esaver.complex"))

        self.assertEqual(self.form.signal_tab_controller.num_signals, num_signals)

        self.form.close_all()
        QTest.qWait(250)

        self.form.add_signalfile(get_path_for_data_file("ask.complex"))
        self.assertEqual(self.form.signal_tab_controller.num_signals, 1)

    def test_zoom(self):
        x_zoom = self.frame.ui.spinBoxXZoom.value()
        self.assertEqual(x_zoom, 100)

        for _ in range(10):
            self.frame.ui.gvSignal.zoom(1.01)
            self.assertGreater(self.frame.ui.spinBoxXZoom.value(), x_zoom)
            x_zoom = self.frame.ui.spinBoxXZoom.value()

        for _ in range(10):
            self.frame.ui.gvSignal.zoom(0.99)
            self.assertLess(self.frame.ui.spinBoxXZoom.value(), x_zoom)
            x_zoom = self.frame.ui.spinBoxXZoom.value()

        samples_in_view = self.frame.ui.lSamplesInView.text()
        self.frame.ui.spinBoxXZoom.setValue(self.frame.ui.spinBoxXZoom.value() + 400)
        self.assertNotEqual(samples_in_view, self.frame.ui.lSamplesInView.text())

    def test_load_proto(self):
        self.form.add_files([get_path_for_data_file("protocol.proto")])
        self.assertEqual(self.form.signal_tab_controller.signal_frames[1].ui.lSignalTyp.text(), "Protocol (*.proto)")

    def test_graphic_view_selection(self):
        self.frame.ui.gvSignal.selection_area.start = 0
        self.frame.ui.gvSignal.selection_area.end = 4000
        self.frame.ui.gvSignal.sel_area_start_end_changed.emit(0, 4000)

        self.assertEqual(self.frame.ui.lNumSelectedSamples.text(), "4000")

        noise_val = self.frame.ui.spinBoxNoiseTreshold.value()
        self.frame.ui.gvSignal.set_noise_clicked.emit()
        self.assertNotEqual(noise_val, self.frame.ui.spinBoxNoiseTreshold.value())

        self.frame.ui.spinBoxSelectionStart.setValue(300)
        self.assertEqual(self.frame.ui.gvSignal.selection_area.start, 300)
        self.frame.ui.spinBoxSelectionEnd.setValue(6000)
        self.assertEqual(self.frame.ui.gvSignal.selection_area.end, 6000)

    def test_graphic_view_zoom_to_selection(self):
        self.frame.ui.gvSignal.context_menu_position = QPoint(0, 0)
        menu = self.frame.ui.gvSignal.create_context_menu()
        self.assertTrue(self.frame.ui.gvSignal.selection_area.is_empty)
        self.assertIsNone(next((action for action in menu.actions() if action.text() == "Zoom selection"), None))

        self.frame.ui.gvSignal.selection_area.start = 1337
        self.frame.ui.gvSignal.selection_area.end = 4711
        self.frame.ui.gvSignal.sel_area_start_end_changed.emit(1337, 4711)

        menu = self.frame.ui.gvSignal.create_context_menu()
        self.assertFalse(self.frame.ui.gvSignal.selection_area.is_empty)
        zoom_action = next(action for action in menu.actions() if action.text() == "Zoom selection")
        zoom_action.trigger()
        self.assertEqual(self.frame.ui.spinBoxSelectionStart.value(), 1337)
        self.assertEqual(self.frame.ui.spinBoxSelectionEnd.value(), 4711)

    def test_show_hide_start_end(self):
        self.assertEqual(self.frame.ui.btnShowHideStartEnd.text(), "+")
        self.frame.ui.btnShowHideStartEnd.click()
        self.assertEqual(self.frame.ui.btnShowHideStartEnd.text(), "-")

    def test_apply_to_all(self):
        self.form.add_signalfile(get_path_for_data_file("ask.complex"))
        frame2 = self.form.signal_tab_controller.signal_frames[1]

        self.frame.ui.spinBoxInfoLen.setValue(42)
        self.frame.ui.spinBoxInfoLen.editingFinished.emit()

        self.frame.ui.spinBoxCenterOffset.setValue(0.1)
        self.frame.ui.spinBoxCenterOffset.editingFinished.emit()

        self.frame.ui.spinBoxNoiseTreshold.setValue(0.5)
        self.frame.ui.spinBoxNoiseTreshold.editingFinished.emit()

        self.frame.ui.spinBoxTolerance.setValue(10)
        self.frame.ui.spinBoxTolerance.editingFinished.emit()

        self.frame.apply_to_all_clicked.emit(self.frame.signal)

        self.assertEqual(42, frame2.ui.spinBoxInfoLen.value())
        self.assertEqual(0.1, frame2.ui.spinBoxCenterOffset.value())
        self.assertEqual(0.5, frame2.ui.spinBoxNoiseTreshold.value())
        self.assertEqual(10, frame2.ui.spinBoxTolerance.value())

    def test_save_all(self):
        self.form.add_signalfile(get_path_for_data_file("ask.complex"))
        frame2 = self.form.signal_tab_controller.signal_frames[1]

        self.frame.signal.changed = True
        self.frame.signal.filename = os.path.join(QDir.tempPath(), "sig1.complex")

        frame2.signal.changed = True
        frame2.signal.filename = os.path.join(QDir.tempPath(), "sig2.complex")

        self.assertFalse(os.path.isfile(self.frame.signal.filename))
        self.assertFalse(os.path.isfile(frame2.signal.filename))

        self.form.signal_tab_controller.save_all()

        self.assertTrue(os.path.isfile(self.frame.signal.filename))
        self.assertTrue(os.path.isfile(frame2.signal.filename))

        os.remove(self.frame.signal.filename)
        os.remove(frame2.signal.filename)

    def test_crop_and_save_signal(self):
        self.frame.ui.gvSignal.selection_area.end = 4000
        self.frame.ui.gvSignal.selection_area.start = 1000

        self.assertEqual(self.frame.ui.gvSignal.selection_area.end, 4000)
        self.assertEqual(self.frame.ui.gvSignal.selection_area.width, 3000)
        self.frame.ui.gvSignal.sel_area_start_end_changed.emit(1000, 4000)

        self.frame.ui.gvSignal.on_crop_action_triggered()
        self.assertEqual(self.frame.signal.num_samples, 3000)
        self.assertTrue(self.frame.signal.changed)

        self.frame.signal.filename = os.path.join(QDir.tempPath(), "sig.complex")
        self.assertFalse(os.path.isfile(self.frame.signal.filename))
        self.frame.ui.btnSaveSignal.click()
        self.form.close_signal_frame(self.frame)
        QTest.qWait(50)
        self.form.add_signalfile(os.path.join(QDir.tempPath(), "sig.complex"))
        self.assertEqual(self.form.signal_tab_controller.signal_frames[0].signal.num_samples, 3000)
        os.remove(os.path.join(QDir.tempPath(), "sig.complex"))
コード例 #10
0
class QtTestCase(unittest.TestCase):
    CLOSE_TIMEOUT = 10
    WAIT_TIMEOUT_BEFORE_NEW = 10
    SHOW = os.path.exists(
        os.path.join(os.path.dirname(os.path.realpath(__file__)), "show_gui"))

    @classmethod
    def setUpClass(cls):
        import multiprocessing as mp
        try:
            mp.set_start_method("spawn")
        except RuntimeError:
            pass
        assert mp.get_start_method() == "spawn"

        write_settings()
        cls.app = QApplication([cls.__name__])

    @classmethod
    def tearDownClass(cls):
        cls.app.quit()
        if sys.platform == "win32" or sys.platform == "darwin":
            sip.delete(cls.app)
            cls.app = None
            QTest.qWait(10)
            time.sleep(0.1)

    def setUp(self):
        self.form = MainController()
        if self.SHOW:
            self.form.show()

    def tearDown(self):
        if hasattr(self, "dialog"):
            self.dialog.close()

            if sys.platform == "win32" or sys.platform == "darwin":
                sip.delete(self.dialog)
                self.dialog = None

        if hasattr(self, "form"):
            self.form.close_all()
            self.form.close()

            if sys.platform == "win32" or sys.platform == "darwin":
                sip.delete(self.form)
                self.form = None
        if sys.platform == "darwin":
            gc.collect()

    def wait_before_new_file(self):
        QApplication.instance().processEvents()
        QTest.qWait(self.WAIT_TIMEOUT_BEFORE_NEW)

    def add_signal_to_form(self, filename: str):
        self.wait_before_new_file()
        self.form.add_signalfile(get_path_for_data_file(filename))

    def get_path_for_filename(self, filename) -> str:
        return get_path_for_data_file(filename)

    def add_signal_to_generator(self, signal_index: int):
        gframe = self.form.generator_tab_controller
        item = gframe.tree_model.rootItem.children[0].children[signal_index]
        index = gframe.tree_model.createIndex(signal_index, 0, item)
        rect = gframe.ui.treeProtocols.visualRect(index)
        QTest.mousePress(gframe.ui.treeProtocols.viewport(),
                         Qt.LeftButton,
                         pos=rect.center())
        self.assertEqual(gframe.ui.treeProtocols.selectedIndexes()[0], index)
        mimedata = gframe.tree_model.mimeData(
            gframe.ui.treeProtocols.selectedIndexes())
        gframe.table_model.dropMimeData(mimedata, 1, -1, -1,
                                        gframe.table_model.createIndex(0, 0))

    def add_all_signals_to_simulator(self):
        assert isinstance(self.form, MainController)
        sim_frame = self.form.simulator_tab_controller
        sim_frame.ui.treeProtocols.selectAll()
        self.assertGreater(len(sim_frame.ui.treeProtocols.selectedIndexes()),
                           0)
        mimedata = sim_frame.tree_model.mimeData(
            sim_frame.ui.treeProtocols.selectedIndexes())
        drop_event = QDropEvent(sim_frame.ui.gvSimulator.rect().center(),
                                Qt.CopyAction | Qt.MoveAction, mimedata,
                                Qt.LeftButton, Qt.NoModifier)
        drop_event.acceptProposedAction()
        sim_frame.ui.gvSimulator.dropEvent(drop_event)

    def get_free_port(self):
        import socket
        s = socket.socket()
        s.bind(("", 0))
        port = s.getsockname()[1]
        s.close()
        return port
コード例 #11
0
ファイル: test_signal_tab_GUI.py プロジェクト: icakir/urh
class TestSignalTabGUI(unittest.TestCase):
    def setUp(self):
        self.form = MainController()

    def test_close_all(self):
        # Add a bunch of signals
        NUM_SIGNALS = 10
        for _ in range(NUM_SIGNALS):
            self.form.add_signalfile(get_path_for_data_file("esaver.complex"))

        self.assertEqual(self.form.signal_tab_controller.num_signals,
                         NUM_SIGNALS)

        self.form.close_all()
        QTest.qWait(100)
        self.assertEqual(self.form.signal_tab_controller.num_signals, 0)

        self.form.add_signalfile(get_path_for_data_file("ask.complex"))
        self.assertEqual(self.form.signal_tab_controller.num_signals, 1)

    def test_zoom(self):
        self.form.add_signalfile(get_path_for_data_file("esaver.complex"))
        frame = self.form.signal_tab_controller.signal_frames[0]
        x_zoom = frame.ui.spinBoxXZoom.value()
        self.assertEqual(x_zoom, 100)

        for _ in range(10):
            frame.ui.gvSignal.zoom(1.01)
            self.assertGreater(frame.ui.spinBoxXZoom.value(), x_zoom)
            x_zoom = frame.ui.spinBoxXZoom.value()

        for _ in range(10):
            frame.ui.gvSignal.zoom(0.99)
            self.assertLess(frame.ui.spinBoxXZoom.value(), x_zoom)
            x_zoom = frame.ui.spinBoxXZoom.value()

        samples_in_view = frame.ui.lSamplesInView.text()
        frame.ui.spinBoxXZoom.setValue(frame.ui.spinBoxXZoom.value() + 400)
        self.assertNotEqual(samples_in_view, frame.ui.lSamplesInView.text())

    def test_load_proto(self):
        self.form.add_files([get_path_for_data_file("protocol.proto")])
        self.assertEqual(
            self.form.signal_tab_controller.signal_frames[0].ui.lSignalTyp.
            text(), "Protocol (*.proto)")

    def test_graphic_view_selection(self):
        self.form.add_signalfile(get_path_for_data_file("esaver.complex"))
        frame = self.form.signal_tab_controller.signal_frames[0]

        frame.ui.gvSignal.selection_area.start = 0
        frame.ui.gvSignal.selection_area.end = 4000
        frame.ui.gvSignal.sel_area_start_end_changed.emit(0, 4000)

        self.assertEqual(frame.ui.lNumSelectedSamples.text(), "4000")

        noise_val = frame.ui.spinBoxNoiseTreshold.value()
        frame.ui.gvSignal.set_noise_clicked.emit()
        self.assertNotEqual(noise_val, frame.ui.spinBoxNoiseTreshold.value())

        frame.ui.spinBoxSelectionStart.setValue(300)
        self.assertEqual(frame.ui.gvSignal.selection_area.start, 300)
        frame.ui.spinBoxSelectionEnd.setValue(6000)
        self.assertEqual(frame.ui.gvSignal.selection_area.end, 6000)

    def test_show_hide_start_end(self):
        self.form.add_signalfile(get_path_for_data_file("esaver.complex"))
        frame = self.form.signal_tab_controller.signal_frames[0]

        self.assertEqual(frame.ui.btnShowHideStartEnd.text(), "+")
        frame.ui.btnShowHideStartEnd.click()
        self.assertEqual(frame.ui.btnShowHideStartEnd.text(), "-")
コード例 #12
0
class TestPlugins(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
        logger.debug("Init form")
        self.form = MainController()
        logger.debug("Initalized form")
        self.form.add_signalfile(get_path_for_data_file("esaver.complex"))
        self.sframe = self.form.signal_tab_controller.signal_frames[0]
        self.cframe = self.form.compare_frame_controller
        self.gframe = self.form.generator_tab_controller
        self.form.ui.tabWidget.setCurrentIndex(1)
        self.assertEqual(self.cframe.protocol_model.row_count, 3)

        self.signal = self.sframe.signal

    def tearDown(self):
        self.form.close_all()
        tests.utils_testing.short_wait()
        self.form.close()
        self.form.setParent(None)
        self.form.deleteLater()
        tests.utils_testing.short_wait()

    def test_message_break_plugin(self):
        bp = MessageBreakPlugin()
        action = bp.get_action(self.cframe.ui.tblViewProtocol,
                               self.cframe.protocol_undo_stack, (1, 1, 4, 4),
                               self.cframe.proto_analyzer, 0)
        self.assertEqual(self.cframe.protocol_model.row_count, 3)
        action.trigger()
        self.assertEqual(self.cframe.protocol_model.row_count, 4)

        self.cframe.protocol_undo_stack.undo()
        self.assertEqual(self.cframe.protocol_model.row_count, 3)

    def test_zero_hide_plugin_gui(self):
        self.assertEqual(
            len(self.cframe.proto_analyzer.decoded_proto_bits_str[0]), 377)
        zh = ZeroHidePlugin()
        zh.following_zeros = 188
        action = zh.get_action(self.cframe.ui.tblViewProtocol,
                               self.cframe.protocol_undo_stack, (),
                               self.cframe.proto_analyzer, 0)
        action.trigger()
        self.assertEqual(
            len(self.cframe.proto_analyzer.decoded_proto_bits_str[0]),
            377 - 188)

        self.cframe.protocol_undo_stack.undo()
        self.assertEqual(
            len(self.cframe.proto_analyzer.decoded_proto_bits_str[0]), 377)

    def test_zero_hide_plugin_function(self):
        zh = ZeroHidePlugin()
        zh.following_zeros = 3
        self.form.add_signalfile(get_path_for_data_file("ask.complex"))
        self.form.ui.tabWidget.setCurrentIndex(1)
        test_bits = "10110010010110110110110110110110110001000000"
        self.assertEqual(self.cframe.proto_analyzer.decoded_proto_bits_str[3],
                         test_bits)

        action = zh.get_action(self.cframe.ui.tblViewProtocol,
                               self.cframe.protocol_undo_stack, (),
                               self.cframe.proto_analyzer, 0)
        action.trigger()
        self.assertEqual(self.cframe.proto_analyzer.decoded_proto_bits_str[3],
                         "10110010010110110110110110110110111")

    def test_sdr_interface_plugin(self):
        si = NetworkSDRInterfacePlugin()
        test_bits = [
            "10101011111", "1010100011000111110001011001010101010101",
            "1010100011000111110001011001010100100", "1101010101011000011",
            "11010101010110000110", "11100010101001110000",
            "111100000011011101010101010000101010101010100001010011010101010011"
        ]

        for bits in test_bits:
            byte_vals = si.bit_str_to_bytearray(bits)
            self.assertEqual(len(byte_vals),
                             int(math.ceil(len(bits) / 8)),
                             msg=bits)

            recalculated = si.bytearray_to_bit_str(byte_vals)

            if len(bits) % 8 == 0:
                self.assertEqual(bits, recalculated)
            elif bits.endswith("1"):
                self.assertEqual(bits, recalculated.rstrip("0"))
            else:
                self.assertTrue(recalculated.startswith(bits))

    def test_insert_sine_plugin(self):
        insert_sine_plugin = self.sframe.ui.gvSignal.insert_sine_plugin
        num_samples = 10000
        tests.utils_testing.short_wait()
        dialog = insert_sine_plugin.get_insert_sine_dialog(
            original_data=self.signal.data,
            position=2000,
            sample_rate=self.signal.sample_rate,
            num_samples=num_samples)

        graphics_view = dialog.graphicsViewSineWave  # type: ZoomableGraphicView

        while not dialog.doubleSpinBoxAmplitude.isEnabled():
            tests.utils_testing.short_wait()

        self.assertEqual(int(graphics_view.sceneRect().width()),
                         self.signal.num_samples + num_samples)
        self.assertEqual(insert_sine_plugin.insert_indicator.rect().width(),
                         num_samples)
        self.assertEqual(insert_sine_plugin.insert_indicator.rect().x(), 2000)

        dialog.doubleSpinBoxAmplitude.setValue(0.1)
        dialog.doubleSpinBoxAmplitude.editingFinished.emit()
        self.assertEqual(insert_sine_plugin.amplitude, 0.1)

        while not dialog.doubleSpinBoxAmplitude.isEnabled():
            tests.utils_testing.short_wait()

        dialog.doubleSpinBoxFrequency.setValue(1e6)
        dialog.doubleSpinBoxFrequency.editingFinished.emit()
        self.assertEqual(insert_sine_plugin.frequency, 1e6)

        while not dialog.doubleSpinBoxAmplitude.isEnabled():
            tests.utils_testing.short_wait()

        dialog.doubleSpinBoxPhase.setValue(100)
        dialog.doubleSpinBoxPhase.editingFinished.emit()
        self.assertEqual(insert_sine_plugin.phase, 100)

        while not dialog.doubleSpinBoxAmplitude.isEnabled():
            tests.utils_testing.short_wait()

        dialog.doubleSpinBoxSampleRate.setValue(2e6)
        dialog.doubleSpinBoxSampleRate.editingFinished.emit()
        self.assertEqual(insert_sine_plugin.sample_rate, 2e6)

        while not dialog.doubleSpinBoxAmplitude.isEnabled():
            tests.utils_testing.short_wait()

        dialog.doubleSpinBoxNSamples.setValue(0.5e6)
        dialog.doubleSpinBoxNSamples.editingFinished.emit()
        self.assertEqual(insert_sine_plugin.num_samples, 0.5e6)

        while not dialog.doubleSpinBoxAmplitude.isEnabled():
            tests.utils_testing.short_wait()

        sep = Formatter.local_decimal_seperator()
        self.assertEqual(dialog.lineEditTime.text(), "250" + sep + "000m")
コード例 #13
0
ファイル: test_analysis_tab_GUI.py プロジェクト: tariq786/urh
class TestAnalysisTabGUI(unittest.TestCase):
    def setUp(self):
        constants.SETTINGS.setValue(
            "not_show_close_dialog",
            True)  # prevent interactive close questions
        self.form = MainController()
        self.cfc = self.form.compare_frame_controller
        self.form.add_signalfile(
            get_path_for_data_file("two_participants.complex"))
        self.signal = self.form.signal_tab_controller.signal_frames[0].signal
        self.signal.noise_threshold = 0.0175
        self.signal.qad_center = 0
        self.signal.bit_len = 100
        self.signal.tolerance = 5

    def test_analyze_button_fsk(self):
        self.form.add_signalfile(get_path_for_data_file("fsk.complex"))
        self.cfc.ui.btnAnalyze.click()
        self.assertTrue(True)

    def test_analyze_button_enocean(self):
        self.form.add_signalfile(get_path_for_data_file("enocean.complex"))
        w = self.form.signal_tab_controller.signal_frames[
            1].ui.spinBoxCenterOffset
        w.setValue(0)
        QTest.keyClick(w, Qt.Key_Enter)
        w = self.form.signal_tab_controller.signal_frames[
            1].ui.spinBoxNoiseTreshold
        w.setValue(0.0111)
        QTest.keyClick(w, Qt.Key_Enter)
        self.cfc.ui.btnAnalyze.click()
        self.assertTrue(True)

    def test_table_selection(self):
        self.form.ui.tabWidget.setCurrentIndex(1)
        self.cfc.ui.cbProtoView.setCurrentIndex(0)
        self.cfc.ui.btnAnalyze.click()

        self.cfc.ui.tblViewProtocol.selectRow(1)
        app.processEvents()
        self.assertEqual(self.cfc.ui.lBitsSelection.text(),
                         self.cfc.proto_analyzer.messages[1].plain_bits_str)

        self.cfc.ui.tblViewProtocol.clearSelection()
        app.processEvents()
        self.assertEqual("", self.cfc.ui.lBitsSelection.text())

        self.cfc.ui.tblViewProtocol.select(0, 0, 0, 3)
        app.processEvents()
        self.assertEqual("1010", self.cfc.ui.lBitsSelection.text())
        self.cfc.ui.cbProtoView.setCurrentIndex(1)
        min_row, max_row, start, end = self.cfc.ui.tblViewProtocol.selection_range(
        )
        self.assertEqual(min_row, 0)
        self.assertEqual(max_row, 0)
        self.assertEqual(start, 0)
        self.assertEqual(end, 1)

    def test_search(self):
        search_str = "100110001"
        self.cfc.ui.cbProtoView.setCurrentIndex(0)
        self.cfc.ui.tblViewProtocol.clearSelection()
        self.cfc.ui.lineEditSearch.setText(search_str)
        self.cfc.ui.btnSearchSelectFilter.click()

        selected_now = self.cfc.ui.tblViewProtocol.selectedIndexes()
        self.assertEqual(len(self.cfc.ui.tblViewProtocol.selectedIndexes()),
                         len(search_str))

        self.cfc.ui.btnNextSearch.click()
        self.assertNotEqual(selected_now,
                            self.cfc.ui.tblViewProtocol.selectedIndexes())

        self.cfc.ui.btnPrevSearch.click()
        self.assertEqual(selected_now,
                         self.cfc.ui.tblViewProtocol.selectedIndexes())

        self.cfc.select_action.trigger()
        self.assertEqual(self.cfc.ui.btnSearchSelectFilter.text(),
                         "Select all")
        self.cfc.ui.btnSearchSelectFilter.click()
        self.assertGreater(len(self.cfc.ui.tblViewProtocol.selectedIndexes()),
                           len(selected_now))

        self.cfc.filter_action.trigger()
        self.assertEqual(self.cfc.ui.btnSearchSelectFilter.text(), "Filter")
        self.cfc.ui.btnSearchSelectFilter.click()
        hidden_rows = [
            i for i in range(self.cfc.protocol_model.row_count)
            if self.cfc.ui.tblViewProtocol.isRowHidden(i)
        ]

        self.assertEqual(hidden_rows, [0, 5, 6, 10, 13, 14, 16, 17])

    def test_show_diff(self):
        hidden_columns_before = [
            i for i in range(self.cfc.protocol_model.col_count)
            if self.cfc.ui.tblViewProtocol.isColumnHidden(i)
        ]
        self.assertEqual(len(hidden_columns_before), 0)

        self.cfc.ui.chkBoxShowOnlyDiffs.click()
        self.assertTrue(self.cfc.ui.cbShowDiffs.isChecked())

        hidden_columns_now = [
            i for i in range(self.cfc.protocol_model.col_count)
            if self.cfc.ui.tblViewProtocol.isColumnHidden(i)
        ]

        self.assertNotEqual(hidden_columns_before, hidden_columns_now)

        self.cfc.ui.chkBoxOnlyShowLabelsInProtocol.click()

        hidden_columns_now = [
            i for i in range(self.cfc.protocol_model.col_count)
            if self.cfc.ui.tblViewProtocol.isColumnHidden(i)
        ]

        self.assertEqual(len(hidden_columns_now),
                         self.cfc.protocol_model.col_count)

    def test_add_message_type(self):
        self.assertEqual(len(self.cfc.proto_analyzer.message_types), 1)
        self.cfc.ui.btnAddMessagetype.click()
        self.assertEqual(len(self.cfc.proto_analyzer.message_types), 2)

    def test_create_context_menu(self):
        # Add protocol label should be disabled if table is empty
        self.form.close_all()
        self.assertEqual(self.cfc.protocol_model.rowCount(), 0)
        self.cfc.ui.tblViewProtocol.context_menu_pos = QPoint(0, 0)
        menu = self.cfc.ui.tblViewProtocol.create_context_menu()

        create_label_action = next(a for a in menu.actions()
                                   if a.text() == "Add protocol label")
        self.assertFalse(create_label_action.isEnabled())

    def test_show_in_interpretation(self):
        self.form.ui.tabWidget.setCurrentIndex(1)
        self.assertEqual(self.form.ui.tabWidget.currentIndex(), 1)
        self.cfc.ui.cbProtoView.setCurrentIndex(0)

        self.cfc.ui.tblViewProtocol.selectRow(1)
        min_row, max_row, start, end = self.cfc.ui.tblViewProtocol.selection_range(
        )
        self.cfc.ui.tblViewProtocol.show_interpretation_clicked.emit(
            min_row, max_row, start, end - 1)
        self.assertEqual(self.form.ui.tabWidget.currentIndex(), 0)
コード例 #14
0
ファイル: test_signal_tab_GUI.py プロジェクト: sthysel/urh
class TestSignalTabGUI(unittest.TestCase):
    def setUp(self):
        constants.SETTINGS.setValue("not_show_save_dialog", True)
        logger.debug("Init Form")
        tests.utils_testing.short_wait()
        self.form = MainController()
        tests.utils_testing.short_wait()
        logger.debug("Add Signal")
        self.form.add_signalfile(get_path_for_data_file("esaver.complex"))
        logger.debug("Added Signal")
        app.processEvents()
        self.frame = self.form.signal_tab_controller.signal_frames[0]
        self.frame.signal.noise_threshold = 0.0023
        self.frame.signal.qad_center = 0.3817
        self.frame.signal.bit_len = 84

    def tearDown(self):
        self.form.close_all()
        tests.utils_testing.short_wait()
        self.form.close()
        self.form.setParent(None)
        self.form.deleteLater()
        tests.utils_testing.short_wait()

    def test_close_all(self):
        logger.debug("Close all")
        self.form.close_all()
        tests.utils_testing.short_wait()
        logger.debug("Called close all")
        app.processEvents()
        self.assertEqual(self.form.signal_tab_controller.num_signals, 0)

        # Add a bunch of signals
        num_signals = 5
        for _ in range(num_signals):
            tests.utils_testing.short_wait()
            self.form.add_signalfile(get_path_for_data_file("esaver.complex"))

        self.assertEqual(self.form.signal_tab_controller.num_signals,
                         num_signals)

        self.form.close_all()
        tests.utils_testing.short_wait()

        self.form.add_signalfile(get_path_for_data_file("ask.complex"))
        self.assertEqual(self.form.signal_tab_controller.num_signals, 1)

    def test_zoom(self):
        tests.utils_testing.short_wait()
        x_zoom = self.frame.ui.spinBoxXZoom.value()
        self.assertEqual(x_zoom, 100)

        for _ in range(10):
            self.frame.ui.gvSignal.zoom(1.01)
            self.assertGreater(self.frame.ui.spinBoxXZoom.value(), x_zoom)
            x_zoom = self.frame.ui.spinBoxXZoom.value()

        for _ in range(10):
            self.frame.ui.gvSignal.zoom(0.99)
            self.assertLess(self.frame.ui.spinBoxXZoom.value(), x_zoom)
            x_zoom = self.frame.ui.spinBoxXZoom.value()

        samples_in_view = self.frame.ui.lSamplesInView.text()
        self.frame.ui.spinBoxXZoom.setValue(
            self.frame.ui.spinBoxXZoom.value() + 400)
        self.assertNotEqual(samples_in_view,
                            self.frame.ui.lSamplesInView.text())

    def test_load_proto(self):
        self.form.add_files([get_path_for_data_file("protocol.proto")])
        self.assertEqual(
            self.form.signal_tab_controller.signal_frames[1].ui.lSignalTyp.
            text(), "Protocol (*.proto)")

    def test_graphic_view_selection(self):
        self.frame.ui.gvSignal.selection_area.start = 0
        self.frame.ui.gvSignal.selection_area.end = 4000
        self.frame.ui.gvSignal.sel_area_start_end_changed.emit(0, 4000)

        self.assertEqual(self.frame.ui.lNumSelectedSamples.text(), "4000")

        noise_val = self.frame.ui.spinBoxNoiseTreshold.value()
        self.frame.ui.gvSignal.set_noise_clicked.emit()
        self.assertNotEqual(noise_val,
                            self.frame.ui.spinBoxNoiseTreshold.value())

        self.frame.ui.spinBoxSelectionStart.setValue(300)
        self.assertEqual(self.frame.ui.gvSignal.selection_area.start, 300)
        self.frame.ui.spinBoxSelectionEnd.setValue(6000)
        self.assertEqual(self.frame.ui.gvSignal.selection_area.end, 6000)

    def test_graphic_view_zoom_to_selection(self):
        self.frame.ui.gvSignal.context_menu_position = QPoint(0, 0)
        menu = self.frame.ui.gvSignal.create_context_menu()
        self.assertTrue(self.frame.ui.gvSignal.selection_area.is_empty)
        self.assertIsNone(
            next((action for action in menu.actions()
                  if action.text() == "Zoom selection"), None))

        self.frame.ui.gvSignal.selection_area.start = 1337
        self.frame.ui.gvSignal.selection_area.end = 4711
        self.frame.ui.gvSignal.sel_area_start_end_changed.emit(1337, 4711)

        menu = self.frame.ui.gvSignal.create_context_menu()
        self.assertFalse(self.frame.ui.gvSignal.selection_area.is_empty)
        zoom_action = next(action for action in menu.actions()
                           if action.text() == "Zoom selection")
        zoom_action.trigger()
        self.assertEqual(self.frame.ui.spinBoxSelectionStart.value(), 1337)
        self.assertEqual(self.frame.ui.spinBoxSelectionEnd.value(), 4711)

    def test_show_hide_start_end(self):
        self.assertEqual(self.frame.ui.btnShowHideStartEnd.text(), "+")
        self.frame.ui.btnShowHideStartEnd.click()
        self.assertEqual(self.frame.ui.btnShowHideStartEnd.text(), "-")

    def test_apply_to_all(self):
        logger.debug("Test apply to all")
        tests.utils_testing.short_wait()
        self.form.add_signalfile(get_path_for_data_file("ask.complex"))
        logger.debug("added new signal")
        frame2 = self.form.signal_tab_controller.signal_frames[1]

        self.frame.ui.spinBoxInfoLen.setValue(42)
        self.frame.ui.spinBoxInfoLen.editingFinished.emit()

        self.frame.ui.spinBoxCenterOffset.setValue(0.1)
        self.frame.ui.spinBoxCenterOffset.editingFinished.emit()

        self.frame.ui.spinBoxNoiseTreshold.setValue(0.5)
        self.frame.ui.spinBoxNoiseTreshold.editingFinished.emit()

        self.frame.ui.spinBoxTolerance.setValue(10)
        self.frame.ui.spinBoxTolerance.editingFinished.emit()

        self.frame.apply_to_all_clicked.emit(self.frame.signal)

        self.assertEqual(42, frame2.ui.spinBoxInfoLen.value())
        self.assertEqual(0.1, frame2.ui.spinBoxCenterOffset.value())
        self.assertEqual(0.5, frame2.ui.spinBoxNoiseTreshold.value())
        self.assertEqual(10, frame2.ui.spinBoxTolerance.value())

    def test_save_all(self):
        logger.debug("Test save all")
        tests.utils_testing.short_wait()
        self.form.add_signalfile(get_path_for_data_file("ask.complex"))
        frame2 = self.form.signal_tab_controller.signal_frames[1]

        self.frame.signal.changed = True
        self.frame.signal.filename = os.path.join(QDir.tempPath(),
                                                  "sig1.complex")

        frame2.signal.changed = True
        frame2.signal.filename = os.path.join(QDir.tempPath(), "sig2.complex")

        self.assertFalse(os.path.isfile(self.frame.signal.filename))
        self.assertFalse(os.path.isfile(frame2.signal.filename))

        self.form.signal_tab_controller.save_all()

        self.assertTrue(os.path.isfile(self.frame.signal.filename))
        self.assertTrue(os.path.isfile(frame2.signal.filename))

        os.remove(self.frame.signal.filename)
        os.remove(frame2.signal.filename)

    def test_crop_and_save_signal(self):
        self.frame.ui.gvSignal.selection_area.end = 4000
        self.frame.ui.gvSignal.selection_area.start = 1000

        self.assertEqual(self.frame.ui.gvSignal.selection_area.end, 4000)
        self.assertEqual(self.frame.ui.gvSignal.selection_area.width, 3000)
        self.frame.ui.gvSignal.sel_area_start_end_changed.emit(1000, 4000)

        self.frame.ui.gvSignal.on_crop_action_triggered()
        self.assertEqual(self.frame.signal.num_samples, 3000)
        self.assertTrue(self.frame.signal.changed)

        self.frame.signal.filename = os.path.join(QDir.tempPath(),
                                                  "sig.complex")
        if os.path.isfile(self.frame.signal.filename):
            os.remove(self.frame.signal.filename)

        self.assertFalse(os.path.isfile(self.frame.signal.filename))
        self.frame.ui.btnSaveSignal.click()
        self.form.close_signal_frame(self.frame)
        tests.utils_testing.short_wait()
        self.form.add_signalfile(os.path.join(QDir.tempPath(), "sig.complex"))
        self.assertEqual(
            self.form.signal_tab_controller.signal_frames[0].signal.
            num_samples, 3000)
        os.remove(os.path.join(QDir.tempPath(), "sig.complex"))

    def test_selection_sync(self):
        self.frame.ui.gvSignal.selection_area.end = 128440
        self.frame.ui.gvSignal.selection_area.start = 89383
        self.frame.ui.gvSignal.sel_area_start_end_changed.emit(89383, 128440)
        tests.utils_testing.short_wait()
        self.assertEqual(self.frame.proto_analyzer.messages[0].plain_bits_str,
                         self.frame.ui.txtEdProto.selected_text)
        self.frame.ui.txtEdProto.show_proto_clicked.emit()
        tests.utils_testing.short_wait()
        self.assertAlmostEqual(
            (128440 - 89383) / 1000000,
            (self.frame.ui.gvSignal.view_rect().width()) / 1000000,
            places=1)

    def test_show_demod_view(self):
        self.assertTrue(self.frame.ui.gvLegend.isHidden())
        self.frame.ui.cbSignalView.setCurrentIndex(1)
        self.assertFalse(self.frame.ui.gvLegend.isHidden())

    def test_auto_detect_button(self):
        self.assertTrue(self.frame.ui.btnAutoDetect.isChecked())
        self.frame.ui.btnAutoDetect.click()
        self.assertFalse(self.frame.ui.btnAutoDetect.isChecked())