1 // Copyright (c) 2012 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/memory/scoped_ptr.h"
6 #include "gpu/config/gpu_info.h"
7 #include "gpu/config/gpu_info_collector.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gl/gl_implementation.h"
11 #include "ui/gl/gl_mock.h"
13 using ::gfx::MockGLInterface
;
14 using ::testing::Return
;
18 class GPUInfoCollectorTest
: public testing::Test
{
20 GPUInfoCollectorTest() {}
21 virtual ~GPUInfoCollectorTest() { }
23 virtual void SetUp() {
24 // TODO(kbr): make this setup robust in the case where
25 // GLSurface::InitializeOneOff() has already been called by
26 // another unit test. http://crbug.com/100285
27 gfx::InitializeStaticGLBindings(gfx::kGLImplementationMockGL
);
28 gl_
.reset(new ::testing::StrictMock
< ::gfx::MockGLInterface
>());
29 ::gfx::GLInterface::SetGLInterface(gl_
.get());
31 const uint32 vendor_id
= 0x10de;
32 const uint32 device_id
= 0x0658;
33 const char* driver_vendor
= ""; // not implemented
34 const char* driver_version
= "";
35 const char* shader_version
= "1.40";
36 const char* gl_version
= "3.1";
37 const char* gl_renderer
= "Quadro FX 380/PCI/SSE2";
38 const char* gl_vendor
= "NVIDIA Corporation";
39 const char* gl_version_string
= "3.1.0";
40 const char* gl_shading_language_version
= "1.40 NVIDIA via Cg compiler";
41 const char* gl_extensions
=
42 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
43 "GL_EXT_read_format_bgra";
44 #elif defined(OS_MACOSX)
45 const uint32 vendor_id
= 0x10de;
46 const uint32 device_id
= 0x0640;
47 const char* driver_vendor
= ""; // not implemented
48 const char* driver_version
= "1.6.18";
49 const char* shader_version
= "1.20";
50 const char* gl_version
= "2.1";
51 const char* gl_renderer
= "NVIDIA GeForce GT 120 OpenGL Engine";
52 const char* gl_vendor
= "NVIDIA Corporation";
53 const char* gl_version_string
= "2.1 NVIDIA-1.6.18";
54 const char* gl_shading_language_version
= "1.20 ";
55 const char* gl_extensions
=
56 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
57 "GL_EXT_read_format_bgra";
58 #else // defined (OS_LINUX)
59 const uint32 vendor_id
= 0x10de;
60 const uint32 device_id
= 0x0658;
61 const char* driver_vendor
= "NVIDIA";
62 const char* driver_version
= "195.36.24";
63 const char* shader_version
= "1.50";
64 const char* gl_version
= "3.2";
65 const char* gl_renderer
= "Quadro FX 380/PCI/SSE2";
66 const char* gl_vendor
= "NVIDIA Corporation";
67 const char* gl_version_string
= "3.2.0 NVIDIA 195.36.24";
68 const char* gl_shading_language_version
= "1.50 NVIDIA via Cg compiler";
69 const char* gl_extensions
=
70 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
71 "GL_EXT_read_format_bgra";
73 test_values_
.gpu
.vendor_id
= vendor_id
;
74 test_values_
.gpu
.device_id
= device_id
;
75 test_values_
.driver_vendor
= driver_vendor
;
76 test_values_
.driver_version
=driver_version
;
77 test_values_
.pixel_shader_version
= shader_version
;
78 test_values_
.vertex_shader_version
= shader_version
;
79 test_values_
.gl_version
= gl_version
;
80 test_values_
.gl_renderer
= gl_renderer
;
81 test_values_
.gl_vendor
= gl_vendor
;
82 test_values_
.gl_version_string
= gl_version_string
;
83 test_values_
.gl_extensions
= gl_extensions
;
84 test_values_
.can_lose_context
= false;
86 EXPECT_CALL(*gl_
, GetString(GL_EXTENSIONS
))
87 .WillRepeatedly(Return(reinterpret_cast<const GLubyte
*>(
89 EXPECT_CALL(*gl_
, GetString(GL_SHADING_LANGUAGE_VERSION
))
90 .WillRepeatedly(Return(reinterpret_cast<const GLubyte
*>(
91 gl_shading_language_version
)));
92 EXPECT_CALL(*gl_
, GetString(GL_VERSION
))
93 .WillRepeatedly(Return(reinterpret_cast<const GLubyte
*>(
95 EXPECT_CALL(*gl_
, GetString(GL_VENDOR
))
96 .WillRepeatedly(Return(reinterpret_cast<const GLubyte
*>(
98 EXPECT_CALL(*gl_
, GetString(GL_RENDERER
))
99 .WillRepeatedly(Return(reinterpret_cast<const GLubyte
*>(
103 virtual void TearDown() {
104 ::gfx::GLInterface::SetGLInterface(NULL
);
109 // Use StrictMock to make 100% sure we know how GL will be called.
110 scoped_ptr
< ::testing::StrictMock
< ::gfx::MockGLInterface
> > gl_
;
111 GPUInfo test_values_
;
114 // TODO(rlp): Test the vendor and device id collection if deemed necessary as
115 // it involves several complicated mocks for each platform.
117 // TODO(kbr): re-enable these tests; see http://crbug.com/100285 .
119 TEST_F(GPUInfoCollectorTest
, DISABLED_DriverVendorGL
) {
121 CollectGraphicsInfoGL(&gpu_info
);
122 EXPECT_EQ(test_values_
.driver_vendor
,
123 gpu_info
.driver_vendor
);
126 // Skip Windows because the driver version is obtained from bot registry.
128 TEST_F(GPUInfoCollectorTest
, DISABLED_DriverVersionGL
) {
130 CollectGraphicsInfoGL(&gpu_info
);
131 EXPECT_EQ(test_values_
.driver_version
,
132 gpu_info
.driver_version
);
136 TEST_F(GPUInfoCollectorTest
, DISABLED_PixelShaderVersionGL
) {
138 CollectGraphicsInfoGL(&gpu_info
);
139 EXPECT_EQ(test_values_
.pixel_shader_version
,
140 gpu_info
.pixel_shader_version
);
143 TEST_F(GPUInfoCollectorTest
, DISABLED_VertexShaderVersionGL
) {
145 CollectGraphicsInfoGL(&gpu_info
);
146 EXPECT_EQ(test_values_
.vertex_shader_version
,
147 gpu_info
.vertex_shader_version
);
150 TEST_F(GPUInfoCollectorTest
, DISABLED_GLVersionGL
) {
152 CollectGraphicsInfoGL(&gpu_info
);
153 EXPECT_EQ(test_values_
.gl_version
,
154 gpu_info
.gl_version
);
157 TEST_F(GPUInfoCollectorTest
, DISABLED_GLVersionStringGL
) {
159 CollectGraphicsInfoGL(&gpu_info
);
160 EXPECT_EQ(test_values_
.gl_version_string
,
161 gpu_info
.gl_version_string
);
164 TEST_F(GPUInfoCollectorTest
, DISABLED_GLRendererGL
) {
166 CollectGraphicsInfoGL(&gpu_info
);
167 EXPECT_EQ(test_values_
.gl_renderer
,
168 gpu_info
.gl_renderer
);
171 TEST_F(GPUInfoCollectorTest
, DISABLED_GLVendorGL
) {
173 CollectGraphicsInfoGL(&gpu_info
);
174 EXPECT_EQ(test_values_
.gl_vendor
,
178 TEST_F(GPUInfoCollectorTest
, DISABLED_GLExtensionsGL
) {
180 CollectGraphicsInfoGL(&gpu_info
);
181 EXPECT_EQ(test_values_
.gl_extensions
,
182 gpu_info
.gl_extensions
);