1 // 2 // Copyright (C) 2013 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_CRYPTO_UTIL_PROXY_H_ 18 #define SHILL_MOCK_CRYPTO_UTIL_PROXY_H_ 19 20 #include "shill/crypto_util_proxy.h" 21 22 #include <string> 23 #include <vector> 24 25 #include <base/macros.h> 26 #include <gmock/gmock.h> 27 28 namespace shill { 29 30 class Error; 31 class EventDispatcher; 32 33 class MockCryptoUtilProxy 34 : public CryptoUtilProxy, 35 public base::SupportsWeakPtr<MockCryptoUtilProxy> { 36 public: 37 explicit MockCryptoUtilProxy(EventDispatcher* dispatcher); 38 ~MockCryptoUtilProxy() override; 39 40 MOCK_METHOD9(VerifyDestination, 41 bool(const std::string& certificate, 42 const std::string& public_key, 43 const std::string& nonce, 44 const std::string& signed_data, 45 const std::string& destination_udn, 46 const std::vector<uint8_t>& ssid, 47 const std::string& bssid, 48 const ResultBoolCallback& result_callback, 49 Error* error)); 50 MOCK_METHOD4(EncryptData, bool(const std::string& public_key, 51 const std::string& data, 52 const ResultStringCallback& result_callback, 53 Error* error)); 54 55 bool RealVerifyDestination(const std::string& certificate, 56 const std::string& public_key, 57 const std::string& nonce, 58 const std::string& signed_data, 59 const std::string& destination_udn, 60 const std::vector<uint8_t>& ssid, 61 const std::string& bssid, 62 const ResultBoolCallback& result_callback, 63 Error* error); 64 65 bool RealEncryptData(const std::string& public_key, 66 const std::string& data, 67 const ResultStringCallback& result_callback, 68 Error* error); 69 70 // Mock methods with useful callback signatures. You can bind these to check 71 // that appropriate async callbacks are firing at expected times. 72 MOCK_METHOD2(TestResultBoolCallback, void(const Error& error, bool)); 73 MOCK_METHOD2(TestResultStringCallback, void(const Error& error, 74 const std::string&)); 75 MOCK_METHOD2(TestResultHandlerCallback, void(const std::string& result, 76 const Error& error)); 77 MOCK_METHOD3(StartShimForCommand, bool(const std::string& command, 78 const std::string& input, 79 const StringCallback& result_handler)); 80 81 // Methods injected to permit us to call the real method implementations. 82 bool RealStartShimForCommand(const std::string& command, 83 const std::string& input, 84 const StringCallback& result_handler); 85 86 private: 87 DISALLOW_COPY_AND_ASSIGN(MockCryptoUtilProxy); 88 }; 89 90 } // namespace shill 91 92 #endif // SHILL_MOCK_CRYPTO_UTIL_PROXY_H_ 93