Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: net/base/host_cache_unittest.cc

Issue 338023: Fix a bad comparator. This caused lookups in std::map to be wrong.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Remove %s from format string Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/host_cache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/host_cache_unittest.cc
===================================================================
--- net/base/host_cache_unittest.cc (revision 30053)
+++ net/base/host_cache_unittest.cc (working copy)
@@ -256,4 +256,77 @@
EXPECT_EQ(0U, cache.size());
}
+// Tests the less than and equal operators for HostCache::Key work.
+TEST(HostCacheTest, KeyComparators) {
+ struct {
+ // Inputs.
+ HostCache::Key key1;
+ HostCache::Key key2;
+
+ // Expectation.
+ // -1 means key1 is less than key2
+ // 0 means key1 equals key2
+ // 1 means key1 is greater than key2
+ int expected_comparison;
+ } tests[] = {
+ {
+ HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED),
+ HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED),
+ 0
+ },
+ {
+ HostCache::Key("host1", ADDRESS_FAMILY_IPV4),
+ HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED),
+ 1
+ },
+ {
+ HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED),
+ HostCache::Key("host1", ADDRESS_FAMILY_IPV4),
+ -1
+ },
+ {
+ HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED),
+ HostCache::Key("host2", ADDRESS_FAMILY_UNSPECIFIED),
+ -1
+ },
+ {
+ HostCache::Key("host1", ADDRESS_FAMILY_IPV4),
+ HostCache::Key("host2", ADDRESS_FAMILY_UNSPECIFIED),
+ 1
+ },
+ {
+ HostCache::Key("host1", ADDRESS_FAMILY_UNSPECIFIED),
+ HostCache::Key("host2", ADDRESS_FAMILY_IPV4),
+ -1
+ },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
+ SCOPED_TRACE(StringPrintf("Test[%d]", i));
+
+ const HostCache::Key& key1 = tests[i].key1;
+ const HostCache::Key& key2 = tests[i].key2;
+
+ switch (tests[i].expected_comparison) {
+ case -1:
+ EXPECT_TRUE(key1 < key2);
+ EXPECT_FALSE(key2 < key1);
+ EXPECT_FALSE(key2 == key1);
+ break;
+ case 0:
+ EXPECT_FALSE(key1 < key2);
+ EXPECT_FALSE(key2 < key1);
+ EXPECT_TRUE(key2 == key1);
+ break;
+ case 1:
+ EXPECT_FALSE(key1 < key2);
+ EXPECT_TRUE(key2 < key1);
+ EXPECT_FALSE(key2 == key1);
+ break;
+ default:
+ FAIL() << "Invalid expectation. Can be only -1, 0, 1";
+ }
+ }
+}
+
} // namespace net
« no previous file with comments | « net/base/host_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698