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 | // |
Jamie Madill | 508a5b7 | 2015-12-08 11:26:14 -0500 | [diff] [blame] | 6 | // ANGLETest: |
| 7 | // Implementation of common ANGLE testing fixture. |
| 8 | // |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 9 | |
| 10 | #ifndef ANGLE_TESTS_ANGLE_TEST_H_ |
| 11 | #define ANGLE_TESTS_ANGLE_TEST_H_ |
| 12 | |
| 13 | #include <gtest/gtest.h> |
| 14 | #include <algorithm> |
| 15 | |
| 16 | #include "angle_gl.h" |
| 17 | #include "angle_test_configs.h" |
| 18 | #include "common/angleutils.h" |
| 19 | #include "shader_utils.h" |
| 20 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 21 | #define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError()) |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 22 | #define EXPECT_GL_NO_ERROR() EXPECT_GL_ERROR(GL_NO_ERROR) |
| 23 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 24 | #define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError()) |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 25 | #define ASSERT_GL_NO_ERROR() ASSERT_GL_ERROR(GL_NO_ERROR) |
| 26 | |
| 27 | #define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError()) |
| 28 | #define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS) |
| 29 | |
Nico Weber | 0c93b8a | 2015-12-09 15:31:40 -0500 | [diff] [blame] | 30 | // EGLBoolean is |unsigned int| but EGL_TRUE is 0, not 0u. |
Nico Weber | 08bf81d | 2015-12-09 16:23:32 -0500 | [diff] [blame] | 31 | #define ASSERT_EGL_TRUE(a) ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE), (a)) |
| 32 | #define ASSERT_EGL_FALSE(a) ASSERT_EQ(static_cast<EGLBoolean>(EGL_FALSE), (a)) |
Nico Weber | 0c93b8a | 2015-12-09 15:31:40 -0500 | [diff] [blame] | 33 | #define EXPECT_EGL_TRUE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_TRUE), (a)) |
| 34 | #define EXPECT_EGL_FALSE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_FALSE), (a)) |
| 35 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 36 | #define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError()) |
| 37 | #define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS) |
| 38 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 39 | #define ASSERT_GLENUM_EQ(expected, actual) ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual)) |
| 40 | #define EXPECT_GLENUM_EQ(expected, actual) EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual)) |
| 41 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 42 | #define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \ |
| 43 | { \ |
| 44 | GLubyte pixel[4]; \ |
| 45 | glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \ |
| 46 | EXPECT_GL_NO_ERROR(); \ |
| 47 | EXPECT_EQ((r), pixel[0]); \ |
| 48 | EXPECT_EQ((g), pixel[1]); \ |
| 49 | EXPECT_EQ((b), pixel[2]); \ |
| 50 | EXPECT_EQ((a), pixel[3]); \ |
| 51 | } |
| 52 | |
| 53 | #define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \ |
| 54 | { \ |
| 55 | GLubyte pixel[4]; \ |
| 56 | glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \ |
| 57 | EXPECT_GL_NO_ERROR(); \ |
| 58 | EXPECT_NEAR((r), pixel[0], abs_error); \ |
| 59 | EXPECT_NEAR((g), pixel[1], abs_error); \ |
| 60 | EXPECT_NEAR((b), pixel[2], abs_error); \ |
| 61 | EXPECT_NEAR((a), pixel[3], abs_error); \ |
| 62 | } |
| 63 | |
| 64 | class EGLWindow; |
| 65 | class OSWindow; |
| 66 | |
| 67 | class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters> |
| 68 | { |
| 69 | protected: |
| 70 | ANGLETest(); |
| 71 | ~ANGLETest(); |
| 72 | |
| 73 | public: |
| 74 | static bool InitTestWindow(); |
| 75 | static bool DestroyTestWindow(); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 76 | static void SetWindowVisible(bool isVisible); |
Cooper Partin | d756145 | 2015-09-10 10:23:29 -0700 | [diff] [blame] | 77 | static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 78 | |
| 79 | protected: |
| 80 | virtual void SetUp(); |
| 81 | virtual void TearDown(); |
| 82 | |
| 83 | virtual void swapBuffers(); |
| 84 | |
| 85 | static void drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale = 1.0f); |
| 86 | static GLuint compileShader(GLenum type, const std::string &source); |
| 87 | static bool extensionEnabled(const std::string &extName); |
Geoff Lang | 63046e2 | 2015-07-21 12:43:50 -0400 | [diff] [blame] | 88 | static bool eglClientExtensionEnabled(const std::string &extName); |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 89 | |
| 90 | void setWindowWidth(int width); |
| 91 | void setWindowHeight(int height); |
| 92 | void setConfigRedBits(int bits); |
| 93 | void setConfigGreenBits(int bits); |
| 94 | void setConfigBlueBits(int bits); |
| 95 | void setConfigAlphaBits(int bits); |
| 96 | void setConfigDepthBits(int bits); |
| 97 | void setConfigStencilBits(int bits); |
| 98 | void setMultisampleEnabled(bool enabled); |
| 99 | |
| 100 | int getClientVersion() const; |
| 101 | |
| 102 | EGLWindow *getEGLWindow() const; |
| 103 | int getWindowWidth() const; |
| 104 | int getWindowHeight() const; |
| 105 | bool isMultisampleEnabled() const; |
| 106 | |
| 107 | bool isIntel() const; |
| 108 | bool isAMD() const; |
| 109 | bool isNVidia() const; |
Jamie Madill | d55d283 | 2015-10-27 13:59:19 -0400 | [diff] [blame] | 110 | // Note: FL9_3 is explicitly *not* considered D3D11. |
| 111 | bool isD3D11() const; |
Jamie Madill | 9fc3682 | 2015-11-18 13:08:07 -0500 | [diff] [blame] | 112 | bool isD3D11_FL93() const; |
| 113 | // Is a D3D9-class renderer. |
| 114 | bool isD3D9() const; |
| 115 | // Is D3D9 or SM9_3 renderer. |
| 116 | bool isD3DSM3() const; |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 117 | EGLint getPlatformRenderer() const; |
| 118 | |
| 119 | private: |
| 120 | bool createEGLContext(); |
| 121 | bool destroyEGLContext(); |
| 122 | |
| 123 | EGLWindow *mEGLWindow; |
Corentin Wallez | f9ac8fe | 2015-07-23 13:40:15 -0400 | [diff] [blame] | 124 | int mWidth; |
| 125 | int mHeight; |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 126 | |
| 127 | static OSWindow *mOSWindow; |
| 128 | }; |
| 129 | |
| 130 | class ANGLETestEnvironment : public testing::Environment |
| 131 | { |
| 132 | public: |
| 133 | virtual void SetUp(); |
| 134 | virtual void TearDown(); |
| 135 | }; |
| 136 | |
| 137 | #endif // ANGLE_TESTS_ANGLE_TEST_H_ |