aboutsummaryrefslogtreecommitdiffstats
path: root/tests/QtOpenGL/qglbuffer_test.py
blob: ae23fbdf3300b3d5981108bedb02fa4ec98a93b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
'''Unit tests for QGLBuffer'''

import unittest

from PySide.QtCore import QByteArray
from PySide.QtOpenGL import QGLBuffer, QGLWidget

from helper import UsesQApplication

class QGLBufferTest(UsesQApplication):
    def usageCheck(self, t):
        w = QGLWidget()
        w.makeCurrent()

        b = QGLBuffer(t)
        self.assertEqual(b.usagePattern(), QGLBuffer.StaticDraw)
        b.setUsagePattern(QGLBuffer.DynamicDraw)

        self.assert_(b.create())
        self.assert_(b.bufferId() != 0)
        self.assert_(b.bind())

        data = QByteArray("12345")
        b.allocate(data)
        self.assertEqual(b.size(), data.size())

        m = b.map(QGLBuffer.ReadOnly)
        self.assertEqual(m.data(), data.data())
        b.unmap()

        other_data = QByteArray("67")
        b.write(0, other_data)
        m = b.map(QGLBuffer.ReadOnly)
        self.assertEqual(m.mid(0, other_data.size()).data(), other_data.data())
        b.unmap()

        result, rdata = b.read(0, other_data.size())
        print result, rdata
        self.assert_(result)
        self.assertEqual(other_data.data(), rdata.data())

        b.release()

    def testUsage(self):
        self.usageCheck(QGLBuffer.IndexBuffer)

if __name__ == '__main__':
    unittest.main()