mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 11:21:52 +00:00
Improve test coverage for log service.
This commit is contained in:
parent
2cc021b2d7
commit
cc11f36940
4 changed files with 69 additions and 4 deletions
|
@ -82,6 +82,7 @@ void SrsThreadContext::clear_cid()
|
|||
}
|
||||
}
|
||||
|
||||
// LCOV_EXCL_START
|
||||
SrsConsoleLog::SrsConsoleLog(SrsLogLevel l, bool u)
|
||||
{
|
||||
level = l;
|
||||
|
@ -208,6 +209,7 @@ void SrsConsoleLog::error(const char* tag, int context_id, const char* fmt, ...)
|
|||
|
||||
fprintf(stderr, "%s\n", buffer);
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, int cid, const char* level, int* psize)
|
||||
{
|
||||
|
|
|
@ -33,12 +33,12 @@ using namespace std;
|
|||
#include <srs_protocol_utility.hpp>
|
||||
#include <srs_service_utility.hpp>
|
||||
|
||||
SrsBasicRtmpClient::SrsBasicRtmpClient(string u, srs_utime_t ctm, srs_utime_t stm)
|
||||
SrsBasicRtmpClient::SrsBasicRtmpClient(string r, srs_utime_t ctm, srs_utime_t stm)
|
||||
{
|
||||
clk = new SrsWallClock();
|
||||
kbps = new SrsKbps(clk);
|
||||
|
||||
url = u;
|
||||
url = r;
|
||||
connect_timeout = ctm;
|
||||
stream_timeout = stm;
|
||||
|
||||
|
|
|
@ -60,10 +60,10 @@ private:
|
|||
int stream_id;
|
||||
public:
|
||||
// Constructor.
|
||||
// @param u The RTMP url, for example, rtmp://ip:port/app/stream?domain=vhost
|
||||
// @param r The RTMP url, for example, rtmp://ip:port/app/stream?domain=vhost
|
||||
// @param ctm The timeout in srs_utime_t to connect to server.
|
||||
// @param stm The timeout in srs_utime_t to delivery A/V stream.
|
||||
SrsBasicRtmpClient(std::string u, srs_utime_t ctm, srs_utime_t stm);
|
||||
SrsBasicRtmpClient(std::string r, srs_utime_t ctm, srs_utime_t stm);
|
||||
virtual ~SrsBasicRtmpClient();
|
||||
public:
|
||||
// Connect, handshake and connect app to RTMP server.
|
||||
|
|
|
@ -37,6 +37,7 @@ using namespace std;
|
|||
#include <srs_utest_http.hpp>
|
||||
#include <srs_service_utility.hpp>
|
||||
#include <srs_service_http_client.hpp>
|
||||
#include <srs_service_rtmp_conn.hpp>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
|
||||
|
@ -1200,6 +1201,7 @@ VOID TEST(TCPServerTest, HTTPClientUtility)
|
|||
SrsHttpClient client;
|
||||
HELPER_ASSERT_SUCCESS(client.initialize("127.0.0.1", 8080, 1*SRS_UTIME_SECONDS));
|
||||
client.set_recv_timeout(1 * SRS_UTIME_SECONDS);
|
||||
client.set_header("agent", "srs");
|
||||
|
||||
ISrsHttpMessage* res = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, res);
|
||||
|
@ -1218,3 +1220,64 @@ VOID TEST(TCPServerTest, HTTPClientUtility)
|
|||
}
|
||||
}
|
||||
|
||||
class MockConnectionManager : public IConnectionManager
|
||||
{
|
||||
public:
|
||||
MockConnectionManager() {
|
||||
}
|
||||
virtual ~MockConnectionManager() {
|
||||
}
|
||||
public:
|
||||
virtual void remove(ISrsConnection* /*c*/) {
|
||||
}
|
||||
};
|
||||
|
||||
VOID TEST(TCPServerTest, ContextUtility)
|
||||
{
|
||||
if (true) {
|
||||
SrsThreadContext ctx;
|
||||
|
||||
EXPECT_EQ(0, ctx.set_id(100));
|
||||
EXPECT_EQ(100, ctx.set_id(1000));
|
||||
EXPECT_EQ(1000, ctx.get_id());
|
||||
|
||||
ctx.clear_cid();
|
||||
EXPECT_EQ(0, ctx.set_id(100));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, true, true, "SRS", 100, "Trace", &size));
|
||||
EXPECT_EQ(53, size);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, false, true, "SRS", 100, "Trace", &size));
|
||||
EXPECT_EQ(53, size);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
errno = 0;
|
||||
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, false, true, NULL, 100, "Trace", &size));
|
||||
EXPECT_EQ(48, size);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, false, false, NULL, 100, "Trace", &size));
|
||||
EXPECT_EQ(45, size);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockConnectionManager cm;
|
||||
cm.remove(NULL);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
srs_utime_t to = 1*SRS_UTIME_SECONDS;
|
||||
SrsBasicRtmpClient rc("rtmp://127.0.0.1/live/livestream", to, to);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue