Commit 8168e4d2 authored by Bartek Nowierski's avatar Bartek Nowierski Committed by Commit Bot

Add NewLinkedHashSet to the combined testset

list_hash_set_test.cc already tests both ListHashSet and LinkedHashSet. It's natural to add NewLinkedHashSet to the list.

Not all tests work right now, due to insertion of 0 (an empty value).

Change-Id: Ib649c3ccc8c28323673b75b07857ac0a89440f0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2130586Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Bartek Nowierski <bartekn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755244}
parent 99264d12
...@@ -41,12 +41,17 @@ namespace { ...@@ -41,12 +41,17 @@ namespace {
template <typename Set> template <typename Set>
class ListOrLinkedHashSetTest : public testing::Test {}; class ListOrLinkedHashSetTest : public testing::Test {};
using SetTypes = using SetTypes = testing::Types<ListHashSet<int>,
testing::Types<ListHashSet<int>, ListHashSet<int, 1>, LinkedHashSet<int>>; ListHashSet<int, 1>,
LinkedHashSet<int>,
NewLinkedHashSet<int>>;
TYPED_TEST_SUITE(ListOrLinkedHashSetTest, SetTypes); TYPED_TEST_SUITE(ListOrLinkedHashSetTest, SetTypes);
TYPED_TEST(ListOrLinkedHashSetTest, RemoveFirst) { TYPED_TEST(ListOrLinkedHashSetTest, RemoveFirst) {
using Set = TypeParam; using Set = TypeParam;
// TODO(bartekn): Make the test work. Fails due to empty value.
if (std::is_same<Set, NewLinkedHashSet<int>>::value)
return;
Set list; Set list;
list.insert(-1); list.insert(-1);
list.insert(0); list.insert(0);
...@@ -197,6 +202,9 @@ TYPED_TEST(ListOrLinkedHashSetTest, PrependOrMoveToLastWithDuplicates) { ...@@ -197,6 +202,9 @@ TYPED_TEST(ListOrLinkedHashSetTest, PrependOrMoveToLastWithDuplicates) {
TYPED_TEST(ListOrLinkedHashSetTest, Find) { TYPED_TEST(ListOrLinkedHashSetTest, Find) {
using Set = TypeParam; using Set = TypeParam;
// TODO(bartekn): Make the test work. Fails due to empty value.
if (std::is_same<Set, NewLinkedHashSet<int>>::value)
return;
Set set; Set set;
set.insert(-1); set.insert(-1);
set.insert(0); set.insert(0);
...@@ -228,6 +236,9 @@ TYPED_TEST(ListOrLinkedHashSetTest, Find) { ...@@ -228,6 +236,9 @@ TYPED_TEST(ListOrLinkedHashSetTest, Find) {
TYPED_TEST(ListOrLinkedHashSetTest, InsertBefore) { TYPED_TEST(ListOrLinkedHashSetTest, InsertBefore) {
using Set = TypeParam; using Set = TypeParam;
// TODO(bartekn): Make the test work. Fails due to empty value.
if (std::is_same<Set, NewLinkedHashSet<int>>::value)
return;
bool can_modify_while_iterating = bool can_modify_while_iterating =
!std::is_same<Set, LinkedHashSet<int>>::value; !std::is_same<Set, LinkedHashSet<int>>::value;
Set set; Set set;
...@@ -361,11 +372,17 @@ class ListOrLinkedHashSetRefPtrTest : public testing::Test {}; ...@@ -361,11 +372,17 @@ class ListOrLinkedHashSetRefPtrTest : public testing::Test {};
using RefPtrSetTypes = using RefPtrSetTypes =
testing::Types<ListHashSet<scoped_refptr<DummyRefCounted>>, testing::Types<ListHashSet<scoped_refptr<DummyRefCounted>>,
ListHashSet<scoped_refptr<DummyRefCounted>, 1>, ListHashSet<scoped_refptr<DummyRefCounted>, 1>,
LinkedHashSet<scoped_refptr<DummyRefCounted>>>; LinkedHashSet<scoped_refptr<DummyRefCounted>>,
NewLinkedHashSet<scoped_refptr<DummyRefCounted>>>;
TYPED_TEST_SUITE(ListOrLinkedHashSetRefPtrTest, RefPtrSetTypes); TYPED_TEST_SUITE(ListOrLinkedHashSetRefPtrTest, RefPtrSetTypes);
TYPED_TEST(ListOrLinkedHashSetRefPtrTest, WithRefPtr) { TYPED_TEST(ListOrLinkedHashSetRefPtrTest, WithRefPtr) {
using Set = TypeParam; using Set = TypeParam;
int expected = 1;
// NewLinkedHashSet stores each object twice.
if (std::is_same<Set,
NewLinkedHashSet<scoped_refptr<DummyRefCounted>>>::value)
expected = 2;
bool is_deleted = false; bool is_deleted = false;
DummyRefCounted::ref_invokes_count_ = 0; DummyRefCounted::ref_invokes_count_ = 0;
scoped_refptr<DummyRefCounted> ptr = scoped_refptr<DummyRefCounted> ptr =
...@@ -375,24 +392,24 @@ TYPED_TEST(ListOrLinkedHashSetRefPtrTest, WithRefPtr) { ...@@ -375,24 +392,24 @@ TYPED_TEST(ListOrLinkedHashSetRefPtrTest, WithRefPtr) {
Set set; Set set;
set.insert(ptr); set.insert(ptr);
// Referenced only once (to store a copy in the container). // Referenced only once (to store a copy in the container).
EXPECT_EQ(1, DummyRefCounted::ref_invokes_count_); EXPECT_EQ(expected, DummyRefCounted::ref_invokes_count_);
EXPECT_EQ(ptr, set.front()); EXPECT_EQ(ptr, set.front());
EXPECT_EQ(1, DummyRefCounted::ref_invokes_count_); EXPECT_EQ(expected, DummyRefCounted::ref_invokes_count_);
DummyRefCounted* raw_ptr = ptr.get(); DummyRefCounted* raw_ptr = ptr.get();
EXPECT_TRUE(set.Contains(ptr)); EXPECT_TRUE(set.Contains(ptr));
EXPECT_TRUE(set.Contains(raw_ptr)); EXPECT_TRUE(set.Contains(raw_ptr));
EXPECT_EQ(1, DummyRefCounted::ref_invokes_count_); EXPECT_EQ(expected, DummyRefCounted::ref_invokes_count_);
ptr = nullptr; ptr = nullptr;
EXPECT_FALSE(is_deleted); EXPECT_FALSE(is_deleted);
EXPECT_EQ(1, DummyRefCounted::ref_invokes_count_); EXPECT_EQ(expected, DummyRefCounted::ref_invokes_count_);
set.erase(raw_ptr); set.erase(raw_ptr);
EXPECT_TRUE(is_deleted); EXPECT_TRUE(is_deleted);
EXPECT_EQ(1, DummyRefCounted::ref_invokes_count_); EXPECT_EQ(expected, DummyRefCounted::ref_invokes_count_);
} }
TYPED_TEST(ListOrLinkedHashSetRefPtrTest, ExerciseValuePeekInType) { TYPED_TEST(ListOrLinkedHashSetRefPtrTest, ExerciseValuePeekInType) {
...@@ -467,6 +484,7 @@ struct ComplexityTranslator { ...@@ -467,6 +484,7 @@ struct ComplexityTranslator {
template <typename Set> template <typename Set>
class ListOrLinkedHashSetTranslatorTest : public testing::Test {}; class ListOrLinkedHashSetTranslatorTest : public testing::Test {};
// TODO(bartekn): Add NewLinkedHashSet once it supports custom hash function.
using TranslatorSetTypes = using TranslatorSetTypes =
testing::Types<ListHashSet<Complicated, 256, ComplicatedHashFunctions>, testing::Types<ListHashSet<Complicated, 256, ComplicatedHashFunctions>,
ListHashSet<Complicated, 1, ComplicatedHashFunctions>, ListHashSet<Complicated, 1, ComplicatedHashFunctions>,
...@@ -576,7 +594,8 @@ class ListOrLinkedHashSetCountCopyTest : public testing::Test {}; ...@@ -576,7 +594,8 @@ class ListOrLinkedHashSetCountCopyTest : public testing::Test {};
using CountCopySetTypes = testing::Types<ListHashSet<CountCopy>, using CountCopySetTypes = testing::Types<ListHashSet<CountCopy>,
ListHashSet<CountCopy, 1>, ListHashSet<CountCopy, 1>,
LinkedHashSet<CountCopy>>; LinkedHashSet<CountCopy>,
NewLinkedHashSet<CountCopy>>;
TYPED_TEST_SUITE(ListOrLinkedHashSetCountCopyTest, CountCopySetTypes); TYPED_TEST_SUITE(ListOrLinkedHashSetCountCopyTest, CountCopySetTypes);
TYPED_TEST(ListOrLinkedHashSetCountCopyTest, TYPED_TEST(ListOrLinkedHashSetCountCopyTest,
...@@ -606,6 +625,7 @@ TYPED_TEST(ListOrLinkedHashSetCountCopyTest, MoveAssignmentShouldNotMakeACopy) { ...@@ -606,6 +625,7 @@ TYPED_TEST(ListOrLinkedHashSetCountCopyTest, MoveAssignmentShouldNotMakeACopy) {
template <typename Set> template <typename Set>
class ListOrLinkedHashSetMoveOnlyTest : public testing::Test {}; class ListOrLinkedHashSetMoveOnlyTest : public testing::Test {};
// TODO(bartekn): Add NewLinkedHashSet once it supports move-only type.
using MoveOnlySetTypes = testing::Types<ListHashSet<MoveOnlyHashValue>, using MoveOnlySetTypes = testing::Types<ListHashSet<MoveOnlyHashValue>,
ListHashSet<MoveOnlyHashValue, 1>, ListHashSet<MoveOnlyHashValue, 1>,
LinkedHashSet<MoveOnlyHashValue>>; LinkedHashSet<MoveOnlyHashValue>>;
...@@ -701,6 +721,7 @@ struct DefaultHash<InvalidZeroValue> { ...@@ -701,6 +721,7 @@ struct DefaultHash<InvalidZeroValue> {
template <typename Set> template <typename Set>
class ListOrLinkedHashSetInvalidZeroTest : public testing::Test {}; class ListOrLinkedHashSetInvalidZeroTest : public testing::Test {};
// TODO(bartekn): Add NewLinkedHashSet once it supports custom hash traits.
using InvalidZeroValueSetTypes = using InvalidZeroValueSetTypes =
testing::Types<ListHashSet<InvalidZeroValue>, testing::Types<ListHashSet<InvalidZeroValue>,
ListHashSet<InvalidZeroValue, 1>, ListHashSet<InvalidZeroValue, 1>,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment