|
|
|
|
@@ -26,8 +26,8 @@ import os, sys
|
|
|
|
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
import rdpy.network.type
|
|
|
|
|
from rdpy.base.error import InvalidSize
|
|
|
|
|
import rdpy.core.type
|
|
|
|
|
from rdpy.core.error import InvalidSize
|
|
|
|
|
|
|
|
|
|
class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@@ -38,24 +38,24 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test if callable value with const ctor doesn't change value
|
|
|
|
|
"""
|
|
|
|
|
c = rdpy.network.type.CallableValue(5)
|
|
|
|
|
c = rdpy.core.type.CallableValue(5)
|
|
|
|
|
self.assertEqual(c.value, 5, "invalid callable const")
|
|
|
|
|
|
|
|
|
|
def test_callable_value_lambda(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test if callable value with lambda ctor return dynamic value
|
|
|
|
|
"""
|
|
|
|
|
c = rdpy.network.type.CallableValue(lambda:5)
|
|
|
|
|
c = rdpy.core.type.CallableValue(lambda:5)
|
|
|
|
|
self.assertEqual(c.value, 5, "invalid callable lambda")
|
|
|
|
|
|
|
|
|
|
def test_type_write_conditional_true(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test when write is obligatory call write function
|
|
|
|
|
"""
|
|
|
|
|
class TestType(rdpy.network.type.Type):
|
|
|
|
|
class TestType(rdpy.core.type.Type):
|
|
|
|
|
def __write__(self, s):
|
|
|
|
|
raise Exception()
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
self.assertRaises(Exception, s.writeType, TestType(conditional = lambda:True))
|
|
|
|
|
|
|
|
|
|
@unittest.expectedFailure
|
|
|
|
|
@@ -63,20 +63,20 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test when write doesn't needed, doesn't call write function
|
|
|
|
|
"""
|
|
|
|
|
class TestType(rdpy.network.type.Type):
|
|
|
|
|
class TestType(rdpy.core.type.Type):
|
|
|
|
|
def __write__(self, s):
|
|
|
|
|
raise Exception()
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
self.assertRaises(Exception, s.writeType, TestType(conditional = lambda:False))
|
|
|
|
|
|
|
|
|
|
def test_type_read_conditional_true(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test when read is obligatory call write function
|
|
|
|
|
"""
|
|
|
|
|
class TestType(rdpy.network.type.Type):
|
|
|
|
|
class TestType(rdpy.core.type.Type):
|
|
|
|
|
def __read__(self, s):
|
|
|
|
|
raise Exception()
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
self.assertRaises(Exception, s.readType, TestType(conditional = lambda:True))
|
|
|
|
|
|
|
|
|
|
@unittest.expectedFailure
|
|
|
|
|
@@ -84,10 +84,10 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test when read doesn't needed, doesn't call read function
|
|
|
|
|
"""
|
|
|
|
|
class TestType(rdpy.network.type.Type):
|
|
|
|
|
class TestType(rdpy.core.type.Type):
|
|
|
|
|
def __read__(self, s):
|
|
|
|
|
raise Exception()
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
self.assertRaises(Exception, s.readType, TestType(conditional = lambda:False))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -95,106 +95,106 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test if sizeof of simple type is init value(4) when type is conditional true
|
|
|
|
|
"""
|
|
|
|
|
v = rdpy.network.type.SimpleType("I", 4, False, 0, conditional = lambda:True)
|
|
|
|
|
self.assertEqual(rdpy.network.type.sizeof(v), 4, "invalid sizeof")
|
|
|
|
|
v = rdpy.core.type.SimpleType("I", 4, False, 0, conditional = lambda:True)
|
|
|
|
|
self.assertEqual(rdpy.core.type.sizeof(v), 4, "invalid sizeof")
|
|
|
|
|
|
|
|
|
|
def test_sizeof_conditional_false(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test if sizeof of simple type is 0 when type is conditional false
|
|
|
|
|
"""
|
|
|
|
|
v = rdpy.network.type.SimpleType("I", 4, False, 0, conditional = lambda:False)
|
|
|
|
|
self.assertEqual(rdpy.network.type.sizeof(v), 0, "invalid sizeof")
|
|
|
|
|
v = rdpy.core.type.SimpleType("I", 4, False, 0, conditional = lambda:False)
|
|
|
|
|
self.assertEqual(rdpy.core.type.sizeof(v), 0, "invalid sizeof")
|
|
|
|
|
|
|
|
|
|
def test_sizeof_list(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test call sizeof on list of type
|
|
|
|
|
"""
|
|
|
|
|
v = [rdpy.network.type.UInt8(), rdpy.network.type.UInt16Le(), rdpy.network.type.UInt32Le()]
|
|
|
|
|
self.assertEqual(rdpy.network.type.sizeof(v), 7, "invalid sizeof")
|
|
|
|
|
v = [rdpy.core.type.UInt8(), rdpy.core.type.UInt16Le(), rdpy.core.type.UInt32Le()]
|
|
|
|
|
self.assertEqual(rdpy.core.type.sizeof(v), 7, "invalid sizeof")
|
|
|
|
|
|
|
|
|
|
def test_sizeof_list_conditional(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test call sizeof on list of type with one type hidden
|
|
|
|
|
"""
|
|
|
|
|
v = [rdpy.network.type.UInt8(), rdpy.network.type.UInt16Le(conditional = lambda:False), rdpy.network.type.UInt32Le()]
|
|
|
|
|
self.assertEqual(rdpy.network.type.sizeof(v), 5, "invalid sizeof")
|
|
|
|
|
v = [rdpy.core.type.UInt8(), rdpy.core.type.UInt16Le(conditional = lambda:False), rdpy.core.type.UInt32Le()]
|
|
|
|
|
self.assertEqual(rdpy.core.type.sizeof(v), 5, "invalid sizeof")
|
|
|
|
|
|
|
|
|
|
def test_sizeof_tuple(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test call sizeof on tuple of type
|
|
|
|
|
"""
|
|
|
|
|
v = [rdpy.network.type.UInt8(), rdpy.network.type.UInt16Le(), rdpy.network.type.UInt32Le()]
|
|
|
|
|
self.assertEqual(rdpy.network.type.sizeof(v), 7, "invalid sizeof")
|
|
|
|
|
v = [rdpy.core.type.UInt8(), rdpy.core.type.UInt16Le(), rdpy.core.type.UInt32Le()]
|
|
|
|
|
self.assertEqual(rdpy.core.type.sizeof(v), 7, "invalid sizeof")
|
|
|
|
|
|
|
|
|
|
def test_sizeof_tuple_conditional(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test call sizeof on tuple of type with one type hidden
|
|
|
|
|
"""
|
|
|
|
|
v = (rdpy.network.type.UInt8(), rdpy.network.type.UInt16Le(), rdpy.network.type.UInt32Le(conditional = lambda:False))
|
|
|
|
|
self.assertEqual(rdpy.network.type.sizeof(v), 3, "invalid sizeof")
|
|
|
|
|
v = (rdpy.core.type.UInt8(), rdpy.core.type.UInt16Le(), rdpy.core.type.UInt32Le(conditional = lambda:False))
|
|
|
|
|
self.assertEqual(rdpy.core.type.sizeof(v), 3, "invalid sizeof")
|
|
|
|
|
|
|
|
|
|
def test_stream_write_uint8_type(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test write uint8 in stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s.writeType(rdpy.network.type.UInt8(1))
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
s.writeType(rdpy.core.type.UInt8(1))
|
|
|
|
|
self.assertEqual(''.join(s.buflist), '\x01', "invalid stream write")
|
|
|
|
|
|
|
|
|
|
def test_stream_write_uint16Le_type(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test write UInt16Le in stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s.writeType(rdpy.network.type.UInt16Le(1))
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
s.writeType(rdpy.core.type.UInt16Le(1))
|
|
|
|
|
self.assertEqual(''.join(s.buflist), '\x01\x00', "invalid stream write")
|
|
|
|
|
|
|
|
|
|
def test_stream_write_uint16Be_type(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test write UInt16Be in stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s.writeType(rdpy.network.type.UInt16Be(1))
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
s.writeType(rdpy.core.type.UInt16Be(1))
|
|
|
|
|
self.assertEqual(''.join(s.buflist), '\x00\x01', "invalid stream write")
|
|
|
|
|
|
|
|
|
|
def test_stream_write_uint24Le_type(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test write UInt24Le in stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s.writeType(rdpy.network.type.UInt24Le(1))
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
s.writeType(rdpy.core.type.UInt24Le(1))
|
|
|
|
|
self.assertEqual(''.join(s.buflist), '\x01\x00\x00', "invalid stream write")
|
|
|
|
|
|
|
|
|
|
def test_stream_write_uint24Be_type(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test write uint24Be in stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s.writeType(rdpy.network.type.UInt24Be(1))
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
s.writeType(rdpy.core.type.UInt24Be(1))
|
|
|
|
|
self.assertEqual(''.join(s.buflist), '\x00\x00\x01', "invalid stream write")
|
|
|
|
|
|
|
|
|
|
def test_stream_write_uint32Le_type(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test write UInt32Le in stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s.writeType(rdpy.network.type.UInt32Le(1))
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
s.writeType(rdpy.core.type.UInt32Le(1))
|
|
|
|
|
self.assertEqual(''.join(s.buflist), '\x01\x00\x00\x00', "invalid stream write")
|
|
|
|
|
|
|
|
|
|
def test_stream_write_uint32Be_type(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test write UInt32Be in stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream()
|
|
|
|
|
s.writeType(rdpy.network.type.UInt32Be(1))
|
|
|
|
|
s = rdpy.core.type.Stream()
|
|
|
|
|
s.writeType(rdpy.core.type.UInt32Be(1))
|
|
|
|
|
self.assertEqual(''.join(s.buflist), '\x00\x00\x00\x01', "invalid stream write")
|
|
|
|
|
|
|
|
|
|
def test_stream_read_uint8_type(self):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test read UInt8 type from stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream('\x01')
|
|
|
|
|
t = rdpy.network.type.UInt8()
|
|
|
|
|
s = rdpy.core.type.Stream('\x01')
|
|
|
|
|
t = rdpy.core.type.UInt8()
|
|
|
|
|
s.readType(t)
|
|
|
|
|
self.assertEqual(t.value, 1, "invalid stream read value")
|
|
|
|
|
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
|
|
|
|
@@ -203,8 +203,8 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test read UInt16Le type from stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream('\x01\x00')
|
|
|
|
|
t = rdpy.network.type.UInt16Le()
|
|
|
|
|
s = rdpy.core.type.Stream('\x01\x00')
|
|
|
|
|
t = rdpy.core.type.UInt16Le()
|
|
|
|
|
s.readType(t)
|
|
|
|
|
self.assertEqual(t.value, 1, "invalid stream read value")
|
|
|
|
|
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
|
|
|
|
@@ -213,8 +213,8 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test read UInt16Be type from stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream('\x00\x01')
|
|
|
|
|
t = rdpy.network.type.UInt16Be()
|
|
|
|
|
s = rdpy.core.type.Stream('\x00\x01')
|
|
|
|
|
t = rdpy.core.type.UInt16Be()
|
|
|
|
|
s.readType(t)
|
|
|
|
|
self.assertEqual(t.value, 1, "invalid stream read value")
|
|
|
|
|
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
|
|
|
|
@@ -223,8 +223,8 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test read UInt24Le type from stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream('\x01\x00\x00')
|
|
|
|
|
t = rdpy.network.type.UInt24Le()
|
|
|
|
|
s = rdpy.core.type.Stream('\x01\x00\x00')
|
|
|
|
|
t = rdpy.core.type.UInt24Le()
|
|
|
|
|
s.readType(t)
|
|
|
|
|
self.assertEqual(t.value, 1, "invalid stream read value")
|
|
|
|
|
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
|
|
|
|
@@ -233,8 +233,8 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test read UInt24Be type from stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream('\x00\x00\x01')
|
|
|
|
|
t = rdpy.network.type.UInt24Be()
|
|
|
|
|
s = rdpy.core.type.Stream('\x00\x00\x01')
|
|
|
|
|
t = rdpy.core.type.UInt24Be()
|
|
|
|
|
s.readType(t)
|
|
|
|
|
self.assertEqual(t.value, 1, "invalid stream read")
|
|
|
|
|
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
|
|
|
|
@@ -243,8 +243,8 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test read UInt32Le type from stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream('\x01\x00\x00\x00')
|
|
|
|
|
t = rdpy.network.type.UInt32Le()
|
|
|
|
|
s = rdpy.core.type.Stream('\x01\x00\x00\x00')
|
|
|
|
|
t = rdpy.core.type.UInt32Le()
|
|
|
|
|
s.readType(t)
|
|
|
|
|
self.assertEqual(t.value, 1, "invalid stream read value")
|
|
|
|
|
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
|
|
|
|
@@ -253,8 +253,8 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test read UInt32Be type from stream
|
|
|
|
|
"""
|
|
|
|
|
s = rdpy.network.type.Stream('\x00\x00\x00\x01')
|
|
|
|
|
t = rdpy.network.type.UInt32Be()
|
|
|
|
|
s = rdpy.core.type.Stream('\x00\x00\x00\x01')
|
|
|
|
|
t = rdpy.core.type.UInt32Be()
|
|
|
|
|
s.readType(t)
|
|
|
|
|
self.assertEqual(t.value, 1, "invalid stream read")
|
|
|
|
|
self.assertEqual(s.dataLen(), 0, "not read all stream")
|
|
|
|
|
@@ -264,9 +264,9 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
@summary: test optional option in case of simple type reading
|
|
|
|
|
"""
|
|
|
|
|
#unsigned int case
|
|
|
|
|
t = rdpy.network.type.SimpleType("I", 4, False, 0, optional = True)
|
|
|
|
|
t = rdpy.core.type.SimpleType("I", 4, False, 0, optional = True)
|
|
|
|
|
#empty stream
|
|
|
|
|
s1 = rdpy.network.type.Stream()
|
|
|
|
|
s1 = rdpy.core.type.Stream()
|
|
|
|
|
s1.readType(t)
|
|
|
|
|
self.assertEqual(t.value, 0, "invalid stream read optional value")
|
|
|
|
|
|
|
|
|
|
@@ -275,8 +275,8 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
@summary: test conditional option in case of simple type reading and when condition is false (not read)
|
|
|
|
|
"""
|
|
|
|
|
#unsigned int case
|
|
|
|
|
t = rdpy.network.type.SimpleType("I", 4, False, 0, conditional = lambda:False)
|
|
|
|
|
s1 = rdpy.network.type.Stream("\x01\x00\x00\x00")
|
|
|
|
|
t = rdpy.core.type.SimpleType("I", 4, False, 0, conditional = lambda:False)
|
|
|
|
|
s1 = rdpy.core.type.Stream("\x01\x00\x00\x00")
|
|
|
|
|
s1.readType(t)
|
|
|
|
|
self.assertEqual(t.value, 0, "invalid stream read conditional value")
|
|
|
|
|
|
|
|
|
|
@@ -285,8 +285,8 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
@summary: test conditional option in case of simple type reading and when condition is true (must be read)
|
|
|
|
|
"""
|
|
|
|
|
#unsigned int case
|
|
|
|
|
t = rdpy.network.type.SimpleType("I", 4, False, 0, conditional = lambda:True)
|
|
|
|
|
s1 = rdpy.network.type.Stream("\x01\x00\x00\x00")
|
|
|
|
|
t = rdpy.core.type.SimpleType("I", 4, False, 0, conditional = lambda:True)
|
|
|
|
|
s1 = rdpy.core.type.Stream("\x01\x00\x00\x00")
|
|
|
|
|
s1.readType(t)
|
|
|
|
|
self.assertEqual(t.value, 1, "invalid stream read conditional value")
|
|
|
|
|
|
|
|
|
|
@@ -294,13 +294,13 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
"""
|
|
|
|
|
@summary: test if constant constraint fail, the reading stream is correctly rollback
|
|
|
|
|
"""
|
|
|
|
|
class TestComposite(rdpy.network.type.CompositeType):
|
|
|
|
|
class TestComposite(rdpy.core.type.CompositeType):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
rdpy.network.type.CompositeType.__init__(self)
|
|
|
|
|
self.padding = rdpy.network.type.UInt32Le(0)
|
|
|
|
|
self.constraint = rdpy.network.type.UInt32Le(1, constant = True)
|
|
|
|
|
rdpy.core.type.CompositeType.__init__(self)
|
|
|
|
|
self.padding = rdpy.core.type.UInt32Le(0)
|
|
|
|
|
self.constraint = rdpy.core.type.UInt32Le(1, constant = True)
|
|
|
|
|
|
|
|
|
|
s = rdpy.network.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
|
|
|
s = rdpy.core.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
|
|
|
try:
|
|
|
|
|
s.readType(TestComposite())
|
|
|
|
|
except Exception:
|
|
|
|
|
@@ -313,19 +313,19 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
@summary: test if constant constraint fail even in recurcive composite type,
|
|
|
|
|
the reading stream is correctly rollback
|
|
|
|
|
"""
|
|
|
|
|
class TestSubComposite(rdpy.network.type.CompositeType):
|
|
|
|
|
class TestSubComposite(rdpy.core.type.CompositeType):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
rdpy.network.type.CompositeType.__init__(self)
|
|
|
|
|
self.padding = rdpy.network.type.UInt32Le(0)
|
|
|
|
|
self.constraint = rdpy.network.type.UInt32Le(1, constant = True)
|
|
|
|
|
rdpy.core.type.CompositeType.__init__(self)
|
|
|
|
|
self.padding = rdpy.core.type.UInt32Le(0)
|
|
|
|
|
self.constraint = rdpy.core.type.UInt32Le(1, constant = True)
|
|
|
|
|
|
|
|
|
|
class TestComposite(rdpy.network.type.CompositeType):
|
|
|
|
|
class TestComposite(rdpy.core.type.CompositeType):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
rdpy.network.type.CompositeType.__init__(self)
|
|
|
|
|
self.padding = rdpy.network.type.UInt32Le(0)
|
|
|
|
|
rdpy.core.type.CompositeType.__init__(self)
|
|
|
|
|
self.padding = rdpy.core.type.UInt32Le(0)
|
|
|
|
|
self.recurcive = TestSubComposite()
|
|
|
|
|
|
|
|
|
|
s = rdpy.network.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
|
|
|
s = rdpy.core.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
|
|
|
try:
|
|
|
|
|
s.readType(TestComposite())
|
|
|
|
|
except Exception:
|
|
|
|
|
@@ -338,19 +338,19 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
@summary: test if constant constraint fail even in recurcive composite type,
|
|
|
|
|
the reading stream is correctly rollback
|
|
|
|
|
"""
|
|
|
|
|
class TestSubComposite(rdpy.network.type.CompositeType):
|
|
|
|
|
class TestSubComposite(rdpy.core.type.CompositeType):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
rdpy.network.type.CompositeType.__init__(self)
|
|
|
|
|
self.padding = rdpy.network.type.UInt32Le(0)
|
|
|
|
|
self.constraint = rdpy.network.type.UInt32Le(1)
|
|
|
|
|
rdpy.core.type.CompositeType.__init__(self)
|
|
|
|
|
self.padding = rdpy.core.type.UInt32Le(0)
|
|
|
|
|
self.constraint = rdpy.core.type.UInt32Le(1)
|
|
|
|
|
|
|
|
|
|
class TestComposite(rdpy.network.type.CompositeType):
|
|
|
|
|
class TestComposite(rdpy.core.type.CompositeType):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
rdpy.network.type.CompositeType.__init__(self)
|
|
|
|
|
self.padding = rdpy.network.type.UInt32Le(0)
|
|
|
|
|
rdpy.core.type.CompositeType.__init__(self)
|
|
|
|
|
self.padding = rdpy.core.type.UInt32Le(0)
|
|
|
|
|
self.recurcive = TestSubComposite()
|
|
|
|
|
|
|
|
|
|
s = rdpy.network.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
|
|
|
s = rdpy.core.type.Stream("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
|
|
|
try:
|
|
|
|
|
s.readType(TestComposite())
|
|
|
|
|
except Exception:
|
|
|
|
|
@@ -364,12 +364,12 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
if total stream read length < to forced read length
|
|
|
|
|
the trash must be read as padding
|
|
|
|
|
"""
|
|
|
|
|
class TestReadLength(rdpy.network.type.CompositeType):
|
|
|
|
|
class TestReadLength(rdpy.core.type.CompositeType):
|
|
|
|
|
def __init__(self, readLen):
|
|
|
|
|
rdpy.network.type.CompositeType.__init__(self, readLen = readLen)
|
|
|
|
|
self.padding = rdpy.network.type.UInt32Le(0)
|
|
|
|
|
s = rdpy.network.type.Stream("\x00" * 10)
|
|
|
|
|
s.readType(TestReadLength(rdpy.network.type.UInt8(10)))
|
|
|
|
|
rdpy.core.type.CompositeType.__init__(self, readLen = readLen)
|
|
|
|
|
self.padding = rdpy.core.type.UInt32Le(0)
|
|
|
|
|
s = rdpy.core.type.Stream("\x00" * 10)
|
|
|
|
|
s.readType(TestReadLength(rdpy.core.type.UInt8(10)))
|
|
|
|
|
self.assertEqual(s.dataLen(), 0, "invalid stream read trash data as padding")
|
|
|
|
|
|
|
|
|
|
def test_stream_read_with_static_length_inferior(self):
|
|
|
|
|
@@ -378,12 +378,12 @@ class TypeCase(unittest.TestCase):
|
|
|
|
|
if total stream read length > to forced read length
|
|
|
|
|
an InvalidSize exception is throw
|
|
|
|
|
"""
|
|
|
|
|
class TestReadLength(rdpy.network.type.CompositeType):
|
|
|
|
|
class TestReadLength(rdpy.core.type.CompositeType):
|
|
|
|
|
def __init__(self, readLen):
|
|
|
|
|
rdpy.network.type.CompositeType.__init__(self, readLen = readLen)
|
|
|
|
|
self.padding = rdpy.network.type.UInt32Le(0)
|
|
|
|
|
s = rdpy.network.type.Stream("\x00" * 10)
|
|
|
|
|
self.assertRaises(InvalidSize, s.readType, TestReadLength(rdpy.network.type.UInt8(2)))
|
|
|
|
|
rdpy.core.type.CompositeType.__init__(self, readLen = readLen)
|
|
|
|
|
self.padding = rdpy.core.type.UInt32Le(0)
|
|
|
|
|
s = rdpy.core.type.Stream("\x00" * 10)
|
|
|
|
|
self.assertRaises(InvalidSize, s.readType, TestReadLength(rdpy.core.type.UInt8(2)))
|
|
|
|
|
|
|
|
|
|
def test_stream_read_string(self):
|
|
|
|
|
"""
|
|
|
|
|
|