blob: 3dc9d19531bfa52be3fc0a7cca5ab1f355240810 [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.
31#define EXPECT_EGL_TRUE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_TRUE), (a))
32#define EXPECT_EGL_FALSE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_FALSE), (a))
33
Corentin Wallezd3970de2015-05-14 11:07:48 -040034#define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError())
35#define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS)
36
Corentin Wallez322653b2015-06-17 18:33:56 +020037#define ASSERT_GLENUM_EQ(expected, actual) ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
38#define EXPECT_GLENUM_EQ(expected, actual) EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
39
Corentin Wallezd3970de2015-05-14 11:07:48 -040040#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
41{ \
42 GLubyte pixel[4]; \
43 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
44 EXPECT_GL_NO_ERROR(); \
45 EXPECT_EQ((r), pixel[0]); \
46 EXPECT_EQ((g), pixel[1]); \
47 EXPECT_EQ((b), pixel[2]); \
48 EXPECT_EQ((a), pixel[3]); \
49}
50
51#define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
52{ \
53 GLubyte pixel[4]; \
54 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
55 EXPECT_GL_NO_ERROR(); \
56 EXPECT_NEAR((r), pixel[0], abs_error); \
57 EXPECT_NEAR((g), pixel[1], abs_error); \
58 EXPECT_NEAR((b), pixel[2], abs_error); \
59 EXPECT_NEAR((a), pixel[3], abs_error); \
60}
61
62class EGLWindow;
63class OSWindow;
64
65class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters>
66{
67 protected:
68 ANGLETest();
69 ~ANGLETest();
70
71 public:
72 static bool InitTestWindow();
73 static bool DestroyTestWindow();
Corentin Wallezd3970de2015-05-14 11:07:48 -040074 static void SetWindowVisible(bool isVisible);
Cooper Partind7561452015-09-10 10:23:29 -070075 static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -040076
77 protected:
78 virtual void SetUp();
79 virtual void TearDown();
80
81 virtual void swapBuffers();
82
83 static void drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale = 1.0f);
84 static GLuint compileShader(GLenum type, const std::string &source);
85 static bool extensionEnabled(const std::string &extName);
Geoff Lang63046e22015-07-21 12:43:50 -040086 static bool eglClientExtensionEnabled(const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -040087
88 void setWindowWidth(int width);
89 void setWindowHeight(int height);
90 void setConfigRedBits(int bits);
91 void setConfigGreenBits(int bits);
92 void setConfigBlueBits(int bits);
93 void setConfigAlphaBits(int bits);
94 void setConfigDepthBits(int bits);
95 void setConfigStencilBits(int bits);
96 void setMultisampleEnabled(bool enabled);
97
98 int getClientVersion() const;
99
100 EGLWindow *getEGLWindow() const;
101 int getWindowWidth() const;
102 int getWindowHeight() const;
103 bool isMultisampleEnabled() const;
104
105 bool isIntel() const;
106 bool isAMD() const;
107 bool isNVidia() const;
Jamie Madilld55d2832015-10-27 13:59:19 -0400108 // Note: FL9_3 is explicitly *not* considered D3D11.
109 bool isD3D11() const;
Jamie Madill9fc36822015-11-18 13:08:07 -0500110 bool isD3D11_FL93() const;
111 // Is a D3D9-class renderer.
112 bool isD3D9() const;
113 // Is D3D9 or SM9_3 renderer.
114 bool isD3DSM3() const;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400115 EGLint getPlatformRenderer() const;
116
117 private:
118 bool createEGLContext();
119 bool destroyEGLContext();
120
121 EGLWindow *mEGLWindow;
Corentin Wallezf9ac8fe2015-07-23 13:40:15 -0400122 int mWidth;
123 int mHeight;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400124
125 static OSWindow *mOSWindow;
126};
127
128class ANGLETestEnvironment : public testing::Environment
129{
130 public:
131 virtual void SetUp();
132 virtual void TearDown();
133};
134
135#endif // ANGLE_TESTS_ANGLE_TEST_H_