blob: 8489acf6246f7d8328909698e421d7fa93de99cc [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
17#include <androidfw/ResourceTypes.h>
18
Tao Baia6d7e3f2015-09-01 18:49:54 -070019#include "data/appaslib/R.h"
20
21#include <gtest/gtest.h>
22
23using namespace android;
24
25namespace {
26
Tao Bai1375e5f2015-11-06 14:00:17 -080027#include "data/appaslib/appaslib_arsc.h"
28#include "data/appaslib/appaslib_lib_arsc.h"
Tao Baia6d7e3f2015-09-01 18:49:54 -070029
Tao Bai1375e5f2015-11-06 14:00:17 -080030// This tests the app resources loaded as app.
Tao Baia6d7e3f2015-09-01 18:49:54 -070031TEST(AppAsLibTest, loadedAsApp) {
32 ResTable table;
Tao Bai1375e5f2015-11-06 14:00:17 -080033 ASSERT_EQ(NO_ERROR, table.add(appaslib_arsc, appaslib_arsc_len));
Tao Baia6d7e3f2015-09-01 18:49:54 -070034
35 Res_value val;
Tao Bai1375e5f2015-11-06 14:00:17 -080036 ssize_t block = table.getResource(appaslib::R::app::integer::number1, &val);
Tao Baia6d7e3f2015-09-01 18:49:54 -070037 ASSERT_GE(block, 0);
38 ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
Tao Bai1375e5f2015-11-06 14:00:17 -080039 ASSERT_EQ(appaslib::R::app::array::integerArray1, val.data);
Tao Baia6d7e3f2015-09-01 18:49:54 -070040}
41
Tao Bai1375e5f2015-11-06 14:00:17 -080042// This tests the app resources loaded as shared-lib.
Tao Baia6d7e3f2015-09-01 18:49:54 -070043TEST(AppAsLibTest, loadedAsSharedLib) {
44 ResTable table;
45 // Load as shared library.
Tao Bai1375e5f2015-11-06 14:00:17 -080046 ASSERT_EQ(NO_ERROR, table.add(appaslib_arsc, appaslib_arsc_len, NULL, 0, -1, false, true));
Tao Baia6d7e3f2015-09-01 18:49:54 -070047
48 Res_value val;
Tao Bai1375e5f2015-11-06 14:00:17 -080049 ssize_t block = table.getResource(appaslib::R::lib::integer::number1, &val);
Tao Baia6d7e3f2015-09-01 18:49:54 -070050 ASSERT_GE(block, 0);
51 ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
Tao Bai1375e5f2015-11-06 14:00:17 -080052 ASSERT_EQ(appaslib::R::lib::array::integerArray1, val.data);
53}
54
55// This tests the shared-lib loaded with appAsLib as true.
56TEST(AppAsLibTest, loadedSharedLib) {
57 ResTable table;
58 // Load shared library with appAsLib as true.
59 ASSERT_EQ(NO_ERROR, table.add(appaslib_lib_arsc, appaslib_lib_arsc_len, NULL, 0, -1, false, true));
60
61 Res_value val;
62 ssize_t block = table.getResource(appaslib::R::lib::integer::number1, &val);
63 ASSERT_GE(block, 0);
64 ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
65 ASSERT_EQ(appaslib::R::lib::array::integerArray1, val.data);
Tao Baia6d7e3f2015-09-01 18:49:54 -070066}
67
68}