コード例 #1
0
ファイル: test_astypes.py プロジェクト: Flumotion/flvlib
    def test_longstring(self):
        self.set_name('longstring')
        self.add_get_test('\x00\x00\x00\x0btest string', 'test string')
        self.add_get_test('\x00\x00\x00\x1azażółć gęślą jaźń', 'zażółć gęślą jaźń')
        self.add_make_test('zażółć gęślą jaźń', '\x00\x00\x00\x1azażółć gęślą jaźń')
        # the resulting string should be UTF-8 encoded, just like this file
        self.add_make_test(u'λ', '\x00\x00\x00\x02λ')
        # A random blob should also work
        self.add_make_test('\x45\x2d\x6e\x55\x00\x23\x50', '\x00\x00\x00\x07\x45\x2d\x6e\x55\x00\x23\x50')
        self.add_make_test('', '\x00\x00\x00\x00')
        self.run_tests()

        # Longstrings are not getter/maker equivalent, because *all*
        # strings are serialized as normal strings, not longstrings.
        # So to test proper deserialization from script_data_values we
        # need to do it manually.
        val = 'a test longstring'
        # serialize, should get a string
        self.assertEquals(astypes.make_script_data_value(val),
                          primitives.make_ui8(constants.VALUE_TYPE_STRING)
                          + '\x00\x11a test longstring')
        # deserialize a longstring
        s = StringIO(primitives.make_ui8(constants.VALUE_TYPE_LONGSTRING)
                     + astypes.make_longstring(val))
        self.assertEquals(val, astypes.get_script_data_value(s))
        self.assertEquals(s.read(), '')
コード例 #2
0
    def test_longstring(self):
        self.set_name('longstring')
        self.add_get_test('\x00\x00\x00\x0btest string', 'test string')
        self.add_get_test('\x00\x00\x00\x1azażółć gęślą jaźń',
                          'zażółć gęślą jaźń')
        self.add_make_test('zażółć gęślą jaźń',
                           '\x00\x00\x00\x1azażółć gęślą jaźń')
        # the resulting string should be UTF-8 encoded, just like this file
        self.add_make_test(u'λ', '\x00\x00\x00\x02λ')
        # A random blob should also work
        self.add_make_test('\x45\x2d\x6e\x55\x00\x23\x50',
                           '\x00\x00\x00\x07\x45\x2d\x6e\x55\x00\x23\x50')
        self.add_make_test('', '\x00\x00\x00\x00')
        self.run_tests()

        # Longstrings are not getter/maker equivalent, because *all*
        # strings are serialized as normal strings, not longstrings.
        # So to test proper deserialization from script_data_values we
        # need to do it manually.
        val = 'a test longstring'
        # serialize, should get a string
        self.assertEquals(
            astypes.make_script_data_value(val),
            primitives.make_ui8(constants.VALUE_TYPE_STRING) +
            '\x00\x11a test longstring')
        # deserialize a longstring
        s = StringIO(
            primitives.make_ui8(constants.VALUE_TYPE_LONGSTRING) +
            astypes.make_longstring(val))
        self.assertEquals(val, astypes.get_script_data_value(s))
        self.assertEquals(s.read(), '')
コード例 #3
0
ファイル: test_astypes.py プロジェクト: Flumotion/flvlib
 def script_data_value_equivalent(self, val, getter, maker, value_type):
     s = StringIO(primitives.make_ui8(value_type) + maker(val))
     self.assertEquals(astypes.make_script_data_value(val), s.getvalue())
     self.assertEquals(val, astypes.get_script_data_value(s))
     self.assertEquals(s.read(), '')
コード例 #4
0
 def script_data_value_equivalent(self, val, getter, maker, value_type):
     s = StringIO(primitives.make_ui8(value_type) + maker(val))
     self.assertEquals(astypes.make_script_data_value(val), s.getvalue())
     self.assertEquals(val, astypes.get_script_data_value(s))
     self.assertEquals(s.read(), '')