OLD | NEW |
1 // Copyright 2008, Google Inc. | 1 // Copyright 2008, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include <iosfwd> | 36 #include <iosfwd> |
37 #include <gtest/internal/gtest-internal.h> | 37 #include <gtest/internal/gtest-internal.h> |
38 #include <gtest/internal/gtest-string.h> | 38 #include <gtest/internal/gtest-string.h> |
39 | 39 |
40 namespace testing { | 40 namespace testing { |
41 | 41 |
42 // A copyable object representing the result of a test part (i.e. an | 42 // A copyable object representing the result of a test part (i.e. an |
43 // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()). | 43 // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()). |
44 // | 44 // |
45 // Don't inherit from TestPartResult as its destructor is not virtual. | 45 // Don't inherit from TestPartResult as its destructor is not virtual. |
46 class TestPartResult { | 46 class GOOGLE_TEST_API TestPartResult { |
47 public: | 47 public: |
48 // The possible outcomes of a test part (i.e. an assertion or an | 48 // The possible outcomes of a test part (i.e. an assertion or an |
49 // explicit SUCCEED(), FAIL(), or ADD_FAILURE()). | 49 // explicit SUCCEED(), FAIL(), or ADD_FAILURE()). |
50 enum Type { | 50 enum Type { |
51 kSuccess, // Succeeded. | 51 kSuccess, // Succeeded. |
52 kNonFatalFailure, // Failed but the test can continue. | 52 kNonFatalFailure, // Failed but the test can continue. |
53 kFatalFailure // Failed and the test should be terminated. | 53 kFatalFailure // Failed and the test should be terminated. |
54 }; | 54 }; |
55 | 55 |
56 // C'tor. TestPartResult does NOT have a default constructor. | 56 // C'tor. TestPartResult does NOT have a default constructor. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // NULL if the source file is unknown. | 106 // NULL if the source file is unknown. |
107 internal::String file_name_; | 107 internal::String file_name_; |
108 // The line in the source file where the test part took place, or -1 | 108 // The line in the source file where the test part took place, or -1 |
109 // if the line number is unknown. | 109 // if the line number is unknown. |
110 int line_number_; | 110 int line_number_; |
111 internal::String summary_; // The test failure summary. | 111 internal::String summary_; // The test failure summary. |
112 internal::String message_; // The test failure message. | 112 internal::String message_; // The test failure message. |
113 }; | 113 }; |
114 | 114 |
115 // Prints a TestPartResult object. | 115 // Prints a TestPartResult object. |
116 std::ostream& operator<<(std::ostream& os, const TestPartResult& result); | 116 GOOGLE_TEST_API std::ostream& operator<<(std::ostream& os, const TestPartResult&
result); |
117 | 117 |
118 // An array of TestPartResult objects. | 118 // An array of TestPartResult objects. |
119 // | 119 // |
120 // We define this class as we cannot use STL containers when compiling | 120 // We define this class as we cannot use STL containers when compiling |
121 // Google Test with MSVC 7.1 and exceptions disabled. | 121 // Google Test with MSVC 7.1 and exceptions disabled. |
122 // | 122 // |
123 // Don't inherit from TestPartResultArray as its destructor is not | 123 // Don't inherit from TestPartResultArray as its destructor is not |
124 // virtual. | 124 // virtual. |
125 class TestPartResultArray { | 125 class GOOGLE_TEST_API TestPartResultArray { |
126 public: | 126 public: |
127 TestPartResultArray(); | 127 TestPartResultArray(); |
128 ~TestPartResultArray(); | 128 ~TestPartResultArray(); |
129 | 129 |
130 // Appends the given TestPartResult to the array. | 130 // Appends the given TestPartResult to the array. |
131 void Append(const TestPartResult& result); | 131 void Append(const TestPartResult& result); |
132 | 132 |
133 // Returns the TestPartResult at the given index (0-based). | 133 // Returns the TestPartResult at the given index (0-based). |
134 const TestPartResult& GetTestPartResult(int index) const; | 134 const TestPartResult& GetTestPartResult(int index) const; |
135 | 135 |
136 // Returns the number of TestPartResult objects in the array. | 136 // Returns the number of TestPartResult objects in the array. |
137 int size() const; | 137 int size() const; |
138 private: | 138 private: |
139 // Internally we use a Vector to implement the array. | 139 // Internally we use a Vector to implement the array. |
140 internal::Vector<TestPartResult>* const array_; | 140 internal::Vector<TestPartResult>* const array_; |
141 | 141 |
142 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray); | 142 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray); |
143 }; | 143 }; |
144 | 144 |
145 // This interface knows how to report a test part result. | 145 // This interface knows how to report a test part result. |
146 class TestPartResultReporterInterface { | 146 class GOOGLE_TEST_API TestPartResultReporterInterface { |
147 public: | 147 public: |
148 virtual ~TestPartResultReporterInterface() {} | 148 virtual ~TestPartResultReporterInterface() {} |
149 | 149 |
150 virtual void ReportTestPartResult(const TestPartResult& result) = 0; | 150 virtual void ReportTestPartResult(const TestPartResult& result) = 0; |
151 }; | 151 }; |
152 | 152 |
153 namespace internal { | 153 namespace internal { |
154 | 154 |
155 // This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a | 155 // This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a |
156 // statement generates new fatal failures. To do so it registers itself as the | 156 // statement generates new fatal failures. To do so it registers itself as the |
157 // current test part result reporter. Besides checking if fatal failures were | 157 // current test part result reporter. Besides checking if fatal failures were |
158 // reported, it only delegates the reporting to the former result reporter. | 158 // reported, it only delegates the reporting to the former result reporter. |
159 // The original result reporter is restored in the destructor. | 159 // The original result reporter is restored in the destructor. |
160 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. | 160 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
161 class HasNewFatalFailureHelper : public TestPartResultReporterInterface { | 161 class GOOGLE_TEST_API HasNewFatalFailureHelper : public TestPartResultReporterIn
terface { |
162 public: | 162 public: |
163 HasNewFatalFailureHelper(); | 163 HasNewFatalFailureHelper(); |
164 virtual ~HasNewFatalFailureHelper(); | 164 virtual ~HasNewFatalFailureHelper(); |
165 virtual void ReportTestPartResult(const TestPartResult& result); | 165 virtual void ReportTestPartResult(const TestPartResult& result); |
166 bool has_new_fatal_failure() const { return has_new_fatal_failure_; } | 166 bool has_new_fatal_failure() const { return has_new_fatal_failure_; } |
167 private: | 167 private: |
168 bool has_new_fatal_failure_; | 168 bool has_new_fatal_failure_; |
169 TestPartResultReporterInterface* original_reporter_; | 169 TestPartResultReporterInterface* original_reporter_; |
170 | 170 |
171 GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper); | 171 GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper); |
172 }; | 172 }; |
173 | 173 |
174 } // namespace internal | 174 } // namespace internal |
175 | 175 |
176 } // namespace testing | 176 } // namespace testing |
177 | 177 |
178 #endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ | 178 #endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ |
OLD | NEW |