• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 <gmock/gmock.h>
18 
19 #include <vintf/ObjectFactory.h>
20 #include <vintf/PropertyFetcher.h>
21 #include "utils.h"
22 
23 using ::testing::_;
24 using ::testing::AtLeast;
25 using ::testing::Invoke;
26 using ::testing::Return;
27 
28 namespace android {
29 namespace vintf {
30 namespace details {
31 
32 class MockFileSystem : public FileSystem {
33    public:
MockFileSystem()34     MockFileSystem() {}
35 
36     MOCK_CONST_METHOD2(fetch, status_t(const std::string& path, std::string& fetched));
37     MOCK_CONST_METHOD3(listFiles,
38                        status_t(const std::string&, std::vector<std::string>*, std::string*));
39 
fetch(const std::string & path,std::string * fetched,std::string *)40     status_t fetch(const std::string& path, std::string* fetched, std::string*) const override {
41         // Call the mocked function
42         return fetch(path, *fetched);
43     }
44    private:
45     FileSystemImpl mImpl;
46 };
47 
48 class MockRuntimeInfo : public RuntimeInfo {
49    public:
MockRuntimeInfo()50     MockRuntimeInfo() {
51         ON_CALL(*this, fetchAllInformation(_))
52             .WillByDefault(Invoke(this, &MockRuntimeInfo::doFetch));
53     }
54     MOCK_METHOD1(fetchAllInformation, status_t(RuntimeInfo::FetchFlags));
55     status_t doFetch(RuntimeInfo::FetchFlags flags);
failNextFetch()56     void failNextFetch() { failNextFetch_ = true; }
57 
58    private:
59     bool failNextFetch_ = false;
60 };
61 class MockRuntimeInfoFactory : public ObjectFactory<RuntimeInfo> {
62    public:
MockRuntimeInfoFactory(const std::shared_ptr<MockRuntimeInfo> & info)63     MockRuntimeInfoFactory(const std::shared_ptr<MockRuntimeInfo>& info) { object_ = info; }
make_shared()64     std::shared_ptr<RuntimeInfo> make_shared() const override { return object_; }
getInfo()65     std::shared_ptr<MockRuntimeInfo> getInfo() const { return object_; }
66 
67    private:
68     std::shared_ptr<MockRuntimeInfo> object_;
69 };
70 
71 class MockPropertyFetcher : public PropertyFetcher {
72    public:
73     MockPropertyFetcher() = default;
74     MOCK_CONST_METHOD2(getProperty, std::string(const std::string&, const std::string&));
75     MOCK_CONST_METHOD2(getBoolProperty, bool(const std::string&, bool));
76     MOCK_CONST_METHOD3(getUintProperty, uint64_t(const std::string&, uint64_t, uint64_t));
77 };
78 
79 }  // namespace details
80 }  // namespace vintf
81 }  // namespace android
82