Coverage for test/d7a/system_files/test_dll_config.py: 100%
41 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
1#
2# Copyright (c) 2015-2021 University of Antwerp, Aloxy NV.
3#
4# This file is part of pyd7a.
5# See https://github.com/Sub-IoT/pyd7a for further info.
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19import unittest
21from bitstring import ConstBitStream
23from d7a.system_files.dll_config import DllConfigFile
26class TestDllConfigFile(unittest.TestCase):
28 def test_default_constructor(self):
29 c = DllConfigFile()
30 self.assertEqual(c.active_access_class, 0)
31 self.assertEqual(c.lq_filter, 0)
32 self.assertEqual(c.nf_ctrl, 0)
33 self.assertEqual(c.rx_nf_method_parameter, 0)
34 self.assertEqual(c.tx_nf_method_parameter, 0)
36 def test_invalid_access_class(self):
37 def bad(): DllConfigFile(active_access_class=0xFF01) # can be max 0xFF
38 self.assertRaises(ValueError, bad)
40 def test_parsing(self):
41 file_contents = [
42 5, # active access class
43 0x00, 0x00, # RFU
44 0x01, # LQ filter
45 0x02, # NF CTRL
46 0x03, # RX NF Method Parameter
47 0x04, # TX NF Method Parameter
48 ]
50 config = DllConfigFile.parse(ConstBitStream(bytes=file_contents))
51 self.assertEqual(config.active_access_class, 5)
52 self.assertEqual(config.lq_filter, 1)
53 self.assertEqual(config.nf_ctrl, 2)
54 self.assertEqual(config.rx_nf_method_parameter, 3)
55 self.assertEqual(config.tx_nf_method_parameter, 4)
57 def test_byte_generation(self):
58 bytes = bytearray(DllConfigFile())
59 self.assertEqual(len(bytes), 7)
60 self.assertEqual(bytes[0], 0)
61 self.assertEqual(bytes[1], 0)
62 self.assertEqual(bytes[2], 0)
63 self.assertEqual(bytes[3], 0)
64 self.assertEqual(bytes[4], 0)
65 self.assertEqual(bytes[5], 0)
66 self.assertEqual(bytes[6], 0)
68 bytes = bytearray(DllConfigFile(active_access_class=5, lq_filter=1, nf_ctrl=2,
69 rx_nf_method_parameter=3, tx_nf_method_parameter=4))
70 self.assertEqual(len(bytes), 7)
71 self.assertEqual(bytes[0], 5)
72 self.assertEqual(bytes[1], 0)
73 self.assertEqual(bytes[2], 0)
74 self.assertEqual(bytes[3], 1)
75 self.assertEqual(bytes[4], 2)
76 self.assertEqual(bytes[5], 3)
77 self.assertEqual(bytes[6], 4)