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 namespace android { 22 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: 34 EXPECT_EQ(1, bba[i]); 35 break; 36 case 10: 37 EXPECT_EQ(2, bba[i]); 38 break; 39 case 26: 40 EXPECT_EQ(3, bba[i]); 41 break; 42 case 129: 43 EXPECT_EQ(4, bba[i]); 44 break; 45 case 234: 46 EXPECT_EQ(5, bba[i]); 47 break; 48 default: 49 EXPECT_EQ(0, bba[i]); 50 break; 51 } 52 } 53 } 54 55 } // namespace android 56