summaryrefslogtreecommitdiff
path: root/unittests/framework/test/test_opengl.py
blob: 59024edf1a731145a6b1dd5a03f7e325fda59df0 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# Copyright (c) 2015-2016 Intel Corporation

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Test the opengl module."""

from __future__ import (
    absolute_import, division, print_function, unicode_literals
)
try:
    from unittest import mock
except ImportError:
    import mock

import pytest

from framework import wflinfo
from framework.test import opengl
from framework.test.base import TestIsSkip as _TestIsSkip

from .. import utils

# pylint: disable=no-self-use,attribute-defined-outside-init,protected-access


class TestFastSkipMixin(object):  # pylint: disable=too-many-public-methods
    """Tests for the FastSkipMixin class."""

    @pytest.yield_fixture(autouse=True, scope='class')
    def patch(self):
        """Create a Class with FastSkipMixin, but patch various bits."""
        _mock_wflinfo = mock.Mock(spec=wflinfo.WflInfo)
        _mock_wflinfo.gl_version = 3.3
        _mock_wflinfo.gles_version = 3.0
        _mock_wflinfo.glsl_version = 3.3
        _mock_wflinfo.glsl_es_version = 2.0
        _mock_wflinfo.gl_extensions = set(['bar'])

        with mock.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo):
            yield

    class _Test(opengl.FastSkipMixin, utils.Test):
        pass

    def test_api(self):
        """Tests that the api works.

        Since you're not suppoed to be able to pass gl and gles version, this
        uses two seperate constructor calls.
        """
        self._Test(['foo'], gl_required={'foo'}, gl_version=3, glsl_version=2)
        self._Test(['foo'], gl_required={'foo'}, gles_version=3,
                   glsl_es_version=2)


class TestFastSkip(object):
    """Tests for the FastSkip class."""

    @pytest.yield_fixture(autouse=True, scope='class')
    def patch(self):
        """Create a Class with FastSkipMixin, but patch various bits."""
        _mock_wflinfo = mock.Mock(spec=wflinfo.WflInfo)
        _mock_wflinfo.gl_version = 3.3
        _mock_wflinfo.gles_version = 3.0
        _mock_wflinfo.glsl_version = 3.3
        _mock_wflinfo.glsl_es_version = 2.0
        _mock_wflinfo.gl_extensions = set(['bar'])

        with mock.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo):
            yield

    @pytest.fixture
    def inst(self):
        return opengl.FastSkip()

    def test_should_skip(self, inst):
        """test.opengl.FastSkipMixin.test: Skips when requires is missing
        from extensions.
        """
        inst.gl_required.add('foobar')
        with pytest.raises(_TestIsSkip):
            inst.test()

    def test_should_not_skip(self, inst):
        """test.opengl.FastSkipMixin.test: runs when requires is in
        extensions.
        """
        inst.gl_required.add('bar')
        inst.test()

    def test_max_gl_version_lt(self, inst):
        """test.opengl.FastSkipMixin.test: skips if gl_version >
        __max_gl_version.
        """
        inst.gl_version = 4.0
        with pytest.raises(_TestIsSkip):
            inst.test()

    def test_max_gl_version_gt(self, inst):
        """test.opengl.FastSkipMixin.test: runs if gl_version <
        __max_gl_version.
        """
        inst.gl_version = 1.0

    def test_max_gl_version_set(self, inst):
        """test.opengl.FastSkipMixin.test: runs if gl_version is None"""
        inst.test()

    def test_max_gles_version_lt(self, inst):
        """test.opengl.FastSkipMixin.test: skips if gles_version >
        __max_gles_version.
        """
        inst.gles_version = 4.0
        with pytest.raises(_TestIsSkip):
            inst.test()

    def test_max_gles_version_gt(self, inst):
        """test.opengl.FastSkipMixin.test: runs if gles_version <
        __max_gles_version.
        """
        inst.gles_version = 1.0

    def test_max_gles_version_set(self, inst):
        """test.opengl.FastSkipMixin.test: runs if gles_version is None"""
        inst.test()

    def test_max_glsl_version_lt(self, inst):
        """test.opengl.FastSkipMixin.test: skips if glsl_version >
        __max_glsl_version.
        """
        inst.glsl_version = 4.0
        with pytest.raises(_TestIsSkip):
            inst.test()

    def test_max_glsl_version_gt(self, inst):
        """test.opengl.FastSkipMixin.test: runs if glsl_version <
        __max_glsl_version.
        """
        inst.glsl_version = 1.0

    def test_max_glsl_version_set(self, inst):
        """test.opengl.FastSkipMixin.test: runs if glsl_version is None"""
        inst.test()

    def test_max_glsl_es_version_lt(self, inst):
        """test.opengl.FastSkipMixin.test: skips if glsl_es_version >
        __max_glsl_es_version.
        """
        inst.glsl_es_version = 4.0
        with pytest.raises(_TestIsSkip):
            inst.test()

    def test_max_glsl_es_version_gt(self, inst):
        """test.opengl.FastSkipMixin.test: runs if glsl_es_version <
        __max_glsl_es_version.
        """
        inst.glsl_es_version = 1.0

    def test_max_glsl_es_version_set(self, inst):
        """test.opengl.FastSkipMixin.test: runs if glsl_es_version is None"""
        inst.test()

    class TestEmpty(object):
        """Tests for the FastSkip class when values are unset."""

        @pytest.yield_fixture(autouse=True, scope='class')
        def patch(self):
            """Create a Class with FastSkipMixin, but patch various bits."""
            _mock_wflinfo = mock.Mock(spec=wflinfo.WflInfo)
            _mock_wflinfo.gl_version = None
            _mock_wflinfo.gles_version = None
            _mock_wflinfo.glsl_version = None
            _mock_wflinfo.glsl_es_version = None
            _mock_wflinfo.gl_extensions = set()

            with mock.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo):
                yield

        @pytest.fixture
        def inst(self):
            return opengl.FastSkip()

        def test_extension_empty(self, inst):
            """test.opengl.FastSkipMixin.test: if extensions are empty test
            runs.
            """
            inst.gl_required.add('foobar')
            inst.test()

        def test_requires_empty(self, inst):
            """test.opengl.FastSkipMixin.test: if gl_requires is empty test
            runs.
            """
            inst.test()

        def test_max_gl_version_unset(self, inst):
            """test.opengl.FastSkipMixin.test: runs if __max_gl_version is
            None.
            """
            inst.gl_version = 1.0
            inst.test()

        def test_max_glsl_es_version_unset(self, inst):
            """test.opengl.FastSkipMixin.test: runs if __max_glsl_es_version is
            None.
            """
            inst.glsl_es_version = 1.0
            inst.test()

    def test_max_glsl_version_unset(self, inst):
        """test.opengl.FastSkipMixin.test: runs if __max_glsl_version is
        None.
        """
        inst.glsl_version = 1.0
        inst.test()

    def test_max_gles_version_unset(self, inst):
        """test.opengl.FastSkipMixin.test: runs if __max_gles_version is
        None.
        """
        inst.gles_version = 1.0
        inst.test()


class TestFastSkipMixinDisabled(object):
    """Tests for the sub version."""

    @pytest.yield_fixture(autouse=True, scope='class')
    def patch(self):
        """Create a Class with FastSkipMixin, but patch various bits."""
        _mock_wflinfo = mock.Mock(spec=wflinfo.WflInfo)
        _mock_wflinfo.gl_version = 3.3
        _mock_wflinfo.gles_version = 3.0
        _mock_wflinfo.glsl_version = 3.3
        _mock_wflinfo.glsl_es_version = 2.0
        _mock_wflinfo.gl_extensions = set(['bar'])

        with mock.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo):
            yield

    class _Test(opengl.FastSkipMixin, utils.Test):
        pass

    def test_api(self):
        """Tests that the api works.

        Since you're not suppoed to be able to pass gl and gles version, this
        uses two seperate constructor calls.
        """
        self._Test(['foo'], gl_required={'foo'}, gl_version=3, glsl_version=2)
        self._Test(['foo'], gl_required={'foo'}, gles_version=3,
                   glsl_es_version=2)