Ejemplo n.º 1
0
 def test_build_terminator(self):
     s = CString("foo", terminators=six.b("XYZ"), encoding="utf8")
     self.assertEqual(s.build(six.u("hello")), six.b("helloX"))
Ejemplo n.º 2
0
        self.assertEqual(s.build(six.u("hello")), six.b("hello\x00"))

    def test_parse_terminator(self):
        s = CString("foo", terminators=six.b("XYZ"), encoding="utf8")
        self.assertEqual(s.parse(six.b("helloX")), six.u("hello"))
        self.assertEqual(s.parse(six.b("helloY")), six.u("hello"))
        self.assertEqual(s.parse(six.b("helloZ")), six.u("hello"))

    def test_build_terminator(self):
        s = CString("foo", terminators=six.b("XYZ"), encoding="utf8")
        self.assertEqual(s.build(six.u("hello")), six.b("helloX"))


class TestGreedyString(unittest.TestCase):
    def test_parse(self):
        s = GreedyString("foo", encoding="utf8")
        self.assertEqual(s.parse(six.b("hello\x00")), six.u("hello\x00"))

    def test_build(self):
        s = GreedyString("foo", encoding="utf8")
        self.assertEqual(s.build(six.u("hello")), six.b("hello"))


if __name__ == "__main__":
    #unittest.main()
    s = CString("foo", encoding="utf8")
    s.build(six.u("hello"))



Ejemplo n.º 3
0
 def test_build(self):
     s = CString("foo", encoding="utf8")
     self.assertEqual(s.build(six.u("hello")), six.b("hello\x00"))
Ejemplo n.º 4
0
 def test_build(self):
     s = CString("foo", encoding="utf8")
     self.assertEqual(s.build(six.u("hello")), six.b("hello\x00"))
Ejemplo n.º 5
0
 def test_build_terminator(self):
     s = CString("foo", terminators=six.b("XYZ"), encoding="utf8")
     self.assertEqual(s.build(six.u("hello")), six.b("helloX"))
Ejemplo n.º 6
0
        s = PascalString("foo",
                         length_field=UBInt16("length"),
                         encoding="utf8")
        self.assertEqual(s.build(six.u("hello")), six.b("\x00\x05hello"))


class TestCString(unittest.TestCase):
    def test_parse(self):
        s = CString("foo", encoding="utf8")
        self.assertEqual(s.parse(six.b("hello\x00")), six.u("hello"))

    def test_build(self):
        s = CString("foo", encoding="utf8")
        self.assertEqual(s.build(six.u("hello")), six.b("hello\x00"))

    def test_parse_terminator(self):
        s = CString("foo", terminators=six.b("XYZ"), encoding="utf8")
        self.assertEqual(s.parse(six.b("helloX")), six.u("hello"))
        self.assertEqual(s.parse(six.b("helloY")), six.u("hello"))
        self.assertEqual(s.parse(six.b("helloZ")), six.u("hello"))

    def test_build_terminator(self):
        s = CString("foo", terminators=six.b("XYZ"), encoding="utf8")
        self.assertEqual(s.build(six.u("hello")), six.b("helloX"))


if __name__ == "__main__":
    #unittest.main()
    s = CString("foo", encoding="utf8")
    s.build(six.u("hello"))
Ejemplo n.º 7
0
 def test_build_terminator(self):
     s = CString("foo", terminators=b"XYZ")
     self.assertEqual(s.build(b"hello"), b"helloX")
Ejemplo n.º 8
0
 def test_build(self):
     s = CString("foo")
     self.assertEqual(s.build(b"hello"), b"hello\x00")
Ejemplo n.º 9
0
 def test_build_terminator(self):
     s = CString("s", terminators=b"XYZ", encoding="utf8")
     self.assertEqual(s.build(u"hello"), b"helloX")
Ejemplo n.º 10
0
 def test_build(self):
     s = CString("s", encoding="utf8")
     self.assertEqual(s.build(u"hello"), b"hello\x00")
     s = CString("s")
     self.assertEqual(s.build(b"hello"), b"hello\x00")