FreeDATA/tests/test_data_frame_factory.py

69 lines
2.6 KiB
Python
Raw Normal View History

2023-11-27 18:22:16 +00:00
import sys
2024-04-17 20:49:08 +00:00
sys.path.append('freedata-server')
2023-11-27 18:22:16 +00:00
import unittest
from config import CONFIG
2023-12-13 08:56:58 +00:00
from data_frame_factory import DataFrameFactory
from codec2 import FREEDV_MODE
2023-11-27 22:08:00 +00:00
import helpers
2023-12-13 15:56:11 +00:00
from modem_frametypes import FRAME_TYPE
2023-11-27 18:22:16 +00:00
class TestDataFrameFactory(unittest.TestCase):
@classmethod
def setUpClass(cls):
2024-04-17 20:49:08 +00:00
config_manager = CONFIG('freedata-server/config.ini.example')
2023-11-27 18:22:16 +00:00
config = config_manager.read()
2023-12-13 08:56:58 +00:00
cls.factory = DataFrameFactory(config)
2023-11-27 18:22:16 +00:00
def testBeacon(self):
beacon_frame = self.factory.build_beacon()
beacon_data = self.factory.deconstruct(beacon_frame)
2023-11-29 16:39:35 +00:00
self.assertEqual(beacon_data['origin'], self.factory.myfullcall.upper())
2023-11-27 22:08:00 +00:00
self.assertEqual(beacon_data['gridsquare'], self.factory.mygrid.upper())
2023-11-27 18:22:16 +00:00
def testPing(self):
dxcall = "DJ2LS-3"
ping_frame = self.factory.build_ping(dxcall)
ping_data = self.factory.deconstruct(ping_frame)
2023-11-29 16:39:35 +00:00
self.assertEqual(ping_data['origin'], self.factory.myfullcall)
2023-12-13 08:24:43 +00:00
self.assertEqual(ping_data['destination_crc'], helpers.get_crc_24(dxcall).hex())
2023-11-27 22:08:00 +00:00
2023-12-13 08:24:43 +00:00
def testARQConnect(self):
2023-11-27 22:08:00 +00:00
dxcall = "DJ2LS-4"
session_id = 123
2024-03-24 20:47:48 +00:00
frame = self.factory.build_arq_session_open(dxcall, session_id, 1700)
2023-11-27 22:08:00 +00:00
frame_data = self.factory.deconstruct(frame)
2023-11-29 16:39:35 +00:00
self.assertEqual(frame_data['origin'], self.factory.myfullcall)
2023-12-05 18:01:48 +00:00
self.assertEqual(frame_data['session_id'] , session_id)
2023-11-27 18:22:16 +00:00
2023-11-29 16:42:44 +00:00
def testCQ(self):
frame = self.factory.build_cq()
frame_data = self.factory.deconstruct(frame)
self.assertEqual(frame_data['origin'], self.factory.myfullcall)
self.assertEqual(frame_data['gridsquare'], self.factory.mygrid.upper())
2023-12-13 08:56:58 +00:00
def testBurstDataFrames(self):
session_id = 123
offset = 40
payload = b'Hello World!'
frame = self.factory.build_arq_burst_frame(FREEDV_MODE.datac3,
2024-02-24 21:27:01 +00:00
session_id, offset, payload, 0)
2023-12-13 08:56:58 +00:00
frame_data = self.factory.deconstruct(frame)
self.assertEqual(frame_data['session_id'], session_id)
self.assertEqual(frame_data['offset'], offset)
data = frame_data['data'][:len(payload)]
self.assertEqual(data, payload)
2023-12-13 09:00:42 +00:00
payload = payload * 1000
2023-12-13 09:05:14 +00:00
self.assertRaises(OverflowError, self.factory.build_arq_burst_frame,
2024-02-24 21:27:01 +00:00
FREEDV_MODE.datac3, session_id, offset, payload, 0)
2023-12-13 15:56:11 +00:00
def testAvailablePayload(self):
2023-12-16 10:33:10 +00:00
avail = self.factory.get_available_data_payload_for_mode(FRAME_TYPE.ARQ_BURST_FRAME, FREEDV_MODE.datac3)
2024-02-24 21:27:01 +00:00
self.assertEqual(avail, 119) # 128 bytes datac3 frame payload - BURST frame overhead
2023-12-13 09:00:42 +00:00
2023-11-27 18:22:16 +00:00
if __name__ == '__main__':
unittest.main()