blob: 0458a2dd7a01ca4db7f44b2d0ff29591bbeeed86 [file] [log] [blame]
Corentin Wallezd3970de2015-05-14 11:07:48 -04001//
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 Madill508a5b72015-12-08 11:26:14 -05006// ANGLETest:
7// Implementation of common ANGLE testing fixture.
8//
Corentin Wallezd3970de2015-05-14 11:07:48 -04009
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 Wallez322653b2015-06-17 18:33:56 +020021#define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError())
Jamie Madill0dfa8072016-01-22 15:27:21 -050022#define EXPECT_GL_NO_ERROR() EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
Corentin Wallezd3970de2015-05-14 11:07:48 -040023
Corentin Wallez322653b2015-06-17 18:33:56 +020024#define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError())
Jamie Madill0dfa8072016-01-22 15:27:21 -050025#define ASSERT_GL_NO_ERROR() ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
Corentin Wallezd3970de2015-05-14 11:07:48 -040026
27#define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError())
28#define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS)
29
Nico Weber0c93b8a2015-12-09 15:31:40 -050030// EGLBoolean is |unsigned int| but EGL_TRUE is 0, not 0u.
Nico Weber08bf81d2015-12-09 16:23:32 -050031#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 Weber0c93b8a2015-12-09 15:31:40 -050033#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 Wallezd3970de2015-05-14 11:07:48 -040036#define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError())
37#define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS)
38
Corentin Wallez322653b2015-06-17 18:33:56 +020039#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
Jamie Madill0dfa8072016-01-22 15:27:21 -050042namespace angle
43{
44struct GLColor
45{
46 GLColor();
47 GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
Jamie Madille2509a32016-02-01 14:09:05 -050048 GLColor(GLuint colorValue);
Jamie Madill0dfa8072016-01-22 15:27:21 -050049
50 GLubyte R, G, B, A;
51};
52
53// Useful to cast any type to GLubyte.
54template <typename TR, typename TG, typename TB, typename TA>
55GLColor MakeGLColor(TR r, TG g, TB b, TA a)
56{
57 return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b),
58 static_cast<GLubyte>(a));
Corentin Wallezd3970de2015-05-14 11:07:48 -040059}
60
Jamie Madill0dfa8072016-01-22 15:27:21 -050061bool operator==(const GLColor &a, const GLColor &b);
62std::ostream &operator<<(std::ostream &ostream, const GLColor &color);
63GLColor ReadColor(GLint x, GLint y);
64
65} // namespace angle
66
67#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
68 EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
69
Olli Etuaho6ee394a2016-02-18 13:30:09 +020070#define EXPECT_PIXEL_ALPHA_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor(x, y).A)
71
Jamie Madille2509a32016-02-01 14:09:05 -050072#define EXPECT_PIXEL_COLOR_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor(x, y))
73
Jamie Madill0dfa8072016-01-22 15:27:21 -050074// TODO(jmadill): Figure out how we can use GLColor's nice printing with EXPECT_NEAR.
Corentin Wallezd3970de2015-05-14 11:07:48 -040075#define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
76{ \
77 GLubyte pixel[4]; \
78 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
79 EXPECT_GL_NO_ERROR(); \
80 EXPECT_NEAR((r), pixel[0], abs_error); \
81 EXPECT_NEAR((g), pixel[1], abs_error); \
82 EXPECT_NEAR((b), pixel[2], abs_error); \
83 EXPECT_NEAR((a), pixel[3], abs_error); \
84}
85
86class EGLWindow;
87class OSWindow;
88
89class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters>
90{
91 protected:
92 ANGLETest();
93 ~ANGLETest();
94
95 public:
96 static bool InitTestWindow();
97 static bool DestroyTestWindow();
Corentin Wallezd3970de2015-05-14 11:07:48 -040098 static void SetWindowVisible(bool isVisible);
Cooper Partind7561452015-09-10 10:23:29 -070099 static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400100
101 protected:
102 virtual void SetUp();
103 virtual void TearDown();
104
105 virtual void swapBuffers();
106
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200107 static void drawQuad(GLuint program,
108 const std::string &positionAttribName,
109 GLfloat positionAttribZ);
110 static void drawQuad(GLuint program,
111 const std::string &positionAttribName,
112 GLfloat positionAttribZ,
113 GLfloat positionAttribXYScale);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400114 static GLuint compileShader(GLenum type, const std::string &source);
115 static bool extensionEnabled(const std::string &extName);
Geoff Lang63046e22015-07-21 12:43:50 -0400116 static bool eglClientExtensionEnabled(const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400117
118 void setWindowWidth(int width);
119 void setWindowHeight(int height);
120 void setConfigRedBits(int bits);
121 void setConfigGreenBits(int bits);
122 void setConfigBlueBits(int bits);
123 void setConfigAlphaBits(int bits);
124 void setConfigDepthBits(int bits);
125 void setConfigStencilBits(int bits);
126 void setMultisampleEnabled(bool enabled);
Geoff Lang70d0f492015-12-10 17:45:46 -0500127 void setDebugEnabled(bool enabled);
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500128 void setNoErrorEnabled(bool enabled);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400129
130 int getClientVersion() const;
131
132 EGLWindow *getEGLWindow() const;
133 int getWindowWidth() const;
134 int getWindowHeight() const;
135 bool isMultisampleEnabled() const;
136
137 bool isIntel() const;
138 bool isAMD() const;
139 bool isNVidia() const;
Jamie Madilld55d2832015-10-27 13:59:19 -0400140 // Note: FL9_3 is explicitly *not* considered D3D11.
141 bool isD3D11() const;
Jamie Madill9fc36822015-11-18 13:08:07 -0500142 bool isD3D11_FL93() const;
143 // Is a D3D9-class renderer.
144 bool isD3D9() const;
145 // Is D3D9 or SM9_3 renderer.
146 bool isD3DSM3() const;
Ian Ewell292f0052016-02-04 10:37:32 -0500147 bool isOSX() const;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400148 EGLint getPlatformRenderer() const;
149
Austin Kinrossd544cc92016-01-11 15:26:42 -0800150 void ignoreD3D11SDKLayersWarnings();
151
Corentin Wallezd3970de2015-05-14 11:07:48 -0400152 private:
153 bool createEGLContext();
154 bool destroyEGLContext();
155
Austin Kinrossd544cc92016-01-11 15:26:42 -0800156 void checkD3D11SDKLayersMessages();
157
Corentin Wallezd3970de2015-05-14 11:07:48 -0400158 EGLWindow *mEGLWindow;
Corentin Wallezf9ac8fe2015-07-23 13:40:15 -0400159 int mWidth;
160 int mHeight;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400161
Austin Kinrossd544cc92016-01-11 15:26:42 -0800162 bool mIgnoreD3D11SDKLayersWarnings;
163
Corentin Wallezd3970de2015-05-14 11:07:48 -0400164 static OSWindow *mOSWindow;
165};
166
167class ANGLETestEnvironment : public testing::Environment
168{
169 public:
170 virtual void SetUp();
171 virtual void TearDown();
172};
173
174#endif // ANGLE_TESTS_ANGLE_TEST_H_