blob: d653615c2934f0cefb7134eadd8a0a5a83256e21 [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//
6
7#ifndef ANGLE_TESTS_ANGLE_TEST_H_
8#define ANGLE_TESTS_ANGLE_TEST_H_
9
10#include <gtest/gtest.h>
11#include <algorithm>
12
13#include "angle_gl.h"
14#include "angle_test_configs.h"
15#include "common/angleutils.h"
16#include "shader_utils.h"
17
Corentin Wallez322653b2015-06-17 18:33:56 +020018#define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError())
Corentin Wallezd3970de2015-05-14 11:07:48 -040019#define EXPECT_GL_NO_ERROR() EXPECT_GL_ERROR(GL_NO_ERROR)
20
Corentin Wallez322653b2015-06-17 18:33:56 +020021#define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError())
Corentin Wallezd3970de2015-05-14 11:07:48 -040022#define ASSERT_GL_NO_ERROR() ASSERT_GL_ERROR(GL_NO_ERROR)
23
24#define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError())
25#define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS)
26
27#define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError())
28#define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS)
29
Corentin Wallez322653b2015-06-17 18:33:56 +020030#define ASSERT_GLENUM_EQ(expected, actual) ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
31#define EXPECT_GLENUM_EQ(expected, actual) EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
32
Corentin Wallezd3970de2015-05-14 11:07:48 -040033#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
34{ \
35 GLubyte pixel[4]; \
36 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
37 EXPECT_GL_NO_ERROR(); \
38 EXPECT_EQ((r), pixel[0]); \
39 EXPECT_EQ((g), pixel[1]); \
40 EXPECT_EQ((b), pixel[2]); \
41 EXPECT_EQ((a), pixel[3]); \
42}
43
44#define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
45{ \
46 GLubyte pixel[4]; \
47 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
48 EXPECT_GL_NO_ERROR(); \
49 EXPECT_NEAR((r), pixel[0], abs_error); \
50 EXPECT_NEAR((g), pixel[1], abs_error); \
51 EXPECT_NEAR((b), pixel[2], abs_error); \
52 EXPECT_NEAR((a), pixel[3], abs_error); \
53}
54
55class EGLWindow;
56class OSWindow;
57
58class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters>
59{
60 protected:
61 ANGLETest();
62 ~ANGLETest();
63
64 public:
65 static bool InitTestWindow();
66 static bool DestroyTestWindow();
Corentin Wallezd3970de2015-05-14 11:07:48 -040067 static void SetWindowVisible(bool isVisible);
Cooper Partind7561452015-09-10 10:23:29 -070068 static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -040069
70 protected:
71 virtual void SetUp();
72 virtual void TearDown();
73
74 virtual void swapBuffers();
75
76 static void drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale = 1.0f);
77 static GLuint compileShader(GLenum type, const std::string &source);
78 static bool extensionEnabled(const std::string &extName);
Geoff Lang63046e22015-07-21 12:43:50 -040079 static bool eglClientExtensionEnabled(const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -040080
81 void setWindowWidth(int width);
82 void setWindowHeight(int height);
83 void setConfigRedBits(int bits);
84 void setConfigGreenBits(int bits);
85 void setConfigBlueBits(int bits);
86 void setConfigAlphaBits(int bits);
87 void setConfigDepthBits(int bits);
88 void setConfigStencilBits(int bits);
89 void setMultisampleEnabled(bool enabled);
90
91 int getClientVersion() const;
92
93 EGLWindow *getEGLWindow() const;
94 int getWindowWidth() const;
95 int getWindowHeight() const;
96 bool isMultisampleEnabled() const;
97
98 bool isIntel() const;
99 bool isAMD() const;
100 bool isNVidia() const;
Jamie Madilld55d2832015-10-27 13:59:19 -0400101 // Note: FL9_3 is explicitly *not* considered D3D11.
102 bool isD3D11() const;
Jamie Madill9fc36822015-11-18 13:08:07 -0500103 bool isD3D11_FL93() const;
104 // Is a D3D9-class renderer.
105 bool isD3D9() const;
106 // Is D3D9 or SM9_3 renderer.
107 bool isD3DSM3() const;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400108 EGLint getPlatformRenderer() const;
109
110 private:
111 bool createEGLContext();
112 bool destroyEGLContext();
113
114 EGLWindow *mEGLWindow;
Corentin Wallezf9ac8fe2015-07-23 13:40:15 -0400115 int mWidth;
116 int mHeight;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400117
118 static OSWindow *mOSWindow;
119};
120
121class ANGLETestEnvironment : public testing::Environment
122{
123 public:
124 virtual void SetUp();
125 virtual void TearDown();
126};
127
128#endif // ANGLE_TESTS_ANGLE_TEST_H_