Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / gpu / config / gpu_control_list_version_info_unittest.cc
bloba2d425ff88d514281ec9492cecdc5b13420a21d0
1 // Copyright (c) 2013 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 "gpu/config/gpu_control_list.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 namespace gpu {
10 class VersionInfoTest : public testing::Test {
11 public:
12 VersionInfoTest() { }
13 ~VersionInfoTest() override {}
15 typedef GpuControlList::VersionInfo VersionInfo;
18 TEST_F(VersionInfoTest, ValidVersionInfo) {
19 const std::string op[] = {
20 "=",
21 "<",
22 "<=",
23 ">",
24 ">=",
25 "any",
26 "between"
28 for (size_t i = 0; i < arraysize(op); ++i) {
29 std::string string1;
30 std::string string2;
31 if (op[i] != "any")
32 string1 = "8.9";
33 if (op[i] == "between")
34 string2 = "9.0";
35 VersionInfo info(op[i], std::string(), string1, string2);
36 EXPECT_TRUE(info.IsValid());
39 const std::string style[] = {
40 "lexical",
41 "numerical",
42 "" // Default, same as "numerical"
44 for (size_t i =0; i < arraysize(style); ++i) {
45 VersionInfo info("=", style[i], "8.9", std::string());
46 EXPECT_TRUE(info.IsValid());
47 if (style[i] == "lexical")
48 EXPECT_TRUE(info.IsLexical());
49 else
50 EXPECT_FALSE(info.IsLexical());
53 const std::string number[] = {
54 "10",
55 "10.9",
56 "10.0",
57 "10.0.9",
58 "0.8",
59 // Leading 0s are valid.
60 "10.09",
61 // Whitespaces are ignored.
62 " 10.9",
63 "10.9 ",
64 "10 .9",
65 "10. 9",
67 for (size_t i =0; i < arraysize(number); ++i) {
68 VersionInfo info("=", std::string(), number[i], std::string());
69 EXPECT_TRUE(info.IsValid());
73 TEST_F(VersionInfoTest, InvalidVersionInfo) {
74 const std::string op[] = {
75 "=",
76 "<",
77 "<=",
78 ">",
79 ">=",
80 "any",
81 "between"
83 for (size_t i = 0; i < arraysize(op); ++i) {
85 VersionInfo info(op[i], std::string(), "8.9", std::string());
86 if (op[i] == "between")
87 EXPECT_FALSE(info.IsValid());
88 else
89 EXPECT_TRUE(info.IsValid());
92 VersionInfo info(op[i], std::string(), std::string(), std::string());
93 if (op[i] == "any")
94 EXPECT_TRUE(info.IsValid());
95 else
96 EXPECT_FALSE(info.IsValid());
99 VersionInfo info(op[i], std::string(), "8.9", "9.0");
100 EXPECT_TRUE(info.IsValid());
104 const std::string number[] = {
105 "8.E",
106 "8-9",
108 for (size_t i = 0; i < arraysize(number); ++i) {
109 VersionInfo info("=", std::string(), number[i], std::string());
110 EXPECT_FALSE(info.IsValid());
114 TEST_F(VersionInfoTest, VersionComparison) {
116 VersionInfo info("any", std::string(), std::string(), std::string());
117 EXPECT_TRUE(info.Contains("0"));
118 EXPECT_TRUE(info.Contains("8.9"));
119 EXPECT_TRUE(info.Contains("100"));
122 VersionInfo info(">", std::string(), "8.9", std::string());
123 EXPECT_FALSE(info.Contains("7"));
124 EXPECT_FALSE(info.Contains("8.9"));
125 EXPECT_FALSE(info.Contains("8.9.1"));
126 EXPECT_TRUE(info.Contains("9"));
129 VersionInfo info(">=", std::string(), "8.9", std::string());
130 EXPECT_FALSE(info.Contains("7"));
131 EXPECT_TRUE(info.Contains("8.9"));
132 EXPECT_TRUE(info.Contains("8.9.1"));
133 EXPECT_TRUE(info.Contains("9"));
136 VersionInfo info("=", std::string(), "8.9", std::string());
137 EXPECT_FALSE(info.Contains("7"));
138 EXPECT_TRUE(info.Contains("8"));
139 EXPECT_TRUE(info.Contains("8.9"));
140 EXPECT_TRUE(info.Contains("8.9.1"));
141 EXPECT_FALSE(info.Contains("9"));
144 VersionInfo info("<", std::string(), "8.9", std::string());
145 EXPECT_TRUE(info.Contains("7"));
146 EXPECT_TRUE(info.Contains("8.8"));
147 EXPECT_FALSE(info.Contains("8"));
148 EXPECT_FALSE(info.Contains("8.9"));
149 EXPECT_FALSE(info.Contains("8.9.1"));
150 EXPECT_FALSE(info.Contains("9"));
153 VersionInfo info("<=", std::string(), "8.9", std::string());
154 EXPECT_TRUE(info.Contains("7"));
155 EXPECT_TRUE(info.Contains("8.8"));
156 EXPECT_TRUE(info.Contains("8"));
157 EXPECT_TRUE(info.Contains("8.9"));
158 EXPECT_TRUE(info.Contains("8.9.1"));
159 EXPECT_FALSE(info.Contains("9"));
162 VersionInfo info("between", std::string(), "8.9", "9.1");
163 EXPECT_FALSE(info.Contains("7"));
164 EXPECT_FALSE(info.Contains("8.8"));
165 EXPECT_TRUE(info.Contains("8"));
166 EXPECT_TRUE(info.Contains("8.9"));
167 EXPECT_TRUE(info.Contains("8.9.1"));
168 EXPECT_TRUE(info.Contains("9"));
169 EXPECT_TRUE(info.Contains("9.1"));
170 EXPECT_TRUE(info.Contains("9.1.9"));
171 EXPECT_FALSE(info.Contains("9.2"));
172 EXPECT_FALSE(info.Contains("10"));
176 TEST_F(VersionInfoTest, DateComparison) {
177 // When we use '-' as splitter, we assume a format of mm-dd-yyyy
178 // or mm-yyyy, i.e., a date.
180 VersionInfo info("=", std::string(), "1976.3.21", std::string());
181 EXPECT_TRUE(info.Contains("3-21-1976", '-'));
182 EXPECT_TRUE(info.Contains("3-1976", '-'));
183 EXPECT_TRUE(info.Contains("03-1976", '-'));
184 EXPECT_FALSE(info.Contains("21-3-1976", '-'));
187 VersionInfo info(">", std::string(), "1976.3.21", std::string());
188 EXPECT_TRUE(info.Contains("3-22-1976", '-'));
189 EXPECT_TRUE(info.Contains("4-1976", '-'));
190 EXPECT_TRUE(info.Contains("04-1976", '-'));
191 EXPECT_FALSE(info.Contains("3-1976", '-'));
192 EXPECT_FALSE(info.Contains("2-1976", '-'));
195 VersionInfo info("between", std::string(), "1976.3.21", "2012.12.25");
196 EXPECT_FALSE(info.Contains("3-20-1976", '-'));
197 EXPECT_TRUE(info.Contains("3-21-1976", '-'));
198 EXPECT_TRUE(info.Contains("3-22-1976", '-'));
199 EXPECT_TRUE(info.Contains("3-1976", '-'));
200 EXPECT_TRUE(info.Contains("4-1976", '-'));
201 EXPECT_TRUE(info.Contains("1-1-2000", '-'));
202 EXPECT_TRUE(info.Contains("1-2000", '-'));
203 EXPECT_TRUE(info.Contains("2000", '-'));
204 EXPECT_TRUE(info.Contains("11-2012", '-'));
205 EXPECT_TRUE(info.Contains("12-2012", '-'));
206 EXPECT_TRUE(info.Contains("12-24-2012", '-'));
207 EXPECT_TRUE(info.Contains("12-25-2012", '-'));
208 EXPECT_FALSE(info.Contains("12-26-2012", '-'));
209 EXPECT_FALSE(info.Contains("1-2013", '-'));
210 EXPECT_FALSE(info.Contains("2013", '-'));
214 TEST_F(VersionInfoTest, LexicalComparison) {
215 // When we use lexical style, we assume a format major.minor.*.
216 // We apply numerical comparison to major, lexical comparison to others.
218 VersionInfo info("<", "lexical", "8.201", std::string());
219 EXPECT_TRUE(info.Contains("8.001.100"));
220 EXPECT_TRUE(info.Contains("8.109"));
221 EXPECT_TRUE(info.Contains("8.10900"));
222 EXPECT_TRUE(info.Contains("8.109.100"));
223 EXPECT_TRUE(info.Contains("8.2"));
224 EXPECT_TRUE(info.Contains("8.20"));
225 EXPECT_TRUE(info.Contains("8.200"));
226 EXPECT_TRUE(info.Contains("8.20.100"));
227 EXPECT_FALSE(info.Contains("8.201"));
228 EXPECT_FALSE(info.Contains("8.2010"));
229 EXPECT_FALSE(info.Contains("8.21"));
230 EXPECT_FALSE(info.Contains("8.21.100"));
231 EXPECT_FALSE(info.Contains("9.002"));
232 EXPECT_FALSE(info.Contains("9.201"));
233 EXPECT_FALSE(info.Contains("12"));
234 EXPECT_FALSE(info.Contains("12.201"));
237 VersionInfo info("<", "lexical", "9.002", std::string());
238 EXPECT_TRUE(info.Contains("8.001.100"));
239 EXPECT_TRUE(info.Contains("8.109"));
240 EXPECT_TRUE(info.Contains("8.10900"));
241 EXPECT_TRUE(info.Contains("8.109.100"));
242 EXPECT_TRUE(info.Contains("8.2"));
243 EXPECT_TRUE(info.Contains("8.20"));
244 EXPECT_TRUE(info.Contains("8.200"));
245 EXPECT_TRUE(info.Contains("8.20.100"));
246 EXPECT_TRUE(info.Contains("8.201"));
247 EXPECT_TRUE(info.Contains("8.2010"));
248 EXPECT_TRUE(info.Contains("8.21"));
249 EXPECT_TRUE(info.Contains("8.21.100"));
250 EXPECT_FALSE(info.Contains("9.002"));
251 EXPECT_FALSE(info.Contains("9.201"));
252 EXPECT_FALSE(info.Contains("12"));
253 EXPECT_FALSE(info.Contains("12.201"));
257 } // namespace gpu