Moves TestResult from gtest-internal-inl.h to gtest.h to prepare for the even listener API work (by Vlad Losev); cleans up the scons script (by Zhanyong Wan).
This commit is contained in:
@@ -472,102 +472,6 @@ class TestPropertyKeyIs {
|
||||
String key_;
|
||||
};
|
||||
|
||||
// The result of a single Test. This includes a list of
|
||||
// TestPartResults, a list of TestProperties, a count of how many
|
||||
// death tests there are in the Test, and how much time it took to run
|
||||
// the Test.
|
||||
//
|
||||
// TestResult is not copyable.
|
||||
class TestResult {
|
||||
public:
|
||||
// Creates an empty TestResult.
|
||||
TestResult();
|
||||
|
||||
// D'tor. Do not inherit from TestResult.
|
||||
~TestResult();
|
||||
|
||||
// Gets the list of TestPartResults.
|
||||
const internal::List<TestPartResult> & test_part_results() const {
|
||||
return test_part_results_;
|
||||
}
|
||||
|
||||
// Gets the list of TestProperties.
|
||||
const internal::List<internal::TestProperty> & test_properties() const {
|
||||
return test_properties_;
|
||||
}
|
||||
|
||||
// Gets the number of successful test parts.
|
||||
int successful_part_count() const;
|
||||
|
||||
// Gets the number of failed test parts.
|
||||
int failed_part_count() const;
|
||||
|
||||
// Gets the number of all test parts. This is the sum of the number
|
||||
// of successful test parts and the number of failed test parts.
|
||||
int total_part_count() const;
|
||||
|
||||
// Returns true iff the test passed (i.e. no test part failed).
|
||||
bool Passed() const { return !Failed(); }
|
||||
|
||||
// Returns true iff the test failed.
|
||||
bool Failed() const { return failed_part_count() > 0; }
|
||||
|
||||
// Returns true iff the test fatally failed.
|
||||
bool HasFatalFailure() const;
|
||||
|
||||
// Returns true iff the test has a non-fatal failure.
|
||||
bool HasNonfatalFailure() const;
|
||||
|
||||
// Returns the elapsed time, in milliseconds.
|
||||
TimeInMillis elapsed_time() const { return elapsed_time_; }
|
||||
|
||||
// Sets the elapsed time.
|
||||
void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
|
||||
|
||||
// Adds a test part result to the list.
|
||||
void AddTestPartResult(const TestPartResult& test_part_result);
|
||||
|
||||
// Adds a test property to the list. The property is validated and may add
|
||||
// a non-fatal failure if invalid (e.g., if it conflicts with reserved
|
||||
// key names). If a property is already recorded for the same key, the
|
||||
// value will be updated, rather than storing multiple values for the same
|
||||
// key.
|
||||
void RecordProperty(const internal::TestProperty& test_property);
|
||||
|
||||
// Adds a failure if the key is a reserved attribute of Google Test
|
||||
// testcase tags. Returns true if the property is valid.
|
||||
// TODO(russr): Validate attribute names are legal and human readable.
|
||||
static bool ValidateTestProperty(const internal::TestProperty& test_property);
|
||||
|
||||
// Returns the death test count.
|
||||
int death_test_count() const { return death_test_count_; }
|
||||
|
||||
// Increments the death test count, returning the new count.
|
||||
int increment_death_test_count() { return ++death_test_count_; }
|
||||
|
||||
// Clears the test part results.
|
||||
void ClearTestPartResults() { test_part_results_.Clear(); }
|
||||
|
||||
// Clears the object.
|
||||
void Clear();
|
||||
private:
|
||||
// Protects mutable state of the property list and of owned properties, whose
|
||||
// values may be updated.
|
||||
internal::Mutex test_properites_mutex_;
|
||||
|
||||
// The list of TestPartResults
|
||||
internal::List<TestPartResult> test_part_results_;
|
||||
// The list of TestProperties
|
||||
internal::List<internal::TestProperty> test_properties_;
|
||||
// Running count of death tests.
|
||||
int death_test_count_;
|
||||
// The elapsed time, in milliseconds.
|
||||
TimeInMillis elapsed_time_;
|
||||
|
||||
// We disallow copying TestResult.
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
|
||||
}; // class TestResult
|
||||
|
||||
class TestInfoImpl {
|
||||
public:
|
||||
TestInfoImpl(TestInfo* parent, const char* test_case_name,
|
||||
|
||||
29
src/gtest.cc
29
src/gtest.cc
@@ -1778,7 +1778,9 @@ String AppendUserMessage(const String& gtest_msg,
|
||||
|
||||
// Creates an empty TestResult.
|
||||
TestResult::TestResult()
|
||||
: death_test_count_(0),
|
||||
: test_part_results_(new List<TestPartResult>),
|
||||
test_properties_(new List<TestProperty>),
|
||||
death_test_count_(0),
|
||||
elapsed_time_(0) {
|
||||
}
|
||||
|
||||
@@ -1786,9 +1788,14 @@ TestResult::TestResult()
|
||||
TestResult::~TestResult() {
|
||||
}
|
||||
|
||||
// Clears the test part results.
|
||||
void TestResult::ClearTestPartResults() {
|
||||
test_part_results_->Clear();
|
||||
}
|
||||
|
||||
// Adds a test part result to the list.
|
||||
void TestResult::AddTestPartResult(const TestPartResult& test_part_result) {
|
||||
test_part_results_.PushBack(test_part_result);
|
||||
test_part_results_->PushBack(test_part_result);
|
||||
}
|
||||
|
||||
// Adds a test property to the list. If a property with the same key as the
|
||||
@@ -1800,9 +1807,9 @@ void TestResult::RecordProperty(const TestProperty& test_property) {
|
||||
}
|
||||
MutexLock lock(&test_properites_mutex_);
|
||||
ListNode<TestProperty>* const node_with_matching_key =
|
||||
test_properties_.FindIf(TestPropertyKeyIs(test_property.key()));
|
||||
test_properties_->FindIf(TestPropertyKeyIs(test_property.key()));
|
||||
if (node_with_matching_key == NULL) {
|
||||
test_properties_.PushBack(test_property);
|
||||
test_properties_->PushBack(test_property);
|
||||
return;
|
||||
}
|
||||
TestProperty& property_with_matching_key = node_with_matching_key->element();
|
||||
@@ -1826,8 +1833,8 @@ bool TestResult::ValidateTestProperty(const TestProperty& test_property) {
|
||||
|
||||
// Clears the object.
|
||||
void TestResult::Clear() {
|
||||
test_part_results_.Clear();
|
||||
test_properties_.Clear();
|
||||
test_part_results_->Clear();
|
||||
test_properties_->Clear();
|
||||
death_test_count_ = 0;
|
||||
elapsed_time_ = 0;
|
||||
}
|
||||
@@ -1839,7 +1846,7 @@ static bool TestPartPassed(const TestPartResult & result) {
|
||||
|
||||
// Gets the number of successful test parts.
|
||||
int TestResult::successful_part_count() const {
|
||||
return test_part_results_.CountIf(TestPartPassed);
|
||||
return test_part_results_->CountIf(TestPartPassed);
|
||||
}
|
||||
|
||||
// Returns true iff the test part failed.
|
||||
@@ -1849,7 +1856,7 @@ static bool TestPartFailed(const TestPartResult & result) {
|
||||
|
||||
// Gets the number of failed test parts.
|
||||
int TestResult::failed_part_count() const {
|
||||
return test_part_results_.CountIf(TestPartFailed);
|
||||
return test_part_results_->CountIf(TestPartFailed);
|
||||
}
|
||||
|
||||
// Returns true iff the test part fatally failed.
|
||||
@@ -1859,7 +1866,7 @@ static bool TestPartFatallyFailed(const TestPartResult& result) {
|
||||
|
||||
// Returns true iff the test fatally failed.
|
||||
bool TestResult::HasFatalFailure() const {
|
||||
return test_part_results_.CountIf(TestPartFatallyFailed) > 0;
|
||||
return test_part_results_->CountIf(TestPartFatallyFailed) > 0;
|
||||
}
|
||||
|
||||
// Returns true iff the test part non-fatally failed.
|
||||
@@ -1869,13 +1876,13 @@ static bool TestPartNonfatallyFailed(const TestPartResult& result) {
|
||||
|
||||
// Returns true iff the test has a non-fatal failure.
|
||||
bool TestResult::HasNonfatalFailure() const {
|
||||
return test_part_results_.CountIf(TestPartNonfatallyFailed) > 0;
|
||||
return test_part_results_->CountIf(TestPartNonfatallyFailed) > 0;
|
||||
}
|
||||
|
||||
// Gets the number of all test parts. This is the sum of the number
|
||||
// of successful test parts and the number of failed test parts.
|
||||
int TestResult::total_part_count() const {
|
||||
return test_part_results_.size();
|
||||
return test_part_results_->size();
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
Reference in New Issue
Block a user