OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/gl/gl_gl_api_implementation.h" |
| 9 #include "ui/gl/gl_implementation.h" |
| 10 #include "ui/gl/gl_switches.h" |
| 11 |
| 12 namespace gfx { |
| 13 |
| 14 class GLApiTest : public testing::Test { |
| 15 public: |
| 16 void SetUp() override { |
| 17 fake_extension_string_ = ""; |
| 18 num_fake_extension_strings_ = 0; |
| 19 fake_extension_strings_ = nullptr; |
| 20 |
| 21 driver_.reset(new DriverGL()); |
| 22 api_.reset(new RealGLApi()); |
| 23 |
| 24 driver_->fn.glGetStringFn = &FakeGetString; |
| 25 driver_->fn.glGetStringiFn = &FakeGetStringi; |
| 26 driver_->fn.glGetIntegervFn = &FakeGetIntegervFn; |
| 27 } |
| 28 |
| 29 void TearDown() override { |
| 30 api_.reset(nullptr); |
| 31 driver_.reset(nullptr); |
| 32 |
| 33 SetGLImplementation(kGLImplementationNone); |
| 34 fake_extension_string_ = ""; |
| 35 num_fake_extension_strings_ = 0; |
| 36 fake_extension_strings_ = nullptr; |
| 37 } |
| 38 |
| 39 void InitializeAPI(base::CommandLine* command_line) { |
| 40 api_.reset(new RealGLApi()); |
| 41 if (command_line) |
| 42 api_->InitializeWithCommandLine(driver_.get(), command_line); |
| 43 else |
| 44 api_->Initialize(driver_.get()); |
| 45 } |
| 46 |
| 47 void SetFakeExtensionString(const char* fake_string) { |
| 48 SetGLImplementation(kGLImplementationDesktopGL); |
| 49 fake_extension_string_ = fake_string; |
| 50 } |
| 51 |
| 52 void SetFakeExtensionStrings(const char** fake_strings, uint32_t count) { |
| 53 SetGLImplementation(kGLImplementationDesktopGLCoreProfile); |
| 54 num_fake_extension_strings_ = count; |
| 55 fake_extension_strings_ = fake_strings; |
| 56 } |
| 57 |
| 58 static const GLubyte* GL_BINDING_CALL FakeGetString(GLenum name) { |
| 59 return reinterpret_cast<const GLubyte*>(fake_extension_string_); |
| 60 } |
| 61 |
| 62 static void GL_BINDING_CALL FakeGetIntegervFn(GLenum pname, GLint* params) { |
| 63 *params = num_fake_extension_strings_; |
| 64 } |
| 65 |
| 66 static const GLubyte* GL_BINDING_CALL FakeGetStringi(GLenum name, |
| 67 GLuint index) { |
| 68 return (index < num_fake_extension_strings_) ? |
| 69 reinterpret_cast<const GLubyte*>(fake_extension_strings_[index]) : |
| 70 nullptr; |
| 71 } |
| 72 |
| 73 const char* GetExtensions() { |
| 74 return reinterpret_cast<const char*>(api_->glGetStringFn(GL_EXTENSIONS)); |
| 75 } |
| 76 |
| 77 uint32_t GetNumExtensions() { |
| 78 GLint num_extensions = 0; |
| 79 api_->glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); |
| 80 return static_cast<uint32_t>(num_extensions); |
| 81 } |
| 82 |
| 83 const char* GetExtensioni(uint32_t index) { |
| 84 return reinterpret_cast<const char*>(api_->glGetStringiFn(GL_EXTENSIONS, |
| 85 index)); |
| 86 } |
| 87 |
| 88 protected: |
| 89 static const char* fake_extension_string_; |
| 90 |
| 91 static uint32_t num_fake_extension_strings_; |
| 92 static const char** fake_extension_strings_; |
| 93 |
| 94 scoped_ptr<DriverGL> driver_; |
| 95 scoped_ptr<RealGLApi> api_; |
| 96 }; |
| 97 |
| 98 const char* GLApiTest::fake_extension_string_ = ""; |
| 99 |
| 100 uint32_t GLApiTest::num_fake_extension_strings_ = 0; |
| 101 const char** GLApiTest::fake_extension_strings_ = nullptr; |
| 102 |
| 103 TEST_F(GLApiTest, DisabledExtensionStringTest) { |
| 104 static const char* kFakeExtensions = "GL_EXT_1 GL_EXT_2 GL_EXT_3 GL_EXT_4"; |
| 105 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; |
| 106 static const char* kFilteredExtensions = "GL_EXT_3 GL_EXT_4"; |
| 107 |
| 108 SetFakeExtensionString(kFakeExtensions); |
| 109 InitializeAPI(nullptr); |
| 110 |
| 111 EXPECT_STREQ(kFakeExtensions, GetExtensions()); |
| 112 |
| 113 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 114 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, |
| 115 kFakeDisabledExtensions); |
| 116 InitializeAPI(&command_line); |
| 117 |
| 118 EXPECT_STREQ(kFilteredExtensions, GetExtensions()); |
| 119 } |
| 120 |
| 121 TEST_F(GLApiTest, DisabledExtensionStringIndexTest) { |
| 122 static const char* kFakeExtensions[] = { |
| 123 "GL_EXT_1", |
| 124 "GL_EXT_2", |
| 125 "GL_EXT_3", |
| 126 "GL_EXT_4" |
| 127 }; |
| 128 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; |
| 129 static const char* kFilteredExtensions[] = { |
| 130 "GL_EXT_3", |
| 131 "GL_EXT_4" |
| 132 }; |
| 133 |
| 134 SetFakeExtensionStrings(kFakeExtensions, arraysize(kFakeExtensions)); |
| 135 InitializeAPI(nullptr); |
| 136 |
| 137 EXPECT_EQ(arraysize(kFakeExtensions), GetNumExtensions()); |
| 138 for (uint32_t i = 0; i < arraysize(kFakeExtensions); ++i) { |
| 139 EXPECT_STREQ(kFakeExtensions[i], GetExtensioni(i)); |
| 140 } |
| 141 |
| 142 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 143 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, |
| 144 kFakeDisabledExtensions); |
| 145 InitializeAPI(&command_line); |
| 146 |
| 147 EXPECT_EQ(arraysize(kFilteredExtensions), GetNumExtensions()); |
| 148 for (uint32_t i = 0; i < arraysize(kFilteredExtensions); ++i) { |
| 149 EXPECT_STREQ(kFilteredExtensions[i], GetExtensioni(i)); |
| 150 } |
| 151 } |
| 152 |
| 153 } // namespace gpu |
OLD | NEW |