Home | History | Annotate | Download | only in angle_tests
      1 //
      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 "angle_gl.h"
     15 #include <algorithm>
     16 
     17 #include "shared_utils.h"
     18 #include "shader_utils.h"
     19 
     20 #define EXPECT_GL_ERROR(err) EXPECT_EQ((err), glGetError())
     21 #define EXPECT_GL_NO_ERROR() EXPECT_GL_ERROR(GL_NO_ERROR)
     22 
     23 #define ASSERT_GL_ERROR(err) ASSERT_EQ((err), glGetError())
     24 #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(); \
     31     EXPECT_EQ((r), pixel[0]); \
     32     EXPECT_EQ((g), pixel[1]); \
     33     EXPECT_EQ((b), pixel[2]); \
     34     EXPECT_EQ((a), pixel[3]); \
     35 }
     36 
     37 class EGLWindow;
     38 class OSWindow;
     39 
     40 class ANGLETest : public testing::Test
     41 {
     42   protected:
     43     ANGLETest();
     44 
     45   public:
     46     static bool InitTestWindow();
     47     static bool DestroyTestWindow();
     48     static bool ResizeWindow(int width, int height);
     49 
     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);
     57     static GLuint compileShader(GLenum type, const std::string &source);
     58     static bool extensionEnabled(const std::string &extName);
     59 
     60     void setClientVersion(int clientVersion);
     61     void setWindowWidth(int width);
     62     void setWindowHeight(int height);
     63     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);
     69     void setMultisampleEnabled(bool enabled);
     70 
     71     int getClientVersion() const;
     72     int getWindowWidth() const;
     73     int getWindowHeight() const;
     74     bool isMultisampleEnabled() const;
     75 
     76   private:
     77     bool createEGLContext();
     78     bool destroyEGLContext();
     79 
     80     EGLWindow *mEGLWindow;
     81 
     82     static OSWindow *mOSWindow;
     83 };
     84 
     85 class ANGLETestEnvironment : public testing::Environment
     86 {
     87   public:
     88     virtual void SetUp();
     89     virtual void TearDown();
     90 };
     91 
     92 #endif  // ANGLE_TESTS_ANGLE_TEST_H_
     93