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

Side by Side Diff: third_party/WebKit/Source/wtf/HashMapTest.cpp

Issue 2042453002: Fix wtf::PairHashTraits to support types with isEmptyValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/HashTraits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 EXPECT_TRUE(iter == map.end()); 601 EXPECT_TRUE(iter == map.end());
602 602
603 { 603 {
604 Map::AddResult addResult = map.add(1, std::move(one)); 604 Map::AddResult addResult = map.add(1, std::move(one));
605 EXPECT_TRUE(addResult.isNewEntry); 605 EXPECT_TRUE(addResult.isNewEntry);
606 EXPECT_EQ(1, addResult.storedValue->key); 606 EXPECT_EQ(1, addResult.storedValue->key);
607 EXPECT_EQ(1, *addResult.storedValue->value); 607 EXPECT_EQ(1, *addResult.storedValue->value);
608 } 608 }
609 } 609 }
610 610
611 TEST(HashMapTest, MoveOnlyPairKeyType)
612 {
613 using Pair = std::pair<MoveOnly, int>;
614 using TheMap = HashMap<Pair, int>;
615 TheMap map;
616 {
617 TheMap::AddResult addResult = map.add(Pair(MoveOnly(1), -1), 10);
618 EXPECT_TRUE(addResult.isNewEntry);
619 EXPECT_EQ(1, addResult.storedValue->key.first.value());
620 EXPECT_EQ(-1, addResult.storedValue->key.second);
621 EXPECT_EQ(10, addResult.storedValue->value);
622 }
623 auto iter = map.find(Pair(MoveOnly(1), -1));
624 ASSERT_TRUE(iter != map.end());
625 EXPECT_EQ(1, iter->key.first.value());
626 EXPECT_EQ(-1, iter->key.second);
627 EXPECT_EQ(10, iter->value);
628
629 iter = map.find(Pair(MoveOnly(1), 0));
630 EXPECT_TRUE(iter == map.end());
631
632 for (int i = 2; i < 32; ++i) {
633 TheMap::AddResult addResult = map.add(Pair(MoveOnly(i), -i), i * 10);
634 EXPECT_TRUE(addResult.isNewEntry);
635 EXPECT_EQ(i, addResult.storedValue->key.first.value());
636 EXPECT_EQ(-i, addResult.storedValue->key.second);
637 EXPECT_EQ(i * 10, addResult.storedValue->value);
638 }
639
640 iter = map.find(Pair(MoveOnly(1), -1));
641 ASSERT_TRUE(iter != map.end());
642 EXPECT_EQ(1, iter->key.first.value());
643 EXPECT_EQ(-1, iter->key.second);
644 EXPECT_EQ(10, iter->value);
645
646 iter = map.find(Pair(MoveOnly(7), -7));
647 ASSERT_TRUE(iter != map.end());
648 EXPECT_EQ(7, iter->key.first.value());
649 EXPECT_EQ(-7, iter->key.second);
650 EXPECT_EQ(70, iter->value);
651
652 {
653 TheMap::AddResult addResult = map.set(Pair(MoveOnly(9), -9), 999);
654 EXPECT_FALSE(addResult.isNewEntry);
655 EXPECT_EQ(9, addResult.storedValue->key.first.value());
656 EXPECT_EQ(-9, addResult.storedValue->key.second);
657 EXPECT_EQ(999, addResult.storedValue->value);
658 }
659
660 map.remove(Pair(MoveOnly(11), -11));
661 iter = map.find(Pair(MoveOnly(11), -11));
662 EXPECT_TRUE(iter == map.end());
663
664 int oneThirty = map.take(Pair(MoveOnly(13), -13));
665 EXPECT_EQ(130, oneThirty);
666 iter = map.find(Pair(MoveOnly(13), -13));
667 EXPECT_TRUE(iter == map.end());
668
669 map.clear();
670 }
671
611 } // anonymous namespace 672 } // anonymous namespace
612 673
613 } // namespace WTF 674 } // namespace WTF
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/HashTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698