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_mock.h"
12 using ::gfx::MockGLInterface;
13 using ::testing::Return;
17 class GPUInfoCollectorTest : public testing::Test {
19 GPUInfoCollectorTest() {}
20 virtual ~GPUInfoCollectorTest() { }
22 virtual void SetUp() {
23 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
24 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
26 const uint32 vendor_id = 0x10de;
27 const uint32 device_id = 0x0658;
28 const char* driver_vendor = ""; // not implemented
29 const char* driver_version = "";
30 const char* shader_version = "1.40";
31 const char* gl_version = "3.1";
32 const char* gl_renderer = "Quadro FX 380/PCI/SSE2";
33 const char* gl_vendor = "NVIDIA Corporation";
34 const char* gl_version_string = "3.1.0";
35 const char* gl_shading_language_version = "1.40 NVIDIA via Cg compiler";
36 const char* gl_extensions =
37 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
38 "GL_EXT_read_format_bgra";
39 #elif defined(OS_MACOSX)
40 const uint32 vendor_id = 0x10de;
41 const uint32 device_id = 0x0640;
42 const char* driver_vendor = ""; // not implemented
43 const char* driver_version = "1.6.18";
44 const char* shader_version = "1.20";
45 const char* gl_version = "2.1";
46 const char* gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
47 const char* gl_vendor = "NVIDIA Corporation";
48 const char* gl_version_string = "2.1 NVIDIA-1.6.18";
49 const char* gl_shading_language_version = "1.20 ";
50 const char* gl_extensions =
51 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
52 "GL_EXT_read_format_bgra";
53 #else // defined (OS_LINUX)
54 const uint32 vendor_id = 0x10de;
55 const uint32 device_id = 0x0658;
56 const char* driver_vendor = "NVIDIA";
57 const char* driver_version = "195.36.24";
58 const char* shader_version = "1.50";
59 const char* gl_version = "3.2";
60 const char* gl_renderer = "Quadro FX 380/PCI/SSE2";
61 const char* gl_vendor = "NVIDIA Corporation";
62 const char* gl_version_string = "3.2.0 NVIDIA 195.36.24";
63 const char* gl_shading_language_version = "1.50 NVIDIA via Cg compiler";
64 const char* gl_extensions =
65 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
66 "GL_EXT_read_format_bgra";
68 test_values_.gpu.vendor_id = vendor_id;
69 test_values_.gpu.device_id = device_id;
70 test_values_.driver_vendor = driver_vendor;
71 test_values_.driver_version =driver_version;
72 test_values_.pixel_shader_version = shader_version;
73 test_values_.vertex_shader_version = shader_version;
74 test_values_.gl_version = gl_version;
75 test_values_.gl_renderer = gl_renderer;
76 test_values_.gl_vendor = gl_vendor;
77 test_values_.gl_version_string = gl_version_string;
78 test_values_.gl_extensions = gl_extensions;
79 test_values_.can_lose_context = false;
81 EXPECT_CALL(*gl_, GetString(GL_EXTENSIONS))
82 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
84 EXPECT_CALL(*gl_, GetString(GL_SHADING_LANGUAGE_VERSION))
85 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
86 gl_shading_language_version)));
87 EXPECT_CALL(*gl_, GetString(GL_VERSION))
88 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
90 EXPECT_CALL(*gl_, GetString(GL_VENDOR))
91 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
93 EXPECT_CALL(*gl_, GetString(GL_RENDERER))
94 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
98 virtual void TearDown() {
99 ::gfx::MockGLInterface::SetGLInterface(NULL);
104 // Use StrictMock to make 100% sure we know how GL will be called.
105 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
106 GPUInfo test_values_;
109 // TODO(rlp): Test the vendor and device id collection if deemed necessary as
110 // it involves several complicated mocks for each platform.
112 // TODO(kbr): re-enable these tests; see http://crbug.com/100285 .
114 TEST_F(GPUInfoCollectorTest, DISABLED_DriverVendorGL) {
116 CollectGraphicsInfoGL(&gpu_info);
117 EXPECT_EQ(test_values_.driver_vendor,
118 gpu_info.driver_vendor);
121 // Skip Windows because the driver version is obtained from bot registry.
123 TEST_F(GPUInfoCollectorTest, DISABLED_DriverVersionGL) {
125 CollectGraphicsInfoGL(&gpu_info);
126 EXPECT_EQ(test_values_.driver_version,
127 gpu_info.driver_version);
131 TEST_F(GPUInfoCollectorTest, DISABLED_PixelShaderVersionGL) {
133 CollectGraphicsInfoGL(&gpu_info);
134 EXPECT_EQ(test_values_.pixel_shader_version,
135 gpu_info.pixel_shader_version);
138 TEST_F(GPUInfoCollectorTest, DISABLED_VertexShaderVersionGL) {
140 CollectGraphicsInfoGL(&gpu_info);
141 EXPECT_EQ(test_values_.vertex_shader_version,
142 gpu_info.vertex_shader_version);
145 TEST_F(GPUInfoCollectorTest, DISABLED_GLVersionGL) {
147 CollectGraphicsInfoGL(&gpu_info);
148 EXPECT_EQ(test_values_.gl_version,
149 gpu_info.gl_version);
152 TEST_F(GPUInfoCollectorTest, DISABLED_GLVersionStringGL) {
154 CollectGraphicsInfoGL(&gpu_info);
155 EXPECT_EQ(test_values_.gl_version_string,
156 gpu_info.gl_version_string);
159 TEST_F(GPUInfoCollectorTest, DISABLED_GLRendererGL) {
161 CollectGraphicsInfoGL(&gpu_info);
162 EXPECT_EQ(test_values_.gl_renderer,
163 gpu_info.gl_renderer);
166 TEST_F(GPUInfoCollectorTest, DISABLED_GLVendorGL) {
168 CollectGraphicsInfoGL(&gpu_info);
169 EXPECT_EQ(test_values_.gl_vendor,
173 TEST_F(GPUInfoCollectorTest, DISABLED_GLExtensionsGL) {
175 CollectGraphicsInfoGL(&gpu_info);
176 EXPECT_EQ(test_values_.gl_extensions,
177 gpu_info.gl_extensions);