1 // 2 // Copyright (C) 2012 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 #ifndef SHILL_MOCK_SERVICE_H_ 18 #define SHILL_MOCK_SERVICE_H_ 19 20 #include <string> 21 22 #include <base/memory/ref_counted.h> 23 #include <gmock/gmock.h> 24 25 #include "shill/connection.h" 26 #include "shill/refptr_types.h" 27 #include "shill/service.h" 28 #include "shill/technology.h" 29 30 namespace shill { 31 32 class MockService : public Service { 33 public: 34 // A constructor for the Service object 35 MockService(ControlInterface* control_interface, 36 EventDispatcher* dispatcher, 37 Metrics* metrics, 38 Manager* manager); 39 ~MockService() override; 40 41 MOCK_METHOD0(AutoConnect, void()); 42 MOCK_METHOD2(Connect, void(Error* error, const char* reason)); 43 MOCK_METHOD2(Disconnect, void(Error* error, const char* reason)); 44 MOCK_METHOD3(DisconnectWithFailure, void(Service::ConnectFailure failure, 45 Error* error, 46 const char* reason)); 47 MOCK_METHOD1(UserInitiatedDisconnect, void(Error* error)); 48 MOCK_METHOD1(CalculateState, std::string(Error* error)); 49 MOCK_CONST_METHOD0(state, ConnectState()); 50 MOCK_METHOD1(SetState, void(ConnectState state)); 51 MOCK_METHOD2(SetPortalDetectionFailure, void(const std::string& phase, 52 const std::string& status)); 53 MOCK_CONST_METHOD0(IsConnected, bool()); 54 MOCK_CONST_METHOD0(IsConnecting, bool()); 55 MOCK_CONST_METHOD1(IsDependentOn, bool(const ServiceRefPtr& b)); 56 MOCK_CONST_METHOD0(IsFailed, bool()); 57 MOCK_CONST_METHOD0(IsOnline, bool()); 58 MOCK_CONST_METHOD0(IsVisible, bool()); 59 MOCK_METHOD1(SetFailure, void(ConnectFailure failure)); 60 MOCK_CONST_METHOD0(failure, ConnectFailure()); 61 MOCK_CONST_METHOD1(GetDeviceRpcId, std::string(Error* error)); 62 MOCK_CONST_METHOD0(GetInnerDeviceRpcIdentifier, std::string()); 63 MOCK_CONST_METHOD0(GetRpcIdentifier, std::string()); 64 MOCK_CONST_METHOD0(GetStorageIdentifier, std::string()); 65 MOCK_CONST_METHOD1(GetLoadableStorageIdentifier, 66 std::string(const StoreInterface& store_interface)); 67 MOCK_METHOD1(Load, bool(StoreInterface* store_interface)); 68 MOCK_METHOD0(Unload, bool()); 69 MOCK_METHOD1(Save, bool(StoreInterface* store_interface)); 70 MOCK_METHOD2(Configure, void(const KeyValueStore& args, Error* error)); 71 MOCK_CONST_METHOD1(DoPropertiesMatch, bool(const KeyValueStore& args)); 72 MOCK_CONST_METHOD0(Is8021xConnectable, bool()); 73 MOCK_CONST_METHOD0(HasStaticNameServers, bool()); 74 MOCK_CONST_METHOD0(IsPortalDetectionDisabled, bool()); 75 MOCK_CONST_METHOD0(IsPortalDetectionAuto, bool()); 76 MOCK_CONST_METHOD0(IsRemembered, bool()); 77 MOCK_CONST_METHOD0(HasProxyConfig, bool()); 78 MOCK_METHOD1(SetConnection, void(const ConnectionRefPtr& connection)); 79 MOCK_CONST_METHOD0(connection, const ConnectionRefPtr&()); 80 MOCK_CONST_METHOD0(explicitly_disconnected, bool()); 81 #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X) 82 MOCK_CONST_METHOD0(eap, const EapCredentials*()); 83 #endif // DISABLE_WIFI || DISABLE_WIRED_8021X 84 MOCK_CONST_METHOD0(technology, Technology::Identifier()); 85 MOCK_METHOD1(OnPropertyChanged, void(const std::string& property)); 86 MOCK_METHOD0(ClearExplicitlyDisconnected, void()); 87 MOCK_CONST_METHOD0(is_dns_auto_fallback_allowed, bool()); 88 MOCK_METHOD0(NotifyIPConfigChanges, void()); 89 MOCK_CONST_METHOD0(link_monitor_disabled, bool()); 90 MOCK_METHOD0(EnableAndRetainAutoConnect, void()); 91 92 // Set a string for this Service via |store|. Can be wired to Save() for 93 // test purposes. 94 bool FauxSave(StoreInterface* store); 95 // Sets the connection reference returned by default when connection() 96 // is called. 97 void set_mock_connection(const ConnectionRefPtr& connection) { 98 mock_connection_ = connection; 99 } 100 const std::string& friendly_name() const { return Service::friendly_name(); } 101 102 private: 103 ConnectionRefPtr mock_connection_; 104 DISALLOW_COPY_AND_ASSIGN(MockService); 105 }; 106 107 } // namespace shill 108 109 #endif // SHILL_MOCK_SERVICE_H_ 110