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 "base/test/expectations/expectation.h"
7 #include "base/logging.h"
10 #include "base/win/windows_version.h"
11 #elif defined(OS_MACOSX) && !defined(OS_IOS)
12 #include "base/mac/mac_util.h"
13 #elif defined(OS_LINUX)
14 #include "base/sys_info.h"
17 namespace test_expectations
{
19 bool ResultFromString(const base::StringPiece
& result
, Result
* out_result
) {
20 if (result
== "Failure")
21 *out_result
= RESULT_FAILURE
;
22 else if (result
== "Timeout")
23 *out_result
= RESULT_TIMEOUT
;
24 else if (result
== "Crash")
25 *out_result
= RESULT_CRASH
;
26 else if (result
== "Skip")
27 *out_result
= RESULT_SKIP
;
28 else if (result
== "Pass")
29 *out_result
= RESULT_PASS
;
36 static bool IsValidPlatform(const Platform
* platform
) {
37 const std::string
& name
= platform
->name
;
38 const std::string
& variant
= platform
->variant
;
41 if (!variant
.empty() &&
48 } else if (name
== "Mac") {
49 if (!variant
.empty() &&
57 } else if (name
== "Linux") {
58 if (!variant
.empty() &&
63 } else if (name
== "ChromeOS") {
64 // TODO(rsesek): Figure out what ChromeOS needs.
65 } else if (name
== "iOS") {
66 // TODO(rsesek): Figure out what iOS needs. Probably Device and Simulator.
67 } else if (name
== "Android") {
68 // TODO(rsesek): Figure out what Android needs.
76 bool PlatformFromString(const base::StringPiece
& modifier
,
77 Platform
* out_platform
) {
78 size_t sep
= modifier
.find('-');
79 if (sep
== std::string::npos
) {
80 out_platform
->name
= modifier
.as_string();
81 out_platform
->variant
.clear();
83 out_platform
->name
= modifier
.substr(0, sep
).as_string();
84 out_platform
->variant
= modifier
.substr(sep
+ 1).as_string();
87 return IsValidPlatform(out_platform
);
90 Platform
GetCurrentPlatform() {
93 platform
.name
= "Win";
94 base::win::Version version
= base::win::GetVersion();
95 if (version
== base::win::VERSION_XP
)
96 platform
.variant
= "XP";
97 else if (version
== base::win::VERSION_VISTA
)
98 platform
.variant
= "Vista";
99 else if (version
== base::win::VERSION_WIN7
)
100 platform
.variant
= "7";
101 else if (version
== base::win::VERSION_WIN8
)
102 platform
.variant
= "8";
103 #elif defined(OS_IOS)
104 platform
.name
= "iOS";
105 #elif defined(OS_MACOSX)
106 platform
.name
= "Mac";
107 if (base::mac::IsOSSnowLeopard())
108 platform
.variant
= "10.6";
109 else if (base::mac::IsOSLion())
110 platform
.variant
= "10.7";
111 else if (base::mac::IsOSMountainLion())
112 platform
.variant
= "10.8";
113 else if (base::mac::IsOSMavericks())
114 platform
.variant
= "10.9";
115 else if (base::mac::IsOSYosemite())
116 platform
.variant
= "10.10";
117 #elif defined(OS_CHROMEOS)
118 platform
.name
= "ChromeOS";
119 #elif defined(OS_ANDROID)
120 platform
.name
= "Android";
121 #elif defined(OS_LINUX)
122 platform
.name
= "Linux";
123 std::string arch
= base::SysInfo::OperatingSystemArchitecture();
125 platform
.variant
= "32";
126 else if (arch
== "x86_64")
127 platform
.variant
= "64";
134 bool ConfigurationFromString(const base::StringPiece
& modifier
,
135 Configuration
* out_configuration
) {
136 if (modifier
== "Debug")
137 *out_configuration
= CONFIGURATION_DEBUG
;
138 else if (modifier
== "Release")
139 *out_configuration
= CONFIGURATION_RELEASE
;
146 Configuration
GetCurrentConfiguration() {
148 return CONFIGURATION_RELEASE
;
150 return CONFIGURATION_DEBUG
;
154 Expectation::Expectation()
155 : configuration(CONFIGURATION_UNSPECIFIED
),
156 result(RESULT_PASS
) {
159 Expectation::~Expectation() {}
161 } // namespace test_expectations