1 /*
2 * Copyright (C) 2015 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
19 #include "TestHelpers.h"
20 #include "data/appaslib/R.h"
21
22 namespace app = com::android::appaslib::app;
23 namespace lib = com::android::appaslib::lib;
24
25 namespace android {
26
27 // This tests the app resources loaded as app.
TEST(AppAsLibTest,LoadedAsApp)28 TEST(AppAsLibTest, LoadedAsApp) {
29 std::string contents;
30 ASSERT_TRUE(
31 ReadFileFromZipToString(GetTestDataPath() + "/appaslib/appaslib.apk",
32 "resources.arsc", &contents));
33
34 ResTable table;
35 ASSERT_EQ(NO_ERROR, table.add(contents.data(), contents.size()));
36
37 Res_value val;
38 ssize_t block = table.getResource(app::R::integer::number1, &val);
39 ASSERT_GE(block, 0);
40 ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
41 ASSERT_EQ(app::R::array::integerArray1, val.data);
42 }
43
44 // This tests the app resources loaded as shared-lib.
TEST(AppAsLibTest,LoadedAsSharedLib)45 TEST(AppAsLibTest, LoadedAsSharedLib) {
46 std::string contents;
47 ASSERT_TRUE(
48 ReadFileFromZipToString(GetTestDataPath() + "/appaslib/appaslib.apk",
49 "resources.arsc", &contents));
50
51 ResTable table;
52 // Load as shared library.
53 ASSERT_EQ(NO_ERROR, table.add(contents.data(), contents.size(), NULL, 0, -1,
54 false, true));
55
56 Res_value val;
57 ssize_t block = table.getResource(lib::R::integer::number1, &val);
58 ASSERT_GE(block, 0);
59 ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
60 ASSERT_EQ(lib::R::array::integerArray1, val.data);
61 }
62
63 // This tests the shared-lib loaded with appAsLib as true.
TEST(AppAsLibTest,LoadedSharedLib)64 TEST(AppAsLibTest, LoadedSharedLib) {
65 std::string contents;
66 ASSERT_TRUE(
67 ReadFileFromZipToString(GetTestDataPath() + "/appaslib/appaslib_lib.apk",
68 "resources.arsc", &contents));
69
70 ResTable table;
71 // Load shared library with appAsLib as true.
72 ASSERT_EQ(NO_ERROR, table.add(contents.data(), contents.size(), NULL, 0, -1,
73 false, true));
74
75 Res_value val;
76 ssize_t block = table.getResource(lib::R::integer::number1, &val);
77 ASSERT_GE(block, 0);
78 ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
79 ASSERT_EQ(lib::R::array::integerArray1, val.data);
80 }
81
82 } // namespace android
83