2 # Copyright (c) 2015-2016, 2019 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 """Test the opengl module."""
24 from unittest
import mock
28 from framework
import wflinfo
29 from framework
.test
import opengl
30 from framework
.test
.base
import TestIsSkip
as _TestIsSkip
34 # pylint: disable=no-self-use,attribute-defined-outside-init,protected-access
37 class TestFastSkipMixin(object): # pylint: disable=too-many-public-methods
38 """Tests for the FastSkipMixin class."""
40 @pytest.fixture(autouse
=True, scope
='class')
42 """Create a Class with FastSkipMixin, but patch various bits."""
43 _mock_wflinfo
= mock
.Mock(spec
=wflinfo
.WflInfo
)
44 _mock_wflinfo
.core
.api_version
= 3.3
45 _mock_wflinfo
.core
.shader_version
= 3.3
46 _mock_wflinfo
.core
.extensions
= set(['bar'])
47 _mock_wflinfo
.es2
.api_version
= 3.0
48 _mock_wflinfo
.es2
.shader_version
= 2.0
49 _mock_wflinfo
.es2
.extensions
= set(['bar'])
51 with mock
.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo
):
54 class _Test(opengl
.FastSkipMixin
, utils
.Test
):
58 """Tests that the api works.
60 Since you're not supposed to be able to pass gl and gles version, this
61 uses two separate constructor calls.
63 self
._Test
(['foo'], extensions
={'foo'}, api_version
=3, shader_version
=2)
64 self
._Test
(['foo'], extensions
={'foo'}, api_version
=3,
68 class TestFastSkip(object):
69 """Tests for the FastSkip class."""
71 @pytest.fixture(autouse
=True, scope
='class')
73 """Create a Class with FastSkipMixin, but patch various bits."""
74 _mock_wflinfo
= mock
.Mock(spec
=wflinfo
.WflInfo
)
75 _mock_wflinfo
.core
.api_version
= 3.3
76 _mock_wflinfo
.core
.shader_version
= 3.3
77 _mock_wflinfo
.core
.extensions
= set(['bar'])
78 _mock_wflinfo
.es2
.api_version
= 3.0
79 _mock_wflinfo
.es2
.shader_version
= 2.0
80 _mock_wflinfo
.es2
.extensions
= set(['bar'])
82 with mock
.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo
):
87 return opengl
.FastSkip(api
='core')
89 def test_should_skip(self
, inst
):
90 """test.opengl.FastSkipMixin.test: Skips when requires is missing
93 inst
.extensions
.add('foobar')
94 with pytest
.raises(_TestIsSkip
):
97 def test_should_not_skip(self
, inst
):
98 """test.opengl.FastSkipMixin.test: runs when requires is in
101 inst
.extensions
.add('bar')
104 def test_max_api_version_lt(self
, inst
):
105 """test.opengl.FastSkipMixin.test: skips if api_version >
108 inst
.api_version
= 4.0
109 with pytest
.raises(_TestIsSkip
):
112 def test_max_api_version_gt(self
, inst
):
113 """test.opengl.FastSkipMixin.test: runs if api_version <
116 inst
.api_version
= 1.0
118 def test_max_api_version_set(self
, inst
):
119 """test.opengl.FastSkipMixin.test: runs if api_version is None"""
122 def test_max_api_version_lt(self
, inst
):
123 """test.opengl.FastSkipMixin.test: skips if api_version >
126 inst
.api_version
= 4.0
127 with pytest
.raises(_TestIsSkip
):
130 def test_max_api_version_gt(self
, inst
):
131 """test.opengl.FastSkipMixin.test: runs if api_version <
134 inst
.api_version
= 1.0
136 def test_max_api_version_set(self
, inst
):
137 """test.opengl.FastSkipMixin.test: runs if api_version is None"""
140 def test_max_shader_version_lt(self
, inst
):
141 """test.opengl.FastSkipMixin.test: skips if shader_version >
142 __max_shader_version.
144 inst
.shader_version
= 4.0
145 with pytest
.raises(_TestIsSkip
):
148 def test_max_shader_version_gt(self
, inst
):
149 """test.opengl.FastSkipMixin.test: runs if shader_version <
150 __max_shader_version.
152 inst
.shader_version
= 1.0
154 def test_max_shader_version_set(self
, inst
):
155 """test.opengl.FastSkipMixin.test: runs if shader_version is None"""
158 def test_max_shader_version_lt(self
, inst
):
159 """test.opengl.FastSkipMixin.test: skips if shader_version >
160 __max_shader_version.
162 inst
.shader_version
= 4.0
163 with pytest
.raises(_TestIsSkip
):
166 def test_max_shader_version_gt(self
, inst
):
167 """test.opengl.FastSkipMixin.test: runs if shader_version <
168 __max_shader_version.
170 inst
.shader_version
= 1.0
172 def test_max_shader_version_set(self
, inst
):
173 """test.opengl.FastSkipMixin.test: runs if shader_version is None"""
176 class TestEmpty(object):
177 """Tests for the FastSkip class when values are unset."""
179 @pytest.fixture(autouse
=True, scope
='class')
181 """Create a Class with FastSkipMixin, but patch various bits."""
182 _mock_wflinfo
= mock
.Mock(spec
=wflinfo
.WflInfo
)
183 _mock_wflinfo
.core
.api_version
= 0.0
184 _mock_wflinfo
.core
.shader_version
= 0.0
185 _mock_wflinfo
.core
.extensions
= set()
186 _mock_wflinfo
.es2
.api_version
= 0.0
187 _mock_wflinfo
.es2
.shader_version
= 0.0
188 _mock_wflinfo
.es2
.extensions
= set()
190 with mock
.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo
):
195 return opengl
.FastSkip(api
='core')
197 def test_extension_empty(self
, inst
):
198 """test.opengl.FastSkipMixin.test: if extensions are empty test
201 inst
.info
.core
.extensions
.add('foobar')
204 def test_requires_empty(self
, inst
):
205 """test.opengl.FastSkipMixin.test: if gl_requires is empty test
210 def test_max_shader_version_unset(self
, inst
):
211 """test.opengl.FastSkipMixin.test: runs if __max_shader_version is
214 inst
.shader_version
= 1.0
217 def test_max_api_version_unset(self
, inst
):
218 """test.opengl.FastSkipMixin.test: runs if __max_api_version is
221 inst
.api_version
= 1.0
225 class TestFastSkipMixinDisabled(object):
226 """Tests for the sub version."""
228 @pytest.fixture(autouse
=True, scope
='class')
230 """Create a Class with FastSkipMixin, but patch various bits."""
231 _mock_wflinfo
= mock
.Mock(spec
=wflinfo
.WflInfo
)
232 _mock_wflinfo
.es2
.api_version
= 3.3
233 _mock_wflinfo
.es2
.shader_version
= 2.0
234 _mock_wflinfo
.es2
.extensions
= set(['bar'])
235 _mock_wflinfo
.core
.api_version
= 3.0
236 _mock_wflinfo
.core
.shader_version
= 3.3
237 _mock_wflinfo
.core
.extensions
= set(['bar'])
239 with mock
.patch('framework.test.opengl.FastSkip.info', _mock_wflinfo
):
242 class _Test(opengl
.FastSkipMixin
, utils
.Test
):
246 """Tests that the api works.
248 Since you're not supposed to be able to pass gl and gles version, this
249 uses two separate constructor calls.
251 self
._Test
(['foo'], extensions
={'foo'}, api_version
=3, shader_version
=2)
252 self
._Test
(['foo'], extensions
={'foo'}, api_version
=3,