1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Merge branch '4.0release' into merge/develop

This commit is contained in:
winlin 2021-09-23 13:36:25 +08:00
commit 8a78dc6868
11 changed files with 282 additions and 8 deletions

View file

@ -143,6 +143,11 @@ string mock_http_response2(int status, string content)
return ss.str();
}
bool is_string_contain(string substr, string str)
{
return (string::npos != str.find(substr));
}
class MockFileReaderFactory : public ISrsFileReaderFactory
{
public:
@ -1183,6 +1188,42 @@ VOID TEST(ProtocolHTTPTest, VodStreamHandlers)
HELPER_ASSERT_SUCCESS(h.serve_http(&w, &r));
__MOCK_HTTP_EXPECT_STREQ(200, "Hello, world!", w);
}
// should return "hls_ctx"
if (true) {
SrsHttpMuxEntry e;
e.pattern = "/";
SrsVodStream h("/tmp");
h.set_fs_factory(new MockFileReaderFactory("Hello, world!"));
h.set_path_check(_mock_srs_path_always_exists);
h.entry = &e;
MockResponseWriter w;
SrsHttpMessage r(NULL, NULL);
HELPER_ASSERT_SUCCESS(r.set_url("/index.m3u8", false));
HELPER_ASSERT_SUCCESS(h.serve_http(&w, &r));
__MOCK_HTTP_EXPECT_STRCT(200, "index.m3u8?hls_ctx=", w);
}
// should return "hls_ctx"
if (true) {
SrsHttpMuxEntry e;
e.pattern = "/";
SrsVodStream h("/tmp");
h.set_fs_factory(new MockFileReaderFactory("Hello, world!"));
h.set_path_check(_mock_srs_path_always_exists);
h.entry = &e;
MockResponseWriter w;
SrsHttpMessage r(NULL, NULL);
HELPER_ASSERT_SUCCESS(r.set_url("/index.m3u8?hls_ctx=123456", false));
HELPER_ASSERT_SUCCESS(h.serve_http(&w, &r));
__MOCK_HTTP_EXPECT_STRCT(200, "index.m3u8?hls_ctx=123456", w);
}
}
VOID TEST(ProtocolHTTPTest, BasicHandlers)

View file

@ -39,6 +39,7 @@ public:
string mock_http_response(int status, string content);
string mock_http_response2(int status, string content);
bool is_string_contain(string substr, string str);
#define __MOCK_HTTP_EXPECT_STREQ(status, text, w) \
EXPECT_STREQ(mock_http_response(status, text).c_str(), HELPER_BUFFER2STR(&w.io.out_buffer).c_str())
@ -46,5 +47,8 @@ string mock_http_response2(int status, string content);
#define __MOCK_HTTP_EXPECT_STREQ2(status, text, w) \
EXPECT_STREQ(mock_http_response2(status, text).c_str(), HELPER_BUFFER2STR(&w.io.out_buffer).c_str())
#define __MOCK_HTTP_EXPECT_STRCT(status, text, w) \
EXPECT_PRED2(is_string_contain, text, HELPER_BUFFER2STR(&w.io.out_buffer).c_str())
#endif