mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Add utest for srs_rtp_seq_distance
This commit is contained in:
parent
be1b0bf941
commit
3f5ab8dc63
13 changed files with 206 additions and 38 deletions
|
@ -5999,15 +5999,17 @@ VOID TEST(ProtocolHTTPTest, HTTPParser)
|
|||
|
||||
VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
MockBufferIO bio;
|
||||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\nContent-Length: 5\r\n\r\nHello");
|
||||
EXPECT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
ISrsHttpMessage* req = NULL;
|
||||
ASSERT_TRUE(0 == hp.parse_message(&bio, &req));
|
||||
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
||||
|
||||
// We should read body, or next parsing message will fail.
|
||||
// @see https://github.com/ossrs/srs/issues/1181
|
||||
|
@ -6019,7 +6021,7 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
|||
|
||||
// Should fail because there is body which not read.
|
||||
// @see https://github.com/ossrs/srs/issues/1181
|
||||
ASSERT_FALSE(0 == hp.parse_message(&bio, &req));
|
||||
HELPER_ASSERT_FAILED(hp.parse_message(&bio, &req));
|
||||
srs_freep(req);
|
||||
}
|
||||
|
||||
|
@ -6028,11 +6030,11 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
|||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET");
|
||||
EXPECT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
// Should fail if not completed message.
|
||||
ISrsHttpMessage* req = NULL;
|
||||
ASSERT_FALSE(0 == hp.parse_message(&bio, &req));
|
||||
HELPER_ASSERT_FAILED(hp.parse_message(&bio, &req));
|
||||
srs_freep(req);
|
||||
}
|
||||
|
||||
|
@ -6041,14 +6043,14 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
|||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\nContent-Length: 5\r\n\r\nHello");
|
||||
ASSERT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
ISrsHttpMessage* req = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
ASSERT_TRUE(0 == hp.parse_message(&bio, &req));
|
||||
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
||||
|
||||
char v[64] = {0};
|
||||
EXPECT_TRUE(0 == req->body_reader()->read(v, sizeof(v), NULL));
|
||||
HELPER_ASSERT_SUCCESS(req->body_reader()->read(v, sizeof(v), NULL));
|
||||
EXPECT_TRUE(string("Hello") == string(v));
|
||||
|
||||
EXPECT_TRUE(req->body_reader()->eof());
|
||||
|
@ -6059,11 +6061,11 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
|||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\nContent-Length: 0\r\n\r\n");
|
||||
ASSERT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
ISrsHttpMessage* req = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
EXPECT_TRUE(0 == hp.parse_message(&bio, &req));
|
||||
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
|
@ -6071,11 +6073,11 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
|||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\n\r\n");
|
||||
ASSERT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
ISrsHttpMessage* req = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
EXPECT_TRUE(0 == hp.parse_message(&bio, &req));
|
||||
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
|
@ -6083,11 +6085,11 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
|||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\n\r\n");
|
||||
ASSERT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
ISrsHttpMessage* req = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
EXPECT_TRUE(0 == hp.parse_message(&bio, &req));
|
||||
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
104
trunk/src/utest/srs_utest_rtc.cpp
Normal file
104
trunk/src/utest/srs_utest_rtc.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2020 Winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <srs_utest_rtc.hpp>
|
||||
|
||||
#include <srs_kernel_error.hpp>
|
||||
#include <srs_core_autofree.hpp>
|
||||
#include <srs_app_rtc_queue.hpp>
|
||||
#include <srs_kernel_rtc_rtp.hpp>
|
||||
|
||||
VOID TEST(KernelRTCTest, SequenceCompare)
|
||||
{
|
||||
if (true) {
|
||||
EXPECT_EQ(0, srs_rtp_seq_distance(0, 0));
|
||||
EXPECT_EQ(0, srs_rtp_seq_distance(1, 1));
|
||||
EXPECT_EQ(0, srs_rtp_seq_distance(3, 3));
|
||||
|
||||
EXPECT_EQ(1, srs_rtp_seq_distance(0, 1));
|
||||
EXPECT_EQ(-1, srs_rtp_seq_distance(1, 0));
|
||||
EXPECT_EQ(1, srs_rtp_seq_distance(65535, 0));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
EXPECT_FALSE(srs_rtp_seq_distance(1, 1) > 0);
|
||||
EXPECT_TRUE(srs_rtp_seq_distance(65534, 65535) > 0);
|
||||
EXPECT_TRUE(srs_rtp_seq_distance(0, 1) > 0);
|
||||
EXPECT_TRUE(srs_rtp_seq_distance(255, 256) > 0);
|
||||
|
||||
EXPECT_TRUE(srs_rtp_seq_distance(65535, 0) > 0);
|
||||
EXPECT_TRUE(srs_rtp_seq_distance(65280, 0) > 0);
|
||||
EXPECT_TRUE(srs_rtp_seq_distance(65535, 255) > 0);
|
||||
EXPECT_TRUE(srs_rtp_seq_distance(65280, 255) > 0);
|
||||
|
||||
EXPECT_FALSE(srs_rtp_seq_distance(0, 65535) > 0);
|
||||
EXPECT_FALSE(srs_rtp_seq_distance(0, 65280) > 0);
|
||||
EXPECT_FALSE(srs_rtp_seq_distance(255, 65535) > 0);
|
||||
EXPECT_FALSE(srs_rtp_seq_distance(255, 65280) > 0);
|
||||
|
||||
// Note that it's TRUE at https://mp.weixin.qq.com/s/JZTInmlB9FUWXBQw_7NYqg
|
||||
EXPECT_FALSE(srs_rtp_seq_distance(0, 32768) > 0);
|
||||
// It's FALSE definitely.
|
||||
EXPECT_FALSE(srs_rtp_seq_distance(32768, 0) > 0);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
EXPECT_FALSE(SrsSeqIsNewer(1, 1));
|
||||
EXPECT_TRUE(SrsSeqIsNewer(65535, 65534));
|
||||
EXPECT_TRUE(SrsSeqIsNewer(1, 0));
|
||||
EXPECT_TRUE(SrsSeqIsNewer(256, 255));
|
||||
|
||||
EXPECT_TRUE(SrsSeqIsNewer(0, 65535));
|
||||
EXPECT_TRUE(SrsSeqIsNewer(0, 65280));
|
||||
EXPECT_TRUE(SrsSeqIsNewer(255, 65535));
|
||||
EXPECT_TRUE(SrsSeqIsNewer(255, 65280));
|
||||
|
||||
EXPECT_FALSE(SrsSeqIsNewer(65535, 0));
|
||||
EXPECT_FALSE(SrsSeqIsNewer(65280, 0));
|
||||
EXPECT_FALSE(SrsSeqIsNewer(65535, 255));
|
||||
EXPECT_FALSE(SrsSeqIsNewer(65280, 255));
|
||||
|
||||
EXPECT_TRUE(SrsSeqIsNewer(32768, 0));
|
||||
EXPECT_FALSE(SrsSeqIsNewer(0, 32768));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
EXPECT_FALSE(SrsSeqDistance(1, 1) > 0);
|
||||
EXPECT_TRUE(SrsSeqDistance(65535, 65534) > 0);
|
||||
EXPECT_TRUE(SrsSeqDistance(1, 0) > 0);
|
||||
EXPECT_TRUE(SrsSeqDistance(256, 255) > 0);
|
||||
|
||||
EXPECT_TRUE(SrsSeqDistance(0, 65535) > 0);
|
||||
EXPECT_TRUE(SrsSeqDistance(0, 65280) > 0);
|
||||
EXPECT_TRUE(SrsSeqDistance(255, 65535) > 0);
|
||||
EXPECT_TRUE(SrsSeqDistance(255, 65280) > 0);
|
||||
|
||||
EXPECT_FALSE(SrsSeqDistance(65535, 0) > 0);
|
||||
EXPECT_FALSE(SrsSeqDistance(65280, 0) > 0);
|
||||
EXPECT_FALSE(SrsSeqDistance(65535, 255) > 0);
|
||||
EXPECT_FALSE(SrsSeqDistance(65280, 255) > 0);
|
||||
|
||||
EXPECT_TRUE(SrsSeqDistance(32768, 0) > 0);
|
||||
EXPECT_FALSE(SrsSeqDistance(0, 32768) > 0);
|
||||
}
|
||||
}
|
||||
|
33
trunk/src/utest/srs_utest_rtc.hpp
Normal file
33
trunk/src/utest/srs_utest_rtc.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2020 Winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_UTEST_RTC_HPP
|
||||
#define SRS_UTEST_RTC_HPP
|
||||
|
||||
/*
|
||||
#include <srs_utest_rtc.hpp>
|
||||
*/
|
||||
#include <srs_utest.hpp>
|
||||
|
||||
#endif
|
||||
|
|
@ -110,7 +110,7 @@ VOID TEST(TCPServerTest, PingPong)
|
|||
SrsTcpClient c(_srs_tmp_host, _srs_tmp_port, _srs_tmp_timeout);
|
||||
HELPER_EXPECT_SUCCESS(c.connect());
|
||||
|
||||
srs_usleep(100 * SRS_UTIME_MILLISECONDS);
|
||||
srs_usleep(30 * SRS_UTIME_MILLISECONDS);
|
||||
EXPECT_TRUE(h.fd != NULL);
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ VOID TEST(TCPServerTest, PingPong)
|
|||
HELPER_EXPECT_SUCCESS(c.connect());
|
||||
|
||||
SrsStSocket skt;
|
||||
srs_usleep(100 * SRS_UTIME_MILLISECONDS);
|
||||
srs_usleep(30 * SRS_UTIME_MILLISECONDS);
|
||||
#ifdef SRS_OSX
|
||||
ASSERT_TRUE(h.fd != NULL);
|
||||
#endif
|
||||
|
@ -145,7 +145,7 @@ VOID TEST(TCPServerTest, PingPong)
|
|||
HELPER_EXPECT_SUCCESS(c.connect());
|
||||
|
||||
SrsStSocket skt;
|
||||
srs_usleep(100 * SRS_UTIME_MILLISECONDS);
|
||||
srs_usleep(30 * SRS_UTIME_MILLISECONDS);
|
||||
#ifdef SRS_OSX
|
||||
ASSERT_TRUE(h.fd != NULL);
|
||||
#endif
|
||||
|
@ -169,7 +169,7 @@ VOID TEST(TCPServerTest, PingPong)
|
|||
HELPER_EXPECT_SUCCESS(c.connect());
|
||||
|
||||
SrsStSocket skt;
|
||||
srs_usleep(100 * SRS_UTIME_MILLISECONDS);
|
||||
srs_usleep(30 * SRS_UTIME_MILLISECONDS);
|
||||
#ifdef SRS_OSX
|
||||
ASSERT_TRUE(h.fd != NULL);
|
||||
#endif
|
||||
|
@ -204,7 +204,7 @@ VOID TEST(TCPServerTest, PingPongWithTimeout)
|
|||
HELPER_EXPECT_SUCCESS(c.connect());
|
||||
|
||||
SrsStSocket skt;
|
||||
srs_usleep(100 * SRS_UTIME_MILLISECONDS);
|
||||
srs_usleep(30 * SRS_UTIME_MILLISECONDS);
|
||||
#ifdef SRS_OSX
|
||||
ASSERT_TRUE(h.fd != NULL);
|
||||
#endif
|
||||
|
@ -226,7 +226,7 @@ VOID TEST(TCPServerTest, PingPongWithTimeout)
|
|||
HELPER_EXPECT_SUCCESS(c.connect());
|
||||
|
||||
SrsStSocket skt;
|
||||
srs_usleep(100 * SRS_UTIME_MILLISECONDS);
|
||||
srs_usleep(30 * SRS_UTIME_MILLISECONDS);
|
||||
#ifdef SRS_OSX
|
||||
ASSERT_TRUE(h.fd != NULL);
|
||||
#endif
|
||||
|
@ -248,7 +248,7 @@ VOID TEST(TCPServerTest, PingPongWithTimeout)
|
|||
HELPER_EXPECT_SUCCESS(c.connect());
|
||||
|
||||
SrsStSocket skt;
|
||||
srs_usleep(100 * SRS_UTIME_MILLISECONDS);
|
||||
srs_usleep(30 * SRS_UTIME_MILLISECONDS);
|
||||
#ifdef SRS_OSX
|
||||
ASSERT_TRUE(h.fd != NULL);
|
||||
#endif
|
||||
|
@ -428,7 +428,7 @@ VOID TEST(TCPServerTest, WritevIOVC)
|
|||
HELPER_EXPECT_SUCCESS(c.connect());
|
||||
|
||||
SrsStSocket skt;
|
||||
srs_usleep(100 * SRS_UTIME_MILLISECONDS);
|
||||
srs_usleep(30 * SRS_UTIME_MILLISECONDS);
|
||||
#ifdef SRS_OSX
|
||||
ASSERT_TRUE(h.fd != NULL);
|
||||
#endif
|
||||
|
@ -458,7 +458,7 @@ VOID TEST(TCPServerTest, WritevIOVC)
|
|||
HELPER_EXPECT_SUCCESS(c.connect());
|
||||
|
||||
SrsStSocket skt;
|
||||
srs_usleep(100 * SRS_UTIME_MILLISECONDS);
|
||||
srs_usleep(30 * SRS_UTIME_MILLISECONDS);
|
||||
#ifdef SRS_OSX
|
||||
ASSERT_TRUE(h.fd != NULL);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue