Commit 0dfa807f by Jamie Madill

Tests: Prettify output for EXPECT_PIXEL_EQ.

Previously our output would spam multiple lines by checking equality for each color component. Instead, use a helper struct with a stream operator to clean up the output. This makes it much more legible. New output style: Expected: (0, 255, 0, 255) Actual: angle::MakeGLColor(255, 0, 127, 255) Which is: (255, 0, 127, 255) BUG=angleproject:1290 Change-Id: Ieea018ab6c149a20b5fd74d74c972118b63a4b5e Reviewed-on: https://chromium-review.googlesource.com/323441Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Tryjob-Request: Jamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent f83cbc65
...@@ -12,6 +12,40 @@ ...@@ -12,6 +12,40 @@
#include "OSWindow.h" #include "OSWindow.h"
#include "system_utils.h" #include "system_utils.h"
namespace angle
{
GLColor::GLColor() : R(0), G(0), B(0), A(0)
{
}
GLColor::GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a)
{
}
GLColor ReadColor(GLint x, GLint y)
{
GLColor actual;
glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &actual.R);
EXPECT_GL_NO_ERROR();
return actual;
}
bool operator==(const GLColor &a, const GLColor &b)
{
return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
}
std::ostream &operator<<(std::ostream &ostream, const GLColor &color)
{
ostream << "(" << static_cast<unsigned int>(color.R) << ", "
<< static_cast<unsigned int>(color.G) << ", " << static_cast<unsigned int>(color.B)
<< ", " << static_cast<unsigned int>(color.A) << ")";
return ostream;
}
} // namespace angle
ANGLETest::ANGLETest() ANGLETest::ANGLETest()
: mEGLWindow(nullptr), mWidth(16), mHeight(16), mIgnoreD3D11SDKLayersWarnings(false) : mEGLWindow(nullptr), mWidth(16), mHeight(16), mIgnoreD3D11SDKLayersWarnings(false)
{ {
......
...@@ -19,10 +19,10 @@ ...@@ -19,10 +19,10 @@
#include "shader_utils.h" #include "shader_utils.h"
#define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError()) #define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError())
#define EXPECT_GL_NO_ERROR() EXPECT_GL_ERROR(GL_NO_ERROR) #define EXPECT_GL_NO_ERROR() EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
#define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError()) #define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError())
#define ASSERT_GL_NO_ERROR() ASSERT_GL_ERROR(GL_NO_ERROR) #define ASSERT_GL_NO_ERROR() ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
#define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError()) #define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError())
#define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS) #define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS)
...@@ -39,17 +39,34 @@ ...@@ -39,17 +39,34 @@
#define ASSERT_GLENUM_EQ(expected, actual) ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual)) #define ASSERT_GLENUM_EQ(expected, actual) ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
#define EXPECT_GLENUM_EQ(expected, actual) EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual)) #define EXPECT_GLENUM_EQ(expected, actual) EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \ namespace angle
{ \ {
GLubyte pixel[4]; \ struct GLColor
glReadPixels((x), (y), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); \ {
EXPECT_GL_NO_ERROR(); \ GLColor();
EXPECT_EQ((r), pixel[0]); \ GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
EXPECT_EQ((g), pixel[1]); \
EXPECT_EQ((b), pixel[2]); \ GLubyte R, G, B, A;
EXPECT_EQ((a), pixel[3]); \ };
// Useful to cast any type to GLubyte.
template <typename TR, typename TG, typename TB, typename TA>
GLColor MakeGLColor(TR r, TG g, TB b, TA a)
{
return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b),
static_cast<GLubyte>(a));
} }
bool operator==(const GLColor &a, const GLColor &b);
std::ostream &operator<<(std::ostream &ostream, const GLColor &color);
GLColor ReadColor(GLint x, GLint y);
} // namespace angle
#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
// TODO(jmadill): Figure out how we can use GLColor's nice printing with EXPECT_NEAR.
#define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \ #define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
{ \ { \
GLubyte pixel[4]; \ GLubyte pixel[4]; \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment