diff options
author | Caio Marcelo de Oliveira Filho <[email protected]> | 2018-06-25 09:51:20 -0700 |
---|---|---|
committer | Rafael Antognolli <[email protected]> | 2018-07-12 14:03:51 -0700 |
commit | b034facfbc446b28f2cc92c32122849a25fb1001 (patch) | |
tree | f999a9ccc39fe025b3d0f442cd542b46e03a7371 /src/util/tests | |
parent | 8af0a45b4701aa99616b6d5975025ce793172a9c (diff) |
util/set: add a clone function
v2: Add unit test. (Eric Anholt)
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/util/tests')
-rw-r--r-- | src/util/tests/set/set_test.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/util/tests/set/set_test.cpp b/src/util/tests/set/set_test.cpp index e6a83f17ca2..c0998560b50 100644 --- a/src/util/tests/set/set_test.cpp +++ b/src/util/tests/set/set_test.cpp @@ -53,3 +53,35 @@ TEST(set, basic) _mesa_set_destroy(s, NULL); } + +TEST(set, clone) +{ + struct set *s = _mesa_set_create(NULL, _mesa_hash_pointer, + _mesa_key_pointer_equal); + struct set_entry *entry; + + const void *a = (const void *)10; + const void *b = (const void *)20; + const void *c = (const void *)30; + + _mesa_set_add(s, a); + _mesa_set_add(s, b); + _mesa_set_add(s, c); + + entry = _mesa_set_search(s, c); + EXPECT_TRUE(entry); + EXPECT_EQ(entry->key, c); + + _mesa_set_remove(s, entry); + EXPECT_EQ(s->entries, 2); + + struct set *clone = _mesa_set_clone(s, NULL); + EXPECT_EQ(clone->entries, 2); + + EXPECT_TRUE(_mesa_set_search(clone, a)); + EXPECT_TRUE(_mesa_set_search(clone, b)); + EXPECT_FALSE(_mesa_set_search(clone, c)); + + _mesa_set_destroy(s, NULL); + _mesa_set_destroy(clone, NULL); +} |