blob: 5d464c7dc0f7555ffe21e2a66b2c025ebdae426f [file] [log] [blame]
Adam Lesinskif90f2f8d2014-06-06 14:27:00 -07001/*
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
Adam Lesinski4c67a472016-11-10 16:43:59 -080017#include "androidfw/ByteBucketArray.h"
Adam Lesinskif90f2f8d2014-06-06 14:27:00 -070018
Adam Lesinski4c67a472016-11-10 16:43:59 -080019#include "gtest/gtest.h"
Adam Lesinskif90f2f8d2014-06-06 14:27:00 -070020
Adam Lesinski4c67a472016-11-10 16:43:59 -080021namespace android {
Adam Lesinskif90f2f8d2014-06-06 14:27:00 -070022
23TEST(ByteBucketArrayTest, TestSparseInsertion) {
Adam Lesinski4c67a472016-11-10 16:43:59 -080024 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));
Adam Lesinskif90f2f8d2014-06-06 14:27:00 -070030
Adam Lesinski4c67a472016-11-10 16:43:59 -080031 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;
Adam Lesinskif90f2f8d2014-06-06 14:27:00 -070051 }
Adam Lesinski4c67a472016-11-10 16:43:59 -080052 }
Adam Lesinskif90f2f8d2014-06-06 14:27:00 -070053}
Adam Lesinski4c67a472016-11-10 16:43:59 -080054
55} // namespace android