github.com/n00py/Slackor@v0.0.0-20200610224921-d007fcea1740/impacket/tests/dot11/test_helper.py (about) 1 #!/usr/bin/env python 2 # Copyright (c) 2003-2013 CORE Security Technologies 3 # 4 # This software is provided under under a slightly modified version 5 # of the Apache Software License. See the accompanying LICENSE file 6 # for more information. 7 # 8 # $Id$ 9 # 10 # Description: 11 # Tests for helper used to build ProtocolPackets 12 # 13 # Author: 14 # Aureliano Calvo 15 16 # sorry, this is very ugly, but I'm in python 2.5 17 import sys 18 sys.path.insert(0,"../../..") 19 20 import unittest 21 import impacket.helper as h 22 23 class TestHelpers(unittest.TestCase): 24 25 def test_well_formed(self): 26 class MockPacket(h.ProtocolPacket): 27 byte_field = h.Byte(0) 28 word_field = h.Word(1, ">") 29 three_bytes_field = h.ThreeBytesBigEndian(3) 30 long_field = h.Long(6, ">") 31 aliased_bit_field = h.Bit(0,0) 32 33 header_size = 4 34 tail_size = 0 35 36 p = MockPacket() 37 p.byte_field = 1 38 p.word_field = 2 39 p.three_bytes_field = 4 40 p.long_field = 8 41 42 self.assertEqual(1, p.byte_field) 43 self.assertEqual(2, p.word_field) 44 self.assertEqual(4, p.three_bytes_field) 45 self.assertEqual(8, p.long_field) 46 47 self.assertEqual(True, p.aliased_bit_field) 48 49 p.aliased_bit_field = False 50 51 self.assertEqual(0, p.byte_field) 52 53 self.assertEqual(p.get_packet(), MockPacket(p.get_packet()).get_packet()) # it is the same packet after reprocessing. 54 55 56 suite = unittest.TestLoader().loadTestsFromTestCase(TestHelpers) 57 unittest.TextTestRunner(verbosity=1).run(suite)