From 717cfd4874876cbb1cedc299b5863a46a11ff758 Mon Sep 17 00:00:00 2001 From: Jukka Jylänki Date: Wed, 13 Nov 2013 14:02:29 +0200 Subject: Add unit test for EGL context creation and confirming that #1775 and #1793 work. --- tests/test_egl.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/test_egl.c (limited to 'tests/test_egl.c') diff --git a/tests/test_egl.c b/tests/test_egl.c new file mode 100644 index 00000000..5864a797 --- /dev/null +++ b/tests/test_egl.c @@ -0,0 +1,73 @@ +#include +#include + +int result = 1; // Success +#define assert(x) do { if (!(x)) {result = 0; printf("Assertion failure: %s in %s:%d!\n", #x, __FILE__, __LINE__); } } while(0) + +int main(int argc, char *argv[]) +{ + EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + assert(display != EGL_NO_DISPLAY); + assert(eglGetError() == EGL_SUCCESS); + + EGLint major = 0, minor = 0; + EGLBoolean ret = eglInitialize(display, &major, &minor); + assert(eglGetError() == EGL_SUCCESS); + assert(ret == EGL_TRUE); + assert(major * 10000 + minor >= 10004); + + EGLint numConfigs; + ret = eglGetConfigs(display, NULL, 0, &numConfigs); + assert(eglGetError() == EGL_SUCCESS); + assert(ret == EGL_TRUE); + + EGLint attribs[] = { + EGL_RED_SIZE, 5, + EGL_GREEN_SIZE, 6, + EGL_BLUE_SIZE, 5, + EGL_NONE + }; + EGLConfig config; + ret = eglChooseConfig(display, attribs, &config, 1, &numConfigs); + assert(eglGetError() == EGL_SUCCESS); + assert(ret == EGL_TRUE); + + EGLNativeWindowType dummyWindow; + EGLSurface surface = eglCreateWindowSurface(display, config, dummyWindow, NULL); + assert(eglGetError() == EGL_SUCCESS); + assert(surface != 0); + + EGLint contextAttribs[] = + { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + EGLContext context = eglCreateContext(display, config, NULL, contextAttribs); + assert(eglGetError() == EGL_SUCCESS); + assert(context != 0); + + assert(eglGetCurrentContext() == 0); // Creating a context does not yet activate it. + assert(eglGetError() == EGL_SUCCESS); + + ret = eglMakeCurrent(display, surface, surface, context); + assert(eglGetError() == EGL_SUCCESS); + assert(ret == EGL_TRUE); + assert(eglGetCurrentContext() == context); + assert(eglGetCurrentSurface(EGL_READ) == surface); + assert(eglGetCurrentSurface(EGL_DRAW) == surface); + + ret = eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + assert(eglGetError() == EGL_SUCCESS); + assert(ret == EGL_TRUE); + assert(eglGetCurrentContext() == EGL_NO_CONTEXT); + assert(eglGetCurrentSurface(EGL_READ) == EGL_NO_SURFACE); + assert(eglGetCurrentSurface(EGL_DRAW) == EGL_NO_SURFACE); + + ret = eglTerminate(display); + assert(eglGetError() == EGL_SUCCESS); + assert(ret == EGL_TRUE); + +#ifdef REPORT_RESULT + REPORT_RESULT(); +#endif +} -- cgit v1.2.3-18-g5258