Skip to content

Commit

Permalink
add utest
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhaibo committed Feb 3, 2022
1 parent 4651fad commit 6ecb3fb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions trunk/src/utest/srs_utest_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ string mock_http_response2(int status, string content)
return ss.str();
}

string mock_http_response3(int status, string content)
{
stringstream ss;
ss << "HTTP/1.1 " << status << " " << srs_generate_http_status_text(status) << "\r\n"
<< "Server:" << "\r\n"
<< "\r\n"
<< content;
return ss.str();
}

bool is_string_contain(string substr, string str)
{
return (string::npos != str.find(substr));
Expand Down Expand Up @@ -528,6 +538,17 @@ VOID TEST(ProtocolHTTPTest, ClientRequest)
EXPECT_STREQ("Hello, world!", res.c_str());
srs_freep(msg);
}

// Normal case, with empty server.
if(true) {
MockBufferIO io; io.append(mock_http_response3(200, "Hello, world!"));
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
string res; HELPER_ASSERT_SUCCESS(msg->body_read_all(res));
EXPECT_EQ(200, msg->status_code());
EXPECT_STREQ("Hello, world!", res.c_str());
srs_freep(msg);
}
}

VOID TEST(ProtocolHTTPTest, ResponseHTTPError)
Expand Down

0 comments on commit 6ecb3fb

Please sign in to comment.