1 // Copyright (C) 2024 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include "aemu/base/containers/HybridEntityManager.h"
15 
16 #include <gtest/gtest.h>
17 
18 namespace android {
19 namespace base {
20 
21 static constexpr uint32_t kTestMaxIndex = 16;
22 using TestHCM = HybridEntityManager<kTestMaxIndex, uint64_t, int>;
23 
TEST(HybridEntityManager,UpdateIndex)24 TEST(HybridEntityManager, UpdateIndex) {
25     TestHCM m;
26     // Occupy all linear entries.
27     for (uint32_t i = 0; i < kTestMaxIndex; i++) {
28         m.add(i, 1);
29     }
30     int indices[4];
31     indices[0] = m.addFixed(kTestMaxIndex, 0, 1);
32     indices[1] = m.add(100, 1);
33     indices[2] = m.add(2, 1);
34     m.remove(indices[1]);
35     m.addFixed(indices[1], 1, 1);
36     // Verify it doesn't overwrite old entries.
37     indices[3] = m.add(3, 1);
38     EXPECT_EQ(0, *m.get_const(indices[0]));
39     EXPECT_EQ(1, *m.get_const(indices[1]));
40     EXPECT_EQ(2, *m.get_const(indices[2]));
41     EXPECT_EQ(3, *m.get_const(indices[3]));
42 }
43 
44 }
45 }