diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-08 18:10:22 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-08 18:10:22 +0000 |
commit | 5904806bfc6c3ab2497500f764ed3927c8af7c5a (patch) | |
tree | 9a465fec4034bd42cc68f0a611eaeed99e4455b4 /gpu/command_buffer/tests/gl_test_utils.cc | |
parent | f2c33c65320e1ec409184c8469ace54d9baaa499 (diff) | |
download | chromium_src-5904806bfc6c3ab2497500f764ed3927c8af7c5a.zip chromium_src-5904806bfc6c3ab2497500f764ed3927c8af7c5a.tar.gz chromium_src-5904806bfc6c3ab2497500f764ed3927c8af7c5a.tar.bz2 |
Make unit test to check glCopyTextureCHROMIUM works with deleted programs
TEST=unit tests
BUG=124720
Review URL: https://chromiumcodereview.appspot.com/10317034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135876 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu/command_buffer/tests/gl_test_utils.cc')
-rw-r--r-- | gpu/command_buffer/tests/gl_test_utils.cc | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/gpu/command_buffer/tests/gl_test_utils.cc b/gpu/command_buffer/tests/gl_test_utils.cc index 82e6222..cfbba24 100644 --- a/gpu/command_buffer/tests/gl_test_utils.cc +++ b/gpu/command_buffer/tests/gl_test_utils.cc @@ -7,6 +7,7 @@ #include <stdio.h> #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" bool GLTestHelper::HasExtension(const char* extension) { @@ -83,6 +84,52 @@ GLuint GLTestHelper::LoadProgram( return SetupProgram(vertex_shader, fragment_shader); } +GLuint GLTestHelper::SetupUnitQuad(GLint position_location) { + GLuint vbo = 0; + glGenBuffers(1, &vbo); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + static float vertices[] = { + 1.0f, 1.0f, + -1.0f, 1.0f, + -1.0f, -1.0f, + 1.0f, 1.0f, + -1.0f, -1.0f, + 1.0f, -1.0f, + }; + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + glEnableVertexAttribArray(position_location); + glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, 0, 0); + + return vbo; +} + +bool GLTestHelper::CheckPixels( + GLint x, GLint y, GLsizei width, GLsizei height, GLint tolerance, + uint8* color) { + GLsizei size = width * height * 4; + scoped_array<uint8> pixels(new uint8[size]); + memset(pixels.get(), 123, size); + glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); + bool same = true; + for (GLint yy = 0; yy < height; ++yy) { + for (GLint xx = 0; xx < width; ++xx) { + int offset = ((yy + y) * width + (xx + x)) * 4; + for (int jj = 0; jj < 4; ++jj) { + uint8 actual = pixels[offset + jj]; + uint8 expected = color[jj]; + int diff = actual - expected; + diff = diff < 0 ? -diff: diff; + if (diff > tolerance) { + EXPECT_EQ(expected, actual) << " at " << (xx + x) << ", " << (yy + y) + << " channel " << jj; + same = false; + } + } + } + } + return same; +} + namespace { void Set16BitValue(uint8 dest[2], uint16 value) { @@ -123,6 +170,7 @@ struct BitmapInfoHeader{ bool GLTestHelper::SaveBackbufferAsBMP( const char* filename, int width, int height) { FILE* fp = fopen(filename, "wb"); + EXPECT_TRUE(fp != NULL); glPixelStorei(GL_PACK_ALIGNMENT, 1); int num_pixels = width * height; int size = num_pixels * 4; @@ -162,9 +210,12 @@ bool GLTestHelper::SaveBackbufferAsBMP( fwrite(&bih, sizeof(bih), 1, fp); fwrite(pixels, size, 1, fp); fclose(fp); - return true; } +int GLTestHelper::RunTests(int argc, char** argv) { + testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +} |