Exemple #1
0
    def testSerializeThenDeserialize(self):
        obj = Xtruct2(i32_thing=1,
                      struct_thing=Xtruct(string_thing="foo"))

        s1 = serialize(obj)
        for i in range(10):
            self.assertEquals(s1, serialize(obj))
            objcopy = Xtruct2()
            deserialize(objcopy, serialize(obj))
            self.assertEquals(obj, objcopy)

        obj = Xtruct(string_thing="bar")
        objcopy = Xtruct()
        deserialize(objcopy, serialize(obj))
        self.assertEquals(obj, objcopy)

        # test booleans
        obj = Bools(im_true=True, im_false=False)
        objcopy = Bools()
        deserialize(objcopy, serialize(obj))
        self.assertEquals(obj, objcopy)

        # test enums
        for num, name in Numberz._VALUES_TO_NAMES.items():
            obj = Bonk(message='enum Numberz value %d is string %s' % (num, name), type=num)
            objcopy = Bonk()
            deserialize(objcopy, serialize(obj))
            self.assertEquals(obj, objcopy)
Exemple #2
0
 def testMultiException(self, arg0, arg1):
     if options.verbose > 1:
         logging.info('testMultiException(%s, %s)' % (arg0, arg1))
     if arg0 == 'Xception':
         raise Xception(errorCode=1001, message='This is an Xception')
     elif arg0 == 'Xception2':
         raise Xception2(
             errorCode=2002,
             struct_thing=Xtruct(string_thing='This is an Xception2'))
     return Xtruct(string_thing=arg1)
Exemple #3
0
    def testStruct(self):
        x = Xtruct()
        x.string_thing = "Zero"
        x.byte_thing = 1
        x.i32_thing = -3
        x.i64_thing = -5
        y = yield self.client.testStruct(x)

        self.assertEquals(y.string_thing, "Zero")
        self.assertEquals(y.byte_thing, 1)
        self.assertEquals(y.i32_thing, -3)
        self.assertEquals(y.i64_thing, -5)
Exemple #4
0
 def testMulti(self, arg0, arg1, arg2, arg3, arg4, arg5):
     if options.verbose > 1:
         logging.info('testMulti(%s)' %
                      [arg0, arg1, arg2, arg3, arg4, arg5])
     return Xtruct(string_thing='Hello2',
                   byte_thing=arg0,
                   i32_thing=arg1,
                   i64_thing=arg2)
Exemple #5
0
 def testNest(self):
     print('testNest')
     inner = Xtruct(string_thing="Zero",
                    byte_thing=1,
                    i32_thing=-3,
                    i64_thing=-5)
     x = Xtruct2(struct_thing=inner, byte_thing=0, i32_thing=0)
     y = self.client.testNest(x)
     self.assertEqual(y, x)
Exemple #6
0
 def testMulti(self):
     print('testMulti')
     xpected = Xtruct(string_thing='Hello2', byte_thing=74, i32_thing=0xff00ff, i64_thing=0xffffffffd0d0)
     y = self.client.testMulti(xpected.byte_thing,
                               xpected.i32_thing,
                               xpected.i64_thing,
                               {0: 'abc'},
                               Numberz.FIVE,
                               0xf0f0f0)
     self.assertEqual(y, xpected)
Exemple #7
0
    def testSerializeThenDeserialize(self):
        obj = Xtruct2(i32_thing=1, struct_thing=Xtruct(string_thing="foo"))

        s1 = serialize(obj)
        for i in range(10):
            self.assertEquals(s1, serialize(obj))
            objcopy = Xtruct2()
            deserialize(objcopy, serialize(obj))
            self.assertEquals(obj, objcopy)

        obj = Xtruct(string_thing="bar")
        objcopy = Xtruct()
        deserialize(objcopy, serialize(obj))
        self.assertEquals(obj, objcopy)

        # test booleans
        obj = Bools(im_true=True, im_false=False)
        objcopy = Bools()
        deserialize(objcopy, serialize(obj))
        self.assertEquals(obj, objcopy)

        # test enums
        def _enumerate_enum(enum_class):
            if hasattr(enum_class, '_VALUES_TO_NAMES'):
                # old-style enums
                for num, name in enum_class._VALUES_TO_NAMES.items():
                    yield (num, name)
            else:
                # assume Python 3.4+ IntEnum-based
                from enum import IntEnum
                self.assertTrue((issubclass(enum_class, IntEnum)))
                for num in enum_class:
                    yield (num.value, num.name)

        for num, name in _enumerate_enum(Numberz):
            obj = Bonk(message='enum Numberz value %d is string %s' %
                       (num, name),
                       type=num)
            objcopy = Bonk()
            deserialize(objcopy, serialize(obj))
            self.assertEquals(obj, objcopy)
Exemple #8
0
 def testStruct(self):
     print('testStruct')
     x = Xtruct()
     x.string_thing = "Zero"
     x.byte_thing = 1
     x.i32_thing = -3
     x.i64_thing = -5
     y = self.client.testStruct(x)
     self.assertEqual(y, x)
Exemple #9
0
    def testStruct(self):
        x = Xtruct()
        x.string_thing = "Zero"
        x.byte_thing = 1
        x.i32_thing = -3
        x.i64_thing = -5
        y = yield from self.client.testStruct(x)

        self.assertEqual(y.string_thing, "Zero")
        self.assertEqual(y.byte_thing, 1)
        self.assertEqual(y.i32_thing, -3)
        self.assertEqual(y.i64_thing, -5)
Exemple #10
0
    def eofTestHelperStress(self, pfactory):
        """Test the ability of TBinaryProtocol to deal with the removal of every byte in the file"""
        # TODO: we should make sure this covers more of the code paths

        data = self.make_data(pfactory)
        for i in range(0, len(data) + 1):
            trans = TTransport.TMemoryBuffer(data[0:i])
            prot = pfactory.getProtocol(trans)
            try:
                x = Xtruct()
                x.read(prot)
                x.read(prot)
                x.read(prot)
            except EOFError:
                continue
            self.fail("Should have gotten an EOFError")
Exemple #11
0
    def eofTestHelper(self, pfactory):
        trans = TTransport.TMemoryBuffer(self.make_data(pfactory))
        prot = pfactory.getProtocol(trans)

        x = Xtruct()
        x.read(prot)
        self.assertEqual(x.string_thing, "Zero")
        self.assertEqual(x.byte_thing, 0)

        x = Xtruct()
        x.read(prot)
        self.assertEqual(x.string_thing, "One")
        self.assertEqual(x.byte_thing, 1)

        try:
            x = Xtruct()
            x.read(prot)
        except EOFError:
            return

        self.fail("Should have gotten EOFError")
Exemple #12
0
    def make_data(self, pfactory=None):
        trans = TTransport.TMemoryBuffer()
        if pfactory:
            prot = pfactory.getProtocol(trans)
        else:
            prot = TBinaryProtocol.TBinaryProtocol(trans)

        x = Xtruct()
        x.string_thing = "Zero"
        x.byte_thing = 0

        x.write(prot)

        x = Xtruct()
        x.string_thing = "One"
        x.byte_thing = 1

        x.write(prot)

        return trans.getvalue()