blob: 64f5e9d4858eb7a4c5274360678cf7c8603da7fe [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())
Corentin Wallezd3970de2015-05-14 11:07:48 -040022#define EXPECT_GL_NO_ERROR() EXPECT_GL_ERROR(GL_NO_ERROR)
23
Corentin Wallez322653b2015-06-17 18:33:56 +020024#define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError())
Corentin Wallezd3970de2015-05-14 11:07:48 -040025#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 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
Corentin Wallezd3970de2015-05-14 11:07:48 -040042#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
64class EGLWindow;
65class OSWindow;
66
67class 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 Wallezd3970de2015-05-14 11:07:48 -040076 static void SetWindowVisible(bool isVisible);
Cooper Partind7561452015-09-10 10:23:29 -070077 static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -040078
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 Lang63046e22015-07-21 12:43:50 -040088 static bool eglClientExtensionEnabled(const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -040089
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);
Geoff Lang70d0f492015-12-10 17:45:46 -050099 void setDebugEnabled(bool enabled);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400100
101 int getClientVersion() const;
102
103 EGLWindow *getEGLWindow() const;
104 int getWindowWidth() const;
105 int getWindowHeight() const;
106 bool isMultisampleEnabled() const;
107
108 bool isIntel() const;
109 bool isAMD() const;
110 bool isNVidia() const;
Jamie Madilld55d2832015-10-27 13:59:19 -0400111 // Note: FL9_3 is explicitly *not* considered D3D11.
112 bool isD3D11() const;
Jamie Madill9fc36822015-11-18 13:08:07 -0500113 bool isD3D11_FL93() const;
114 // Is a D3D9-class renderer.
115 bool isD3D9() const;
116 // Is D3D9 or SM9_3 renderer.
117 bool isD3DSM3() const;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400118 EGLint getPlatformRenderer() const;
119
120 private:
121 bool createEGLContext();
122 bool destroyEGLContext();
123
124 EGLWindow *mEGLWindow;
Corentin Wallezf9ac8fe2015-07-23 13:40:15 -0400125 int mWidth;
126 int mHeight;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400127
128 static OSWindow *mOSWindow;
129};
130
131class ANGLETestEnvironment : public testing::Environment
132{
133 public:
134 virtual void SetUp();
135 virtual void TearDown();
136};
137
138#endif // ANGLE_TESTS_ANGLE_TEST_H_