blob: 675d556f7df97713106fcf83f5d381d4731f940a [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
Geoff Lang63046e22015-07-21 12:43:50 -040010#define GL_GLEXT_PROTOTYPES
11#define EGL_EGLEXT_PROTOTYPES
12
Corentin Wallezd3970de2015-05-14 11:07:48 -040013#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
30#define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError())
31#define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS)
32
Corentin Wallez322653b2015-06-17 18:33:56 +020033#define ASSERT_GLENUM_EQ(expected, actual) ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
34#define EXPECT_GLENUM_EQ(expected, actual) EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
35
Corentin Wallezd3970de2015-05-14 11:07:48 -040036#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
37{ \
38 GLubyte pixel[4]; \
39 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
40 EXPECT_GL_NO_ERROR(); \
41 EXPECT_EQ((r), pixel[0]); \
42 EXPECT_EQ((g), pixel[1]); \
43 EXPECT_EQ((b), pixel[2]); \
44 EXPECT_EQ((a), pixel[3]); \
45}
46
47#define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
48{ \
49 GLubyte pixel[4]; \
50 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
51 EXPECT_GL_NO_ERROR(); \
52 EXPECT_NEAR((r), pixel[0], abs_error); \
53 EXPECT_NEAR((g), pixel[1], abs_error); \
54 EXPECT_NEAR((b), pixel[2], abs_error); \
55 EXPECT_NEAR((a), pixel[3], abs_error); \
56}
57
58class EGLWindow;
59class OSWindow;
60
61class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters>
62{
63 protected:
64 ANGLETest();
65 ~ANGLETest();
66
67 public:
68 static bool InitTestWindow();
69 static bool DestroyTestWindow();
70 static bool ResizeWindow(int width, int height);
71 static void SetWindowVisible(bool isVisible);
72
73 protected:
74 virtual void SetUp();
75 virtual void TearDown();
76
77 virtual void swapBuffers();
78
79 static void drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale = 1.0f);
80 static GLuint compileShader(GLenum type, const std::string &source);
81 static bool extensionEnabled(const std::string &extName);
Geoff Lang63046e22015-07-21 12:43:50 -040082 static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
83 static bool eglClientExtensionEnabled(const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -040084
85 void setWindowWidth(int width);
86 void setWindowHeight(int height);
87 void setConfigRedBits(int bits);
88 void setConfigGreenBits(int bits);
89 void setConfigBlueBits(int bits);
90 void setConfigAlphaBits(int bits);
91 void setConfigDepthBits(int bits);
92 void setConfigStencilBits(int bits);
93 void setMultisampleEnabled(bool enabled);
94
95 int getClientVersion() const;
96
97 EGLWindow *getEGLWindow() const;
98 int getWindowWidth() const;
99 int getWindowHeight() const;
100 bool isMultisampleEnabled() const;
101
102 bool isIntel() const;
103 bool isAMD() const;
104 bool isNVidia() const;
105 EGLint getPlatformRenderer() const;
106
107 private:
108 bool createEGLContext();
109 bool destroyEGLContext();
110
111 EGLWindow *mEGLWindow;
Corentin Wallezf3357ee2015-07-22 14:10:19 -0400112 size_t mWidth;
113 size_t mHeight;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400114
115 static OSWindow *mOSWindow;
116};
117
118class ANGLETestEnvironment : public testing::Environment
119{
120 public:
121 virtual void SetUp();
122 virtual void TearDown();
123};
124
125#endif // ANGLE_TESTS_ANGLE_TEST_H_