Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / gpu / config / gpu_info_collector_unittest.cc
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.
4
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"
11
12 using ::gfx::MockGLInterface;
13 using ::testing::Return;
14
15 namespace gpu {
16
17 class GPUInfoCollectorTest : public testing::Test {
18  public:
19   GPUInfoCollectorTest() {}
20   virtual ~GPUInfoCollectorTest() { }
21
22   virtual void SetUp() {
23     gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
24     ::gfx::MockGLInterface::SetGLInterface(gl_.get());
25 #if defined(OS_WIN)
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";
67 #endif
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;
80
81     EXPECT_CALL(*gl_, GetString(GL_EXTENSIONS))
82         .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
83             gl_extensions)));
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*>(
89             gl_version_string)));
90     EXPECT_CALL(*gl_, GetString(GL_VENDOR))
91         .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
92             gl_vendor)));
93     EXPECT_CALL(*gl_, GetString(GL_RENDERER))
94         .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
95             gl_renderer)));
96   }
97
98   virtual void TearDown() {
99     ::gfx::MockGLInterface::SetGLInterface(NULL);
100     gl_.reset();
101   }
102
103  public:
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_;
107 };
108
109 // TODO(rlp): Test the vendor and device id collection if deemed necessary as
110 //            it involves several complicated mocks for each platform.
111
112 // TODO(kbr): re-enable these tests; see http://crbug.com/100285 .
113
114 TEST_F(GPUInfoCollectorTest, DISABLED_DriverVendorGL) {
115   GPUInfo gpu_info;
116   CollectGraphicsInfoGL(&gpu_info);
117   EXPECT_EQ(test_values_.driver_vendor,
118             gpu_info.driver_vendor);
119 }
120
121 // Skip Windows because the driver version is obtained from bot registry.
122 #if !defined(OS_WIN)
123 TEST_F(GPUInfoCollectorTest, DISABLED_DriverVersionGL) {
124   GPUInfo gpu_info;
125   CollectGraphicsInfoGL(&gpu_info);
126   EXPECT_EQ(test_values_.driver_version,
127             gpu_info.driver_version);
128 }
129 #endif
130
131 TEST_F(GPUInfoCollectorTest, DISABLED_PixelShaderVersionGL) {
132   GPUInfo gpu_info;
133   CollectGraphicsInfoGL(&gpu_info);
134   EXPECT_EQ(test_values_.pixel_shader_version,
135             gpu_info.pixel_shader_version);
136 }
137
138 TEST_F(GPUInfoCollectorTest, DISABLED_VertexShaderVersionGL) {
139   GPUInfo gpu_info;
140   CollectGraphicsInfoGL(&gpu_info);
141   EXPECT_EQ(test_values_.vertex_shader_version,
142             gpu_info.vertex_shader_version);
143 }
144
145 TEST_F(GPUInfoCollectorTest, DISABLED_GLVersionGL) {
146   GPUInfo gpu_info;
147   CollectGraphicsInfoGL(&gpu_info);
148   EXPECT_EQ(test_values_.gl_version,
149             gpu_info.gl_version);
150 }
151
152 TEST_F(GPUInfoCollectorTest, DISABLED_GLVersionStringGL) {
153   GPUInfo gpu_info;
154   CollectGraphicsInfoGL(&gpu_info);
155   EXPECT_EQ(test_values_.gl_version_string,
156             gpu_info.gl_version_string);
157 }
158
159 TEST_F(GPUInfoCollectorTest, DISABLED_GLRendererGL) {
160   GPUInfo gpu_info;
161   CollectGraphicsInfoGL(&gpu_info);
162   EXPECT_EQ(test_values_.gl_renderer,
163             gpu_info.gl_renderer);
164 }
165
166 TEST_F(GPUInfoCollectorTest, DISABLED_GLVendorGL) {
167   GPUInfo gpu_info;
168   CollectGraphicsInfoGL(&gpu_info);
169   EXPECT_EQ(test_values_.gl_vendor,
170             gpu_info.gl_vendor);
171 }
172
173 TEST_F(GPUInfoCollectorTest, DISABLED_GLExtensionsGL) {
174   GPUInfo gpu_info;
175   CollectGraphicsInfoGL(&gpu_info);
176   EXPECT_EQ(test_values_.gl_extensions,
177             gpu_info.gl_extensions);
178 }
179
180 }  // namespace gpu
181