Blame tests/testegldisplay.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
/**
Packit 5af8b3
 * \file
Packit 5af8b3
 *
Packit 5af8b3
 * Tests eglGetDisplay and eglGetPlatformDisplay.
Packit 5af8b3
 *
Packit 5af8b3
 * This test uses the dummy platform to create an EGLDisplay for each of the
Packit 5af8b3
 * dummy vendor libraries, then calls eglQueryString to make sure that each
Packit 5af8b3
 * display goes to the correct vendor.
Packit 5af8b3
 */
Packit 5af8b3
Packit 5af8b3
#include <EGL/egl.h>
Packit 5af8b3
#include <EGL/eglext.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 main(int argc, char **argv)
Packit 5af8b3
{
Packit 5af8b3
    EGLDisplay displays[DUMMY_VENDOR_COUNT];
Packit 5af8b3
    EGLDisplay dpy;
Packit 5af8b3
    EGLint error;
Packit 5af8b3
    int i;
Packit 5af8b3
Packit 5af8b3
    for (i=0; i
Packit 5af8b3
        const char *name = DUMMY_VENDOR_NAMES[i];
Packit 5af8b3
        const char *str;
Packit 5af8b3
        EGLint major, minor;
Packit 5af8b3
Packit 5af8b3
        printf("Testing vendor %d, with name \"%s\"\n", i, name);
Packit 5af8b3
Packit 5af8b3
        displays[i] = eglGetPlatformDisplay(EGL_DUMMY_PLATFORM, (void *) name, NULL);
Packit 5af8b3
        if (displays[i] == EGL_NO_DISPLAY) {
Packit 5af8b3
            printf("eglGetPlatformDisplay failed with vendor \"%s\", error 0x%04x\n", name, eglGetError());
Packit 5af8b3
            exit(1);
Packit 5af8b3
        }
Packit 5af8b3
Packit 5af8b3
        if (!eglInitialize(displays[i], &major, &minor)) {
Packit 5af8b3
            printf("eglInitialize failed\n");
Packit 5af8b3
            return 1;
Packit 5af8b3
        }
Packit 5af8b3
Packit 5af8b3
        str = eglQueryString(displays[i], EGL_VENDOR);
Packit 5af8b3
        if (str == NULL) {
Packit 5af8b3
            printf("eglQueryString failed with vendor \"%s\", error 0x%04x\n", name, eglGetError());
Packit 5af8b3
            exit(1);
Packit 5af8b3
        }
Packit 5af8b3
Packit 5af8b3
        if (strcmp(str, name) != 0) {
Packit 5af8b3
            printf("Got wrong vendor string: Expected \"%s\", but got \"%s\"\n", name, str);
Packit 5af8b3
            exit(1);
Packit 5af8b3
        }
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    // Test getting a default display from eglGetDisplay. This should iterate
Packit 5af8b3
    // over each vendor, and the first vendor library should return the same
Packit 5af8b3
    // display as it did for EGL_DUMMY_PLATFORM.
Packit 5af8b3
    dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Packit 5af8b3
    if (dpy == EGL_NO_DISPLAY) {
Packit 5af8b3
        printf("eglGetDisplay failed with error 0x%04x\n", eglGetError());
Packit 5af8b3
        return 1;
Packit 5af8b3
    }
Packit 5af8b3
    if (dpy != displays[0]) {
Packit 5af8b3
        printf("eglGetDisplay returned incorrect display: Expected %p, got %p\n",
Packit 5af8b3
                displays[0], dpy);
Packit 5af8b3
        return 1;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    // Try getting a display using an invalid platform enum.
Packit 5af8b3
    dpy = eglGetPlatformDisplay(EGL_ALPHA_SIZE, NULL, NULL);
Packit 5af8b3
    if (dpy != EGL_NO_DISPLAY) {
Packit 5af8b3
        printf("Got an EGLDisplay for an invalid platform.\n");
Packit 5af8b3
        return 1;
Packit 5af8b3
    }
Packit 5af8b3
    error = eglGetError();
Packit 5af8b3
    if (error != EGL_BAD_PARAMETER) {
Packit 5af8b3
        printf("Got the wrong error 0x%04x for eglGetPlatformDisplay with invalid platform\n", error);
Packit 5af8b3
        return 1;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    // Pass a valid platform, but with a name that the vendor's won't
Packit 5af8b3
    // recognize. Each vendor will return EGL_NO_DISPLAY, but won't raise an
Packit 5af8b3
    // error.
Packit 5af8b3
    dpy = eglGetPlatformDisplay(EGL_DUMMY_PLATFORM, (void *) "invalid", NULL);
Packit 5af8b3
    if (dpy != EGL_NO_DISPLAY) {
Packit 5af8b3
        printf("Got an EGLDisplay for an invalid vendor name.\n");
Packit 5af8b3
        return 1;
Packit 5af8b3
    }
Packit 5af8b3
    error = eglGetError();
Packit 5af8b3
    if (error != EGL_SUCCESS) {
Packit 5af8b3
        printf("Got the wrong error 0x%04x for eglGetPlatformDisplay with invalid vendor name\n", error);
Packit 5af8b3
        return 1;
Packit 5af8b3
    }
Packit 5af8b3
Packit 5af8b3
    return 0;
Packit 5af8b3
}
Packit 5af8b3