mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
Refine utest
This commit is contained in:
parent
c10671cbb3
commit
58561b9f76
4 changed files with 77 additions and 29 deletions
|
@ -151,8 +151,9 @@ enum SrsMp4BoxBrand
|
||||||
};
|
};
|
||||||
|
|
||||||
// The context to dump.
|
// The context to dump.
|
||||||
struct SrsMp4DumpContext
|
class SrsMp4DumpContext
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
int level;
|
int level;
|
||||||
bool summary;
|
bool summary;
|
||||||
|
|
||||||
|
@ -467,8 +468,9 @@ enum SrsMp4TrunFlags
|
||||||
|
|
||||||
// Entry for trun.
|
// Entry for trun.
|
||||||
// ISO_IEC_14496-12-base-format-2012.pdf, page 69
|
// ISO_IEC_14496-12-base-format-2012.pdf, page 69
|
||||||
struct SrsMp4TrunEntry
|
class SrsMp4TrunEntry
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
SrsMp4FullBox* owner;
|
SrsMp4FullBox* owner;
|
||||||
|
|
||||||
uint32_t sample_duration;
|
uint32_t sample_duration;
|
||||||
|
@ -864,7 +866,7 @@ public:
|
||||||
|
|
||||||
// 8.6.6 Edit List Box
|
// 8.6.6 Edit List Box
|
||||||
// ISO_IEC_14496-12-base-format-2012.pdf, page 55
|
// ISO_IEC_14496-12-base-format-2012.pdf, page 55
|
||||||
struct SrsMp4ElstEntry
|
class SrsMp4ElstEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// An integer that specifies the duration of this edit segment in units of the timescale
|
// An integer that specifies the duration of this edit segment in units of the timescale
|
||||||
|
@ -1514,8 +1516,9 @@ public:
|
||||||
|
|
||||||
// 8.6.1.2 Decoding Time to Sample Box (stts), for Audio/Video.
|
// 8.6.1.2 Decoding Time to Sample Box (stts), for Audio/Video.
|
||||||
// ISO_IEC_14496-12-base-format-2012.pdf, page 48
|
// ISO_IEC_14496-12-base-format-2012.pdf, page 48
|
||||||
struct SrsMp4SttsEntry
|
class SrsMp4SttsEntry
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
// An integer that counts the number of consecutive samples that have the given
|
// An integer that counts the number of consecutive samples that have the given
|
||||||
// duration.
|
// duration.
|
||||||
uint32_t sample_count;
|
uint32_t sample_count;
|
||||||
|
@ -1561,8 +1564,9 @@ public:
|
||||||
|
|
||||||
// 8.6.1.3 Composition Time to Sample Box (ctts), for Video.
|
// 8.6.1.3 Composition Time to Sample Box (ctts), for Video.
|
||||||
// ISO_IEC_14496-12-base-format-2012.pdf, page 49
|
// ISO_IEC_14496-12-base-format-2012.pdf, page 49
|
||||||
struct SrsMp4CttsEntry
|
class SrsMp4CttsEntry
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
// An integer that counts the number of consecutive samples that have the given offset.
|
// An integer that counts the number of consecutive samples that have the given offset.
|
||||||
uint32_t sample_count;
|
uint32_t sample_count;
|
||||||
// uint32_t for version=0
|
// uint32_t for version=0
|
||||||
|
@ -1638,8 +1642,9 @@ public:
|
||||||
|
|
||||||
// 8.7.4 Sample To Chunk Box (stsc), for Audio/Video.
|
// 8.7.4 Sample To Chunk Box (stsc), for Audio/Video.
|
||||||
// ISO_IEC_14496-12-base-format-2012.pdf, page 58
|
// ISO_IEC_14496-12-base-format-2012.pdf, page 58
|
||||||
struct SrsMp4StscEntry
|
class SrsMp4StscEntry
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
// An integer that gives the index of the first chunk in this run of chunks that share the
|
// An integer that gives the index of the first chunk in this run of chunks that share the
|
||||||
// same samples-per-chunk and sample-description-index; the index of the first chunk in a track has the
|
// same samples-per-chunk and sample-description-index; the index of the first chunk in a track has the
|
||||||
// value 1 (the first_chunk field in the first record of this box has the value 1, identifying that the first
|
// value 1 (the first_chunk field in the first record of this box has the value 1, identifying that the first
|
||||||
|
|
|
@ -34,12 +34,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <srs_app_log.hpp>
|
#include <srs_app_log.hpp>
|
||||||
|
|
||||||
// we add an empty macro for upp to show the smart tips.
|
// we add an empty macro for upp to show the smart tips.
|
||||||
#define VOID
|
#define VOID
|
||||||
|
|
||||||
|
// Temporary disk config.
|
||||||
|
std::string _srs_tmp_file_prefix = "/tmp/srs-utest-";
|
||||||
|
// Temporary network config.
|
||||||
|
std::string _srs_tmp_host = "127.0.0.1";
|
||||||
|
int _srs_tmp_port = 11935;
|
||||||
|
srs_utime_t _srs_tmp_timeout = (100 * SRS_UTIME_MILLISECONDS);
|
||||||
|
|
||||||
// For errors.
|
// For errors.
|
||||||
#define HELPER_EXPECT_SUCCESS(x) EXPECT_TRUE(srs_success == (err = x)); srs_freep(err)
|
#define HELPER_EXPECT_SUCCESS(x) EXPECT_TRUE(srs_success == (err = x)); srs_freep(err)
|
||||||
#define HELPER_EXPECT_FAILED(x) EXPECT_TRUE(srs_success != (err = x)); srs_freep(err)
|
#define HELPER_EXPECT_FAILED(x) EXPECT_TRUE(srs_success != (err = x)); srs_freep(err)
|
||||||
|
|
|
@ -3192,6 +3192,45 @@ VOID TEST(KernelFileReaderTest, WriteSpecialCase)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MockFileRemover
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
string f;
|
||||||
|
public:
|
||||||
|
MockFileRemover(string p) {
|
||||||
|
f = p;
|
||||||
|
}
|
||||||
|
virtual ~MockFileRemover() {
|
||||||
|
if (f != "") {
|
||||||
|
::unlink(f.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
VOID TEST(KernelFileTest, ReadWriteCase)
|
||||||
|
{
|
||||||
|
srs_error_t err;
|
||||||
|
|
||||||
|
string filepath = _srs_tmp_file_prefix + "kernel-file-read-write-case";
|
||||||
|
MockFileRemover _mfr(filepath);
|
||||||
|
|
||||||
|
SrsFileWriter w;
|
||||||
|
HELPER_EXPECT_SUCCESS(w.open(filepath.c_str()));
|
||||||
|
|
||||||
|
SrsFileReader r;
|
||||||
|
HELPER_EXPECT_SUCCESS(r.open(filepath.c_str()));
|
||||||
|
|
||||||
|
ssize_t nn = 0;
|
||||||
|
HELPER_EXPECT_SUCCESS(w.write((void*)"Hello", 5, &nn));
|
||||||
|
EXPECT_EQ(5, nn);
|
||||||
|
|
||||||
|
char buf[16] = {0};
|
||||||
|
HELPER_EXPECT_SUCCESS(r.read(buf, sizeof(buf), &nn));
|
||||||
|
EXPECT_EQ(5, nn);
|
||||||
|
|
||||||
|
EXPECT_STREQ("Hello", buf);
|
||||||
|
}
|
||||||
|
|
||||||
VOID TEST(KernelFLVTest, CoverAll)
|
VOID TEST(KernelFLVTest, CoverAll)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
|
|
|
@ -44,10 +44,6 @@ VOID TEST(ServiceTimeTest, TimeUnit)
|
||||||
EXPECT_FALSE(srs_is_never_timeout(0));
|
EXPECT_FALSE(srs_is_never_timeout(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MOCK_LISTEN_HOST "127.0.0.1"
|
|
||||||
#define MOCK_LISTEN_PORT 11935
|
|
||||||
#define MOCK_TCP_TIMEOUT (100 * SRS_UTIME_MILLISECONDS)
|
|
||||||
|
|
||||||
class MockTcpHandler : public ISrsTcpHandler
|
class MockTcpHandler : public ISrsTcpHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -80,7 +76,7 @@ VOID TEST(TCPServerTest, PingPong)
|
||||||
srs_error_t err;
|
srs_error_t err;
|
||||||
if (true) {
|
if (true) {
|
||||||
MockTcpHandler h;
|
MockTcpHandler h;
|
||||||
SrsTcpListener l(&h, MOCK_LISTEN_HOST, MOCK_LISTEN_PORT);
|
SrsTcpListener l(&h, _srs_tmp_host, _srs_tmp_port);
|
||||||
|
|
||||||
HELPER_EXPECT_SUCCESS(l.listen());
|
HELPER_EXPECT_SUCCESS(l.listen());
|
||||||
EXPECT_TRUE(l.fd() > 0);
|
EXPECT_TRUE(l.fd() > 0);
|
||||||
|
@ -88,10 +84,10 @@ VOID TEST(TCPServerTest, PingPong)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockTcpHandler h;
|
MockTcpHandler h;
|
||||||
SrsTcpListener l(&h, MOCK_LISTEN_HOST, MOCK_LISTEN_PORT);
|
SrsTcpListener l(&h, _srs_tmp_host, _srs_tmp_port);
|
||||||
HELPER_EXPECT_SUCCESS(l.listen());
|
HELPER_EXPECT_SUCCESS(l.listen());
|
||||||
|
|
||||||
SrsTcpClient c(MOCK_LISTEN_HOST, MOCK_LISTEN_PORT, MOCK_TCP_TIMEOUT);
|
SrsTcpClient c(_srs_tmp_host, _srs_tmp_port, _srs_tmp_timeout);
|
||||||
HELPER_EXPECT_SUCCESS(c.connect());
|
HELPER_EXPECT_SUCCESS(c.connect());
|
||||||
|
|
||||||
EXPECT_TRUE(h.fd != NULL);
|
EXPECT_TRUE(h.fd != NULL);
|
||||||
|
@ -99,10 +95,10 @@ VOID TEST(TCPServerTest, PingPong)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockTcpHandler h;
|
MockTcpHandler h;
|
||||||
SrsTcpListener l(&h, MOCK_LISTEN_HOST, MOCK_LISTEN_PORT);
|
SrsTcpListener l(&h, _srs_tmp_host, _srs_tmp_port);
|
||||||
HELPER_EXPECT_SUCCESS(l.listen());
|
HELPER_EXPECT_SUCCESS(l.listen());
|
||||||
|
|
||||||
SrsTcpClient c(MOCK_LISTEN_HOST, MOCK_LISTEN_PORT, MOCK_TCP_TIMEOUT);
|
SrsTcpClient c(_srs_tmp_host, _srs_tmp_port, _srs_tmp_timeout);
|
||||||
HELPER_EXPECT_SUCCESS(c.connect());
|
HELPER_EXPECT_SUCCESS(c.connect());
|
||||||
|
|
||||||
SrsStSocket skt;
|
SrsStSocket skt;
|
||||||
|
@ -118,10 +114,10 @@ VOID TEST(TCPServerTest, PingPong)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockTcpHandler h;
|
MockTcpHandler h;
|
||||||
SrsTcpListener l(&h, MOCK_LISTEN_HOST, MOCK_LISTEN_PORT);
|
SrsTcpListener l(&h, _srs_tmp_host, _srs_tmp_port);
|
||||||
HELPER_EXPECT_SUCCESS(l.listen());
|
HELPER_EXPECT_SUCCESS(l.listen());
|
||||||
|
|
||||||
SrsTcpClient c(MOCK_LISTEN_HOST, MOCK_LISTEN_PORT, MOCK_TCP_TIMEOUT);
|
SrsTcpClient c(_srs_tmp_host, _srs_tmp_port, _srs_tmp_timeout);
|
||||||
HELPER_EXPECT_SUCCESS(c.connect());
|
HELPER_EXPECT_SUCCESS(c.connect());
|
||||||
|
|
||||||
SrsStSocket skt;
|
SrsStSocket skt;
|
||||||
|
@ -139,10 +135,10 @@ VOID TEST(TCPServerTest, PingPong)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockTcpHandler h;
|
MockTcpHandler h;
|
||||||
SrsTcpListener l(&h, MOCK_LISTEN_HOST, MOCK_LISTEN_PORT);
|
SrsTcpListener l(&h, _srs_tmp_host, _srs_tmp_port);
|
||||||
HELPER_EXPECT_SUCCESS(l.listen());
|
HELPER_EXPECT_SUCCESS(l.listen());
|
||||||
|
|
||||||
SrsTcpClient c(MOCK_LISTEN_HOST, MOCK_LISTEN_PORT, MOCK_TCP_TIMEOUT);
|
SrsTcpClient c(_srs_tmp_host, _srs_tmp_port, _srs_tmp_timeout);
|
||||||
HELPER_EXPECT_SUCCESS(c.connect());
|
HELPER_EXPECT_SUCCESS(c.connect());
|
||||||
|
|
||||||
SrsStSocket skt;
|
SrsStSocket skt;
|
||||||
|
@ -171,10 +167,10 @@ VOID TEST(TCPServerTest, PingPongWithTimeout)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockTcpHandler h;
|
MockTcpHandler h;
|
||||||
SrsTcpListener l(&h, MOCK_LISTEN_HOST, MOCK_LISTEN_PORT);
|
SrsTcpListener l(&h, _srs_tmp_host, _srs_tmp_port);
|
||||||
HELPER_EXPECT_SUCCESS(l.listen());
|
HELPER_EXPECT_SUCCESS(l.listen());
|
||||||
|
|
||||||
SrsTcpClient c(MOCK_LISTEN_HOST, MOCK_LISTEN_PORT, MOCK_TCP_TIMEOUT);
|
SrsTcpClient c(_srs_tmp_host, _srs_tmp_port, _srs_tmp_timeout);
|
||||||
HELPER_EXPECT_SUCCESS(c.connect());
|
HELPER_EXPECT_SUCCESS(c.connect());
|
||||||
|
|
||||||
SrsStSocket skt;
|
SrsStSocket skt;
|
||||||
|
@ -190,10 +186,10 @@ VOID TEST(TCPServerTest, PingPongWithTimeout)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockTcpHandler h;
|
MockTcpHandler h;
|
||||||
SrsTcpListener l(&h, MOCK_LISTEN_HOST, MOCK_LISTEN_PORT);
|
SrsTcpListener l(&h, _srs_tmp_host, _srs_tmp_port);
|
||||||
HELPER_EXPECT_SUCCESS(l.listen());
|
HELPER_EXPECT_SUCCESS(l.listen());
|
||||||
|
|
||||||
SrsTcpClient c(MOCK_LISTEN_HOST, MOCK_LISTEN_PORT, MOCK_TCP_TIMEOUT);
|
SrsTcpClient c(_srs_tmp_host, _srs_tmp_port, _srs_tmp_timeout);
|
||||||
HELPER_EXPECT_SUCCESS(c.connect());
|
HELPER_EXPECT_SUCCESS(c.connect());
|
||||||
|
|
||||||
SrsStSocket skt;
|
SrsStSocket skt;
|
||||||
|
@ -209,10 +205,10 @@ VOID TEST(TCPServerTest, PingPongWithTimeout)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockTcpHandler h;
|
MockTcpHandler h;
|
||||||
SrsTcpListener l(&h, MOCK_LISTEN_HOST, MOCK_LISTEN_PORT);
|
SrsTcpListener l(&h, _srs_tmp_host, _srs_tmp_port);
|
||||||
HELPER_EXPECT_SUCCESS(l.listen());
|
HELPER_EXPECT_SUCCESS(l.listen());
|
||||||
|
|
||||||
SrsTcpClient c(MOCK_LISTEN_HOST, MOCK_LISTEN_PORT, MOCK_TCP_TIMEOUT);
|
SrsTcpClient c(_srs_tmp_host, _srs_tmp_port, _srs_tmp_timeout);
|
||||||
HELPER_EXPECT_SUCCESS(c.connect());
|
HELPER_EXPECT_SUCCESS(c.connect());
|
||||||
|
|
||||||
SrsStSocket skt;
|
SrsStSocket skt;
|
||||||
|
@ -234,10 +230,10 @@ VOID TEST(TCPServerTest, WritevIOVC)
|
||||||
srs_error_t err;
|
srs_error_t err;
|
||||||
if (true) {
|
if (true) {
|
||||||
MockTcpHandler h;
|
MockTcpHandler h;
|
||||||
SrsTcpListener l(&h, MOCK_LISTEN_HOST, MOCK_LISTEN_PORT);
|
SrsTcpListener l(&h, _srs_tmp_host, _srs_tmp_port);
|
||||||
HELPER_EXPECT_SUCCESS(l.listen());
|
HELPER_EXPECT_SUCCESS(l.listen());
|
||||||
|
|
||||||
SrsTcpClient c(MOCK_LISTEN_HOST, MOCK_LISTEN_PORT, MOCK_TCP_TIMEOUT);
|
SrsTcpClient c(_srs_tmp_host, _srs_tmp_port, _srs_tmp_timeout);
|
||||||
HELPER_EXPECT_SUCCESS(c.connect());
|
HELPER_EXPECT_SUCCESS(c.connect());
|
||||||
|
|
||||||
SrsStSocket skt;
|
SrsStSocket skt;
|
||||||
|
@ -261,10 +257,10 @@ VOID TEST(TCPServerTest, WritevIOVC)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockTcpHandler h;
|
MockTcpHandler h;
|
||||||
SrsTcpListener l(&h, MOCK_LISTEN_HOST, MOCK_LISTEN_PORT);
|
SrsTcpListener l(&h, _srs_tmp_host, _srs_tmp_port);
|
||||||
HELPER_EXPECT_SUCCESS(l.listen());
|
HELPER_EXPECT_SUCCESS(l.listen());
|
||||||
|
|
||||||
SrsTcpClient c(MOCK_LISTEN_HOST, MOCK_LISTEN_PORT, MOCK_TCP_TIMEOUT);
|
SrsTcpClient c(_srs_tmp_host, _srs_tmp_port, _srs_tmp_timeout);
|
||||||
HELPER_EXPECT_SUCCESS(c.connect());
|
HELPER_EXPECT_SUCCESS(c.connect());
|
||||||
|
|
||||||
SrsStSocket skt;
|
SrsStSocket skt;
|
||||||
|
|
Loading…
Reference in a new issue