Update UnusedResources lint suppressions.
[chromium-blink-merge.git] / ui / gl / gl_api_unittest.cc
blob9b15bec443e97ea48fdb27f19ac16f14d52df41e
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.
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"
12 namespace gfx {
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;
21 driver_.reset(new DriverGL());
22 api_.reset(new RealGLApi());
24 driver_->fn.glGetStringFn = &FakeGetString;
25 driver_->fn.glGetStringiFn = &FakeGetStringi;
26 driver_->fn.glGetIntegervFn = &FakeGetIntegervFn;
29 void TearDown() override {
30 api_.reset(nullptr);
31 driver_.reset(nullptr);
33 SetGLImplementation(kGLImplementationNone);
34 fake_extension_string_ = "";
35 num_fake_extension_strings_ = 0;
36 fake_extension_strings_ = nullptr;
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 api_->InitializeWithContext();
48 void SetFakeExtensionString(const char* fake_string) {
49 SetGLImplementation(kGLImplementationDesktopGL);
50 fake_extension_string_ = fake_string;
53 void SetFakeExtensionStrings(const char** fake_strings, uint32_t count) {
54 SetGLImplementation(kGLImplementationDesktopGLCoreProfile);
55 num_fake_extension_strings_ = count;
56 fake_extension_strings_ = fake_strings;
59 static const GLubyte* GL_BINDING_CALL FakeGetString(GLenum name) {
60 return reinterpret_cast<const GLubyte*>(fake_extension_string_);
63 static void GL_BINDING_CALL FakeGetIntegervFn(GLenum pname, GLint* params) {
64 *params = num_fake_extension_strings_;
67 static const GLubyte* GL_BINDING_CALL FakeGetStringi(GLenum name,
68 GLuint index) {
69 return (index < num_fake_extension_strings_) ?
70 reinterpret_cast<const GLubyte*>(fake_extension_strings_[index]) :
71 nullptr;
74 const char* GetExtensions() {
75 return reinterpret_cast<const char*>(api_->glGetStringFn(GL_EXTENSIONS));
78 uint32_t GetNumExtensions() {
79 GLint num_extensions = 0;
80 api_->glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions);
81 return static_cast<uint32_t>(num_extensions);
84 const char* GetExtensioni(uint32_t index) {
85 return reinterpret_cast<const char*>(api_->glGetStringiFn(GL_EXTENSIONS,
86 index));
89 protected:
90 static const char* fake_extension_string_;
92 static uint32_t num_fake_extension_strings_;
93 static const char** fake_extension_strings_;
95 scoped_ptr<DriverGL> driver_;
96 scoped_ptr<RealGLApi> api_;
99 const char* GLApiTest::fake_extension_string_ = "";
101 uint32_t GLApiTest::num_fake_extension_strings_ = 0;
102 const char** GLApiTest::fake_extension_strings_ = nullptr;
104 TEST_F(GLApiTest, DisabledExtensionStringTest) {
105 static const char* kFakeExtensions = "GL_EXT_1 GL_EXT_2 GL_EXT_3 GL_EXT_4";
106 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE";
107 static const char* kFilteredExtensions = "GL_EXT_3 GL_EXT_4";
109 SetFakeExtensionString(kFakeExtensions);
110 InitializeAPI(nullptr);
112 EXPECT_STREQ(kFakeExtensions, GetExtensions());
114 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
115 command_line.AppendSwitchASCII(switches::kDisableGLExtensions,
116 kFakeDisabledExtensions);
117 InitializeAPI(&command_line);
119 EXPECT_STREQ(kFilteredExtensions, GetExtensions());
122 TEST_F(GLApiTest, DisabledExtensionStringIndexTest) {
123 static const char* kFakeExtensions[] = {
124 "GL_EXT_1",
125 "GL_EXT_2",
126 "GL_EXT_3",
127 "GL_EXT_4"
129 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE";
130 static const char* kFilteredExtensions[] = {
131 "GL_EXT_3",
132 "GL_EXT_4"
135 SetFakeExtensionStrings(kFakeExtensions, arraysize(kFakeExtensions));
136 InitializeAPI(nullptr);
138 EXPECT_EQ(arraysize(kFakeExtensions), GetNumExtensions());
139 for (uint32_t i = 0; i < arraysize(kFakeExtensions); ++i) {
140 EXPECT_STREQ(kFakeExtensions[i], GetExtensioni(i));
143 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
144 command_line.AppendSwitchASCII(switches::kDisableGLExtensions,
145 kFakeDisabledExtensions);
146 InitializeAPI(&command_line);
148 EXPECT_EQ(arraysize(kFilteredExtensions), GetNumExtensions());
149 for (uint32_t i = 0; i < arraysize(kFilteredExtensions); ++i) {
150 EXPECT_STREQ(kFilteredExtensions[i], GetExtensioni(i));
154 } // namespace gfx