blob: 7193c096a5092e3a331459a28bd0de711fa86166 [file] [log] [blame]
Geoff Lang8a079e52013-10-18 16:13:33 -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
12#define GL_GLEXT_PROTOTYPES
13
14#include <GLES3/gl3.h>
15#include <GLES3/gl3ext.h>
16#include <GLES2/gl2.h>
17#include <GLES2/gl2ext.h>
18#include <EGL/egl.h>
19#include <EGL/eglext.h>
Jamie Madill4b8c3eb2014-01-14 16:09:43 -050020#include <algorithm>
Geoff Lang8a079e52013-10-18 16:13:33 -040021
Geoff Lang496123f2014-02-12 11:33:51 -050022#define EXPECT_GL_ERROR(err) EXPECT_EQ((err), glGetError())
Geoff Lang8a079e52013-10-18 16:13:33 -040023#define EXPECT_GL_NO_ERROR() EXPECT_GL_ERROR(GL_NO_ERROR)
24
Geoff Lang496123f2014-02-12 11:33:51 -050025#define ASSERT_GL_ERROR(err) ASSERT_EQ((err), glGetError())
Geoff Lang8a079e52013-10-18 16:13:33 -040026#define ASSERT_GL_NO_ERROR() ASSERT_GL_ERROR(GL_NO_ERROR)
27
28#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
29{ \
30 GLubyte pixel[4]; \
31 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
32 EXPECT_GL_NO_ERROR(); \
Geoff Lang496123f2014-02-12 11:33:51 -050033 EXPECT_EQ((r), pixel[0]); \
34 EXPECT_EQ((g), pixel[1]); \
35 EXPECT_EQ((b), pixel[2]); \
36 EXPECT_EQ((a), pixel[3]); \
Geoff Lang8a079e52013-10-18 16:13:33 -040037}
38
39#define SHADER_SOURCE(...) #__VA_ARGS__
40
41class ANGLETest : public testing::Test
42{
43 protected:
44 ANGLETest();
45
46 public:
47 static bool InitTestWindow();
48 static bool DestroyTestWindow();
49 static bool ReizeWindow(int width, int height);
50
51 protected:
52 virtual void SetUp();
53 virtual void TearDown();
54
55 virtual void swapBuffers();
56
57 static void drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth);
Geoff Langefc551f2013-10-31 10:20:28 -040058 static GLuint compileShader(GLenum type, const std::string &source);
Geoff Lang8a079e52013-10-18 16:13:33 -040059 static GLuint compileProgram(const std::string &vsSource, const std::string &fsSource);
60 static bool extensionEnabled(const std::string &extName);
61
62 void setClientVersion(int clientVersion);
63 void setWindowWidth(int width);
64 void setWindowHeight(int height);
Geoff Langefc551f2013-10-31 10:20:28 -040065 void setConfigRedBits(int bits);
66 void setConfigGreenBits(int bits);
67 void setConfigBlueBits(int bits);
68 void setConfigAlphaBits(int bits);
69 void setConfigDepthBits(int bits);
70 void setConfigStencilBits(int bits);
Geoff Lang8a079e52013-10-18 16:13:33 -040071 void setMultisampleEnabled(bool enabled);
72
73 int getClientVersion() const;
74 int getWindowWidth() const;
75 int getWindowHeight() const;
Geoff Langefc551f2013-10-31 10:20:28 -040076 int getConfigRedBits() const;
77 int getConfigGreenBits() const;
78 int getConfigBlueBits() const;
79 int getConfigAlphaBits() const;
80 int getConfigDepthBits() const;
81 int getConfigStencilBits() const;
82 bool isMultisampleEnabled() const;
Geoff Lang8a079e52013-10-18 16:13:33 -040083
84 private:
85 bool createEGLContext();
86 bool destroyEGLContext();
87
88 int mClientVersion;
89 int mWidth;
90 int mHeight;
91 int mRedBits;
92 int mGreenBits;
93 int mBlueBits;
94 int mAlphaBits;
95 int mDepthBits;
96 int mStencilBits;
97 bool mMultisample;
98
99 EGLConfig mConfig;
100 EGLSurface mSurface;
101 EGLContext mContext;
102
103 static EGLDisplay mDisplay;
104 static EGLNativeWindowType mNativeWindow;
105 static EGLNativeDisplayType mNativeDisplay;
106};
107
Geoff Langbb134672013-10-23 13:06:46 -0400108class ANGLETestEnvironment : public testing::Environment
109{
110 public:
111 virtual void SetUp();
112 virtual void TearDown();
113};
114
Geoff Lang8a079e52013-10-18 16:13:33 -0400115#endif // ANGLE_TESTS_ANGLE_TEST_H_