forked from jopohl/urh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_util.py
111 lines (84 loc) · 4.08 KB
/
test_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import array
import copy
import os
import sys
import tempfile
from PyQt5.QtGui import QIcon
from tests.QtTestCase import QtTestCase
from tests.utils_testing import get_path_for_data_file
from urh import settings
from urh.dev.PCAP import PCAP
from urh.signalprocessing.ProtocolAnalyzer import ProtocolAnalyzer
from urh.signalprocessing.Signal import Signal
from urh.util import util
from urh.util.Logger import logger
from urh.cythonext import util as c_util
class TestUtil(QtTestCase):
def test_set_icon_theme(self):
settings.write("icon_theme_index", 0)
util.set_icon_theme()
self.assertEqual(QIcon.themeName(), "oxy")
settings.write("icon_theme_index", 1)
util.set_icon_theme()
if sys.platform == "linux":
self.assertNotEqual(QIcon.themeName(), "oxy")
else:
self.assertEqual(QIcon.themeName(), "oxy")
def test_set_shared_lib_path(self):
before = os.environ["PATH"]
util.set_shared_library_path()
def test_create_textbox_dialog(self):
dialog = util.create_textbox_dialog("Test content", "Test title", parent=self.form)
self.assertEqual(dialog.windowTitle(), "Test title")
self.assertEqual(dialog.layout().itemAt(0).widget().toPlainText(), "Test content")
dialog.close()
def test_get_receive_buffer_size(self):
settings.OVERWRITE_RECEIVE_BUFFER_SIZE = None
ns = settings.get_receive_buffer_size(resume_on_full_receive_buffer=True, spectrum_mode=True)
self.assertEqual(ns, settings.SPECTRUM_BUFFER_SIZE)
ns = settings.get_receive_buffer_size(resume_on_full_receive_buffer=True, spectrum_mode=False)
self.assertEqual(ns, settings.SNIFF_BUFFER_SIZE)
ns1 = settings.get_receive_buffer_size(resume_on_full_receive_buffer=False, spectrum_mode=True)
ns2 = settings.get_receive_buffer_size(resume_on_full_receive_buffer=False, spectrum_mode=False)
self.assertEqual(len(str(ns1)), len(str(ns2)))
def test_write_pcap(self):
signal = Signal(get_path_for_data_file("ask.complex"), "ASK-Test")
signal.modulation_type = "ASK"
signal.samples_per_symbol = 295
signal.center = -0.1667
self.assertEqual(signal.num_samples, 13710)
proto_analyzer = ProtocolAnalyzer(signal)
proto_analyzer.get_protocol_from_signal()
self.assertEqual(proto_analyzer.decoded_hex_str[0], "b25b6db6c80")
proto_analyzer.messages.append(copy.deepcopy(proto_analyzer.messages[0]))
proto_analyzer.messages.append(copy.deepcopy(proto_analyzer.messages[0]))
proto_analyzer.messages.append(copy.deepcopy(proto_analyzer.messages[0]))
pcap = PCAP()
pcap.write_packets(proto_analyzer.messages, os.path.join(tempfile.gettempdir(), "test.pcap"), 1e6)
def test_de_bruijn_fuzzing(self):
self.assertEqual(c_util.de_bruijn(3), array.array("B", [0, 0, 0, 1, 0, 1, 1, 1]))
self.assertEqual(c_util.de_bruijn(4), array.array("B", [0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1]))
def test_native_backends_installed(self):
from urh.util import util
if not util.get_shared_library_path():
logger.info("Shared library dir not found, skipping check of native device extensions")
return
util.set_shared_library_path()
# noinspection PyUnresolvedReferences
from urh.dev.native.lib import airspy
# noinspection PyUnresolvedReferences
from urh.dev.native.lib import bladerf
# noinspection PyUnresolvedReferences
from urh.dev.native.lib import hackrf
# noinspection PyUnresolvedReferences
from urh.dev.native.lib import rtlsdr
# noinspection PyUnresolvedReferences
from urh.dev.native.lib import limesdr
# noinspection PyUnresolvedReferences
from urh.dev.native.lib import plutosdr
# noinspection PyUnresolvedReferences
from urh.dev.native.lib import usrp
if sys.platform != "darwin":
# noinspection PyUnresolvedReferences
from urh.dev.native.lib import sdrplay
self.assertTrue(True)