Chromium Code Reviews| Index: gpu/command_buffer/tests/gl_chromium_path_rendering_unittest.cc |
| diff --git a/gpu/command_buffer/tests/gl_chromium_path_rendering_unittest.cc b/gpu/command_buffer/tests/gl_chromium_path_rendering_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..86c35b560b4d0f4a19bc7e084406b913c57d177a |
| --- /dev/null |
| +++ b/gpu/command_buffer/tests/gl_chromium_path_rendering_unittest.cc |
| @@ -0,0 +1,108 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <GLES2/gl2.h> |
| +#include <GLES2/gl2ext.h> |
| +#include <GLES2/gl2extchromium.h> |
| + |
| +#include "gpu/command_buffer/tests/gl_manager.h" |
| +#include "gpu/command_buffer/tests/gl_test_utils.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace gpu { |
| + |
| +class CHROMIUMPathRenderingTest : public testing::Test { |
| +public: |
| + static const GLsizei kResolution = 100; |
| + |
| +protected: |
| + virtual void SetUp() { |
| + GLManager::Options options; |
| + options.size = gfx::Size(kResolution, kResolution); |
| + gl_.Initialize(options); |
| + } |
| + |
| + virtual void TearDown() { |
| + gl_.Destroy(); |
| + } |
| + |
| + template<typename T> |
| + void AssertEqualMatrix(const GLfloat* expected, const T* actual) { |
| + for (size_t i = 0; i < 16; ++i) { |
| + ASSERT_EQ(static_cast<T>(expected[i]), actual[i]); |
|
vmiura
2014/04/15 18:02:43
nit: EXPECT_EQ instead of ASSERT_EQ?
Kimmo Kinnunen
2014/04/23 12:26:55
Done.
|
| + } |
| + } |
| + GLManager gl_; |
| +}; |
| + |
| +TEST_F(CHROMIUMPathRenderingTest, TestMatrix) { |
| + if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { |
| + return; |
| + } |
| + GLfloat identity_matrix[16] = { |
| + 1.0f, 0.0f, 0.0f, 0.0f, |
| + 0.0f, 1.0f, 0.0f, 0.0f, |
| + 0.0f, 0.0f, 1.0f, 0.0f, |
| + 0.0f, 0.0f, 0.0f, 1.0f |
| + }; |
| + GLfloat seq_matrix[16] = { |
| + 0.0f, 1.0f, 2.0f, 3.0f, |
| + 4.0f, 5.0f, 6.0f, 7.0f, |
| + 8.0f, 9.0f, 10.0f, 11.0f, |
| + 12.0f, 13.0f, 14.0f, 15.0f |
| + }; |
| + GLenum matrix_modes[] = { |
| + GL_MODELVIEW_CHROMIUM, GL_PROJECTION_CHROMIUM |
| + }; |
| + GLenum get_matrix_modes[] = { |
| + GL_MODELVIEW_MATRIX_CHROMIUM, GL_PROJECTION_MATRIX_CHROMIUM |
| + }; |
| + |
| + for (size_t i = 0; i < arraysize(matrix_modes); ++i) { |
| + GLfloat mf[16]; |
| + GLint mi[16]; |
| + memset(mf, 0, sizeof(mf)); |
| + memset(mi, 0, sizeof(mi)); |
| + glGetFloatv(get_matrix_modes[i], mf); |
| + glMatrixLoadIdentityCHROMIUM(matrix_modes[i]); |
| + glGetFloatv(get_matrix_modes[i], mf); |
| + glGetIntegerv(get_matrix_modes[i], mi); |
| + AssertEqualMatrix(identity_matrix, mf); |
| + AssertEqualMatrix(identity_matrix, mi); |
| + |
| + memset(mf, 0, sizeof(mf)); |
| + memset(mi, 0, sizeof(mi)); |
| + glMatrixLoadfCHROMIUM(matrix_modes[i], seq_matrix); |
| + glGetFloatv(get_matrix_modes[i], mf); |
| + glGetIntegerv(get_matrix_modes[i], mi); |
| + AssertEqualMatrix(seq_matrix, mf); |
| + AssertEqualMatrix(seq_matrix, mi); |
| + EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| + } |
| +} |
| + |
| +TEST_F(CHROMIUMPathRenderingTest, TestMatrixErrors) { |
| + if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) { |
| + return; |
| + } |
| + GLfloat mf[16]; |
| + memset(mf, 0, sizeof(mf)); |
| + |
| + // This should fail. |
| + glMatrixLoadfCHROMIUM(GL_MODELVIEW_CHROMIUM - 1, mf); |
| + EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); |
| + |
| + glMatrixLoadfCHROMIUM(GL_MODELVIEW_CHROMIUM, mf); |
| + EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| + |
| + // This should fail. |
| + glMatrixLoadIdentityCHROMIUM(GL_PROJECTION_CHROMIUM + 1); |
| + EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); |
| + |
| + glMatrixLoadIdentityCHROMIUM(GL_PROJECTION_CHROMIUM); |
| + EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| +} |
| + |
| +} // namespace gpu |