Coverage for test/d7a/d7atp/test_control.py: 100%

18 statements  

« 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 

20 

21from bitstring import ConstBitStream 

22 

23from d7a.d7atp.control import Control 

24 

25 

26class TestControl(unittest.TestCase): 

27 def test_parsing(self): 

28 ctrl = Control.parse(ConstBitStream(bytes=[0x93])) 

29 self.assertEqual(ctrl.is_dialog_start, True) 

30 self.assertEqual(ctrl.has_tl, False) 

31 self.assertEqual(ctrl.has_te, True) 

32 self.assertEqual(ctrl.is_ack_requested, False) 

33 self.assertEqual(ctrl.is_ack_not_void, False) 

34 self.assertEqual(ctrl.is_ack_record_requested, True) 

35 self.assertEqual(ctrl.has_agc, True) 

36 

37 def test_byte_generation(self): 

38 ctrl = Control( 

39 is_dialog_start=True, 

40 has_tl=True, 

41 has_te=False, 

42 is_ack_requested=True, 

43 is_ack_not_void=True, 

44 is_ack_record_requested=False, 

45 has_agc=False 

46 ) 

47 

48 data = bytearray(ctrl) 

49 self.assertEqual(len(data), 1) 

50 self.assertEqual(data[0], 0xAC)