ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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)) + ")")