• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "data/appaslib/R.h"
20 
21 #include <gtest/gtest.h>
22 
23 using namespace android;
24 
25 namespace {
26 
27 #include "data/appaslib/appaslib_arsc.h"
28 #include "data/appaslib/appaslib_lib_arsc.h"
29 
30 // This tests the app resources loaded as app.
TEST(AppAsLibTest,loadedAsApp)31 TEST(AppAsLibTest, loadedAsApp) {
32   ResTable table;
33   ASSERT_EQ(NO_ERROR, table.add(appaslib_arsc, appaslib_arsc_len));
34 
35   Res_value val;
36   ssize_t block = table.getResource(appaslib::R::app::integer::number1, &val);
37   ASSERT_GE(block, 0);
38   ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
39   ASSERT_EQ(appaslib::R::app::array::integerArray1, val.data);
40 }
41 
42 // This tests the app resources loaded as shared-lib.
TEST(AppAsLibTest,loadedAsSharedLib)43 TEST(AppAsLibTest, loadedAsSharedLib) {
44   ResTable table;
45   // Load as shared library.
46   ASSERT_EQ(NO_ERROR, table.add(appaslib_arsc, appaslib_arsc_len, NULL, 0, -1, false, true));
47 
48   Res_value val;
49   ssize_t block = table.getResource(appaslib::R::lib::integer::number1, &val);
50   ASSERT_GE(block, 0);
51   ASSERT_EQ(Res_value::TYPE_REFERENCE, val.dataType);
52   ASSERT_EQ(appaslib::R::lib::array::integerArray1, val.data);
53 }
54 
55 // This tests the shared-lib loaded with appAsLib as true.
TEST(AppAsLibTest,loadedSharedLib)56 TEST(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);
66 }
67 
68 }
69