• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef LIBBRILLO_BRILLO_HTTP_MOCK_CURL_API_H_
6 #define LIBBRILLO_BRILLO_HTTP_MOCK_CURL_API_H_
7 
8 #include <string>
9 
10 #include <brillo/http/curl_api.h>
11 #include <gmock/gmock.h>
12 
13 namespace brillo {
14 namespace http {
15 
16 // This is a mock for CURL interfaces which allows to mock out the CURL's
17 // low-level C APIs in tests by intercepting the virtual function calls on
18 // the abstract CurlInterface.
19 class MockCurlInterface : public CurlInterface {
20  public:
21   MockCurlInterface() = default;
22 
23   MOCK_METHOD0(EasyInit, CURL*());
24   MOCK_METHOD1(EasyCleanup, void(CURL*));
25   MOCK_METHOD3(EasySetOptInt, CURLcode(CURL*, CURLoption, int));
26   MOCK_METHOD3(EasySetOptStr, CURLcode(CURL*, CURLoption, const std::string&));
27   MOCK_METHOD3(EasySetOptPtr, CURLcode(CURL*, CURLoption, void*));
28   MOCK_METHOD3(EasySetOptCallback, CURLcode(CURL*, CURLoption, intptr_t));
29   MOCK_METHOD3(EasySetOptOffT, CURLcode(CURL*, CURLoption, curl_off_t));
30   MOCK_METHOD1(EasyPerform, CURLcode(CURL*));
31   MOCK_CONST_METHOD3(EasyGetInfoInt, CURLcode(CURL*, CURLINFO, int*));
32   MOCK_CONST_METHOD3(EasyGetInfoDbl, CURLcode(CURL*, CURLINFO, double*));
33   MOCK_CONST_METHOD3(EasyGetInfoStr, CURLcode(CURL*, CURLINFO, std::string*));
34   MOCK_CONST_METHOD3(EasyGetInfoPtr, CURLcode(CURL*, CURLINFO, void**));
35   MOCK_CONST_METHOD1(EasyStrError, std::string(CURLcode));
36   MOCK_METHOD0(MultiInit, CURLM*());
37   MOCK_METHOD1(MultiCleanup, CURLMcode(CURLM*));
38   MOCK_METHOD2(MultiInfoRead, CURLMsg*(CURLM*, int*));
39   MOCK_METHOD2(MultiAddHandle, CURLMcode(CURLM*, CURL*));
40   MOCK_METHOD2(MultiRemoveHandle, CURLMcode(CURLM*, CURL*));
41   MOCK_METHOD3(MultiSetSocketCallback,
42                CURLMcode(CURLM*, curl_socket_callback, void*));
43   MOCK_METHOD3(MultiSetTimerCallback,
44                CURLMcode(CURLM*, curl_multi_timer_callback, void*));
45   MOCK_METHOD3(MultiAssign, CURLMcode(CURLM*, curl_socket_t, void*));
46   MOCK_METHOD4(MultiSocketAction, CURLMcode(CURLM*, curl_socket_t, int, int*));
47   MOCK_CONST_METHOD1(MultiStrError, std::string(CURLMcode));
48 
49  private:
50   DISALLOW_COPY_AND_ASSIGN(MockCurlInterface);
51 };
52 
53 }  // namespace http
54 }  // namespace brillo
55 
56 #endif  // LIBBRILLO_BRILLO_HTTP_MOCK_CURL_API_H_
57