blob: 2c39776c76721692ae98ff6a22415010a62cb513 [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
Olli Etuaho4a8329f2016-01-11 17:12:57 +020085 static void drawQuad(GLuint program,
86 const std::string &positionAttribName,
87 GLfloat positionAttribZ);
88 static void drawQuad(GLuint program,
89 const std::string &positionAttribName,
90 GLfloat positionAttribZ,
91 GLfloat positionAttribXYScale);
Corentin Wallezd3970de2015-05-14 11:07:48 -040092 static GLuint compileShader(GLenum type, const std::string &source);
93 static bool extensionEnabled(const std::string &extName);
Geoff Lang63046e22015-07-21 12:43:50 -040094 static bool eglClientExtensionEnabled(const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -040095
96 void setWindowWidth(int width);
97 void setWindowHeight(int height);
98 void setConfigRedBits(int bits);
99 void setConfigGreenBits(int bits);
100 void setConfigBlueBits(int bits);
101 void setConfigAlphaBits(int bits);
102 void setConfigDepthBits(int bits);
103 void setConfigStencilBits(int bits);
104 void setMultisampleEnabled(bool enabled);
Geoff Lang70d0f492015-12-10 17:45:46 -0500105 void setDebugEnabled(bool enabled);
Corentin Wallezd3970de2015-05-14 11:07:48 -0400106
107 int getClientVersion() const;
108
109 EGLWindow *getEGLWindow() const;
110 int getWindowWidth() const;
111 int getWindowHeight() const;
112 bool isMultisampleEnabled() const;
113
114 bool isIntel() const;
115 bool isAMD() const;
116 bool isNVidia() const;
Jamie Madilld55d2832015-10-27 13:59:19 -0400117 // Note: FL9_3 is explicitly *not* considered D3D11.
118 bool isD3D11() const;
Jamie Madill9fc36822015-11-18 13:08:07 -0500119 bool isD3D11_FL93() const;
120 // Is a D3D9-class renderer.
121 bool isD3D9() const;
122 // Is D3D9 or SM9_3 renderer.
123 bool isD3DSM3() const;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400124 EGLint getPlatformRenderer() const;
125
126 private:
127 bool createEGLContext();
128 bool destroyEGLContext();
129
130 EGLWindow *mEGLWindow;
Corentin Wallezf9ac8fe2015-07-23 13:40:15 -0400131 int mWidth;
132 int mHeight;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400133
134 static OSWindow *mOSWindow;
135};
136
137class ANGLETestEnvironment : public testing::Environment
138{
139 public:
140 virtual void SetUp();
141 virtual void TearDown();
142};
143
144#endif // ANGLE_TESTS_ANGLE_TEST_H_