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.
4
5#include "gpu/config/gpu_control_list.h"
6#include "testing/gtest/include/gtest/gtest.h"
7
8namespace gpu {
9
10class NumberInfoTest : public testing::Test {
11 public:
12  NumberInfoTest() { }
13  virtual ~NumberInfoTest() { }
14
15  typedef GpuControlList::FloatInfo FloatInfo;
16  typedef GpuControlList::IntInfo IntInfo;
17  typedef GpuControlList::BoolInfo BoolInfo;
18};
19
20TEST_F(NumberInfoTest, ValidFloatInfo) {
21  const std::string op[] = {
22    "=",
23    "<",
24    "<=",
25    ">",
26    ">=",
27    "any",
28    "between"
29  };
30  for (size_t i = 0; i < arraysize(op); ++i) {
31    std::string value1;
32    std::string value2;
33    if (op[i] != "any")
34      value1 = "3.14";
35    if (op[i] == "between")
36      value2 = "4.21";
37    FloatInfo info(op[i], value1, value2);
38    EXPECT_TRUE(info.IsValid());
39  }
40
41  const std::string value[] = {
42    "1.0E12",
43    "1.0e12",
44    "2013",
45    "1.0e-12",
46    "2.1400",
47    "-2.14",
48  };
49  for (size_t i = 0; i < arraysize(value); ++i) {
50    FloatInfo info("=", value[i], std::string());
51    EXPECT_TRUE(info.IsValid());
52  }
53}
54
55TEST_F(NumberInfoTest, InvalidFloatInfo) {
56  const std::string op[] = {
57    "=",
58    "<",
59    "<=",
60    ">",
61    ">=",
62  };
63  for (size_t i = 0; i < arraysize(op); ++i) {
64    FloatInfo info(op[i], std::string(), std::string());
65    EXPECT_FALSE(info.IsValid());
66  }
67  {
68    FloatInfo info("between", "3.14", std::string());
69    EXPECT_FALSE(info.IsValid());
70  }
71  const std::string value[] = {
72    "1.0 E12",
73    "1.0e 12",
74    " 2013",
75    "2013 ",
76    "- 2.14",
77  };
78  for (size_t i = 0; i < arraysize(value); ++i) {
79    FloatInfo info("=", value[i], std::string());
80    EXPECT_FALSE(info.IsValid());
81  }
82}
83
84TEST_F(NumberInfoTest, FloatComparison) {
85  {
86    FloatInfo info("=", "3.14", std::string());
87    EXPECT_TRUE(info.Contains(3.14f));
88    EXPECT_TRUE(info.Contains(3.1400f));
89    EXPECT_FALSE(info.Contains(3.1f));
90    EXPECT_FALSE(info.Contains(3));
91  }
92  {
93    FloatInfo info(">", "3.14", std::string());
94    EXPECT_FALSE(info.Contains(3.14f));
95    EXPECT_TRUE(info.Contains(3.141f));
96    EXPECT_FALSE(info.Contains(3.1f));
97  }
98  {
99    FloatInfo info("<=", "3.14", std::string());
100    EXPECT_TRUE(info.Contains(3.14f));
101    EXPECT_FALSE(info.Contains(3.141f));
102    EXPECT_TRUE(info.Contains(3.1f));
103  }
104  {
105    FloatInfo info("any", std::string(), std::string());
106    EXPECT_TRUE(info.Contains(3.14f));
107  }
108  {
109    FloatInfo info("between", "3.14", "5.4");
110    EXPECT_TRUE(info.Contains(3.14f));
111    EXPECT_TRUE(info.Contains(5.4f));
112    EXPECT_TRUE(info.Contains(4));
113    EXPECT_FALSE(info.Contains(5.6f));
114    EXPECT_FALSE(info.Contains(3.12f));
115  }
116}
117
118TEST_F(NumberInfoTest, ValidIntInfo) {
119  const std::string op[] = {
120    "=",
121    "<",
122    "<=",
123    ">",
124    ">=",
125    "any",
126    "between"
127  };
128  for (size_t i = 0; i < arraysize(op); ++i) {
129    std::string value1;
130    std::string value2;
131    if (op[i] != "any")
132      value1 = "3";
133    if (op[i] == "between")
134      value2 = "9";
135    IntInfo info(op[i], value1, value2);
136    EXPECT_TRUE(info.IsValid());
137  }
138
139  const std::string value[] = {
140    "12",
141    "-12",
142  };
143  for (size_t i = 0; i < arraysize(value); ++i) {
144    IntInfo info("=", value[i], std::string());
145    EXPECT_TRUE(info.IsValid());
146  }
147}
148
149TEST_F(NumberInfoTest, InvalidIntInfo) {
150  const std::string op[] = {
151    "=",
152    "<",
153    "<=",
154    ">",
155    ">=",
156  };
157  for (size_t i = 0; i < arraysize(op); ++i) {
158    IntInfo info(op[i], std::string(), std::string());
159    EXPECT_FALSE(info.IsValid());
160  }
161  {
162    IntInfo info("between", "3", std::string());
163    EXPECT_FALSE(info.IsValid());
164  }
165  const std::string value[] = {
166    " 12",
167    "12 ",
168    "- 12",
169    " -12",
170    "3.14"
171  };
172  for (size_t i = 0; i < arraysize(value); ++i) {
173    IntInfo info("=", value[i], std::string());
174    EXPECT_FALSE(info.IsValid());
175  }
176}
177
178TEST_F(NumberInfoTest, IntComparison) {
179  {
180    IntInfo info("=", "3", std::string());
181    EXPECT_TRUE(info.Contains(3));
182    EXPECT_FALSE(info.Contains(4));
183  }
184  {
185    IntInfo info(">", "3", std::string());
186    EXPECT_FALSE(info.Contains(2));
187    EXPECT_FALSE(info.Contains(3));
188    EXPECT_TRUE(info.Contains(4));
189  }
190  {
191    IntInfo info("<=", "3", std::string());
192    EXPECT_TRUE(info.Contains(2));
193    EXPECT_TRUE(info.Contains(3));
194    EXPECT_FALSE(info.Contains(4));
195  }
196  {
197    IntInfo info("any", std::string(), std::string());
198    EXPECT_TRUE(info.Contains(3));
199  }
200  {
201    IntInfo info("between", "3", "5");
202    EXPECT_TRUE(info.Contains(3));
203    EXPECT_TRUE(info.Contains(5));
204    EXPECT_TRUE(info.Contains(4));
205    EXPECT_FALSE(info.Contains(6));
206    EXPECT_FALSE(info.Contains(2));
207  }
208}
209
210TEST_F(NumberInfoTest, Bool) {
211  {
212    BoolInfo info(true);
213    EXPECT_TRUE(info.Contains(true));
214    EXPECT_FALSE(info.Contains(false));
215  }
216  {
217    BoolInfo info(false);
218    EXPECT_FALSE(info.Contains(true));
219    EXPECT_TRUE(info.Contains(false));
220  }
221}
222
223}  // namespace gpu
224
225