• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 iSoftStone Information Technology (Group) Co.,Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 #ifndef FOUNDATION_ACE_TEST_UNITTEST_CORE_COMMON_FLUTTER_MOCK_FLUTTER_H
16 #define FOUNDATION_ACE_TEST_UNITTEST_CORE_COMMON_FLUTTER_MOCK_FLUTTER_H
17 
18 #include "gmock/gmock.h"
19 
20 namespace OHOS::Ace {
21 class MockAsset final : public Asset {
22 public:
23     ~MockAsset() override = default;
24 
25     MOCK_METHOD(size_t, GetSize, (), (const, override));
26 
27     MOCK_METHOD(uint8_t*, GetData, (), (const, override));
28 };
29 
30 class MockFileAssetProvider final : public Plugin::FileAssetProvider {
31 public:
32     MockFileAssetProvider() = default;
33 
34     MOCK_METHOD(std::string, GetAssetPath, (const std::string& /* assetName */, bool /* isAddHapPath */),
35         (override));
36 
37     MOCK_METHOD(bool, IsValid, (), (const, override));
38 
39     MOCK_METHOD(void, GetAssetList, (const std::string& path, std::vector<std::string>& assetList),
40         (override));
41 
42     MOCK_METHOD(bool, Initialize, (const std::string& packagePath, const std::vector<std::string>& assetBasePaths));
43 
GetAsMapping(const std::string & assetName)44     std::unique_ptr<fml::Mapping> GetAsMapping(const std::string& assetName) const
45     {
46         int64_t size = 101;
47         uint8_t* dataArray = new (std::nothrow) uint8_t[size];
48         std::unique_ptr<uint8_t[]> data(dataArray);
49 
50         return std::make_unique<MockFileAssetProvider::FileAssetMapping>(std::move(data), size);
51     }
52 
GetFileInfo(const std::string &,MediaFileInfo &)53     bool GetFileInfo(const std::string& /* fileName */, MediaFileInfo& /* fileInfo */) const
54     {
55         return true;
56     }
57 };
58 
59 class MockAssetManager final : public AssetManager {
60 public:
61     ~MockAssetManager() override = default;
62 
63     MOCK_METHOD(void, PushFront, (RefPtr<AssetProvider> provider), (override));
64     MOCK_METHOD(void, PushBack, (RefPtr<AssetProvider> provider), (override));
65     MOCK_METHOD(RefPtr<Asset>, GetAsset, (const std::string& assetName), (override));
66     MOCK_METHOD(std::string, GetAssetPath, (const std::string& /* assetName */, bool /* isAddHapPath */),
67         (override));
68     MOCK_METHOD(void, SetLibPath, (const std::string& appLibPathKey, const std::vector<std::string>& packagePath),
69         (override));
70     MOCK_METHOD(std::string, GetAppLibPathKey, (), (const, override));
71     MOCK_METHOD(std::vector<std::string>, GetLibPath, (), (const, override));
72     MOCK_METHOD(void, GetAssetList, (const std::string& path, std::vector<std::string>& assetList),
73         (const, override));
74     MOCK_METHOD(bool, GetFileInfo, (const std::string& /* fileName */, MediaFileInfo& /* fileInfo */),
75         (const, override));
76 };
77 }
78 #endif // FOUNDATION_ACE_TEST_UNITTEST_CORE_COMMON_FLUTTER_MOCK_FLUTTER_H
79 
80