1 /*
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>
19
20 #include "TestHelpers.h"
21 #include "androidfw/ApkAssets.h"
22 #include "gmock/gmock.h"
23 #include "gtest/gtest.h"
24 #include "idmap2/ResourceUtils.h"
25 #include "idmap2/Result.h"
26
27 using ::testing::NotNull;
28
29 namespace android::idmap2 {
30
31 class ResourceUtilsTests : public Idmap2Tests {
32 protected:
SetUp()33 void SetUp() override {
34 Idmap2Tests::SetUp();
35
36 apk_assets_ = ApkAssets::Load(GetTargetApkPath());
37 ASSERT_THAT(apk_assets_, NotNull());
38
39 am_.SetApkAssets({apk_assets_.get()});
40 }
41
GetAssetManager()42 const AssetManager2& GetAssetManager() {
43 return am_;
44 }
45
46 private:
47 AssetManager2 am_;
48 std::unique_ptr<const ApkAssets> apk_assets_;
49 };
50
TEST_F(ResourceUtilsTests,ResToTypeEntryName)51 TEST_F(ResourceUtilsTests, ResToTypeEntryName) {
52 Result<std::string> name = utils::ResToTypeEntryName(GetAssetManager(), 0x7f010000U);
53 ASSERT_TRUE(name);
54 ASSERT_EQ(*name, "integer/int1");
55 }
56
TEST_F(ResourceUtilsTests,ResToTypeEntryNameNoSuchResourceId)57 TEST_F(ResourceUtilsTests, ResToTypeEntryNameNoSuchResourceId) {
58 Result<std::string> name = utils::ResToTypeEntryName(GetAssetManager(), 0x7f123456U);
59 ASSERT_FALSE(name);
60 }
61
62 } // namespace android::idmap2
63