Home | History | Annotate | Download | only in contrib
      1 # PPI_Geotag tests
      2 
      3 ############
      4 ############
      5 + PPI Geotags tests
      6 
      7 = Import PPI Geotag
      8 
      9 from scapy.contrib.ppi_geotag import *
     10 
     11 = Test GPS dissection
     12 
     13 assert raw(GPS()) == b'2u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
     14 
     15 = Test Vector dissection
     16 
     17 assert raw(Vector()) == b'3u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
     18 
     19 = Test Sensor dissection
     20 
     21 assert raw(Sensor()) == b'4u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
     22 
     23 = Test Antenna dissection
     24 
     25 assert raw(Antenna()) == b'5u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00'
     26 
     27 = Test GPSTime_Field time handling
     28 
     29 assert GPSTime_Field("GPSTime", None).delta == 0.0
     30 
     31 = Define local_to_utc
     32 
     33 def local_to_utc(local_time):
     34     # BUG workaroung: on Python 2, summer time is ignored while converting time to UTC.
     35     # This function converts it properly. That was fixed on Python 3
     36     if six.PY3:
     37         return local_time
     38     utc_time_clock = time.gmtime(time.mktime(local_time))
     39     utc_time_clock = list(utc_time_clock.__reduce__()[1][0])
     40     if local_time.tm_isdst:
     41         utc_time_clock[3] = (utc_time_clock[3]+1)%24
     42     return time.struct_time(tuple(utc_time_clock))
     43 
     44 = Test UTCTimeField with time values
     45 
     46 local_time = time.localtime()
     47 utc_time = UTCTimeField("Test", None, epoch=local_time)
     48 assert time.localtime(utc_time.epoch) == local_time
     49 assert time.mktime(time.gmtime(utc_time.delta)) == time.mktime(local_time)
     50 strft_time = time.strftime("%a, %d %b %Y %H:%M:%S +0000", local_to_utc(local_time))
     51 
     52 assert utc_time.i2repr(None, None) == (strft_time + " (" + str(int(utc_time.delta)) + ")")
     53 
     54 = Test LETimeField with time values
     55 
     56 local_time = time.localtime()
     57 lme_time = LETimeField("Test", None, epoch=local_time)
     58 assert time.localtime(lme_time.epoch) == local_time
     59 assert time.mktime(time.gmtime(lme_time.delta)) == time.mktime(local_time)
     60 strft_time = time.strftime("%a, %d %b %Y %H:%M:%S +0000", local_to_utc(local_time))
     61 
     62 assert lme_time.i2repr(None, None) == (strft_time + " (" + str(int(lme_time.delta)) + ")")
     63