• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors
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 <ostream>
10 
11 #include "base/check_op.h"
12 #include "base/notreached.h"
13 
14 namespace base {
15 
16 TestResultPart::TestResultPart() = default;
17 TestResultPart::~TestResultPart() = default;
18 
19 TestResultPart::TestResultPart(const TestResultPart& other) = default;
20 TestResultPart::TestResultPart(TestResultPart&& other) = default;
21 TestResultPart& TestResultPart::operator=(const TestResultPart& other) =
22     default;
23 TestResultPart& TestResultPart::operator=(TestResultPart&& other) = default;
24 
25 // static
TypeFromString(const std::string & str,Type * type)26 bool TestResultPart::TypeFromString(const std::string& str, Type* type) {
27   if (str == "success")
28     *type = kSuccess;
29   else if (str == "failure")
30     *type = kNonFatalFailure;
31   else if (str == "fatal_failure")
32     *type = kFatalFailure;
33   else if (str == "skip")
34     *type = kSkip;
35   else
36     return false;
37   return true;
38 }
39 
TypeAsString() const40 std::string TestResultPart::TypeAsString() const {
41   switch (type) {
42     case kSuccess:
43       return "success";
44     case kNonFatalFailure:
45       return "failure";
46     case kFatalFailure:
47       return "fatal_failure";
48     case kSkip:
49       return "skip";
50   }
51   return "unknown";
52 }
53 
TestResult()54 TestResult::TestResult() : status(TEST_UNKNOWN) {
55 }
56 
57 TestResult::~TestResult() = default;
58 
59 TestResult::TestResult(const TestResult& other) = default;
60 TestResult::TestResult(TestResult&& other) = default;
61 TestResult& TestResult::operator=(const TestResult& other) = default;
62 TestResult& TestResult::operator=(TestResult&& other) = default;
63 
StatusAsString() const64 std::string TestResult::StatusAsString() const {
65   switch (status) {
66     case TEST_UNKNOWN:
67       return "UNKNOWN";
68     case TEST_SUCCESS:
69       return "SUCCESS";
70     case TEST_FAILURE:
71       return "FAILURE";
72     case TEST_FAILURE_ON_EXIT:
73       return "FAILURE_ON_EXIT";
74     case TEST_CRASH:
75       return "CRASH";
76     case TEST_TIMEOUT:
77       return "TIMEOUT";
78     case TEST_SKIPPED:
79       return "SKIPPED";
80     case TEST_EXCESSIVE_OUTPUT:
81       return "EXCESSIVE_OUTPUT";
82     case TEST_NOT_RUN:
83       return "NOTRUN";
84       // Rely on compiler warnings to ensure all possible values are handled.
85   }
86 
87   NOTREACHED();
88   return std::string();
89 }
90 
GetTestName() const91 std::string TestResult::GetTestName() const {
92   size_t dot_pos = full_name.find('.');
93   CHECK_NE(dot_pos, std::string::npos);
94   return full_name.substr(dot_pos + 1);
95 }
96 
GetTestCaseName() const97 std::string TestResult::GetTestCaseName() const {
98   size_t dot_pos = full_name.find('.');
99   CHECK_NE(dot_pos, std::string::npos);
100   return full_name.substr(0, dot_pos);
101 }
102 
AddLink(const std::string & name,const std::string & url)103 void TestResult::AddLink(const std::string& name, const std::string& url) {
104   auto [it, inserted] = links.insert({name, url});
105   DCHECK(inserted) << name << " is already used as a link name. Ignoring...";
106 }
107 
AddTag(const std::string & name,const std::string & value)108 void TestResult::AddTag(const std::string& name, const std::string& value) {
109   tags[name].push_back(value);
110 }
111 
AddProperty(const std::string & name,const std::string & value)112 void TestResult::AddProperty(const std::string& name,
113                              const std::string& value) {
114   auto [it, inserted] = properties.insert({name, value});
115   DCHECK(inserted) << name
116                    << " is already used as a property name. Ignoring...";
117 }
118 
119 }  // namespace base
120