blob: 95de91a285880ae29e81a1fa1ae5cfd80eb81988 [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();
67 static bool ResizeWindow(int width, int height);
68 static void SetWindowVisible(bool isVisible);
69
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);
79
80 void setWindowWidth(int width);
81 void setWindowHeight(int height);
82 void setConfigRedBits(int bits);
83 void setConfigGreenBits(int bits);
84 void setConfigBlueBits(int bits);
85 void setConfigAlphaBits(int bits);
86 void setConfigDepthBits(int bits);
87 void setConfigStencilBits(int bits);
88 void setMultisampleEnabled(bool enabled);
89
90 int getClientVersion() const;
91
92 EGLWindow *getEGLWindow() const;
93 int getWindowWidth() const;
94 int getWindowHeight() const;
95 bool isMultisampleEnabled() const;
96
97 bool isIntel() const;
98 bool isAMD() const;
99 bool isNVidia() const;
100 EGLint getPlatformRenderer() const;
101
102 private:
103 bool createEGLContext();
104 bool destroyEGLContext();
105
106 EGLWindow *mEGLWindow;
107
108 static OSWindow *mOSWindow;
109};
110
111class ANGLETestEnvironment : public testing::Environment
112{
113 public:
114 virtual void SetUp();
115 virtual void TearDown();
116};
117
118#endif // ANGLE_TESTS_ANGLE_TEST_H_