blob: f84ce923ae7c4d44fce23ead71d0a1fb071bc0e3 [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();
Corentin Wallezd3970de2015-05-14 11:07:48 -040070 static void SetWindowVisible(bool isVisible);
71
72 protected:
73 virtual void SetUp();
74 virtual void TearDown();
75
76 virtual void swapBuffers();
77
78 static void drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale = 1.0f);
79 static GLuint compileShader(GLenum type, const std::string &source);
80 static bool extensionEnabled(const std::string &extName);
Geoff Lang63046e22015-07-21 12:43:50 -040081 static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
82 static bool eglClientExtensionEnabled(const std::string &extName);
Corentin Wallezd3970de2015-05-14 11:07:48 -040083
84 void setWindowWidth(int width);
85 void setWindowHeight(int height);
86 void setConfigRedBits(int bits);
87 void setConfigGreenBits(int bits);
88 void setConfigBlueBits(int bits);
89 void setConfigAlphaBits(int bits);
90 void setConfigDepthBits(int bits);
91 void setConfigStencilBits(int bits);
92 void setMultisampleEnabled(bool enabled);
93
94 int getClientVersion() const;
95
96 EGLWindow *getEGLWindow() const;
97 int getWindowWidth() const;
98 int getWindowHeight() const;
99 bool isMultisampleEnabled() const;
100
101 bool isIntel() const;
102 bool isAMD() const;
103 bool isNVidia() const;
104 EGLint getPlatformRenderer() const;
105
106 private:
107 bool createEGLContext();
108 bool destroyEGLContext();
109
110 EGLWindow *mEGLWindow;
Corentin Wallezf9ac8fe2015-07-23 13:40:15 -0400111 int mWidth;
112 int mHeight;
Corentin Wallezd3970de2015-05-14 11:07:48 -0400113
114 static OSWindow *mOSWindow;
115};
116
117class ANGLETestEnvironment : public testing::Environment
118{
119 public:
120 virtual void SetUp();
121 virtual void TearDown();
122};
123
124#endif // ANGLE_TESTS_ANGLE_TEST_H_