Skip to content

Commit d536f78

Browse files
authored
Merge pull request #195 from anholt/version-unit-test
test: Add unit tests for epoxy_gl_version() and epoxy_glsl_version().
2 parents a7439f9 + e94a081 commit d536f78

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

test/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ TESTS = \
5757
$(GLX_TESTS) \
5858
$(EGL_AND_GLX_TESTS) \
5959
$(WGL_TESTS) \
60+
gl_version$(EXEEXT) \
6061
headerguards$(EXEEXT) \
6162
miscdefines$(EXEEXT) \
6263
khronos_typedefs$(EXEEXT) \

test/gl_version.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright © 2018 Broadcom
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice (including the next
12+
* paragraph) shall be included in all copies or substantial portions of the
13+
* Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21+
* IN THE SOFTWARE.
22+
*/
23+
24+
#include <stdio.h>
25+
#include <assert.h>
26+
#include "epoxy/gl.h"
27+
28+
GLenum mock_enum;
29+
const char *mock_gl_version;
30+
const char *mock_glsl_version;
31+
32+
static const GLubyte *override_glGetString(GLenum name)
33+
{
34+
switch (name) {
35+
case GL_VERSION:
36+
return (GLubyte *)mock_gl_version;
37+
case GL_SHADING_LANGUAGE_VERSION:
38+
return (GLubyte *)mock_glsl_version;
39+
default:
40+
assert(!"unexpected glGetString() enum");
41+
return 0;
42+
}
43+
}
44+
45+
static bool
46+
test_version(const char *gl_string, int gl_version,
47+
const char *glsl_string, int glsl_version)
48+
{
49+
int epoxy_version;
50+
51+
mock_gl_version = gl_string;
52+
mock_glsl_version = glsl_string;
53+
54+
epoxy_version = epoxy_gl_version();
55+
if (epoxy_version != gl_version) {
56+
fprintf(stderr,
57+
"glGetString(GL_VERSION) = \"%s\" returned epoxy_gl_version() "
58+
"%d instead of %d\n", gl_string, epoxy_version, gl_version);
59+
return false;
60+
}
61+
62+
63+
epoxy_version = epoxy_glsl_version();
64+
if (epoxy_version != glsl_version) {
65+
fprintf(stderr,
66+
"glGetString() = \"%s\" returned epoxy_glsl_version() "
67+
"%d instead of %d\n", glsl_string, epoxy_version, glsl_version);
68+
return false;
69+
}
70+
71+
return true;
72+
}
73+
74+
int
75+
main(int argc, char **argv)
76+
{
77+
bool pass = true;
78+
79+
epoxy_glGetString = override_glGetString;
80+
81+
pass = pass && test_version("3.0 Mesa 13.0.6", 30,
82+
"1.30", 130);
83+
pass = pass && test_version("OpenGL ES 3.2 Mesa 18.3.0-devel", 32,
84+
"OpenGL ES GLSL ES 3.20", 320);
85+
pass = pass && test_version("4.5.0 NVIDIA 384.130", 45,
86+
"4.50", 450);
87+
88+
return pass != true;
89+
}

test/meson.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ test('khronos_typedefs',
3333
c_args: common_cflags,
3434
dependencies: libepoxy_dep,
3535
include_directories: libepoxy_inc))
36+
test('gl_version',
37+
executable('gl_version',
38+
'gl_version.c',
39+
c_args: common_cflags,
40+
dependencies: libepoxy_dep,
41+
include_directories: libepoxy_inc))
3642

3743
if build_egl and build_x11_tests
3844
egl_common_sources = [ 'egl_common.h', 'egl_common.c', ]

0 commit comments

Comments
 (0)