Blame tests/testeglerror.c

Packit 5af8b3
/*
Packit 5af8b3
 * Copyright (c) 2016, NVIDIA CORPORATION.
Packit 5af8b3
 *
Packit 5af8b3
 * Permission is hereby granted, free of charge, to any person obtaining a
Packit 5af8b3
 * copy of this software and/or associated documentation files (the
Packit 5af8b3
 * "Materials"), to deal in the Materials without restriction, including
Packit 5af8b3
 * without limitation the rights to use, copy, modify, merge, publish,
Packit 5af8b3
 * distribute, sublicense, and/or sell copies of the Materials, and to
Packit 5af8b3
 * permit persons to whom the Materials are furnished to do so, subject to
Packit 5af8b3
 * the following conditions:
Packit 5af8b3
 *
Packit 5af8b3
 * The above copyright notice and this permission notice shall be included
Packit 5af8b3
 * unaltered in all copies or substantial portions of the Materials.
Packit 5af8b3
 * Any additions, deletions, or changes to the original source files
Packit 5af8b3
 * must be clearly indicated in accompanying documentation.
Packit 5af8b3
 *
Packit 5af8b3
 * If only executable code is distributed, then the accompanying
Packit 5af8b3
 * documentation must state that "this software is based in part on the
Packit 5af8b3
 * work of the Khronos Group."
Packit 5af8b3
 *
Packit 5af8b3
 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 5af8b3
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 5af8b3
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Packit 5af8b3
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
Packit 5af8b3
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
Packit 5af8b3
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
Packit 5af8b3
 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
Packit 5af8b3
 */
Packit 5af8b3
Packit 5af8b3
#include <EGL/egl.h>
Packit 5af8b3
#include <EGL/eglext.h>
Packit 5af8b3
#include <GL/gl.h>
Packit 5af8b3
#include <stdio.h>
Packit 5af8b3
#include <stdlib.h>
Packit 5af8b3
#include <string.h>
Packit 5af8b3
Packit 5af8b3
#include "dummy/EGL_dummy.h"
Packit 5af8b3
#include "egl_test_utils.h"
Packit 5af8b3
Packit 5af8b3
int checkError(EGLint expectedError);
Packit 5af8b3
Packit 5af8b3
int main(int argc, char **argv)
Packit 5af8b3
{
Packit 5af8b3
    EGLDisplay dpy;
Packit 5af8b3
Packit 5af8b3
    static const EGLint ERROR_ATTRIBS[] = {
Packit 5af8b3
        EGL_CREATE_CONTEXT_FAIL, EGL_BAD_MATCH,
Packit 5af8b3
        EGL_NONE
Packit 5af8b3
    };
Packit 5af8b3
Packit 5af8b3
    loadEGLExtensions();
Packit 5af8b3
Packit 5af8b3
    // Make sure the last error starts out as EGL_SUCCESS.
Packit 5af8b3
    printf("Checking initial state.\n");
Packit 5af8b3
    checkError(EGL_SUCCESS);
Packit 5af8b3
Packit 5af8b3
    dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Packit 5af8b3
    checkError(EGL_SUCCESS);
Packit 5af8b3
Packit 5af8b3
    // Test a function call where libEGL.so will set an error on its own.
Packit 5af8b3
    printf("Checking error in libEGL\n");
Packit 5af8b3
    eglGetCurrentSurface(EGL_NONE);
Packit 5af8b3
    checkError(EGL_BAD_PARAMETER);
Packit 5af8b3
Packit 5af8b3
    // Test an error set through a dispatch stub in libEGL.so.
Packit 5af8b3
    printf("Testing eglCreateContext with invalid display\n");
Packit 5af8b3
    eglCreateContext(EGL_NO_DISPLAY, NULL, EGL_NO_CONTEXT, NULL);
Packit 5af8b3
    checkError(EGL_BAD_DISPLAY);
Packit 5af8b3
Packit 5af8b3
    // Test a dispatch stub, with the error set in the vendor library. Note
Packit 5af8b3
    // that this case should be identical for a vendor-provided dispatch
Packit 5af8b3
    // function or one from libEGL.so.
Packit 5af8b3
    printf("Testing eglCreateContext, vendor error\n");
Packit 5af8b3
    eglCreateContext(dpy, NULL, EGL_NO_CONTEXT, ERROR_ATTRIBS);
Packit 5af8b3
    checkError(EGL_BAD_MATCH);
Packit 5af8b3
Packit 5af8b3
    // Test an error set through a vendor-provided dispatch stub. This is
Packit 5af8b3
    // different from the eglCreateContext error because the vendor-provided
Packit 5af8b3
    // stub has to set the error through the setEGLError callback.
Packit 5af8b3
    printf("Testing eglTestDispatchDisplay with invalid display\n");
Packit 5af8b3
    ptr_eglTestDispatchDisplay(EGL_NO_DISPLAY, DUMMY_COMMAND_GET_VENDOR_NAME, 0);
Packit 5af8b3
    checkError(EGL_BAD_DISPLAY);
Packit 5af8b3
Packit 5af8b3
    // Same, but with a valid display.
Packit 5af8b3
    printf("Testing eglTestDispatchDisplay with valid display\n");
Packit 5af8b3
    ptr_eglTestDispatchDisplay(dpy, DUMMY_COMMAND_GET_VENDOR_NAME, 0);
Packit 5af8b3
    checkError(EGL_SUCCESS);
Packit 5af8b3
Packit 5af8b3
    return 0;
Packit 5af8b3
}
Packit 5af8b3
Packit 5af8b3
int checkError(EGLint expectedError)
Packit 5af8b3
{
Packit 5af8b3
    EGLint error = eglGetError();
Packit 5af8b3
    if (error != expectedError) {
Packit 5af8b3
        printf("Got wrong error: Expected 0x%04x, got 0x%04x\n", expectedError, error);
Packit 5af8b3
        exit(1);
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    // Calling eglGetError should also clear the last error, so make sure the
Packit 5af8b3
    // next call returns EGL_SUCCESS.
Packit 5af8b3
    error = eglGetError();
Packit 5af8b3
    if (error != EGL_SUCCESS) {
Packit 5af8b3
        printf("Got wrong error: Expected 0x%04x, got EGL_SUCCESS\n", expectedError);
Packit 5af8b3
        exit(1);
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    return 0;
Packit 5af8b3
}