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/strings/string_split.h" | |
7 #include "base/strings/string_util.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 #include "ui/gl/gl_gl_api_implementation.h" | |
10 #include "ui/gl/gl_surface.h" | |
no sievers
2015/05/01 21:54:59
nit: gl_surface.h not needed. what about string_ut
David Yen
2015/05/01 22:34:38
Done.
| |
11 #include "ui/gl/gl_switches.h" | |
12 | |
13 namespace gfx { | |
14 | |
15 class GLApiTest : public testing::Test { | |
16 public: | |
17 void SetUp() override { | |
18 g_fake_extension_string = ""; | |
no sievers
2015/05/01 21:55:00
nit: no "g_" prefix here and for other static vari
David Yen
2015/05/01 22:34:38
Done.
| |
19 g_num_fake_extension_strings = 0; | |
20 g_fake_extension_strings = nullptr; | |
21 | |
22 driver_.fn.glGetStringFn = &FakeGetString; | |
23 driver_.fn.glGetStringiFn = &FakeGetStringi; | |
24 driver_.fn.glGetIntegervFn = &FakeGetIntegervFn; | |
25 } | |
26 | |
27 void TearDown() override { | |
28 SetGLImplementation(kGLImplementationNone); | |
29 g_fake_extension_string = ""; | |
30 g_num_fake_extension_strings = 0; | |
31 g_fake_extension_strings = nullptr; | |
32 } | |
33 | |
34 void SetFakeExtensionString(const char* fake_string) { | |
35 SetGLImplementation(kGLImplementationDesktopGL); | |
36 g_fake_extension_string = fake_string; | |
37 } | |
38 | |
39 void SetFakeExtensionStrings(const char** fake_strings, uint32_t count) { | |
40 SetGLImplementation(kGLImplementationDesktopGLCoreProfile); | |
41 g_num_fake_extension_strings = count; | |
42 g_fake_extension_strings = fake_strings; | |
43 } | |
44 | |
45 static const GLubyte* FakeGetString(GLenum name) { | |
46 return reinterpret_cast<const GLubyte*>(g_fake_extension_string); | |
47 } | |
48 | |
49 static void FakeGetIntegervFn(GLenum pname, GLint* params) { | |
50 *params = g_num_fake_extension_strings; | |
51 } | |
52 | |
53 static const GLubyte* FakeGetStringi(GLenum name, GLuint index) { | |
54 return (index < g_num_fake_extension_strings) ? | |
55 reinterpret_cast<const GLubyte*>(g_fake_extension_strings[index]) : | |
56 nullptr; | |
57 } | |
58 | |
59 const char* GetExtensions() { | |
60 return reinterpret_cast<const char*>(api_.glGetStringFn(GL_EXTENSIONS)); | |
61 } | |
62 | |
63 uint32_t GetNumExtensions() { | |
64 GLint num_extensions = 0; | |
65 api_.glGetIntegervFn(GL_NUM_EXTENSIONS, &num_extensions); | |
66 return static_cast<uint32_t>(num_extensions); | |
67 } | |
68 | |
69 const char* GetExtensioni(uint32_t index) { | |
70 return reinterpret_cast<const char*>(api_.glGetStringiFn(GL_EXTENSIONS, | |
71 index)); | |
72 } | |
73 | |
74 protected: | |
75 static const char* g_fake_extension_string; | |
76 | |
77 static uint32_t g_num_fake_extension_strings; | |
no sievers
2015/05/01 21:55:00
Actually can you make them non-static since you ar
David Yen
2015/05/01 22:34:38
They are being modified in static functions so the
no sievers
2015/05/01 22:44:49
Why do the functions have to be static? If they ar
David Yen
2015/05/01 22:46:03
FakeGetString, FakeGetIntegervFn, FakeGetStringi a
| |
78 static const char** g_fake_extension_strings; | |
79 | |
80 DriverGL driver_; | |
81 RealGLApi api_; | |
82 }; | |
83 | |
84 const char* GLApiTest::g_fake_extension_string = ""; | |
85 | |
86 uint32_t GLApiTest::g_num_fake_extension_strings = 0; | |
87 const char** GLApiTest::g_fake_extension_strings = nullptr; | |
88 | |
89 TEST_F(GLApiTest, DisabledExtensionStringTest) { | |
90 static const char* kFakeExtensions = "GL_EXT_1 GL_EXT_2 GL_EXT_3 GL_EXT_4"; | |
91 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; | |
92 static const char* kFilteredExtensions = "GL_EXT_3 GL_EXT_4"; | |
93 | |
94 SetFakeExtensionString(kFakeExtensions); | |
95 api_.Initialize(&driver_); | |
96 | |
97 EXPECT_STREQ(kFakeExtensions, GetExtensions()); | |
98 | |
99 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
100 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, | |
101 kFakeDisabledExtensions); | |
102 api_.InitializeWithCommandLine(&driver_, &command_line); | |
103 | |
104 EXPECT_STREQ(kFilteredExtensions, GetExtensions()); | |
105 } | |
106 | |
107 TEST_F(GLApiTest, DisabledExtensionStringIndexTest) { | |
108 static const char* kFakeExtensions[] = { | |
109 "GL_EXT_1", | |
110 "GL_EXT_2", | |
111 "GL_EXT_3", | |
112 "GL_EXT_4" | |
113 }; | |
114 static const char* kFakeDisabledExtensions = "GL_EXT_1,GL_EXT_2,GL_FAKE"; | |
115 static const char* kFilteredExtensions[] = { | |
116 "GL_EXT_3", | |
117 "GL_EXT_4" | |
118 }; | |
119 | |
120 SetFakeExtensionStrings(kFakeExtensions, arraysize(kFakeExtensions)); | |
121 api_.Initialize(&driver_); | |
122 | |
123 EXPECT_EQ(arraysize(kFakeExtensions), GetNumExtensions()); | |
124 for (uint32_t i = 0; i < arraysize(kFakeExtensions); ++i) { | |
125 EXPECT_STREQ(kFakeExtensions[i], GetExtensioni(i)); | |
126 } | |
127 | |
128 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | |
129 command_line.AppendSwitchASCII(switches::kDisableGLExtensions, | |
130 kFakeDisabledExtensions); | |
131 api_.InitializeWithCommandLine(&driver_, &command_line); | |
132 | |
133 EXPECT_EQ(arraysize(kFilteredExtensions), GetNumExtensions()); | |
134 for (uint32_t i = 0; i < arraysize(kFilteredExtensions); ++i) { | |
135 EXPECT_STREQ(kFilteredExtensions[i], GetExtensioni(i)); | |
136 } | |
137 } | |
138 | |
139 } // namespace gpu | |
OLD | NEW |