diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-29 07:10:46 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-29 07:10:46 +0000 |
commit | e9002a949c6ab690c4e178d45f1ecb876c535aa4 (patch) | |
tree | 3e9872db48aa6be97987ef2fa7d100aae24e85c3 /net/base | |
parent | 86c72c63d6d70e040bc6a10f09a1b8a190f6d3c6 (diff) | |
download | chromium_src-e9002a949c6ab690c4e178d45f1ecb876c535aa4.zip chromium_src-e9002a949c6ab690c4e178d45f1ecb876c535aa4.tar.gz chromium_src-e9002a949c6ab690c4e178d45f1ecb876c535aa4.tar.bz2 |
Cleanup the unittest helpers in load_log_unittest.h.
Consolidates all the callers to using the testing::AssertionResult() flavor, and renames them to have "Event" in the name. This rename is in anticipation of adding testers for other entry types.
BUG=NONE
TEST=existing
Review URL: http://codereview.chromium.org/551135
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37501 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/host_resolver_impl_unittest.cc | 44 | ||||
-rw-r--r-- | net/base/load_log_unittest.cc | 44 | ||||
-rw-r--r-- | net/base/load_log_unittest.h | 75 |
3 files changed, 89 insertions, 74 deletions
diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc index 68bd8a6..c2cd1b5 100644 --- a/net/base/host_resolver_impl_unittest.cc +++ b/net/base/host_resolver_impl_unittest.cc @@ -194,10 +194,8 @@ TEST_F(HostResolverImplTest, SynchronousLookup) { EXPECT_EQ(OK, err); EXPECT_EQ(2u, log->entries().size()); - ExpectLogContains(log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_BEGIN); - ExpectLogContains(log, 1, LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_END); + EXPECT_TRUE(LogContainsBeginEvent(*log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL)); + EXPECT_TRUE(LogContainsEndEvent(*log, 1, LoadLog::TYPE_HOST_RESOLVER_IMPL)); const struct addrinfo* ainfo = adrlist.head(); EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); @@ -226,8 +224,7 @@ TEST_F(HostResolverImplTest, AsynchronousLookup) { EXPECT_EQ(ERR_IO_PENDING, err); EXPECT_EQ(1u, log->entries().size()); - ExpectLogContains(log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_BEGIN); + EXPECT_TRUE(LogContainsBeginEvent(*log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL)); MessageLoop::current()->Run(); @@ -235,8 +232,7 @@ TEST_F(HostResolverImplTest, AsynchronousLookup) { ASSERT_EQ(OK, callback_result_); EXPECT_EQ(2u, log->entries().size()); - ExpectLogContains(log, 1, LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_END); + EXPECT_TRUE(LogContainsEndEvent(*log, 1, LoadLog::TYPE_HOST_RESOLVER_IMPL)); const struct addrinfo* ainfo = adrlist.head(); EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); @@ -273,11 +269,10 @@ TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { resolver_proc->Signal(); EXPECT_EQ(3u, log->entries().size()); - ExpectLogContains(log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_BEGIN); - ExpectLogContains(log, 1, LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); - ExpectLogContains(log, 2, LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_END); + EXPECT_TRUE(LogContainsBeginEvent(*log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL)); + EXPECT_TRUE(LogContainsEvent( + *log, 1, LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE)); + EXPECT_TRUE(LogContainsEndEvent(*log, 2, LoadLog::TYPE_HOST_RESOLVER_IMPL)); EXPECT_FALSE(callback_called_); } @@ -827,18 +822,17 @@ TEST_F(HostResolverImplTest, Observers) { EXPECT_EQ(OK, rv); EXPECT_EQ(6u, log->entries().size()); - ExpectLogContains(log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_BEGIN); - ExpectLogContains(log, 1, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, - LoadLog::PHASE_BEGIN); - ExpectLogContains(log, 2, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, - LoadLog::PHASE_END); - ExpectLogContains(log, 3, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH, - LoadLog::PHASE_BEGIN); - ExpectLogContains(log, 4, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH, - LoadLog::PHASE_END); - ExpectLogContains(log, 5, LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_END); + EXPECT_TRUE(LogContainsBeginEvent(*log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL)); + EXPECT_TRUE(LogContainsBeginEvent( + *log, 1, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART)); + EXPECT_TRUE(LogContainsEndEvent( + *log, 2, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART)); + EXPECT_TRUE(LogContainsBeginEvent( + *log, 3, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH)); + EXPECT_TRUE(LogContainsEndEvent( + *log, 4, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH)); + EXPECT_TRUE(LogContainsEndEvent( + *log, 5, LoadLog::TYPE_HOST_RESOLVER_IMPL)); EXPECT_EQ(1U, observer.start_log.size()); EXPECT_EQ(1U, observer.finish_log.size()); diff --git a/net/base/load_log_unittest.cc b/net/base/load_log_unittest.cc index d3f5ed5..c55cf9b 100644 --- a/net/base/load_log_unittest.cc +++ b/net/base/load_log_unittest.cc @@ -41,15 +41,16 @@ TEST(LoadLogTest, Basic) { EXPECT_EQ(3u, log->entries().size()); EXPECT_EQ(0u, log->num_entries_truncated()); - ExpectLogContains(log, 0, MakeTime(0), LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_BEGIN); + EXPECT_TRUE(LogContainsEventAtTime( + *log, 0, MakeTime(0), LoadLog::TYPE_HOST_RESOLVER_IMPL, + LoadLog::PHASE_BEGIN)); - ExpectLogContains(log, 1, MakeTime(2), LoadLog::TYPE_CANCELLED, - LoadLog::PHASE_NONE); + EXPECT_TRUE(LogContainsEventAtTime( + *log, 1, MakeTime(2), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE)); - ExpectLogContains(log, 2, MakeTime(11), - LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, - LoadLog::PHASE_END); + EXPECT_TRUE(LogContainsEventAtTime( + *log, 2, MakeTime(11), LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, + LoadLog::PHASE_END)); } // Test that the log's size is strictly bounded. @@ -68,9 +69,8 @@ TEST(LoadLogTest, Truncation) { EXPECT_EQ(0u, log->num_entries_truncated()); // Check the last entry. - ExpectLogContains(log, 9, MakeTime(9), - LoadLog::TYPE_CANCELLED, - LoadLog::PHASE_NONE); + EXPECT_TRUE(LogContainsEventAtTime( + *log, 9, MakeTime(9), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE)); // Add three entries while maxed out (will cause truncation) log->Add(LoadLog::Entry(MakeTime(0), @@ -87,9 +87,8 @@ TEST(LoadLogTest, Truncation) { EXPECT_EQ(3u, log->num_entries_truncated()); // Check the last entry -- it should be the final entry we added. - ExpectLogContains(log, 9, MakeTime(2), - LoadLog::TYPE_CANCELLED, - LoadLog::PHASE_NONE); + EXPECT_TRUE(LogContainsEventAtTime( + *log, 9, MakeTime(2), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE)); } TEST(LoadLogTest, Append) { @@ -117,14 +116,17 @@ TEST(LoadLogTest, Append) { EXPECT_EQ(3u, log1->entries().size()); EXPECT_EQ(0u, log1->num_entries_truncated()); - ExpectLogContains(log1, 0, MakeTime(0), LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_BEGIN); + EXPECT_TRUE(LogContainsEventAtTime( + *log1, 0, MakeTime(0), LoadLog::TYPE_HOST_RESOLVER_IMPL, + LoadLog::PHASE_BEGIN)); - ExpectLogContains(log1, 1, MakeTime(3), LoadLog::TYPE_CANCELLED, - LoadLog::PHASE_NONE); + EXPECT_TRUE(LogContainsEventAtTime( + *log1, 1, MakeTime(3), LoadLog::TYPE_CANCELLED, + LoadLog::PHASE_NONE)); - ExpectLogContains(log1, 2, MakeTime(9), LoadLog::TYPE_HOST_RESOLVER_IMPL, - LoadLog::PHASE_END); + EXPECT_TRUE(LogContainsEventAtTime( + *log1, 2, MakeTime(9), LoadLog::TYPE_HOST_RESOLVER_IMPL, + LoadLog::PHASE_END)); } TEST(LoadLogTest, AppendWithTruncation) { @@ -152,8 +154,8 @@ TEST(LoadLogTest, AppendWithTruncation) { EXPECT_EQ(2u, log1->num_entries_truncated()); // Combined log should end with the final entry of log2. - ExpectLogContains(log1, 9, MakeTime(10), LoadLog::TYPE_CANCELLED, - LoadLog::PHASE_NONE); + EXPECT_TRUE(LogContainsEventAtTime( + *log1, 9, MakeTime(10), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE)); } TEST(LoadLogTest, EventTypeToString) { diff --git a/net/base/load_log_unittest.h b/net/base/load_log_unittest.h index ea9a37d..1efbd46b 100644 --- a/net/base/load_log_unittest.h +++ b/net/base/load_log_unittest.h @@ -18,36 +18,11 @@ inline base::TimeTicks MakeTime(int t) { return ticks; } -// Call gtest's EXPECT_* to verify that |log| contains the specified entry -// at index |i|. -inline void ExpectLogContains(const LoadLog* log, - size_t i, - base::TimeTicks expected_time, - LoadLog::EventType expected_event, - LoadLog::EventPhase expected_phase) { - ASSERT_LT(i, log->entries().size()); - const LoadLog::Entry& entry = log->entries()[i]; - EXPECT_EQ(LoadLog::Entry::TYPE_EVENT, entry.type); - EXPECT_TRUE(expected_time == entry.time); - EXPECT_EQ(expected_event, entry.event.type); - EXPECT_EQ(expected_phase, entry.event.phase); -} - -// Same as above, but without an expectation for the timestamp. -inline void ExpectLogContains(const LoadLog* log, - size_t i, - LoadLog::EventType expected_event, - LoadLog::EventPhase expected_phase) { - ASSERT_LT(i, log->entries().size()); - const LoadLog::Entry& entry = log->entries()[i]; - EXPECT_EQ(LoadLog::Entry::TYPE_EVENT, entry.type); - EXPECT_EQ(expected_event, entry.event.type); - EXPECT_EQ(expected_phase, entry.event.phase); -} - -inline ::testing::AssertionResult LogContains( +inline ::testing::AssertionResult LogContainsEventHelper( const LoadLog& log, int i, // Negative indices are reverse indices. + const base::TimeTicks& expected_time, + bool check_time, LoadLog::EventType expected_event, LoadLog::EventPhase expected_phase) { // Negative indices are reverse indices. @@ -69,9 +44,53 @@ inline ::testing::AssertionResult LogContains( << "Actual phase: " << entry.event.phase << ". Expected phase: " << expected_phase << "."; } + if (check_time) { + if (expected_time != entry.time) { + return ::testing::AssertionFailure() + << "Actual time: " << entry.time.ToInternalValue() + << ". Expected time: " << expected_time.ToInternalValue() + << "."; + } + } return ::testing::AssertionSuccess(); } +inline ::testing::AssertionResult LogContainsEventAtTime( + const LoadLog& log, + int i, // Negative indices are reverse indices. + const base::TimeTicks& expected_time, + LoadLog::EventType expected_event, + LoadLog::EventPhase expected_phase) { + return LogContainsEventHelper(log, i, expected_time, true, + expected_event, expected_phase); +} + +// Version without timestamp. +inline ::testing::AssertionResult LogContainsEvent( + const LoadLog& log, + int i, // Negative indices are reverse indices. + LoadLog::EventType expected_event, + LoadLog::EventPhase expected_phase) { + return LogContainsEventHelper(log, i, base::TimeTicks(), false, + expected_event, expected_phase); +} + +// Version for PHASE_BEGIN (and no timestamp). +inline ::testing::AssertionResult LogContainsBeginEvent( + const LoadLog& log, + int i, // Negative indices are reverse indices. + LoadLog::EventType expected_event) { + return LogContainsEvent(log, i, expected_event, LoadLog::PHASE_BEGIN); +} + +// Version for PHASE_END (and no timestamp). +inline ::testing::AssertionResult LogContainsEndEvent( + const LoadLog& log, + int i, // Negative indices are reverse indices. + LoadLog::EventType expected_event) { + return LogContainsEvent(log, i, expected_event, LoadLog::PHASE_END); +} + // Expect that the log contains an event, but don't care about where // as long as the index where it is found is greater than min_index. // Returns the position where the event was found. |