1 // Copyright 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/launcher/test_result.h" 6 7 #include <stddef.h> 8 9 #include "base/logging.h" 10 11 namespace base { 12 13 TestResultPart::TestResultPart() = default; 14 TestResultPart::~TestResultPart() = default; 15 16 TestResultPart::TestResultPart(const TestResultPart& other) = default; 17 TestResultPart::TestResultPart(TestResultPart&& other) = default; 18 TestResultPart& TestResultPart::operator=(const TestResultPart& other) = 19 default; 20 TestResultPart& TestResultPart::operator=(TestResultPart&& other) = default; 21 22 // static TypeFromString(const std::string & str,Type * type)23bool TestResultPart::TypeFromString(const std::string& str, Type* type) { 24 if (str == "success") 25 *type = kSuccess; 26 else if (str == "failure") 27 *type = kNonFatalFailure; 28 else if (str == "fatal_failure") 29 *type = kFatalFailure; 30 else 31 return false; 32 return true; 33 } 34 TypeAsString() const35std::string TestResultPart::TypeAsString() const { 36 switch (type) { 37 case kSuccess: 38 return "success"; 39 case kNonFatalFailure: 40 return "failure"; 41 case kFatalFailure: 42 return "fatal_failure"; 43 default: 44 NOTREACHED(); 45 } 46 return "unknown"; 47 } 48 TestResult()49TestResult::TestResult() : status(TEST_UNKNOWN) { 50 } 51 52 TestResult::~TestResult() = default; 53 54 TestResult::TestResult(const TestResult& other) = default; 55 TestResult::TestResult(TestResult&& other) = default; 56 TestResult& TestResult::operator=(const TestResult& other) = default; 57 TestResult& TestResult::operator=(TestResult&& other) = default; 58 StatusAsString() const59std::string TestResult::StatusAsString() const { 60 switch (status) { 61 case TEST_UNKNOWN: 62 return "UNKNOWN"; 63 case TEST_SUCCESS: 64 return "SUCCESS"; 65 case TEST_FAILURE: 66 return "FAILURE"; 67 case TEST_FAILURE_ON_EXIT: 68 return "FAILURE_ON_EXIT"; 69 case TEST_CRASH: 70 return "CRASH"; 71 case TEST_TIMEOUT: 72 return "TIMEOUT"; 73 case TEST_SKIPPED: 74 return "SKIPPED"; 75 case TEST_EXCESSIVE_OUTPUT: 76 return "EXCESSIVE_OUTPUT"; 77 // Rely on compiler warnings to ensure all possible values are handled. 78 } 79 80 NOTREACHED(); 81 return std::string(); 82 } 83 GetTestName() const84std::string TestResult::GetTestName() const { 85 size_t dot_pos = full_name.find('.'); 86 CHECK_NE(dot_pos, std::string::npos); 87 return full_name.substr(dot_pos + 1); 88 } 89 GetTestCaseName() const90std::string TestResult::GetTestCaseName() const { 91 size_t dot_pos = full_name.find('.'); 92 CHECK_NE(dot_pos, std::string::npos); 93 return full_name.substr(0, dot_pos); 94 } 95 96 } // namespace base 97