MÃ¥rten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame^] | 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 | #include <utility> |
| 20 | |
| 21 | #include "gmock/gmock.h" |
| 22 | #include "gtest/gtest.h" |
| 23 | |
| 24 | #include "androidfw/ApkAssets.h" |
| 25 | #include "idmap2/ResourceUtils.h" |
| 26 | |
| 27 | #include "TestHelpers.h" |
| 28 | |
| 29 | using ::testing::NotNull; |
| 30 | |
| 31 | namespace android { |
| 32 | namespace idmap2 { |
| 33 | |
| 34 | class 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 | |
| 54 | TEST_F(ResourceUtilsTests, ResToTypeEntryName) { |
| 55 | bool lookup_ok; |
| 56 | std::string name; |
| 57 | std::tie(lookup_ok, name) = utils::ResToTypeEntryName(GetAssetManager(), 0x7f010000u); |
| 58 | ASSERT_TRUE(lookup_ok); |
| 59 | ASSERT_EQ(name, "integer/int1"); |
| 60 | } |
| 61 | |
| 62 | TEST_F(ResourceUtilsTests, ResToTypeEntryNameNoSuchResourceId) { |
| 63 | bool lookup_ok; |
| 64 | std::tie(lookup_ok, std::ignore) = utils::ResToTypeEntryName(GetAssetManager(), 0x7f123456u); |
| 65 | ASSERT_FALSE(lookup_ok); |
| 66 | } |
| 67 | |
| 68 | } // namespace idmap2 |
| 69 | } // namespace android |