Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / base / test / expectations / expectation.cc
blob9b06e282f27a2e56fa7f6749b9fd3635d0669d22
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"
9 #if defined(OS_WIN)
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"
15 #endif
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;
30 else
31 return false;
33 return true;
36 static bool IsValidPlatform(const Platform* platform) {
37 const std::string& name = platform->name;
38 const std::string& variant = platform->variant;
40 if (name == "Win") {
41 if (variant != "" &&
42 variant != "XP" &&
43 variant != "Vista" &&
44 variant != "7" &&
45 variant != "8") {
46 return false;
48 } else if (name == "Mac") {
49 if (variant != "" &&
50 variant != "10.6" &&
51 variant != "10.7" &&
52 variant != "10.8" &&
53 variant != "10.9" &&
54 variant != "10.10") {
55 return false;
57 } else if (name == "Linux") {
58 if (variant != "" &&
59 variant != "32" &&
60 variant != "64") {
61 return false;
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.
69 } else {
70 return false;
73 return true;
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();
82 } else {
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() {
91 Platform platform;
92 #if defined(OS_WIN)
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();
124 if (arch == "x86")
125 platform.variant = "32";
126 else if (arch == "x86_64")
127 platform.variant = "64";
128 #else
129 NOTREACHED();
130 #endif
131 return platform;
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;
140 else
141 return false;
143 return true;
146 Configuration GetCurrentConfiguration() {
147 #if NDEBUG
148 return CONFIGURATION_RELEASE;
149 #else
150 return CONFIGURATION_DEBUG;
151 #endif
154 Expectation::Expectation()
155 : configuration(CONFIGURATION_UNSPECIFIED),
156 result(RESULT_PASS) {
159 Expectation::~Expectation() {}
161 } // namespace test_expectations