1# Eddystone unit tests 2# 3# Type the following command to launch start the tests: 4# $ test/run_tests -P "load_contrib('eddystone')" -t test/contrib/eddystone.uts 5 6+ Eddystone tests 7 8= Setup 9 10def expect_exception(e, c): 11 try: 12 c() 13 return False 14 except e: 15 return True 16 17= Eddystone URL (decode EIR) 18 19d = hex_bytes('0c16aafe10040373636170790a') 20p = EIR_Hdr(d) 21p.show() 22 23assert p[EIR_ServiceData16BitUUID].svc_uuid == 0xfeaa 24assert p[Eddystone_URL].to_url() == b'https://scapy.net' 25 26= Eddystone URL (decode LE Set Advertising Data) 27 28d = hex_bytes('01082020140201020303aafe0c16aafe10040373636170790a0000000000000000000000') 29p = HCI_Hdr(d) 30 31assert p[EIR_ServiceData16BitUUID].svc_uuid == 0xfeaa 32assert p[Eddystone_URL].to_url() == b'https://scapy.net' 33 34= Eddystone URL (encode frames) 35 36d = raw(Eddystone_URL.from_url('https://scapy.net')) 37assert d == hex_bytes('10000373636170790a') 38 39d = raw(Eddystone_URL.from_url('https://www.scapy.net')) 40assert d == hex_bytes('10000173636170790a') 41 42# Include some other .extensions in the path 43d = raw(Eddystone_URL.from_url('http://www.example.com/hello.info.html')) 44assert d == hex_bytes('1000006578616d706c650068656c6c6f0b2e68746d6c') 45 46= Eddystone URL (encode unsupported scheme) 47 48assert expect_exception(Exception, lambda: Eddystone_URL.from_url('gopher://example.com')) 49 50= Eddystone URL (encode advertising report) 51 52p = Eddystone_URL.from_url('https://scapy.net').build_advertising_report() 53assert raw(p[EIR_ServiceData16BitUUID]) == hex_bytes('aafe10000373636170790a') 54 55