Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | #ifndef ANGLE_TESTS_ANGLE_TEST_H_ |
| 8 | #define ANGLE_TESTS_ANGLE_TEST_H_ |
| 9 | |
| 10 | #include <gtest/gtest.h> |
| 11 | #include <algorithm> |
| 12 | |
| 13 | #include "angle_gl.h" |
| 14 | #include "angle_test_configs.h" |
| 15 | #include "common/angleutils.h" |
| 16 | #include "shader_utils.h" |
| 17 | |
| 18 | #define EXPECT_GL_ERROR(err) EXPECT_EQ((err), glGetError()) |
| 19 | #define EXPECT_GL_NO_ERROR() EXPECT_GL_ERROR(GL_NO_ERROR) |
| 20 | |
| 21 | #define ASSERT_GL_ERROR(err) ASSERT_EQ((err), glGetError()) |
| 22 | #define ASSERT_GL_NO_ERROR() ASSERT_GL_ERROR(GL_NO_ERROR) |
| 23 | |
| 24 | #define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError()) |
| 25 | #define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS) |
| 26 | |
| 27 | #define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError()) |
| 28 | #define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS) |
| 29 | |
| 30 | #define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \ |
| 31 | { \ |
| 32 | GLubyte pixel[4]; \ |
| 33 | glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \ |
| 34 | EXPECT_GL_NO_ERROR(); \ |
| 35 | EXPECT_EQ((r), pixel[0]); \ |
| 36 | EXPECT_EQ((g), pixel[1]); \ |
| 37 | EXPECT_EQ((b), pixel[2]); \ |
| 38 | EXPECT_EQ((a), pixel[3]); \ |
| 39 | } |
| 40 | |
| 41 | #define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \ |
| 42 | { \ |
| 43 | GLubyte pixel[4]; \ |
| 44 | glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \ |
| 45 | EXPECT_GL_NO_ERROR(); \ |
| 46 | EXPECT_NEAR((r), pixel[0], abs_error); \ |
| 47 | EXPECT_NEAR((g), pixel[1], abs_error); \ |
| 48 | EXPECT_NEAR((b), pixel[2], abs_error); \ |
| 49 | EXPECT_NEAR((a), pixel[3], abs_error); \ |
| 50 | } |
| 51 | |
| 52 | class EGLWindow; |
| 53 | class OSWindow; |
| 54 | |
| 55 | class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters> |
| 56 | { |
| 57 | protected: |
| 58 | ANGLETest(); |
| 59 | ~ANGLETest(); |
| 60 | |
| 61 | public: |
| 62 | static bool InitTestWindow(); |
| 63 | static bool DestroyTestWindow(); |
| 64 | static bool ResizeWindow(int width, int height); |
| 65 | static void SetWindowVisible(bool isVisible); |
| 66 | |
| 67 | protected: |
| 68 | virtual void SetUp(); |
| 69 | virtual void TearDown(); |
| 70 | |
| 71 | virtual void swapBuffers(); |
| 72 | |
| 73 | static void drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale = 1.0f); |
| 74 | static GLuint compileShader(GLenum type, const std::string &source); |
| 75 | static bool extensionEnabled(const std::string &extName); |
| 76 | |
| 77 | void setWindowWidth(int width); |
| 78 | void setWindowHeight(int height); |
| 79 | void setConfigRedBits(int bits); |
| 80 | void setConfigGreenBits(int bits); |
| 81 | void setConfigBlueBits(int bits); |
| 82 | void setConfigAlphaBits(int bits); |
| 83 | void setConfigDepthBits(int bits); |
| 84 | void setConfigStencilBits(int bits); |
| 85 | void setMultisampleEnabled(bool enabled); |
| 86 | |
| 87 | int getClientVersion() const; |
| 88 | |
| 89 | EGLWindow *getEGLWindow() const; |
| 90 | int getWindowWidth() const; |
| 91 | int getWindowHeight() const; |
| 92 | bool isMultisampleEnabled() const; |
| 93 | |
| 94 | bool isIntel() const; |
| 95 | bool isAMD() const; |
| 96 | bool isNVidia() const; |
| 97 | EGLint getPlatformRenderer() const; |
| 98 | |
| 99 | private: |
| 100 | bool createEGLContext(); |
| 101 | bool destroyEGLContext(); |
| 102 | |
| 103 | EGLWindow *mEGLWindow; |
| 104 | |
| 105 | static OSWindow *mOSWindow; |
| 106 | }; |
| 107 | |
| 108 | class ANGLETestEnvironment : public testing::Environment |
| 109 | { |
| 110 | public: |
| 111 | virtual void SetUp(); |
| 112 | virtual void TearDown(); |
| 113 | }; |
| 114 | |
| 115 | #endif // ANGLE_TESTS_ANGLE_TEST_H_ |