diff --git a/tests/fixtures/centos-7.7/hciconfig-a.json b/tests/fixtures/centos-7.7/hciconfig-a.json new file mode 100644 index 00000000..8a7791c6 --- /dev/null +++ b/tests/fixtures/centos-7.7/hciconfig-a.json @@ -0,0 +1 @@ +[{"device": "hci0", "type": "Primary", "bus": "USB", "bd_address": "00:50:56:FE:FD:38", "acl_mtu": 8192, "acl_mtu_packets": 128, "sco_mtu": 64, "sco_mtu_packets": 128, "state": ["DOWN"], "rx_bytes": 503, "rx_acl": 0, "rx_sco": 0, "rx_events": 22, "rx_errors": 0, "tx_bytes": 336, "tx_acl": 0, "tx_sco": 0, "tx_commands": 22, "tx_errors": 0, "features": ["0xff", "0xff", "0x8f", "0xfe", "0x83", "0xe1", "0x08", "0x80"], "packet_type": ["DM1", "DM3", "DM5", "DH1", "DH3", "DH5", "HV1", "HV2", "HV3"], "link_policy": ["RSWITCH", "HOLD", "SNIFF", "PARK"], "link_mode": ["SLAVE", "ACCEPT"]}] diff --git a/tests/fixtures/centos-7.7/hciconfig.json b/tests/fixtures/centos-7.7/hciconfig.json new file mode 100644 index 00000000..105c0766 --- /dev/null +++ b/tests/fixtures/centos-7.7/hciconfig.json @@ -0,0 +1 @@ +[{"device": "hci0", "type": "Primary", "bus": "USB", "bd_address": "00:50:56:FE:FD:38", "acl_mtu": 8192, "acl_mtu_packets": 128, "sco_mtu": 64, "sco_mtu_packets": 128, "state": ["DOWN"], "rx_bytes": 503, "rx_acl": 0, "rx_sco": 0, "rx_events": 22, "rx_errors": 0, "tx_bytes": 336, "tx_acl": 0, "tx_sco": 0, "tx_commands": 22, "tx_errors": 0}] diff --git a/tests/fixtures/ubuntu-20.04/hciconfig-a.json b/tests/fixtures/ubuntu-20.04/hciconfig-a.json new file mode 100644 index 00000000..09582a7d --- /dev/null +++ b/tests/fixtures/ubuntu-20.04/hciconfig-a.json @@ -0,0 +1 @@ +[{"device": "hci0", "type": "Primary", "bus": "USB", "bd_address": "00:1A:7D:DA:71:13", "acl_mtu": 310, "acl_mtu_packets": 10, "sco_mtu": 64, "sco_mtu_packets": 8, "state": ["UP", "RUNNING"], "rx_bytes": 13905869, "rx_acl": 0, "rx_sco": 0, "rx_events": 393300, "rx_errors": 0, "tx_bytes": 62629, "tx_acl": 0, "tx_sco": 0, "tx_commands": 3893, "tx_errors": 0, "features": ["0xff", "0xff", "0x8f", "0xfe", "0xdb", "0xff", "0x5b", "0x87"], "packet_type": ["DM1", "DM3", "DM5", "DH1", "DH3", "DH5", "HV1", "HV2", "HV3"], "link_policy": ["RSWITCH", "HOLD", "SNIFF", "PARK"], "link_mode": ["SLAVE", "ACCEPT"], "name": "CSR8510 A10", "class": "0x000000", "service_classes": null, "device_class": "Miscellaneous", "hci_version": "4.0 (0x6)", "hci_revision": "0x22bb", "lmp_version": "4.0 (0x6)", "lmp_subversion": "0x22bb", "manufacturer": "Cambridge Silicon Radio (10)"}, {"device": "hci1", "type": "Primary", "bus": "USB", "bd_address": "00:1A:7D:DA:71:13", "acl_mtu": 310, "acl_mtu_packets": 10, "sco_mtu": 64, "sco_mtu_packets": 8, "state": ["DOWN"], "rx_bytes": 4388363, "rx_acl": 0, "rx_sco": 0, "rx_events": 122021, "rx_errors": 0, "tx_bytes": 52350, "tx_acl": 0, "tx_sco": 0, "tx_commands": 3480, "tx_errors": 2, "features": ["0xff", "0xff", "0x8f", "0xfe", "0xdb", "0xff", "0x5b", "0x87"], "packet_type": ["DM1", "DM3", "DM5", "DH1", "DH3", "DH5", "HV1", "HV2", "HV3"], "link_policy": ["RSWITCH", "HOLD", "SNIFF", "PARK"], "link_mode": ["SLAVE", "ACCEPT"]}] diff --git a/tests/fixtures/ubuntu-20.04/hciconfig.json b/tests/fixtures/ubuntu-20.04/hciconfig.json new file mode 100644 index 00000000..97b33992 --- /dev/null +++ b/tests/fixtures/ubuntu-20.04/hciconfig.json @@ -0,0 +1 @@ +[{"device": "hci0", "type": "Primary", "bus": "USB", "bd_address": "00:50:56:E7:46:1A", "acl_mtu": 8192, "acl_mtu_packets": 128, "sco_mtu": 64, "sco_mtu_packets": 128, "state": ["UP", "RUNNING"], "rx_bytes": 1307, "rx_acl": 0, "rx_sco": 0, "rx_events": 51, "rx_errors": 0, "tx_bytes": 1200, "tx_acl": 0, "tx_sco": 0, "tx_commands": 51, "tx_errors": 0, "features": ["0xff", "0xff", "0x8f", "0xfe", "0x83", "0xe1", "0x08", "0x80"], "packet_type": ["DM1", "DM3", "DM5", "DH1", "DH3", "DH5", "HV1", "HV2", "HV3"], "link_policy": ["RSWITCH", "HOLD", "SNIFF", "PARK"], "link_mode": ["SLAVE", "ACCEPT"], "name": "kbrazil-ubuntu", "class": "0x000000", "service_classes": null, "device_class": "Miscellaneous", "hci_version": "2.1 (0x4)", "hci_revision": "0x100", "lmp_version": "2.1 (0x4)", "lmp_subversion": "0x100", "manufacturer": "not assigned (6502)"}] diff --git a/tests/test_hciconfig.py b/tests/test_hciconfig.py new file mode 100644 index 00000000..61662956 --- /dev/null +++ b/tests/test_hciconfig.py @@ -0,0 +1,70 @@ +import os +import json +import unittest +import jc.parsers.hciconfig + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hciconfig.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_hciconfig = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hciconfig-a.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_hciconfig_a = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/hciconfig.out'), 'r', encoding='utf-8') as f: + self.ubuntu_20_4_hciconfig = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/hciconfig-a.out'), 'r', encoding='utf-8') as f: + self.ubuntu_20_4_hciconfig_a = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hciconfig.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_hciconfig_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/hciconfig-a.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_hciconfig_a_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/hciconfig.json'), 'r', encoding='utf-8') as f: + self.ubuntu_20_4_hciconfig_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/hciconfig-a.json'), 'r', encoding='utf-8') as f: + self.ubuntu_20_4_hciconfig_a_json = json.loads(f.read()) + + def test_hciconfig_nodata(self): + """ + Test plain 'hciconfig' with no data + """ + self.assertEqual(jc.parsers.hciconfig.parse('', quiet=True), []) + + def test_hciconfig_centos_7_7(self): + """ + Test plain 'hciconfig' on Centos 7.7 + """ + self.assertEqual(jc.parsers.hciconfig.parse(self.centos_7_7_hciconfig, quiet=True), self.centos_7_7_hciconfig_json) + + def test_hciconfig_a_centos_7_7(self): + """ + Test 'hciconfig -a' on Centos 7.7 + """ + self.assertEqual(jc.parsers.hciconfig.parse(self.centos_7_7_hciconfig_a, quiet=True), self.centos_7_7_hciconfig_a_json) + + def test_hciconfig_ubuntu_18_4(self): + """ + Test plain 'hciconfig' on Ubuntu 20.4 + """ + self.assertEqual(jc.parsers.hciconfig.parse(self.ubuntu_20_4_hciconfig, quiet=True), self.ubuntu_20_4_hciconfig_json) + + def test_hciconfig_a_ubuntu_18_4(self): + """ + Test 'hciconfig -a' on Ubuntu 20.4 + """ + self.assertEqual(jc.parsers.hciconfig.parse(self.ubuntu_20_4_hciconfig_a, quiet=True), self.ubuntu_20_4_hciconfig_a_json) + + +if __name__ == '__main__': + unittest.main()