xref: /aosp_15_r20/system/libvintf/test/utils-fake.h (revision 70a7ec852fcefd15a4fb57f8f183a8b1c3aacb08)
1*70a7ec85SAndroid Build Coastguard Worker /*
2*70a7ec85SAndroid Build Coastguard Worker  * Copyright (C) 2017 The Android Open Source Project
3*70a7ec85SAndroid Build Coastguard Worker  *
4*70a7ec85SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*70a7ec85SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*70a7ec85SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*70a7ec85SAndroid Build Coastguard Worker  *
8*70a7ec85SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*70a7ec85SAndroid Build Coastguard Worker  *
10*70a7ec85SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*70a7ec85SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*70a7ec85SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*70a7ec85SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*70a7ec85SAndroid Build Coastguard Worker  * limitations under the License.
15*70a7ec85SAndroid Build Coastguard Worker  */
16*70a7ec85SAndroid Build Coastguard Worker 
17*70a7ec85SAndroid Build Coastguard Worker #include <gmock/gmock.h>
18*70a7ec85SAndroid Build Coastguard Worker 
19*70a7ec85SAndroid Build Coastguard Worker #include <vintf/Apex.h>
20*70a7ec85SAndroid Build Coastguard Worker #include <vintf/ObjectFactory.h>
21*70a7ec85SAndroid Build Coastguard Worker #include <vintf/PropertyFetcher.h>
22*70a7ec85SAndroid Build Coastguard Worker #include "utils.h"
23*70a7ec85SAndroid Build Coastguard Worker 
24*70a7ec85SAndroid Build Coastguard Worker using ::testing::_;
25*70a7ec85SAndroid Build Coastguard Worker using ::testing::AtLeast;
26*70a7ec85SAndroid Build Coastguard Worker using ::testing::Invoke;
27*70a7ec85SAndroid Build Coastguard Worker using ::testing::Return;
28*70a7ec85SAndroid Build Coastguard Worker 
29*70a7ec85SAndroid Build Coastguard Worker namespace android {
30*70a7ec85SAndroid Build Coastguard Worker namespace vintf {
31*70a7ec85SAndroid Build Coastguard Worker namespace details {
32*70a7ec85SAndroid Build Coastguard Worker 
33*70a7ec85SAndroid Build Coastguard Worker class MockFileSystem : public FileSystem {
34*70a7ec85SAndroid Build Coastguard Worker    public:
MockFileSystem()35*70a7ec85SAndroid Build Coastguard Worker     MockFileSystem() {}
36*70a7ec85SAndroid Build Coastguard Worker 
37*70a7ec85SAndroid Build Coastguard Worker     MOCK_CONST_METHOD2(fetch, status_t(const std::string& path, std::string& fetched));
38*70a7ec85SAndroid Build Coastguard Worker     MOCK_CONST_METHOD3(listFiles,
39*70a7ec85SAndroid Build Coastguard Worker                        status_t(const std::string&, std::vector<std::string>*, std::string*));
40*70a7ec85SAndroid Build Coastguard Worker     MOCK_CONST_METHOD3(modifiedTime, status_t(const std::string&, timespec*, std::string*));
41*70a7ec85SAndroid Build Coastguard Worker 
fetch(const std::string & path,std::string * fetched,std::string *)42*70a7ec85SAndroid Build Coastguard Worker     status_t fetch(const std::string& path, std::string* fetched, std::string*) const override {
43*70a7ec85SAndroid Build Coastguard Worker         // Call the mocked function
44*70a7ec85SAndroid Build Coastguard Worker         return fetch(path, *fetched);
45*70a7ec85SAndroid Build Coastguard Worker     }
46*70a7ec85SAndroid Build Coastguard Worker    private:
47*70a7ec85SAndroid Build Coastguard Worker     FileSystemImpl mImpl;
48*70a7ec85SAndroid Build Coastguard Worker };
49*70a7ec85SAndroid Build Coastguard Worker 
50*70a7ec85SAndroid Build Coastguard Worker class MockFileSystemWithError : public FileSystem {
51*70a7ec85SAndroid Build Coastguard Worker    public:
52*70a7ec85SAndroid Build Coastguard Worker     MOCK_METHOD(status_t, fetch, (const std::string&, std::string*, std::string*),
53*70a7ec85SAndroid Build Coastguard Worker                 (const override));
54*70a7ec85SAndroid Build Coastguard Worker     MOCK_METHOD(status_t, listFiles, (const std::string&, std::vector<std::string>*, std::string*),
55*70a7ec85SAndroid Build Coastguard Worker                 (const override));
56*70a7ec85SAndroid Build Coastguard Worker     MOCK_METHOD(status_t, modifiedTime, (const std::string&, timespec*, std::string*),
57*70a7ec85SAndroid Build Coastguard Worker                 (const override));
58*70a7ec85SAndroid Build Coastguard Worker };
59*70a7ec85SAndroid Build Coastguard Worker 
60*70a7ec85SAndroid Build Coastguard Worker class MockRuntimeInfo : public RuntimeInfo {
61*70a7ec85SAndroid Build Coastguard Worker    public:
62*70a7ec85SAndroid Build Coastguard Worker     MockRuntimeInfo();
63*70a7ec85SAndroid Build Coastguard Worker     MOCK_METHOD1(fetchAllInformation, status_t(RuntimeInfo::FetchFlags));
64*70a7ec85SAndroid Build Coastguard Worker     status_t doFetch(RuntimeInfo::FetchFlags flags);
failNextFetch()65*70a7ec85SAndroid Build Coastguard Worker     void failNextFetch() { failNextFetch_ = true; }
66*70a7ec85SAndroid Build Coastguard Worker     void setNextFetchKernelInfo(KernelVersion&& v, std::map<std::string, std::string>&& configs);
67*70a7ec85SAndroid Build Coastguard Worker     void setNextFetchKernelInfo(const KernelVersion& v,
68*70a7ec85SAndroid Build Coastguard Worker                                 const std::map<std::string, std::string>& configs);
69*70a7ec85SAndroid Build Coastguard Worker     void setNextFetchKernelLevel(Level level);
70*70a7ec85SAndroid Build Coastguard Worker 
71*70a7ec85SAndroid Build Coastguard Worker    private:
72*70a7ec85SAndroid Build Coastguard Worker     bool failNextFetch_ = false;
73*70a7ec85SAndroid Build Coastguard Worker     // KernelInfo returned in next fetch.
74*70a7ec85SAndroid Build Coastguard Worker     KernelInfo kernel_info_;
75*70a7ec85SAndroid Build Coastguard Worker };
76*70a7ec85SAndroid Build Coastguard Worker class MockRuntimeInfoFactory : public ObjectFactory<RuntimeInfo> {
77*70a7ec85SAndroid Build Coastguard Worker    public:
MockRuntimeInfoFactory(const std::shared_ptr<MockRuntimeInfo> & info)78*70a7ec85SAndroid Build Coastguard Worker     MockRuntimeInfoFactory(const std::shared_ptr<MockRuntimeInfo>& info) { object_ = info; }
make_shared()79*70a7ec85SAndroid Build Coastguard Worker     std::shared_ptr<RuntimeInfo> make_shared() const override { return object_; }
getInfo()80*70a7ec85SAndroid Build Coastguard Worker     std::shared_ptr<MockRuntimeInfo> getInfo() const { return object_; }
81*70a7ec85SAndroid Build Coastguard Worker 
82*70a7ec85SAndroid Build Coastguard Worker    private:
83*70a7ec85SAndroid Build Coastguard Worker     std::shared_ptr<MockRuntimeInfo> object_;
84*70a7ec85SAndroid Build Coastguard Worker };
85*70a7ec85SAndroid Build Coastguard Worker 
86*70a7ec85SAndroid Build Coastguard Worker class MockPropertyFetcher : public PropertyFetcher {
87*70a7ec85SAndroid Build Coastguard Worker    public:
88*70a7ec85SAndroid Build Coastguard Worker     MockPropertyFetcher() = default;
89*70a7ec85SAndroid Build Coastguard Worker     MOCK_CONST_METHOD2(getProperty, std::string(const std::string&, const std::string&));
90*70a7ec85SAndroid Build Coastguard Worker     MOCK_CONST_METHOD2(getBoolProperty, bool(const std::string&, bool));
91*70a7ec85SAndroid Build Coastguard Worker     MOCK_CONST_METHOD3(getUintProperty, uint64_t(const std::string&, uint64_t, uint64_t));
92*70a7ec85SAndroid Build Coastguard Worker };
93*70a7ec85SAndroid Build Coastguard Worker 
94*70a7ec85SAndroid Build Coastguard Worker }  // namespace details
95*70a7ec85SAndroid Build Coastguard Worker }  // namespace vintf
96*70a7ec85SAndroid Build Coastguard Worker }  // namespace android
97