tesseract v5.3.3.20231005
gtest-test-part.h File Reference
#include <iosfwd>
#include <vector>
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-string.h"

Go to the source code of this file.

Functions

 GTEST_DISABLE_MSC_WARNINGS_PUSH_ (4251) namespace testing
 

Function Documentation

◆ GTEST_DISABLE_MSC_WARNINGS_PUSH_()

GTEST_DISABLE_MSC_WARNINGS_PUSH_ ( 4251  )

Definition at line 40 of file gtest-test-part.h.

43 {
44
45// A copyable object representing the result of a test part (i.e. an
46// assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
47//
48// Don't inherit from TestPartResult as its destructor is not virtual.
49class GTEST_API_ TestPartResult {
50 public:
51 // The possible outcomes of a test part (i.e. an assertion or an
52 // explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
53 enum Type {
54 kSuccess, // Succeeded.
55 kNonFatalFailure, // Failed but the test can continue.
56 kFatalFailure, // Failed and the test should be terminated.
57 kSkip // Skipped.
58 };
59
60 // C'tor. TestPartResult does NOT have a default constructor.
61 // Always use this constructor (with parameters) to create a
62 // TestPartResult object.
63 TestPartResult(Type a_type, const char* a_file_name, int a_line_number,
64 const char* a_message)
65 : type_(a_type),
66 file_name_(a_file_name == nullptr ? "" : a_file_name),
67 line_number_(a_line_number),
68 summary_(ExtractSummary(a_message)),
69 message_(a_message) {}
70
71 // Gets the outcome of the test part.
72 Type type() const { return type_; }
73
74 // Gets the name of the source file where the test part took place, or
75 // NULL if it's unknown.
76 const char* file_name() const {
77 return file_name_.empty() ? nullptr : file_name_.c_str();
78 }
79
80 // Gets the line in the source file where the test part took place,
81 // or -1 if it's unknown.
82 int line_number() const { return line_number_; }
83
84 // Gets the summary of the failure message.
85 const char* summary() const { return summary_.c_str(); }
86
87 // Gets the message associated with the test part.
88 const char* message() const { return message_.c_str(); }
89
90 // Returns true if and only if the test part was skipped.
91 bool skipped() const { return type_ == kSkip; }
92
93 // Returns true if and only if the test part passed.
94 bool passed() const { return type_ == kSuccess; }
95
96 // Returns true if and only if the test part non-fatally failed.
97 bool nonfatally_failed() const { return type_ == kNonFatalFailure; }
98
99 // Returns true if and only if the test part fatally failed.
100 bool fatally_failed() const { return type_ == kFatalFailure; }
101
102 // Returns true if and only if the test part failed.
103 bool failed() const { return fatally_failed() || nonfatally_failed(); }
104
105 private:
106 Type type_;
107
108 // Gets the summary of the failure message by omitting the stack
109 // trace in it.
110 static std::string ExtractSummary(const char* message);
111
112 // The name of the source file where the test part took place, or
113 // "" if the source file is unknown.
114 std::string file_name_;
115 // The line in the source file where the test part took place, or -1
116 // if the line number is unknown.
117 int line_number_;
118 std::string summary_; // The test failure summary.
119 std::string message_; // The test failure message.
120};
121
122// Prints a TestPartResult object.
123std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
124
125// An array of TestPartResult objects.
126//
127// Don't inherit from TestPartResultArray as its destructor is not
128// virtual.
129class GTEST_API_ TestPartResultArray {
130 public:
131 TestPartResultArray() {}
132
133 // Appends the given TestPartResult to the array.
134 void Append(const TestPartResult& result);
135
136 // Returns the TestPartResult at the given index (0-based).
137 const TestPartResult& GetTestPartResult(int index) const;
138
139 // Returns the number of TestPartResult objects in the array.
140 int size() const;
141
142 private:
143 std::vector<TestPartResult> array_;
144
145 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray);
146};
147
148// This interface knows how to report a test part result.
149class GTEST_API_ TestPartResultReporterInterface {
150 public:
151 virtual ~TestPartResultReporterInterface() {}
152
153 virtual void ReportTestPartResult(const TestPartResult& result) = 0;
154};
155
156namespace internal {
157
158// This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a
159// statement generates new fatal failures. To do so it registers itself as the
160// current test part result reporter. Besides checking if fatal failures were
161// reported, it only delegates the reporting to the former result reporter.
162// The original result reporter is restored in the destructor.
163// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
164class GTEST_API_ HasNewFatalFailureHelper
165 : public TestPartResultReporterInterface {
166 public:
167 HasNewFatalFailureHelper();
168 ~HasNewFatalFailureHelper() override;
169 void ReportTestPartResult(const TestPartResult& result) override;
170 bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
171 private:
172 bool has_new_fatal_failure_;
173 TestPartResultReporterInterface* original_reporter_;
174
175 GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper);
176};
177
178} // namespace internal
179
180} // namespace testing
#define GTEST_API_
Definition: gtest-port.h:779
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:697
std::ostream & operator<<(std::ostream &os, const Message &sb)
type
Definition: upload.py:458