Commit 600105ee by zhanyong.wan

Makes List a random-access data structure. This simplifies the implementation…

Makes List a random-access data structure. This simplifies the implementation and makes it easier to implement test shuffling.
parent b2db677c
...@@ -434,13 +434,14 @@ class TestResult { ...@@ -434,13 +434,14 @@ class TestResult {
TimeInMillis elapsed_time() const { return elapsed_time_; } TimeInMillis elapsed_time() const { return elapsed_time_; }
// Returns the i-th test part result among all the results. i can range // Returns the i-th test part result among all the results. i can range
// from 0 to test_property_count() - 1. If i is not in that range, returns // from 0 to test_property_count() - 1. If i is not in that range, aborts
// NULL. // the program.
const TestPartResult* GetTestPartResult(int i) const; const TestPartResult& GetTestPartResult(int i) const;
// Returns the i-th test property. i can range from 0 to // Returns the i-th test property. i can range from 0 to
// test_property_count() - 1. If i is not in that range, returns NULL. // test_property_count() - 1. If i is not in that range, aborts the
const TestProperty* GetTestProperty(int i) const; // program.
const TestProperty& GetTestProperty(int i) const;
private: private:
friend class DefaultGlobalTestPartResultReporter; friend class DefaultGlobalTestPartResultReporter;
......
...@@ -116,9 +116,7 @@ class ScopedTrace; // Implements scoped trace. ...@@ -116,9 +116,7 @@ class ScopedTrace; // Implements scoped trace.
class TestInfoImpl; // Opaque implementation of TestInfo class TestInfoImpl; // Opaque implementation of TestInfo
class TestResult; // Result of a single Test. class TestResult; // Result of a single Test.
class UnitTestImpl; // Opaque implementation of UnitTest class UnitTestImpl; // Opaque implementation of UnitTest
template <typename E> class List; // A generic list. template <typename E> class List; // A generic list.
template <typename E> class ListNode; // A node in a generic list.
// How many times InitGoogleTest() has been called. // How many times InitGoogleTest() has been called.
extern int g_init_gtest_count; extern int g_init_gtest_count;
......
...@@ -86,12 +86,7 @@ const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { ...@@ -86,12 +86,7 @@ const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {
internal::posix::Abort(); internal::posix::Abort();
} }
const internal::ListNode<TestPartResult>* p = list_->Head(); return list_->GetElement(index);
for (int i = 0; i < index; i++) {
p = p->next();
}
return p->element();
} }
// Returns the number of TestPartResult objects in the array. // Returns the number of TestPartResult objects in the array.
......
...@@ -46,7 +46,6 @@ namespace testing { ...@@ -46,7 +46,6 @@ namespace testing {
namespace { namespace {
using internal::List; using internal::List;
using internal::ListNode;
using internal::String; using internal::String;
using internal::TestProperty; using internal::TestProperty;
using internal::TestPropertyKeyIs; using internal::TestPropertyKeyIs;
...@@ -70,9 +69,10 @@ void ExpectKeyAndValueWereRecordedForId(const List<TestProperty>& properties, ...@@ -70,9 +69,10 @@ void ExpectKeyAndValueWereRecordedForId(const List<TestProperty>& properties,
int id, int id,
const char* suffix) { const char* suffix) {
TestPropertyKeyIs matches_key(IdToKey(id, suffix).c_str()); TestPropertyKeyIs matches_key(IdToKey(id, suffix).c_str());
const ListNode<TestProperty>* node = properties.FindIf(matches_key); const TestProperty* property = properties.FindIf(matches_key);
EXPECT_TRUE(node != NULL) << "expecting " << suffix << " node for id " << id; ASSERT_TRUE(property != NULL)
EXPECT_STREQ(IdToString(id).c_str(), node->element().value()); << "expecting " << suffix << " value for id " << id;
EXPECT_STREQ(IdToString(id).c_str(), property->value());
} }
// Calls a large number of Google Test assertions, where exactly one of them // Calls a large number of Google Test assertions, where exactly one of them
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment