add unit test for const and layer module
This commit is contained in:
@@ -4,15 +4,23 @@
|
||||
import sys, os
|
||||
# Change path so we find rdpy
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import unittest, rdpy.test.network.type
|
||||
import unittest, rdpy.test.network.type, rdpy.test.network.const, rdpy.test.network.layer
|
||||
|
||||
def headerTest(name):
|
||||
print "-"*40
|
||||
print "*"*70
|
||||
print name
|
||||
print "-"*40
|
||||
print "*"*70
|
||||
|
||||
if __name__ == '__main__':
|
||||
headerTest("Test case rdpy.test.network.type.TypeCase")
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(rdpy.test.network.type.TypeCase)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
||||
headerTest("Test case rdpy.test.network.const.ConstCase")
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(rdpy.test.network.const.ConstCase)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
||||
headerTest("Test case rdpy.test.network.type.layer.LayerCase")
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(rdpy.test.network.layer.LayerCase)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
||||
|
||||
34
rdpy/test/network/const.py
Normal file
34
rdpy/test/network/const.py
Normal file
@@ -0,0 +1,34 @@
|
||||
'''
|
||||
@author: sylvain
|
||||
'''
|
||||
import unittest
|
||||
import rdpy.network.const
|
||||
import rdpy.network.type
|
||||
|
||||
class ConstCase(unittest.TestCase):
|
||||
'''
|
||||
represent test case for all classes and function
|
||||
present in rdpy.network.const
|
||||
'''
|
||||
def test_type_attributes(self):
|
||||
'''
|
||||
test if type attributes decorator works
|
||||
'''
|
||||
@rdpy.network.const.TypeAttributes(rdpy.network.type.UInt16Le)
|
||||
class Test:
|
||||
MEMBER_1 = 1
|
||||
MEMBER_2 = 2
|
||||
|
||||
self.assertIsInstance(Test.MEMBER_1, rdpy.network.type.UInt16Le, "MEMBER_1 is not in correct type")
|
||||
self.assertIsInstance(Test.MEMBER_2, rdpy.network.type.UInt16Le, "MEMBER_2 is not in correct type")
|
||||
|
||||
def test_const(self):
|
||||
'''
|
||||
test if get on const class member generate new object each
|
||||
'''
|
||||
@rdpy.network.const.ConstAttributes
|
||||
class Test:
|
||||
MEMBER_1 = 1
|
||||
MEMBER_2 = 2
|
||||
|
||||
self.assertEquals(Test.MEMBER_1, Test.MEMBER_1, "handle same type of object")
|
||||
38
rdpy/test/network/layer.py
Normal file
38
rdpy/test/network/layer.py
Normal file
@@ -0,0 +1,38 @@
|
||||
'''
|
||||
@author: sylvain
|
||||
'''
|
||||
import unittest
|
||||
import rdpy.network.layer
|
||||
|
||||
class LayerCase(unittest.TestCase):
|
||||
'''
|
||||
represent test case for all classes and function
|
||||
present in rdpy.network.layer
|
||||
'''
|
||||
|
||||
class LayerCaseException(Exception):
|
||||
'''
|
||||
exception use for event base test
|
||||
'''
|
||||
pass
|
||||
|
||||
def test_layer_connect_event(self):
|
||||
'''
|
||||
test if connect event is send from transport to presentation
|
||||
'''
|
||||
class TestConnect(rdpy.network.layer.Layer):
|
||||
def connect(self):
|
||||
raise LayerCase.LayerCaseException()
|
||||
|
||||
self.assertRaises(LayerCase.LayerCaseException, rdpy.network.layer.Layer(presentation = TestConnect()).connect)
|
||||
|
||||
def test_layer_receive_event(self):
|
||||
'''
|
||||
test if recv event is send from transport to presentation
|
||||
'''
|
||||
class TestConnect(rdpy.network.layer.Layer):
|
||||
def recv(self, s):
|
||||
if s == "message":
|
||||
raise LayerCase.LayerCaseException()
|
||||
|
||||
self.assertRaises(LayerCase.LayerCaseException, rdpy.network.layer.Layer(presentation = TestConnect()).recv, "message")
|
||||
@@ -240,7 +240,28 @@ class TypeCase(unittest.TestCase):
|
||||
'''
|
||||
#unsigned int case
|
||||
t = rdpy.network.type.SimpleType("I", 4, False, 0, optional = True)
|
||||
#empty stream
|
||||
s1 = rdpy.network.type.Stream()
|
||||
s1.readType(t)
|
||||
self.assertEqual(t.value, 0, "invalid stream read optional value")
|
||||
|
||||
def test_stream_read_conditional_singletype_false(self):
|
||||
'''
|
||||
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")
|
||||
s1.readType(t)
|
||||
self.assertEqual(t.value, 0, "invalid stream read conditional value")
|
||||
|
||||
def test_stream_read_conditional_singletype_true(self):
|
||||
'''
|
||||
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")
|
||||
s1.readType(t)
|
||||
self.assertEqual(t.value, 1, "invalid stream read conditional value")
|
||||
|
||||
Reference in New Issue
Block a user