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 "base/test/expectations/expectation.h" 6 7 #include "base/logging.h" 8 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 16 17 namespace test_expectations { 18 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; 32 33 return true; 34 } 35 36 static bool IsValidPlatform(const Platform* platform) { 37 const std::string& name = platform->name; 38 const std::string& variant = platform->variant; 39 40 if (name == "Win") { 41 if (variant != "" && 42 variant != "XP" && 43 variant != "Vista" && 44 variant != "7" && 45 variant != "8") { 46 return false; 47 } 48 } else if (name == "Mac") { 49 if (variant != "" && 50 variant != "10.6" && 51 variant != "10.7" && 52 variant != "10.8") { 53 return false; 54 } 55 } else if (name == "Linux") { 56 if (variant != "" && 57 variant != "32" && 58 variant != "64") { 59 return false; 60 } 61 } else if (name == "ChromeOS") { 62 // TODO(rsesek): Figure out what ChromeOS needs. 63 } else if (name == "iOS") { 64 // TODO(rsesek): Figure out what iOS needs. Probably Device and Simulator. 65 } else if (name == "Android") { 66 // TODO(rsesek): Figure out what Android needs. 67 } else { 68 return false; 69 } 70 71 return true; 72 } 73 74 bool PlatformFromString(const base::StringPiece& modifier, 75 Platform* out_platform) { 76 size_t sep = modifier.find('-'); 77 if (sep == std::string::npos) { 78 out_platform->name = modifier.as_string(); 79 out_platform->variant.clear(); 80 } else { 81 out_platform->name = modifier.substr(0, sep).as_string(); 82 out_platform->variant = modifier.substr(sep + 1).as_string(); 83 } 84 85 return IsValidPlatform(out_platform); 86 } 87 88 Platform GetCurrentPlatform() { 89 Platform platform; 90 #if defined(OS_WIN) 91 platform.name = "Win"; 92 base::win::Version version = base::win::GetVersion(); 93 if (version == base::win::VERSION_XP) 94 platform.variant = "XP"; 95 else if (version == base::win::VERSION_VISTA) 96 platform.variant = "Vista"; 97 else if (version == base::win::VERSION_WIN7) 98 platform.variant = "7"; 99 else if (version == base::win::VERSION_WIN8) 100 platform.variant = "8"; 101 #elif defined(OS_IOS) 102 platform.name = "iOS"; 103 #elif defined(OS_MACOSX) 104 platform.name = "Mac"; 105 if (base::mac::IsOSSnowLeopard()) 106 platform.variant = "10.6"; 107 else if (base::mac::IsOSLion()) 108 platform.variant = "10.7"; 109 else if (base::mac::IsOSMountainLion()) 110 platform.variant = "10.8"; 111 #elif defined(OS_CHROMEOS) 112 platform.name = "ChromeOS"; 113 #elif defined(OS_ANDROID) 114 platform.name = "Android"; 115 #elif defined(OS_LINUX) 116 platform.name = "Linux"; 117 std::string arch = base::SysInfo::OperatingSystemArchitecture(); 118 if (arch == "x86") 119 platform.variant = "32"; 120 else if (arch == "x86_64") 121 platform.variant = "64"; 122 #else 123 NOTREACHED(); 124 #endif 125 return platform; 126 } 127 128 bool ConfigurationFromString(const base::StringPiece& modifier, 129 Configuration* out_configuration) { 130 if (modifier == "Debug") 131 *out_configuration = CONFIGURATION_DEBUG; 132 else if (modifier == "Release") 133 *out_configuration = CONFIGURATION_RELEASE; 134 else 135 return false; 136 137 return true; 138 } 139 140 Configuration GetCurrentConfiguration() { 141 #if NDEBUG 142 return CONFIGURATION_RELEASE; 143 #else 144 return CONFIGURATION_DEBUG; 145 #endif 146 NOTREACHED(); 147 return CONFIGURATION_UNSPECIFIED; 148 } 149 150 Expectation::Expectation() 151 : configuration(CONFIGURATION_UNSPECIFIED), 152 result(RESULT_PASS) { 153 } 154 155 Expectation::~Expectation() {} 156 157 } // namespace test_expectations 158