blob: ad78685646b4676dd93b2e2b3afd8eeff628cfcc [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
Mårten Kongstad0eba72a2018-11-29 08:23:14 +010031namespace android::idmap2 {
Mårten Kongstad02751232018-04-27 13:16:32 +020032
33class ResourceUtilsTests : public Idmap2Tests {
34 protected:
35 void SetUp() override {
36 Idmap2Tests::SetUp();
37
38 apk_assets_ = ApkAssets::Load(GetTargetApkPath());
39 ASSERT_THAT(apk_assets_, NotNull());
40
41 am_.SetApkAssets({apk_assets_.get()});
42 }
43
44 const AssetManager2& GetAssetManager() {
45 return am_;
46 }
47
48 private:
49 AssetManager2 am_;
50 std::unique_ptr<const ApkAssets> apk_assets_;
51};
52
53TEST_F(ResourceUtilsTests, ResToTypeEntryName) {
Mårten Kongstadb8779022018-11-29 09:53:17 +010054 Result<std::string> name = utils::ResToTypeEntryName(GetAssetManager(), 0x7f010000U);
Mårten Kongstad0f763112018-11-19 14:14:37 +010055 ASSERT_TRUE(name);
56 ASSERT_EQ(*name, "integer/int1");
Mårten Kongstad02751232018-04-27 13:16:32 +020057}
58
59TEST_F(ResourceUtilsTests, ResToTypeEntryNameNoSuchResourceId) {
Mårten Kongstadb8779022018-11-29 09:53:17 +010060 Result<std::string> name = utils::ResToTypeEntryName(GetAssetManager(), 0x7f123456U);
Mårten Kongstad0f763112018-11-19 14:14:37 +010061 ASSERT_FALSE(name);
Mårten Kongstad02751232018-04-27 13:16:32 +020062}
63
Mårten Kongstad0eba72a2018-11-29 08:23:14 +010064} // namespace android::idmap2