• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 namespace gpu {
9 
10 class OsInfoTest : public testing::Test {
11  public:
OsInfoTest()12   OsInfoTest() { }
~OsInfoTest()13   virtual ~OsInfoTest() { }
14 
15   typedef GpuControlList::OsInfo OsInfo;
16 };
17 
TEST_F(OsInfoTest,ValidOsInfo)18 TEST_F(OsInfoTest, ValidOsInfo) {
19   const std::string os[] = {
20     "win",
21     "linux",
22     "macosx",
23     "chromeos",
24     "android",
25     "any"
26   };
27   const GpuControlList::OsType os_type[] = {
28     GpuControlList::kOsWin,
29     GpuControlList::kOsLinux,
30     GpuControlList::kOsMacosx,
31     GpuControlList::kOsChromeOS,
32     GpuControlList::kOsAndroid,
33     GpuControlList::kOsAny
34   };
35   for (size_t i = 0; i < arraysize(os); ++i) {
36     OsInfo info(os[i], "=", "10.6", std::string());
37     EXPECT_TRUE(info.IsValid());
38     EXPECT_EQ(os_type[i], info.type());
39   }
40   {
41     OsInfo info("any", "any", std::string(), std::string());
42     EXPECT_TRUE(info.IsValid());
43   }
44 }
45 
TEST_F(OsInfoTest,InvalidOsInfo)46 TEST_F(OsInfoTest, InvalidOsInfo) {
47   const std::string os[] = {
48     "win",
49     "linux",
50     "macosx",
51     "chromeos",
52     "android",
53     "any"
54   };
55   for (size_t i = 0; i < arraysize(os); ++i) {
56     {
57       OsInfo info(os[i], std::string(), std::string(), std::string());
58       EXPECT_FALSE(info.IsValid());
59     }
60     {
61       OsInfo info(os[i], "=", std::string(), std::string());
62       EXPECT_FALSE(info.IsValid());
63     }
64     {
65       OsInfo info(os[i], std::string(), "10.6", std::string());
66       EXPECT_FALSE(info.IsValid());
67     }
68   }
69   const std::string os_cap[] = {
70     "Win",
71     "Linux",
72     "MacOSX",
73     "ChromeOS",
74     "Android",
75   };
76   for (size_t i = 0; i < arraysize(os_cap); ++i) {
77     OsInfo info(os_cap[i], "=", "10.6", std::string());
78     EXPECT_FALSE(info.IsValid());
79   }
80 }
81 
TEST_F(OsInfoTest,NonNumericOsVersion)82 TEST_F(OsInfoTest, NonNumericOsVersion) {
83   {
84     OsInfo info("android", "<", "4.2", std::string());
85     EXPECT_TRUE(info.IsValid());
86     // The expectation is the version number first, then extra info.
87     EXPECT_TRUE(info.Contains(
88         GpuControlList::kOsAndroid, "4.0 bug fix version 5.2"));
89     EXPECT_FALSE(info.Contains(GpuControlList::kOsAndroid, "F"));
90     EXPECT_FALSE(info.Contains(GpuControlList::kOsAndroid, "F 4.0"));
91     EXPECT_FALSE(info.Contains(GpuControlList::kOsAndroid, std::string()));
92   }
93   {
94     OsInfo info("android", "any", std::string(), std::string());
95     EXPECT_TRUE(info.IsValid());
96     EXPECT_TRUE(info.Contains(
97         GpuControlList::kOsAndroid, "4.0 bug fix version 5.2"));
98     EXPECT_TRUE(info.Contains(GpuControlList::kOsAndroid, "F"));
99     EXPECT_TRUE(info.Contains(GpuControlList::kOsAndroid, "F 4.0"));
100     EXPECT_TRUE(info.Contains(GpuControlList::kOsAndroid, std::string()));
101   }
102 }
103 
TEST_F(OsInfoTest,OsVersionZero)104 TEST_F(OsInfoTest, OsVersionZero) {
105   {
106     OsInfo info("android", "<", "4.2", std::string());
107     EXPECT_TRUE(info.IsValid());
108     // All forms of version 0 is considered invalid.
109     EXPECT_FALSE(info.Contains(GpuControlList::kOsAndroid, "0"));
110     EXPECT_FALSE(info.Contains(GpuControlList::kOsAndroid, "0.0"));
111     EXPECT_FALSE(info.Contains(GpuControlList::kOsAndroid, "0.00.0"));
112   }
113   {
114     OsInfo info("android", "any", std::string(), std::string());
115     EXPECT_TRUE(info.IsValid());
116     EXPECT_TRUE(info.Contains(GpuControlList::kOsAndroid, "0"));
117     EXPECT_TRUE(info.Contains(GpuControlList::kOsAndroid, "0.0"));
118     EXPECT_TRUE(info.Contains(GpuControlList::kOsAndroid, "0.00.0"));
119   }
120 }
121 
TEST_F(OsInfoTest,OsComparison)122 TEST_F(OsInfoTest, OsComparison) {
123   {
124     OsInfo info("any", "any", std::string(), std::string());
125     const GpuControlList::OsType os_type[] = {
126       GpuControlList::kOsWin, GpuControlList::kOsLinux,
127       GpuControlList::kOsMacosx, GpuControlList::kOsChromeOS,
128       GpuControlList::kOsAndroid,
129     };
130     for (size_t i = 0; i < arraysize(os_type); ++i) {
131       EXPECT_TRUE(info.Contains(os_type[i], std::string()));
132       EXPECT_TRUE(info.Contains(os_type[i], "7.8"));
133     }
134   }
135   {
136     OsInfo info("win", ">=", "6", std::string());
137     EXPECT_FALSE(info.Contains(GpuControlList::kOsMacosx, "10.8.3"));
138     EXPECT_FALSE(info.Contains(GpuControlList::kOsLinux, "10"));
139     EXPECT_FALSE(info.Contains(GpuControlList::kOsChromeOS, "13"));
140     EXPECT_FALSE(info.Contains(GpuControlList::kOsAndroid, "7"));
141     EXPECT_FALSE(info.Contains(GpuControlList::kOsAny, "7"));
142     EXPECT_FALSE(info.Contains(GpuControlList::kOsWin, std::string()));
143     EXPECT_TRUE(info.Contains(GpuControlList::kOsWin, "6"));
144     EXPECT_TRUE(info.Contains(GpuControlList::kOsWin, "6.1"));
145     EXPECT_TRUE(info.Contains(GpuControlList::kOsWin, "7"));
146     EXPECT_FALSE(info.Contains(GpuControlList::kOsWin, "5"));
147   }
148 }
149 
150 }  // namespace gpu
151 
152