blob: 7f60d7529a61bfad1ef81dadd50cea7d87b9baf9 [file] [log] [blame]
Mårten Kongstad02751232018-04-27 13:16:32 +02001/*
2 * Copyright (C) 2018 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 <memory>
18#include <string>
Mårten Kongstad02751232018-04-27 13:16:32 +020019
20#include "gmock/gmock.h"
21#include "gtest/gtest.h"
22
23#include "androidfw/ApkAssets.h"
24#include "idmap2/ResourceUtils.h"
Mårten Kongstad0f763112018-11-19 14:14:37 +010025#include "idmap2/Result.h"
Mårten Kongstad02751232018-04-27 13:16:32 +020026
27#include "TestHelpers.h"
28
29using ::testing::NotNull;
30
31namespace android {
32namespace idmap2 {
33
34class ResourceUtilsTests : public Idmap2Tests {
35 protected:
36 void SetUp() override {
37 Idmap2Tests::SetUp();
38
39 apk_assets_ = ApkAssets::Load(GetTargetApkPath());
40 ASSERT_THAT(apk_assets_, NotNull());
41
42 am_.SetApkAssets({apk_assets_.get()});
43 }
44
45 const AssetManager2& GetAssetManager() {
46 return am_;
47 }
48
49 private:
50 AssetManager2 am_;
51 std::unique_ptr<const ApkAssets> apk_assets_;
52};
53
54TEST_F(ResourceUtilsTests, ResToTypeEntryName) {
Mårten Kongstad0f763112018-11-19 14:14:37 +010055 Result<std::string> name = utils::ResToTypeEntryName(GetAssetManager(), 0x7f010000u);
56 ASSERT_TRUE(name);
57 ASSERT_EQ(*name, "integer/int1");
Mårten Kongstad02751232018-04-27 13:16:32 +020058}
59
60TEST_F(ResourceUtilsTests, ResToTypeEntryNameNoSuchResourceId) {
Mårten Kongstad0f763112018-11-19 14:14:37 +010061 Result<std::string> name = utils::ResToTypeEntryName(GetAssetManager(), 0x7f123456u);
62 ASSERT_FALSE(name);
Mårten Kongstad02751232018-04-27 13:16:32 +020063}
64
65} // namespace idmap2
66} // namespace android