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 "utils.h"
20
21using ::testing::_;
22using ::testing::AtLeast;
23using ::testing::Invoke;
24using ::testing::Return;
25
26namespace android {
27namespace vintf {
28namespace details {
29
30class MockFileFetcher : public FileFetcher {
31   public:
32    MockFileFetcher() {
33        // By default call through to the original.
34        ON_CALL(*this, fetch(_, _)).WillByDefault(Invoke(&real_, &FileFetcher::fetch));
35    }
36
37    MOCK_METHOD2(fetch, status_t(const std::string& path, std::string& fetched));
38
39   private:
40    FileFetcher real_;
41};
42
43class MockPartitionMounter : public PartitionMounter {
44   public:
45    MockPartitionMounter() {
46        ON_CALL(*this, mountSystem()).WillByDefault(Invoke([&] {
47            systemMounted_ = true;
48            return OK;
49        }));
50        ON_CALL(*this, umountSystem()).WillByDefault(Invoke([&] {
51            systemMounted_ = false;
52            return OK;
53        }));
54        ON_CALL(*this, mountVendor()).WillByDefault(Invoke([&] {
55            vendorMounted_ = true;
56            return OK;
57        }));
58        ON_CALL(*this, umountVendor()).WillByDefault(Invoke([&] {
59            vendorMounted_ = false;
60            return OK;
61        }));
62    }
63    MOCK_CONST_METHOD0(mountSystem, status_t());
64    MOCK_CONST_METHOD0(umountSystem, status_t());
65    MOCK_CONST_METHOD0(mountVendor, status_t());
66    MOCK_CONST_METHOD0(umountVendor, status_t());
67
68    bool systemMounted() const { return systemMounted_; }
69    bool vendorMounted() const { return vendorMounted_; }
70
71    void reset() {
72        systemMounted_ = false;
73        vendorMounted_ = false;
74    }
75
76   private:
77    bool systemMounted_;
78    bool vendorMounted_;
79};
80
81}  // namespace details
82}  // namespace vintf
83}  // namespace android
84