示例#1
0
 def testMemoryStream(self):
     stream = MemoryStream()
     stream.writeString("aA")
     stream.writeString("bB")
     stream.resetPos()
     s1 = stream.readString()
     self.assertEqual(s1, "aA")
     s2 = stream.readString()
     self.assertEqual(s2, "bB")
示例#2
0
    def testReadWriteIntFromStream(self):
        stream = MemoryStream()
        stream.writeInt(1)
        stream.resetPos()

        v = IntValue()
        v.readFromStream(stream)
        self.assertEqual(v.getVal(), 1)

        v.setVal(2)
        stream.resetPos()
        v.writeToStream(stream)

        self.assertEqual(stream.tellg(), 4)
        stream.resetPos()
        self.assertEqual(stream.readInt(), 2)
示例#3
0
    def testReadWriteVec4FromStream(self):
        stream = MemoryStream()
        stream.writeFloat(1.5)
        stream.writeFloat(2.5)
        stream.writeFloat(3.5)
        stream.writeFloat(4.5)
        stream.resetPos()

        v = Vec4Value()
        v.readFromStream(stream)
        self.assertEqual(v.getVal(), (1.5, 2.5, 3.5, 4.5))

        v.setVal(5.5, 6.5, 7.5, 8.5)
        stream.resetPos()
        v.writeToStream(stream)

        self.assertEqual(stream.tellg(), 16)
        stream.resetPos()
        self.assertEqual(stream.readFloat(), 5.5)
        self.assertEqual(stream.readFloat(), 6.5)
        self.assertEqual(stream.readFloat(), 7.5)
        self.assertEqual(stream.readFloat(), 8.5)
示例#4
0
    def testReadWriteColorFromStream(self):
        stream = MemoryStream()
        stream.writeUChar(120)
        stream.writeUChar(121)
        stream.writeUChar(122)
        stream.writeUChar(123)
        stream.resetPos()

        v = ColorValue()
        v.readFromStream(stream)
        self.assertEqual(v.getVal(), (120, 121, 122, 123))

        v.setVal(251, 252, 253, 254)
        stream.resetPos()
        v.writeToStream(stream)

        self.assertEqual(stream.tellg(), 4)
        stream.resetPos()
        self.assertEqual(stream.readUChar(), 251)
        self.assertEqual(stream.readUChar(), 252)
        self.assertEqual(stream.readUChar(), 253)
        self.assertEqual(stream.readUChar(), 254)
示例#5
0
    def testReadWriteBoolFromStream(self):
        stream = MemoryStream()
        stream.writeBool(False)
        stream.resetPos()

        v = BoolValue()
        v.readFromStream(stream)
        self.assertEqual(v.getVal(), False)

        v.setVal(True)
        stream.resetPos()
        v.writeToStream(stream)

        self.assertEqual(stream.tellg(), 1)
        stream.resetPos()
        self.assertEqual(stream.readBool(), True)
示例#6
0
    def testReadWriteVec2FromStream(self):
        stream = MemoryStream()
        stream.writeFloat(1.5)
        stream.writeFloat(2.5)
        stream.resetPos()

        v = Vec2Value()
        v.readFromStream(stream)
        self.assertEqual(v.getVal(), (1.5, 2.5))

        v.setVal(3.5, 4.5)
        stream.resetPos()
        v.writeToStream(stream)

        self.assertEqual(stream.tellg(), 8)
        stream.resetPos()
        self.assertEqual(stream.readFloat(), 3.5)
        self.assertEqual(stream.readFloat(), 4.5)
示例#7
0
    def testReadWriteVe2iFromStream(self):
        stream = MemoryStream()
        stream.writeInt(1)
        stream.writeInt(2)
        stream.resetPos()

        v = Vec2iValue()
        v.readFromStream(stream)
        self.assertEqual(v.getVal(), (1, 2))

        v.setVal(3, 4)
        stream.resetPos()
        v.writeToStream(stream)

        self.assertEqual(stream.tellg(), 8)
        stream.resetPos()
        self.assertEqual(stream.readInt(), 3)
        self.assertEqual(stream.readInt(), 4)
示例#8
0
    def testReadWriteStringFromStream(self):
        stream = MemoryStream()
        stream.writeString("1")
        stream.resetPos()

        v = StringValue()
        v.readFromStream(stream)
        self.assertEqual(v.getVal(), "1")

        v.setVal("2")
        stream.resetPos()
        v.writeToStream(stream)

        self.assertEqual(stream.tellg(), 2)
        stream.resetPos()
        self.assertEqual(stream.readString(), "2")
示例#9
0
    def testReadWriteFloatFromStream(self):
        stream = MemoryStream()
        stream.writeFloat(1.5)
        stream.resetPos()

        v = FloatValue()
        v.readFromStream(stream)
        self.assertEqual(v.getVal(), 1.5)

        v.setVal(2.5)
        stream.resetPos()
        v.writeToStream(stream)

        self.assertEqual(stream.tellg(), 4)
        stream.resetPos()
        self.assertEqual(stream.readFloat(), 2.5)