# PPI_Geotag tests
|
|
############
|
############
|
+ PPI Geotags tests
|
|
= Import PPI Geotag
|
|
from scapy.contrib.ppi_geotag import *
|
|
= Test GPS dissection
|
|
assert raw(GPS()) == b'2u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
|
|
= Test Vector dissection
|
|
assert raw(Vector()) == b'3u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
|
|
= Test Sensor dissection
|
|
assert raw(Sensor()) == b'4u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
|
|
= Test Antenna dissection
|
|
assert raw(Antenna()) == b'5u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
|
|
= Test GPSTime_Field time handling
|
|
assert GPSTime_Field("GPSTime", None).delta == 0.0
|
|
= Define local_to_utc
|
|
def local_to_utc(local_time):
|
# BUG workaroung: on Python 2, summer time is ignored while converting time to UTC.
|
# This function converts it properly. That was fixed on Python 3
|
if six.PY3:
|
return local_time
|
utc_time_clock = time.gmtime(time.mktime(local_time))
|
utc_time_clock = list(utc_time_clock.__reduce__()[1][0])
|
if local_time.tm_isdst:
|
utc_time_clock[3] = (utc_time_clock[3]+1)%24
|
return time.struct_time(tuple(utc_time_clock))
|
|
= Test UTCTimeField with time values
|
|
local_time = time.localtime()
|
utc_time = UTCTimeField("Test", None, epoch=local_time)
|
assert time.localtime(utc_time.epoch) == local_time
|
assert time.mktime(time.gmtime(utc_time.delta)) == time.mktime(local_time)
|
strft_time = time.strftime("%a, %d %b %Y %H:%M:%S +0000", local_to_utc(local_time))
|
|
assert utc_time.i2repr(None, None) == (strft_time + " (" + str(int(utc_time.delta)) + ")")
|
|
= Test LETimeField with time values
|
|
local_time = time.localtime()
|
lme_time = LETimeField("Test", None, epoch=local_time)
|
assert time.localtime(lme_time.epoch) == local_time
|
assert time.mktime(time.gmtime(lme_time.delta)) == time.mktime(local_time)
|
strft_time = time.strftime("%a, %d %b %Y %H:%M:%S +0000", local_to_utc(local_time))
|
|
assert lme_time.i2repr(None, None) == (strft_time + " (" + str(int(lme_time.delta)) + ")")
|