blob: ddaa46d274cdbd1580b5213d4e2b2724ce0e0718 [file] [log] [blame]
Tao Baia6d7e3f2015-09-01 18:49:54 -07001/*
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
Adam Lesinski4c67a472016-11-10 16:43:59 -080017#include "androidfw/ResourceTypes.h"
Tao Baia6d7e3f2015-09-01 18:49:54 -070018
Adam Lesinski4c67a472016-11-10 16:43:59 -080019#include "TestHelpers.h"
Tao Baia6d7e3f2015-09-01 18:49:54 -070020#include "data/appaslib/R.h"
21
Adam Lesinski4c67a472016-11-10 16:43:59 -080022namespace app = com::android::appaslib::app;
23namespace lib = com::android::appaslib::lib;
Tao Baia6d7e3f2015-09-01 18:49:54 -070024
Adam Lesinski4c67a472016-11-10 16:43:59 -080025namespace android {
Tao Baia6d7e3f2015-09-01 18:49:54 -070026
Tao Bai1375e5f2015-11-06 14:00:17 -080027// This tests the app resources loaded as app.
Adam Lesinski4c67a472016-11-10 16:43:59 -080028TEST(AppAsLibTest, LoadedAsApp) {
29 std::string contents;
30 ASSERT_TRUE(
31 ReadFileFromZipToString(GetTestDataPath() + "/appaslib/appaslib.apk",
32 "resources.arsc", &contents));
33
Tao Baia6d7e3f2015-09-01 18:49:54 -070034 ResTable table;
Adam Lesinski4c67a472016-11-10 16:43:59 -080035 ASSERT_EQ(NO_ERROR, table.add(contents.data(), contents.size()));
Tao Baia6d7e3f2015-09-01 18:49:54 -070036
37 Res_value val;
Adam Lesinski4c67a472016-11-10 16:43:59 -080038 ssize_t block = table.getResource(app::R::integer::number1, &val);
Tao Baia6d7e3f2015-09-01 18:49:54 -070039 ASSERT_GE(block, 0);
40 ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
Adam Lesinski4c67a472016-11-10 16:43:59 -080041 ASSERT_EQ(app::R::array::integerArray1, val.data);
Tao Baia6d7e3f2015-09-01 18:49:54 -070042}
43
Tao Bai1375e5f2015-11-06 14:00:17 -080044// This tests the app resources loaded as shared-lib.
Adam Lesinski4c67a472016-11-10 16:43:59 -080045TEST(AppAsLibTest, LoadedAsSharedLib) {
46 std::string contents;
47 ASSERT_TRUE(
48 ReadFileFromZipToString(GetTestDataPath() + "/appaslib/appaslib.apk",
49 "resources.arsc", &contents));
50
Tao Baia6d7e3f2015-09-01 18:49:54 -070051 ResTable table;
52 // Load as shared library.
Adam Lesinski4c67a472016-11-10 16:43:59 -080053 ASSERT_EQ(NO_ERROR, table.add(contents.data(), contents.size(), NULL, 0, -1,
54 false, true));
Tao Baia6d7e3f2015-09-01 18:49:54 -070055
56 Res_value val;
Adam Lesinski4c67a472016-11-10 16:43:59 -080057 ssize_t block = table.getResource(lib::R::integer::number1, &val);
Tao Baia6d7e3f2015-09-01 18:49:54 -070058 ASSERT_GE(block, 0);
59 ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
Adam Lesinski4c67a472016-11-10 16:43:59 -080060 ASSERT_EQ(lib::R::array::integerArray1, val.data);
Tao Bai1375e5f2015-11-06 14:00:17 -080061}
62
63// This tests the shared-lib loaded with appAsLib as true.
Adam Lesinski4c67a472016-11-10 16:43:59 -080064TEST(AppAsLibTest, LoadedSharedLib) {
65 std::string contents;
66 ASSERT_TRUE(
67 ReadFileFromZipToString(GetTestDataPath() + "/appaslib/appaslib_lib.apk",
68 "resources.arsc", &contents));
69
Tao Bai1375e5f2015-11-06 14:00:17 -080070 ResTable table;
71 // Load shared library with appAsLib as true.
Adam Lesinski4c67a472016-11-10 16:43:59 -080072 ASSERT_EQ(NO_ERROR, table.add(contents.data(), contents.size(), NULL, 0, -1,
73 false, true));
Tao Bai1375e5f2015-11-06 14:00:17 -080074
75 Res_value val;
Adam Lesinski4c67a472016-11-10 16:43:59 -080076 ssize_t block = table.getResource(lib::R::integer::number1, &val);
Tao Bai1375e5f2015-11-06 14:00:17 -080077 ASSERT_GE(block, 0);
78 ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
Adam Lesinski4c67a472016-11-10 16:43:59 -080079 ASSERT_EQ(lib::R::array::integerArray1, val.data);
Tao Baia6d7e3f2015-09-01 18:49:54 -070080}
81
Adam Lesinski4c67a472016-11-10 16:43:59 -080082} // namespace android