OLD | NEW |
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 Loading... |
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 |
OLD | NEW |