1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <androidfw/ResourceTypes.h>
#include <utils/String8.h>
#include <utils/String16.h>
#include "TestHelpers.h"
#include <gtest/gtest.h>
/**
* Include a binary resource table. This table
* is a base table for an APK split.
*
* Package: com.android.example.split
*
* layout/main 0x7f020000 {default, fr-sw600dp-v13}
*
* string/app_title 0x7f030000 {default}
* string/test 0x7f030001 {default}
* string/boom 0x7f030002 {default}
* string/blah 0x7f030003 {default}
*
* array/lotsofstrings 0x7f040000 {default}
* array/numList 0x7f040001 {default}
* array/ary 0x7f040002 {default}
*
*/
#include "data/split_base_arsc.h"
/**
* Include a binary resource table. This table
* is a configuration split table for an APK split.
*
* Package: com.android.example.split
*
* string/app_title 0x7f030000 {fr}
* string/test 0x7f030001 {de,fr}
* string/blah 0x7f030003 {fr}
*
* array/lotsofstrings 0x7f040000 {fr}
*
*/
#include "data/split_de_fr_arsc.h"
using namespace android;
enum { MAY_NOT_BE_BAG = false };
void makeConfigFrench(ResTable_config* config) {
memset(config, 0, sizeof(*config));
config->language[0] = 'f';
config->language[1] = 'r';
}
TEST(SplitTest, TestLoadBase) {
ResTable table;
ASSERT_EQ(NO_ERROR, table.add(split_base_arsc, split_base_arsc_len));
}
TEST(SplitTest, TestGetResourceFromBase) {
ResTable_config frenchConfig;
makeConfigFrench(&frenchConfig);
ResTable table;
table.setParameters(&frenchConfig);
ASSERT_EQ(NO_ERROR, table.add(split_base_arsc, split_base_arsc_len));
ResTable_config expectedConfig;
memset(&expectedConfig, 0, sizeof(expectedConfig));
Res_value val;
ResTable_config config;
ssize_t block = table.getResource(0x7f030000, &val, MAY_NOT_BE_BAG, 0, NULL, &config);
// The returned block should tell us which string pool to get the value, if it is a string.
EXPECT_GE(block, 0);
// We expect the default resource to be selected since it is the only resource configuration.
EXPECT_EQ(0, expectedConfig.compare(config));
EXPECT_EQ(Res_value::TYPE_STRING, val.dataType);
}
TEST(SplitTest, TestGetResourceFromSplit) {
ResTable_config expectedConfig;
makeConfigFrench(&expectedConfig);
ResTable table;
table.setParameters(&expectedConfig);
ASSERT_EQ(NO_ERROR, table.add(split_base_arsc, split_base_arsc_len));
ASSERT_EQ(NO_ERROR, table.add(split_de_fr_arsc, split_de_fr_arsc_len));
Res_value val;
ResTable_config config;
ssize_t block = table.getResource(0x7f030000, &val, MAY_NOT_BE_BAG, 0, NULL, &config);
EXPECT_GE(block, 0);
EXPECT_EQ(0, expectedConfig.compare(config));
EXPECT_EQ(Res_value::TYPE_STRING, val.dataType);
}
TEST(SplitTest, ResourcesFromBaseAndSplitHaveSameNames) {
ResTable_config expectedConfig;
makeConfigFrench(&expectedConfig);
ResTable table;
table.setParameters(&expectedConfig);
ASSERT_EQ(NO_ERROR, table.add(split_base_arsc, split_base_arsc_len));
ResTable::resource_name baseName;
EXPECT_TRUE(table.getResourceName(0x7f030003, false, &baseName));
ASSERT_EQ(NO_ERROR, table.add(split_de_fr_arsc, split_de_fr_arsc_len));
ResTable::resource_name frName;
EXPECT_TRUE(table.getResourceName(0x7f030003, false, &frName));
EXPECT_EQ(
String16(baseName.package, baseName.packageLen),
String16(frName.package, frName.packageLen));
EXPECT_EQ(
String16(baseName.type, baseName.typeLen),
String16(frName.type, frName.typeLen));
EXPECT_EQ(
String16(baseName.name, baseName.nameLen),
String16(frName.name, frName.nameLen));
}
TEST(SplitTest, TypeEntrySpecFlagsAreUpdated) {
ResTable_config defaultConfig;
memset(&defaultConfig, 0, sizeof(defaultConfig));
ResTable table;
ASSERT_EQ(NO_ERROR, table.add(split_base_arsc, split_base_arsc_len));
Res_value val;
uint32_t specFlags = 0;
ssize_t block = table.getResource(0x7f030000, &val, MAY_NOT_BE_BAG, 0, &specFlags, NULL);
EXPECT_GE(block, 0);
EXPECT_EQ(static_cast<uint32_t>(0), specFlags);
ASSERT_EQ(NO_ERROR, table.add(split_de_fr_arsc, split_de_fr_arsc_len));
uint32_t frSpecFlags = 0;
block = table.getResource(0x7f030000, &val, MAY_NOT_BE_BAG, 0, &frSpecFlags, NULL);
EXPECT_GE(block, 0);
EXPECT_EQ(ResTable_config::CONFIG_LOCALE, frSpecFlags);
}
|