diff options
Diffstat (limited to 'src/gtest-internal-inl.h')
-rw-r--r-- | src/gtest-internal-inl.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h index 589be02e..3abe9a26 100644 --- a/src/gtest-internal-inl.h +++ b/src/gtest-internal-inl.h @@ -430,6 +430,26 @@ class List { return NULL; } + // Returns a pointer to the i-th element of the list, or NULL if i is not + // in range [0, size()). + const E* GetElement(int i) const { + if (i < 0 || i >= size()) + return NULL; + + const ListNode<E>* node = Head(); + for (int index = 0; index < i && node != NULL; ++index, node = node->next()) + continue; + + return node ? &(node->element()) : NULL; + } + + // Returns the i-th element of the list, or default_value if i is not + // in range [0, size()). + E GetElementOr(int i, E default_value) const { + const E* element = GetElement(i); + return element ? *element : default_value; + } + private: ListNode<E>* head_; // The first node of the list. ListNode<E>* last_; // The last node of the list. @@ -765,6 +785,12 @@ class UnitTestImpl { return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed(); } + // Gets the i-th test case among all the test cases. i can range from 0 to + // total_test_case_count() - 1. If i is not in that range, returns NULL. + const TestCase* GetTestCase(int i) const { + return test_cases_.GetElementOr(i, NULL); + } + // Returns the TestResult for the test that's currently running, or // the TestResult for the ad hoc test if no test is running. internal::TestResult* current_test_result(); |