Publishing R3
[platform/upstream/dldt.git] / inference-engine / tests / libs / gtest / googletest / include / gtest / gtest-test-part.h
1 // Copyright (C) 2018 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5
6 #ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
7 #define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
8
9 #include <iosfwd>
10 #include <vector>
11 #include "gtest/internal/gtest-internal.h"
12 #include "gtest/internal/gtest-string.h"
13
14 namespace testing {
15
16 // A copyable object representing the result of a test part (i.e. an
17 // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
18 //
19 // Don't inherit from TestPartResult as its destructor is not virtual.
20 class GTEST_API_ TestPartResult {
21  public:
22   // The possible outcomes of a test part (i.e. an assertion or an
23   // explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
24   enum Type {
25     kSuccess,          // Succeeded.
26     kNonFatalFailure,  // Failed but the test can continue.
27     kFatalFailure,     // Failed and the test should be terminated.
28     kSkip              // Skipped.
29   };
30
31   // C'tor.  TestPartResult does NOT have a default constructor.
32   // Always use this constructor (with parameters) to create a
33   // TestPartResult object.
34   TestPartResult(Type a_type,
35                  const char* a_file_name,
36                  int a_line_number,
37                  const char* a_message)
38       : type_(a_type),
39         file_name_(a_file_name == NULL ? "" : a_file_name),
40         line_number_(a_line_number),
41         summary_(ExtractSummary(a_message)),
42         message_(a_message) {
43   }
44
45   // Gets the outcome of the test part.
46   Type type() const { return type_; }
47
48   // Gets the name of the source file where the test part took place, or
49   // NULL if it's unknown.
50   const char* file_name() const {
51     return file_name_.empty() ? NULL : file_name_.c_str();
52   }
53
54   // Gets the line in the source file where the test part took place,
55   // or -1 if it's unknown.
56   int line_number() const { return line_number_; }
57
58   // Gets the summary of the failure message.
59   const char* summary() const { return summary_.c_str(); }
60
61   // Gets the message associated with the test part.
62   const char* message() const { return message_.c_str(); }
63
64   // Returns true iff the test part was skipped.
65   bool skipped() const { return type_ == kSkip; }
66
67   // Returns true iff the test part passed.
68   bool passed() const { return type_ == kSuccess; }
69
70   // Returns true iff the test part non-fatally failed.
71   bool nonfatally_failed() const { return type_ == kNonFatalFailure; }
72
73   // Returns true iff the test part fatally failed.
74   bool fatally_failed() const { return type_ == kFatalFailure; }
75
76   // Returns true iff the test part failed.
77   bool failed() const { return fatally_failed() || nonfatally_failed(); }
78
79  private:
80   Type type_;
81
82   // Gets the summary of the failure message by omitting the stack
83   // trace in it.
84   static std::string ExtractSummary(const char* message);
85
86   // The name of the source file where the test part took place, or
87   // "" if the source file is unknown.
88   std::string file_name_;
89   // The line in the source file where the test part took place, or -1
90   // if the line number is unknown.
91   int line_number_;
92   std::string summary_;  // The test failure summary.
93   std::string message_;  // The test failure message.
94 };
95
96 // Prints a TestPartResult object.
97 std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
98
99 // An array of TestPartResult objects.
100 //
101 // Don't inherit from TestPartResultArray as its destructor is not
102 // virtual.
103 class GTEST_API_ TestPartResultArray {
104  public:
105   TestPartResultArray() {}
106
107   // Appends the given TestPartResult to the array.
108   void Append(const TestPartResult& result);
109
110   // Returns the TestPartResult at the given index (0-based).
111   const TestPartResult& GetTestPartResult(int index) const;
112
113   // Returns the number of TestPartResult objects in the array.
114   int size() const;
115
116  private:
117   std::vector<TestPartResult> array_;
118
119   GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray);
120 };
121
122 // This interface knows how to report a test part result.
123 class TestPartResultReporterInterface {
124  public:
125   virtual ~TestPartResultReporterInterface() {}
126
127   virtual void ReportTestPartResult(const TestPartResult& result) = 0;
128 };
129
130 namespace internal {
131
132 // This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a
133 // statement generates new fatal failures. To do so it registers itself as the
134 // current test part result reporter. Besides checking if fatal failures were
135 // reported, it only delegates the reporting to the former result reporter.
136 // The original result reporter is restored in the destructor.
137 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
138 class GTEST_API_ HasNewFatalFailureHelper
139     : public TestPartResultReporterInterface {
140  public:
141   HasNewFatalFailureHelper();
142   virtual ~HasNewFatalFailureHelper();
143   virtual void ReportTestPartResult(const TestPartResult& result);
144   bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
145  private:
146   bool has_new_fatal_failure_;
147   TestPartResultReporterInterface* original_reporter_;
148
149   GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper);
150 };
151
152 }  // namespace internal
153
154 }  // namespace testing
155
156 #endif  // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_