• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BASE_TEST_LAUNCHER_TEST_RESULT_H_
6 #define BASE_TEST_LAUNCHER_TEST_RESULT_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/time/time.h"
12 
13 namespace base {
14 
15 // Structure contains result of a single EXPECT/ASSERT/SUCCESS.
16 struct TestResultPart {
17   enum Type {
18     kSuccess,          // SUCCESS
19     kNonFatalFailure,  // EXPECT
20     kFatalFailure,     // ASSERT
21   };
22   Type type;
23 
24   TestResultPart();
25   ~TestResultPart();
26 
27   TestResultPart(const TestResultPart& other);
28   TestResultPart(TestResultPart&& other);
29   TestResultPart& operator=(const TestResultPart& other);
30   TestResultPart& operator=(TestResultPart&& other);
31 
32   // Convert type to string and back.
33   static bool TypeFromString(const std::string& str, Type* type);
34   std::string TypeAsString() const;
35 
36   // Filename and line of EXPECT/ASSERT.
37   std::string file_name;
38   int line_number;
39 
40   // Message without stacktrace, etc.
41   std::string summary;
42 
43   // Complete message.
44   std::string message;
45 };
46 
47 // Structure containing result of a single test.
48 struct TestResult {
49   enum Status {
50     TEST_UNKNOWN,           // Status not set.
51     TEST_SUCCESS,           // Test passed.
52     TEST_FAILURE,           // Assertion failure (e.g. EXPECT_TRUE, not DCHECK).
53     TEST_FAILURE_ON_EXIT,   // Passed but executable exit code was non-zero.
54     TEST_TIMEOUT,           // Test timed out and was killed.
55     TEST_CRASH,             // Test crashed (includes CHECK/DCHECK failures).
56     TEST_SKIPPED,           // Test skipped (not run at all).
57     TEST_EXCESSIVE_OUTPUT,  // Test exceeded output limit.
58   };
59 
60   TestResult();
61   ~TestResult();
62 
63   TestResult(const TestResult& other);
64   TestResult(TestResult&& other);
65   TestResult& operator=(const TestResult& other);
66   TestResult& operator=(TestResult&& other);
67 
68   // Returns the test status as string (e.g. for display).
69   std::string StatusAsString() const;
70 
71   // Returns the test name (e.g. "B" for "A.B").
72   std::string GetTestName() const;
73 
74   // Returns the test case name (e.g. "A" for "A.B").
75   std::string GetTestCaseName() const;
76 
77   // Returns true if the test has completed (i.e. the test binary exited
78   // normally, possibly with an exit code indicating failure, but didn't crash
79   // or time out in the middle of the test).
completedTestResult80   bool completed() const {
81     return status == TEST_SUCCESS ||
82         status == TEST_FAILURE ||
83         status == TEST_FAILURE_ON_EXIT ||
84         status == TEST_EXCESSIVE_OUTPUT;
85   }
86 
87   // Full name of the test (e.g. "A.B").
88   std::string full_name;
89 
90   Status status;
91 
92   // Time it took to run the test.
93   base::TimeDelta elapsed_time;
94 
95   // Output of just this test (optional).
96   std::string output_snippet;
97 
98   // Information about failed expectations.
99   std::vector<TestResultPart> test_result_parts;
100 };
101 
102 }  // namespace base
103 
104 #endif  // BASE_TEST_LAUNCHER_TEST_RESULT_H_
105