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