-
Notifications
You must be signed in to change notification settings - Fork 5
/
pave_test.py
58 lines (47 loc) · 1.77 KB
/
pave_test.py
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
from pave import *
import unittest
def buildPacket( payload ):
return "PaVE" + struct.pack("BBHI", 3, 4, 12, len(payload)), payload
class PaVETest( unittest.TestCase ):
def testEmpty( self ):
p = PaVE()
p.append( "" )
self.assertEqual( p.extract(), ("","") )
def testDummyCompletePacket( self ):
p = PaVE()
h,s = buildPacket( "ABCDE" )
p.append( h+s )
self.assertEqual( p.extract(), (h,s) )
self.assertEqual( p.extract(), ("","") ) # nothing is left
def testPartialPacket( self ):
p = PaVE()
h,s = buildPacket( "ABCDE" )
p.append( (h+s)[:5] )
self.assertEqual( p.extract(), ("","") ) # not ready yet
p.append( (h+s)[5:] )
self.assertEqual( p.extract(), (h,s) )
self.assertEqual( p.extract(), ("","") ) # nothing is left
def testCorruptedStart( self ):
p = PaVE()
h,s = buildPacket( "There will be corrupted few bytes in front ..." )
p.append( "blabla" + h + s )
self.assertEqual( p.extract(), (h,s) ) # skip non-PaVE part
def testTwoPackes( self ):
p = PaVE()
h1,s1 = buildPacket( "First packet" )
h2,s2 = buildPacket( "Second packet" )
p. append( h1 + s1 + h2 + s2 )
self.assertEqual( p.extract(), (h1,s1) )
self.assertEqual( p.extract(), (h2,s2) )
def testBadBytesBetweenTwoPackes( self ):
p = PaVE()
h1,s1 = buildPacket( "First packet" )
h2,s2 = buildPacket( "Second packet" )
p. append( h1 + s1 + "bad bytes" + h2 + s2 )
self.assertEqual( p.extract(), (h1,s1) )
self.assertEqual( p.extract(), (h2,s2) )
def testCorrectTimePeriod( self ):
self.assertAlmostEqual( correctTimePeriod( 0.0, ref=0.0 ), 0.0, 5 )
self.assertAlmostEqual( correctTimePeriod( 7806.415, ref=1662.753082 ), 1662.753082-0.338082, 5 )
if __name__ == "__main__":
unittest.main()