File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ set(TEST_SOURCES
5
5
test_large_data_transfer.cpp
6
6
test_raii.cpp )
7
7
8
+ if (WITH_HTTP )
9
+ set (TEST_SOURCES ${TEST_SOURCES} test_http_parser.cpp )
10
+ endif ()
11
+
8
12
enable_testing ()
9
13
add_executable (test_libnetcpp main.cpp ${TEST_SOURCES} )
10
14
target_link_libraries (test_libnetcpp ${CMAKE_THREAD_LIBS_INIT} )
Original file line number Diff line number Diff line change 1
- //
2
- // Created by lpcvoid on 26.12.22.
3
- //
1
+ #include " ../doctest/doctest/doctest.h"
2
+ #include " ../src/http/http.hpp"
3
+ #include " ../src/netlib.hpp"
4
+ #include < atomic>
5
+
6
+ using namespace std ::chrono_literals;
7
+ extern uint16_t test_port;
8
+
9
+ TEST_CASE (" Test HTTP response parser" )
10
+ {
11
+ netlib::http::http_response resp;
12
+
13
+ std::string raw_response = " HTTP/1.1 200 OK\r\n "
14
+ " Content-Type: text/html; charset=UTF-8\r\n "
15
+ " Content-Length: 1256\r\n "
16
+ " \r\n\r\n "
17
+ " TEST" ;
18
+
19
+ CHECK_FALSE (resp.from_raw_response (raw_response));
20
+ CHECK_EQ (resp.version .first , 1 );
21
+ CHECK_EQ (resp.version .second , 1 );
22
+ CHECK_EQ (resp.response_code , 200 );
23
+ CHECK_EQ (resp.headers .size (), 2 );
24
+ CHECK_EQ (resp.headers [0 ].first , " Content-Type" );
25
+ CHECK_EQ (resp.headers [1 ].first , " Content-Length" );
26
+ CHECK_EQ (resp.headers [0 ].second , " text/html; charset=UTF-8" );
27
+ CHECK_EQ (resp.headers [1 ].second , " 1256" );
28
+ CHECK_EQ (resp.body , " TEST" );
29
+
30
+ }
You can’t perform that action at this time.
0 commit comments