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
28GLenum mock_enum;
29const char *mock_gl_version;
30const char *mock_glsl_version;
31
32static const GLubyte * EPOXY_CALLSPEC 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
45static bool
46test_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 format: "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 format: "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
74int
75main(int argc, char **argv)
76{
77 bool pass = true;
78
79 epoxy_glGetString = override_glGetString;
80
81 pass = pass && test_version(gl_string: "3.0 Mesa 13.0.6", gl_version: 30,
82 glsl_string: "1.30", glsl_version: 130);
83 pass = pass && test_version(gl_string: "OpenGL ES 2.0 Mesa 20.1.0-devel (git-4bb19a330e)", gl_version: 20,
84 glsl_string: "OpenGL ES GLSL ES 1.0.16", glsl_version: 100);
85 pass = pass && test_version(gl_string: "OpenGL ES 3.2 Mesa 18.3.0-devel", gl_version: 32,
86 glsl_string: "OpenGL ES GLSL ES 3.20", glsl_version: 320);
87 pass = pass && test_version(gl_string: "4.5.0 NVIDIA 384.130", gl_version: 45,
88 glsl_string: "4.50", glsl_version: 450);
89
90 return pass != true;
91}
92

source code of gtk/subprojects/libepoxy/test/gl_version.c