• 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_METHOD(CURL*, EasyInit, (), (override));
24   MOCK_METHOD(void, EasyCleanup, (CURL*), (override));
25   MOCK_METHOD(CURLcode, EasySetOptInt, (CURL*, CURLoption, int), (override));
26   MOCK_METHOD(CURLcode,
27               EasySetOptStr,
28               (CURL*, CURLoption, const std::string&),
29               (override));
30   MOCK_METHOD(CURLcode, EasySetOptPtr, (CURL*, CURLoption, void*), (override));
31   MOCK_METHOD(CURLcode,
32               EasySetOptCallback,
33               (CURL*, CURLoption, intptr_t),
34               (override));
35   MOCK_METHOD(CURLcode,
36               EasySetOptOffT,
37               (CURL*, CURLoption, curl_off_t),
38               (override));
39   MOCK_METHOD(CURLcode, EasyPerform, (CURL*), (override));
40   MOCK_METHOD(CURLcode,
41               EasyGetInfoInt,
42               (CURL*, CURLINFO, int*),
43               (const, override));
44   MOCK_METHOD(CURLcode,
45               EasyGetInfoDbl,
46               (CURL*, CURLINFO, double*),
47               (const, override));
48   MOCK_METHOD(CURLcode,
49               EasyGetInfoStr,
50               (CURL*, CURLINFO, std::string*),
51               (const, override));
52   MOCK_METHOD(CURLcode,
53               EasyGetInfoPtr,
54               (CURL*, CURLINFO, void**),
55               (const, override));
56   MOCK_METHOD(std::string, EasyStrError, (CURLcode), (const, override));
57   MOCK_METHOD(CURLM*, MultiInit, (), (override));
58   MOCK_METHOD(CURLMcode, MultiCleanup, (CURLM*), (override));
59   MOCK_METHOD(CURLMsg*, MultiInfoRead, (CURLM*, int*), (override));
60   MOCK_METHOD(CURLMcode, MultiAddHandle, (CURLM*, CURL*), (override));
61   MOCK_METHOD(CURLMcode, MultiRemoveHandle, (CURLM*, CURL*), (override));
62   MOCK_METHOD(CURLMcode,
63               MultiSetSocketCallback,
64               (CURLM*, curl_socket_callback, void*),
65               (override));
66   MOCK_METHOD(CURLMcode,
67               MultiSetTimerCallback,
68               (CURLM*, curl_multi_timer_callback, void*),
69               (override));
70   MOCK_METHOD(CURLMcode,
71               MultiAssign,
72               (CURLM*, curl_socket_t, void*),
73               (override));
74   MOCK_METHOD(CURLMcode,
75               MultiSocketAction,
76               (CURLM*, curl_socket_t, int, int*),
77               (override));
78   MOCK_METHOD(std::string, MultiStrError, (CURLMcode), (const, override));
79   MOCK_METHOD(CURLMcode, MultiPerform, (CURLM*, int*), (override));
80   MOCK_METHOD(CURLMcode,
81               MultiWait,
82               (CURLM*, curl_waitfd[], unsigned int, int, int*),
83               (override));
84 
85  private:
86   DISALLOW_COPY_AND_ASSIGN(MockCurlInterface);
87 };
88 
89 }  // namespace http
90 }  // namespace brillo
91 
92 #endif  // LIBBRILLO_BRILLO_HTTP_MOCK_CURL_API_H_
93