blob: df44e343b2b45d9fc8ec75d11c82bd81703c278c [file] [log] [blame]
Ryan Mitchellb9b540b2018-08-22 11:22:54 -07001/*
2 * Copyright (C) 2018 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/ResourceTypes.h"
18#include "utils/String8.h"
19
20#include "gtest/gtest.h"
21namespace android {
22
23TEST(DynamicRefTableTest, LookupSharedLibSelfReferences) {
24 // Shared library
25 DynamicRefTable shared_table(0x02, /* appAsLib */ false);
26 shared_table.addMapping(0x00, 0x02);
27 Res_value value;
28 value.dataType = Res_value::TYPE_REFERENCE;
29 value.data = 0x00010000;
30 ASSERT_EQ(shared_table.lookupResourceValue(&value), NO_ERROR);
31 EXPECT_EQ(value.data, 0x02010000);
32
33 // App loaded as a shared library
34 DynamicRefTable shared_app_table(0x02, /* appAsLib */ true);
35 shared_app_table.addMapping(0x7f, 0x02);
36 Res_value value2;
37 value2.dataType = Res_value::TYPE_REFERENCE;
38 value2.data = 0x7f010000;
39 ASSERT_EQ(shared_app_table.lookupResourceValue(&value2), NO_ERROR);
40 EXPECT_EQ(value2.data, 0x02010000);
41};
42
43TEST(DynamicRefTableTest, LookupDynamicReferences) {
44 // Shared library
45 DynamicRefTable shared_table(0x2, /* appAsLib */ false);
46 shared_table.addMapping(0x00, 0x02);
47 shared_table.addMapping(0x03, 0x05);
48 Res_value value;
49 value.dataType = Res_value::TYPE_DYNAMIC_REFERENCE;
50 value.data = 0x03010000;
51 ASSERT_EQ(shared_table.lookupResourceValue(&value), NO_ERROR);
52 EXPECT_EQ(value.data, 0x05010000);
53
54 // App loaded as a shared library
55 DynamicRefTable shared_app_table(0x2, /* appAsLib */ true);
56 shared_app_table.addMapping(0x03, 0x05);
57 shared_app_table.addMapping(0x7f, 0x2);
58 Res_value value2;
59 value2.dataType = Res_value::TYPE_DYNAMIC_REFERENCE;
60 value2.data = 0x03010000;
61 ASSERT_EQ(shared_app_table.lookupResourceValue(&value2), NO_ERROR);
62 EXPECT_EQ(value2.data, 0x05010000);
63
64 // Regular application
65 DynamicRefTable app_table(0x7f, /* appAsLib */ false);
66 app_table.addMapping(0x03, 0x05);
67 Res_value value3;
68 value3.dataType = Res_value::TYPE_REFERENCE;
69 value3.data = 0x03010000;
70 ASSERT_EQ(app_table.lookupResourceValue(&value3), NO_ERROR);
71 EXPECT_EQ(value3.data, 0x05010000);
72};
73
74} // namespace android