1 #ifndef QUICHE_HTTP2_ADAPTER_MOCK_NGHTTP2_CALLBACKS_H_ 2 #define QUICHE_HTTP2_ADAPTER_MOCK_NGHTTP2_CALLBACKS_H_ 3 4 #include <cstdint> 5 6 #include "absl/strings/string_view.h" 7 #include "quiche/http2/adapter/nghttp2.h" 8 #include "quiche/http2/adapter/nghttp2_util.h" 9 #include "quiche/common/platform/api/quiche_export.h" 10 #include "quiche/common/platform/api/quiche_test.h" 11 12 namespace http2 { 13 namespace adapter { 14 namespace test { 15 16 // This class provides a set of mock nghttp2 callbacks for use in unit test 17 // expectations. 18 class QUICHE_NO_EXPORT MockNghttp2Callbacks { 19 public: 20 MockNghttp2Callbacks() = default; 21 22 // The caller takes ownership of the |nghttp2_session_callbacks|. 23 static nghttp2_session_callbacks_unique_ptr GetCallbacks(); 24 25 MOCK_METHOD(ssize_t, Send, (const uint8_t* data, size_t length, int flags), 26 ()); 27 28 MOCK_METHOD(int, SendData, 29 (nghttp2_frame * frame, const uint8_t* framehd, size_t length, 30 nghttp2_data_source* source), 31 ()); 32 33 MOCK_METHOD(int, OnBeginHeaders, (const nghttp2_frame* frame), ()); 34 35 MOCK_METHOD(int, OnHeader, 36 (const nghttp2_frame* frame, absl::string_view name, 37 absl::string_view value, uint8_t flags), 38 ()); 39 40 MOCK_METHOD(int, OnDataChunkRecv, 41 (uint8_t flags, int32_t stream_id, absl::string_view data), ()); 42 43 MOCK_METHOD(int, OnBeginFrame, (const nghttp2_frame_hd* hd), ()); 44 45 MOCK_METHOD(int, OnFrameRecv, (const nghttp2_frame* frame), ()); 46 47 MOCK_METHOD(int, OnStreamClose, (int32_t stream_id, uint32_t error_code), ()); 48 49 MOCK_METHOD(int, BeforeFrameSend, (const nghttp2_frame* frame), ()); 50 51 MOCK_METHOD(int, OnFrameSend, (const nghttp2_frame* frame), ()); 52 53 MOCK_METHOD(int, OnFrameNotSend, 54 (const nghttp2_frame* frame, int lib_error_code), ()); 55 56 MOCK_METHOD(int, OnInvalidFrameRecv, 57 (const nghttp2_frame* frame, int error_code), ()); 58 59 MOCK_METHOD(int, OnErrorCallback2, 60 (int lib_error_code, const char* msg, size_t len), ()); 61 62 MOCK_METHOD(ssize_t, OnPackExtension, 63 (uint8_t * buf, size_t len, const nghttp2_frame* frame), ()); 64 }; 65 66 } // namespace test 67 } // namespace adapter 68 } // namespace http2 69 70 #endif // QUICHE_HTTP2_ADAPTER_MOCK_NGHTTP2_CALLBACKS_H_ 71