1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <androidfw/ByteBucketArray.h>
18 
19 #include <gtest/gtest.h>
20 
21 using android::ByteBucketArray;
22 
TEST(ByteBucketArrayTest,TestSparseInsertion)23 TEST(ByteBucketArrayTest, TestSparseInsertion) {
24     ByteBucketArray<int> bba;
25     ASSERT_TRUE(bba.set(0, 1));
26     ASSERT_TRUE(bba.set(10, 2));
27     ASSERT_TRUE(bba.set(26, 3));
28     ASSERT_TRUE(bba.set(129, 4));
29     ASSERT_TRUE(bba.set(234, 5));
30 
31     for (size_t i = 0; i < bba.size(); i++) {
32         switch (i) {
33             case 0: EXPECT_EQ(1, bba[i]); break;
34             case 10: EXPECT_EQ(2, bba[i]); break;
35             case 26: EXPECT_EQ(3, bba[i]); break;
36             case 129: EXPECT_EQ(4, bba[i]); break;
37             case 234: EXPECT_EQ(5, bba[i]); break;
38             default: EXPECT_EQ(0, bba[i]); break;
39         }
40     }
41 }
42