blob: c3de55cc5ba61c1a9228adf67aad8f6f1b957a30 [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
Jamie Madillf51639a2014-06-25 16:04:57 -040014#include "angle_gl.h"
Jamie Madill4b8c3eb2014-01-14 16:09:43 -050015#include <algorithm>
Geoff Lang8a079e52013-10-18 16:13:33 -040016
Jamie Madill5704d6e2014-08-26 13:16:38 -040017#include "shared_utils.h"
Jamie Madill5599c8f2014-08-26 13:16:39 -040018#include "shader_utils.h"
Jamie Madill5704d6e2014-08-26 13:16:38 -040019
Geoff Lang496123f2014-02-12 11:33:51 -050020#define EXPECT_GL_ERROR(err) EXPECT_EQ((err), glGetError())
Geoff Lang8a079e52013-10-18 16:13:33 -040021#define EXPECT_GL_NO_ERROR() EXPECT_GL_ERROR(GL_NO_ERROR)
22
Geoff Lang496123f2014-02-12 11:33:51 -050023#define ASSERT_GL_ERROR(err) ASSERT_EQ((err), glGetError())
Geoff Lang8a079e52013-10-18 16:13:33 -040024#define ASSERT_GL_NO_ERROR() ASSERT_GL_ERROR(GL_NO_ERROR)
25
26#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
27{ \
28 GLubyte pixel[4]; \
29 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \
30 EXPECT_GL_NO_ERROR(); \
Geoff Lang496123f2014-02-12 11:33:51 -050031 EXPECT_EQ((r), pixel[0]); \
32 EXPECT_EQ((g), pixel[1]); \
33 EXPECT_EQ((b), pixel[2]); \
34 EXPECT_EQ((a), pixel[3]); \
Geoff Lang8a079e52013-10-18 16:13:33 -040035}
36
Jamie Madill62af5462014-08-26 13:16:37 -040037class EGLWindow;
Jamie Madill8add0eb2014-08-26 13:16:35 -040038class OSWindow;
39
Geoff Lang8a079e52013-10-18 16:13:33 -040040class ANGLETest : public testing::Test
41{
42 protected:
43 ANGLETest();
44
45 public:
46 static bool InitTestWindow();
47 static bool DestroyTestWindow();
Jamie Madill39e7bc02014-08-21 10:04:07 -040048 static bool ResizeWindow(int width, int height);
Geoff Lang8a079e52013-10-18 16:13:33 -040049
50 protected:
51 virtual void SetUp();
52 virtual void TearDown();
53
54 virtual void swapBuffers();
55
56 static void drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth);
Geoff Langefc551f2013-10-31 10:20:28 -040057 static GLuint compileShader(GLenum type, const std::string &source);
Geoff Lang8a079e52013-10-18 16:13:33 -040058 static bool extensionEnabled(const std::string &extName);
59
60 void setClientVersion(int clientVersion);
61 void setWindowWidth(int width);
62 void setWindowHeight(int height);
Geoff Langefc551f2013-10-31 10:20:28 -040063 void setConfigRedBits(int bits);
64 void setConfigGreenBits(int bits);
65 void setConfigBlueBits(int bits);
66 void setConfigAlphaBits(int bits);
67 void setConfigDepthBits(int bits);
68 void setConfigStencilBits(int bits);
Geoff Lang8a079e52013-10-18 16:13:33 -040069 void setMultisampleEnabled(bool enabled);
70
71 int getClientVersion() const;
72 int getWindowWidth() const;
73 int getWindowHeight() const;
Geoff Langefc551f2013-10-31 10:20:28 -040074 bool isMultisampleEnabled() const;
Geoff Lang8a079e52013-10-18 16:13:33 -040075
76 private:
77 bool createEGLContext();
78 bool destroyEGLContext();
79
Jamie Madill62af5462014-08-26 13:16:37 -040080 EGLWindow *mEGLWindow;
Geoff Lang8a079e52013-10-18 16:13:33 -040081
Jamie Madill8add0eb2014-08-26 13:16:35 -040082 static OSWindow *mOSWindow;
Geoff Lang8a079e52013-10-18 16:13:33 -040083};
84
Geoff Langbb134672013-10-23 13:06:46 -040085class ANGLETestEnvironment : public testing::Environment
86{
87 public:
88 virtual void SetUp();
89 virtual void TearDown();
90};
91
Geoff Lang8a079e52013-10-18 16:13:33 -040092#endif // ANGLE_TESTS_ANGLE_TEST_H_