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
;
48 } else if (name
== "Mac") {
56 } else if (name
== "Linux") {
62 } else if (name
== "ChromeOS") {
63 // TODO(rsesek): Figure out what ChromeOS needs.
64 } else if (name
== "iOS") {
65 // TODO(rsesek): Figure out what iOS needs. Probably Device and Simulator.
66 } else if (name
== "Android") {
67 // TODO(rsesek): Figure out what Android needs.
75 bool PlatformFromString(const base::StringPiece
& modifier
,
76 Platform
* out_platform
) {
77 size_t sep
= modifier
.find('-');
78 if (sep
== std::string::npos
) {
79 out_platform
->name
= modifier
.as_string();
80 out_platform
->variant
.clear();
82 out_platform
->name
= modifier
.substr(0, sep
).as_string();
83 out_platform
->variant
= modifier
.substr(sep
+ 1).as_string();
86 return IsValidPlatform(out_platform
);
89 Platform
GetCurrentPlatform() {
92 platform
.name
= "Win";
93 base::win::Version version
= base::win::GetVersion();
94 if (version
== base::win::VERSION_XP
)
95 platform
.variant
= "XP";
96 else if (version
== base::win::VERSION_VISTA
)
97 platform
.variant
= "Vista";
98 else if (version
== base::win::VERSION_WIN7
)
99 platform
.variant
= "7";
100 else if (version
== base::win::VERSION_WIN8
)
101 platform
.variant
= "8";
102 #elif defined(OS_IOS)
103 platform
.name
= "iOS";
104 #elif defined(OS_MACOSX)
105 platform
.name
= "Mac";
106 if (base::mac::IsOSSnowLeopard())
107 platform
.variant
= "10.6";
108 else if (base::mac::IsOSLion())
109 platform
.variant
= "10.7";
110 else if (base::mac::IsOSMountainLion())
111 platform
.variant
= "10.8";
112 else if (base::mac::IsOSMavericks())
113 platform
.variant
= "10.9";
114 #elif defined(OS_CHROMEOS)
115 platform
.name
= "ChromeOS";
116 #elif defined(OS_ANDROID)
117 platform
.name
= "Android";
118 #elif defined(OS_LINUX)
119 platform
.name
= "Linux";
120 std::string arch
= base::SysInfo::OperatingSystemArchitecture();
122 platform
.variant
= "32";
123 else if (arch
== "x86_64")
124 platform
.variant
= "64";
131 bool ConfigurationFromString(const base::StringPiece
& modifier
,
132 Configuration
* out_configuration
) {
133 if (modifier
== "Debug")
134 *out_configuration
= CONFIGURATION_DEBUG
;
135 else if (modifier
== "Release")
136 *out_configuration
= CONFIGURATION_RELEASE
;
143 Configuration
GetCurrentConfiguration() {
145 return CONFIGURATION_RELEASE
;
147 return CONFIGURATION_DEBUG
;
150 return CONFIGURATION_UNSPECIFIED
;
153 Expectation::Expectation()
154 : configuration(CONFIGURATION_UNSPECIFIED
),
155 result(RESULT_PASS
) {
158 Expectation::~Expectation() {}
160 } // namespace test_expectations