/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include "utils.h" using ::testing::_; using ::testing::AtLeast; using ::testing::Invoke; using ::testing::Return; namespace android { namespace vintf { namespace details { class MockFileSystem : public FileSystem { public: MockFileSystem() {} MOCK_CONST_METHOD2(fetch, status_t(const std::string& path, std::string& fetched)); MOCK_CONST_METHOD3(listFiles, status_t(const std::string&, std::vector*, std::string*)); status_t fetch(const std::string& path, std::string* fetched, std::string*) const override { // Call the mocked function return fetch(path, *fetched); } private: FileSystemImpl mImpl; }; class MockRuntimeInfo : public RuntimeInfo { public: MockRuntimeInfo(); MOCK_METHOD1(fetchAllInformation, status_t(RuntimeInfo::FetchFlags)); status_t doFetch(RuntimeInfo::FetchFlags flags); void failNextFetch() { failNextFetch_ = true; } void setNextFetchKernelInfo(KernelVersion&& v, std::map&& configs); void setNextFetchKernelInfo(const KernelVersion& v, const std::map& configs); private: bool failNextFetch_ = false; // KernelInfo returned in next fetch. KernelInfo kernel_info_; }; class MockRuntimeInfoFactory : public ObjectFactory { public: MockRuntimeInfoFactory(const std::shared_ptr& info) { object_ = info; } std::shared_ptr make_shared() const override { return object_; } std::shared_ptr getInfo() const { return object_; } private: std::shared_ptr object_; }; class MockPropertyFetcher : public PropertyFetcher { public: MockPropertyFetcher() = default; MOCK_CONST_METHOD2(getProperty, std::string(const std::string&, const std::string&)); MOCK_CONST_METHOD2(getBoolProperty, bool(const std::string&, bool)); MOCK_CONST_METHOD3(getUintProperty, uint64_t(const std::string&, uint64_t, uint64_t)); }; } // namespace details } // namespace vintf } // namespace android