diff options
author | David 'Digit' Turner <digit@google.com> | 2014-09-15 19:34:57 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2014-09-16 03:01:26 +0200 |
commit | 9f35027153ad98865b57ef0fcd86940c44afd3e6 (patch) | |
tree | 3e09a7012ef4d7332c03d8dabe7a5f5d9580ba84 /emulator/opengl/shared/emugl/common/unique_integer_map_unittest.cpp | |
parent | a92a69909f5bbbbd980cc9551dd85e961fd02f82 (diff) | |
download | sdk-9f35027153ad98865b57ef0fcd86940c44afd3e6.zip sdk-9f35027153ad98865b57ef0fcd86940c44afd3e6.tar.gz sdk-9f35027153ad98865b57ef0fcd86940c44afd3e6.tar.bz2 |
emulator/opengl: Add UniqueIntegerMap class.
This helper class will be used by future patches to map arbitraty
opaque 'void*' values (e.g. EGLImage values) to 32-bit unique values
that can be sent through the wire protocol.
Change-Id: I5b17a1f230e5f9f8b905af66ba79b312f3f01e55
Diffstat (limited to 'emulator/opengl/shared/emugl/common/unique_integer_map_unittest.cpp')
-rw-r--r-- | emulator/opengl/shared/emugl/common/unique_integer_map_unittest.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/emulator/opengl/shared/emugl/common/unique_integer_map_unittest.cpp b/emulator/opengl/shared/emugl/common/unique_integer_map_unittest.cpp new file mode 100644 index 0000000..8aee013 --- /dev/null +++ b/emulator/opengl/shared/emugl/common/unique_integer_map_unittest.cpp @@ -0,0 +1,103 @@ +// Copyright (C) 2014 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "emugl/common/unique_integer_map.h" + +#include <gtest/gtest.h> + +#include <stdio.h> + +namespace emugl { + +typedef UniqueIntegerMap<uintptr_t,uint32_t> MyMap; + +TEST(UniqueIntegerMap, Empty) { + MyMap map; + + EXPECT_TRUE(map.empty()); + EXPECT_EQ(0U, map.size()); + EXPECT_EQ(0U, map.find(0U)); + EXPECT_EQ(0U, map.find(1U)); + EXPECT_EQ(0U, map.find(2U)); + EXPECT_EQ(0U, map.find(4U)); +} + +TEST(UniqueIntegerMap, AddOne) { + MyMap map; + uintptr_t key1 = 1U; + uint32_t val1 = map.add(key1); + + EXPECT_NE(0U, val1); + EXPECT_EQ(val1, map.find(key1)); + EXPECT_EQ(key1, map.findKeyFor(val1)); + + EXPECT_FALSE(map.empty()); + EXPECT_EQ(1U, map.size()); + + EXPECT_EQ(0U, map.find(0)); + EXPECT_EQ(0U, map.findKeyFor(0)); + + EXPECT_EQ(0U, map.find(key1 + 1)); + EXPECT_EQ(0U, map.findKeyFor(val1 + 1)); +} + +TEST(UniqueIntegerMap, AddMultiple) { + MyMap map; + const size_t kCount = 100; + const size_t kKeyMultiplier = 3U; // must be >= 2. + uint32_t values[kCount]; + + for (size_t n = 0; n < kCount; ++n) { + uintptr_t key = 1U + n * kKeyMultiplier; + values[n] = map.add(key); + EXPECT_NE(0U, values[n]) << "key #" << n; + } + + EXPECT_EQ(kCount, map.size()); + + for (size_t n = 0; n < kCount; ++n) { + uintptr_t key = 1U + n * kKeyMultiplier; + EXPECT_EQ(values[n], map.find(key)) << "key #" << n; + EXPECT_EQ(0U, map.find(key + 1U)) << "key #" << n; + } + + for (size_t n = 0; n < kCount; ++n) { + uintptr_t key = 1U + n * kKeyMultiplier; + EXPECT_EQ(key, map.findKeyFor(values[n])); + } +} + +TEST(UniqueIntegerMap, Del) { + MyMap map; + const size_t kCount = 100; + const size_t kKeyMultiplier = 3U; // must be >= 2. + uint32_t values[kCount]; + + for (size_t n = 0; n < kCount; ++n) { + uintptr_t key = 1U + n * kKeyMultiplier; + values[n] = map.add(key); + } + + for (size_t n = 0; n < kCount; ++n) { + uintptr_t key = 1U + n * kKeyMultiplier; + map.del(key); + EXPECT_EQ(kCount - 1U - n, map.size()); + EXPECT_EQ(0U, map.find(key)); + EXPECT_EQ(0U, map.findKeyFor(values[n])); + } + + EXPECT_TRUE(map.empty()); +} + +} // namespace emugl |