From d2052fd4cd902a7588304d25736d74bbd33bb765 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 11:54:53 +0800 Subject: [PATCH 01/12] Support sequence header only for mp4 --- trunk/src/kernel/srs_kernel_mp4.cpp | 16 +- trunk/src/utest/srs_utest.hpp | 10 +- trunk/src/utest/srs_utest_kernel.cpp | 787 +++++++++++++++++---------- 3 files changed, 531 insertions(+), 282 deletions(-) diff --git a/trunk/src/kernel/srs_kernel_mp4.cpp b/trunk/src/kernel/srs_kernel_mp4.cpp index ddcce00be..1845a87b2 100644 --- a/trunk/src/kernel/srs_kernel_mp4.cpp +++ b/trunk/src/kernel/srs_kernel_mp4.cpp @@ -3884,6 +3884,11 @@ SrsMp4DecodingTime2SampleBox::~SrsMp4DecodingTime2SampleBox() srs_error_t SrsMp4DecodingTime2SampleBox::initialize_counter() { srs_error_t err = srs_success; + + // If only sps/pps and no frames, there is no stts entries. + if (entries.empty()) { + return err; + } index = 0; if (index >= entries.size()) { @@ -4005,6 +4010,11 @@ SrsMp4CompositionTime2SampleBox::~SrsMp4CompositionTime2SampleBox() srs_error_t SrsMp4CompositionTime2SampleBox::initialize_counter() { srs_error_t err = srs_success; + + // If only sps/pps and no frames, there is no stts entries. + if (entries.empty()) { + return err; + } index = 0; if (index >= entries.size()) { @@ -4812,7 +4822,7 @@ srs_error_t SrsMp4SampleManager::write(SrsMp4MovieBox* moov) vector::iterator it; for (it = samples.begin(); it != samples.end(); ++it) { SrsMp4Sample* sample = *it; - if (sample->dts != sample->pts) { + if (sample->dts != sample->pts && sample->type == SrsFrameTypeVideo) { has_cts = true; break; } @@ -5760,7 +5770,7 @@ srs_error_t SrsMp4Encoder::flush() mvhd->duration_in_tbn = srs_max(vduration, aduration); mvhd->next_track_ID = 1; // Starts from 1, increase when use it. - if (nb_videos) { + if (nb_videos || !pavcc.empty()) { SrsMp4TrackBox* trak = new SrsMp4TrackBox(); moov->add_trak(trak); @@ -5824,7 +5834,7 @@ srs_error_t SrsMp4Encoder::flush() avcC->avc_config = pavcc; } - if (nb_audios) { + if (nb_audios || !pasc.empty()) { SrsMp4TrackBox* trak = new SrsMp4TrackBox(); moov->add_trak(trak); diff --git a/trunk/src/utest/srs_utest.hpp b/trunk/src/utest/srs_utest.hpp index fb8c03eea..ffda614d9 100644 --- a/trunk/src/utest/srs_utest.hpp +++ b/trunk/src/utest/srs_utest.hpp @@ -51,12 +51,18 @@ extern int _srs_tmp_port; extern srs_utime_t _srs_tmp_timeout; // For errors. -#define HELPER_EXPECT_SUCCESS(x) EXPECT_TRUE(srs_success == (err = x)); srs_freep(err) +#define HELPER_EXPECT_SUCCESS(x) \ + if ((err = x) != srs_success) fprintf(stderr, "err %s", srs_error_desc(err).c_str()); \ + EXPECT_TRUE(srs_success == err); \ + srs_freep(err) #define HELPER_EXPECT_FAILED(x) EXPECT_TRUE(srs_success != (err = x)); srs_freep(err) // For errors, assert. // @remark The err is leak when error, but it's ok in utest. -#define HELPER_ASSERT_SUCCESS(x) ASSERT_TRUE(srs_success == (err = x)); srs_freep(err) +#define HELPER_ASSERT_SUCCESS(x) \ + if ((err = x) != srs_success) fprintf(stderr, "err %s", srs_error_desc(err).c_str()); \ + ASSERT_TRUE(srs_success == err); \ + srs_freep(err) #define HELPER_ASSERT_FAILED(x) ASSERT_TRUE(srs_success != (err = x)); srs_freep(err) // For init array data. diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index 7e4d32f11..1a2f4c796 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -37,6 +37,7 @@ using namespace std; #include #include #include +#include #define MAX_MOCK_DATA_SIZE 1024 * 1024 @@ -90,6 +91,10 @@ srs_error_t MockSrsFile::read(void* data, size_t count, ssize_t* pnread) { srs_error_t err = srs_success; + if (_buf->left() == 0) { + return srs_error_new(ERROR_SYSTEM_FILE_EOF, "EOF"); + } + int limit = srs_min(_buf->left(), (int)count); if (limit <= 0) { @@ -319,6 +324,10 @@ MockBufferReader::~MockBufferReader() srs_error_t MockBufferReader::read(void* buf, size_t size, ssize_t* nread) { + if (str.empty()) { + return srs_error_new(ERROR_SYSTEM_FILE_EOF, "EOF"); + } + int len = srs_min(str.length(), size); if (len == 0) { return srs_error_new(-1, "no data"); @@ -375,6 +384,60 @@ srs_error_t MockTsHandler::on_ts_message(SrsTsMessage* m) return srs_success; } +void mock_print_err(srs_error_t err) +{ + fprintf(stderr, "err %s\n", srs_error_desc(err).c_str()); + srs_freep(err); +} + +void mock_print_mp4(string data) +{ + srs_error_t err = srs_success; + + MockSrsFileReader fr(data.data(), data.length()); + + SrsMp4BoxReader br; + if ((err = br.initialize(&fr)) != srs_success) { + mock_print_err(srs_error_wrap(err, "init br")); + return; + } + + SrsSimpleStream* stream = new SrsSimpleStream(); + SrsAutoFree(SrsSimpleStream, stream); + + while (true) { + SrsMp4Box* box = NULL; + SrsAutoFree(SrsMp4Box, box); + + if ((err = br.read(stream, &box)) != srs_success) { + if (srs_error_code(err) != ERROR_SYSTEM_FILE_EOF) { + mock_print_err(srs_error_wrap(err, "read")); + } + return; + } + + SrsBuffer* buffer = new SrsBuffer(stream->bytes(), stream->length()); + SrsAutoFree(SrsBuffer, buffer); + + if ((err = box->decode(buffer)) != srs_success) { + mock_print_err(srs_error_wrap(err, "decode")); + return; + } + + if ((err = br.skip(box, stream)) != srs_success) { + mock_print_err(srs_error_wrap(err, "skip")); + return; + } + + SrsMp4DumpContext ctx; + ctx.level = 1; + ctx.summary = true; + + stringstream ss; + fprintf(stderr, "%s", box->dumps(ss, ctx).str().c_str()); + } +} + VOID TEST(KernelBufferTest, DefaultObject) { SrsSimpleStream b; @@ -1947,11 +2010,13 @@ VOID TEST(KernelStreamTest, StreamWriteBytes) VOID TEST(KernelBufferTest, CoverAll) { + srs_error_t err; + if (true) { MockSrsCodec codec; EXPECT_TRUE(0 == codec.nb_bytes()); - EXPECT_TRUE(srs_success == codec.encode(NULL)); - EXPECT_TRUE(srs_success == codec.decode(NULL)); + HELPER_EXPECT_SUCCESS(codec.encode(NULL)); + HELPER_EXPECT_SUCCESS(codec.decode(NULL)); } if (true) { @@ -2310,11 +2375,13 @@ VOID TEST(KernelUtility, CRC32MPEGTS) VOID TEST(KernelUtility, Base64Decode) { + srs_error_t err; + string cipher = "dXNlcjpwYXNzd29yZA=="; string expect = "user:password"; string plaintext; - EXPECT_TRUE(srs_success == srs_av_base64_decode(cipher, plaintext)); + HELPER_EXPECT_SUCCESS(srs_av_base64_decode(cipher, plaintext)); EXPECT_TRUE(expect == plaintext); } @@ -2789,7 +2856,7 @@ VOID TEST(KernelErrorTest, CoverAll) if (true) { srs_error_t err = srs_success; - EXPECT_TRUE(srs_success == srs_error_copy(err)); + HELPER_EXPECT_SUCCESS(srs_error_copy(err)); } if (true) { @@ -2803,10 +2870,12 @@ VOID TEST(KernelErrorTest, CoverAll) VOID TEST(KernelAACTest, TransmaxRTMP2AAC) { + srs_error_t err; + if (true) { SrsAacTransmuxer m; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); srs_error_t err = m.write_audio(0, (char*)"", 0); EXPECT_EQ(ERROR_AAC_DECODE_ERROR, srs_error_code(err)); @@ -2824,7 +2893,7 @@ VOID TEST(KernelAACTest, TransmaxRTMP2AAC) if (true) { SrsAacTransmuxer m; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); srs_error_t err = m.write_audio(0, (char*)"\xaf\x01\x00", 3); EXPECT_TRUE(ERROR_AAC_DECODE_ERROR == srs_error_code(err)); @@ -2836,23 +2905,21 @@ VOID TEST(KernelAACTest, TransmaxRTMP2AAC) if (true) { SrsAacTransmuxer m; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); srs_error_t err = m.write_audio(0, (char*)"\xaf\x00", 2); EXPECT_TRUE(ERROR_AAC_DECODE_ERROR == srs_error_code(err)); srs_freep(err); err = m.write_audio(0, (char*)"\xaf\x00\x12\x10", 4); - EXPECT_TRUE(srs_success == err); - srs_freep(err); + HELPER_EXPECT_SUCCESS(err); EXPECT_TRUE(m.got_sequence_header); EXPECT_EQ(44100, srs_aac_srates[m.aac_sample_rate]); EXPECT_EQ(2, m.aac_channels); err = m.write_audio(0, (char*)"\xaf\x01\xcb", 3); - EXPECT_TRUE(srs_success == err); - srs_freep(err); + HELPER_EXPECT_SUCCESS(err); EXPECT_EQ(8, f.tellg()); EXPECT_EQ((char)0xff, f.data()[0]); @@ -2868,15 +2935,14 @@ VOID TEST(KernelAACTest, TransmaxRTMP2AAC) if (true) { SrsAacTransmuxer m; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); srs_error_t err = m.write_audio(0, (char*)"\xaf\x00", 2); EXPECT_TRUE(ERROR_AAC_DECODE_ERROR == srs_error_code(err)); srs_freep(err); err = m.write_audio(0, (char*)"\xaf\x00\x12\x10", 4); - EXPECT_TRUE(srs_success == err); - srs_freep(err); + HELPER_EXPECT_SUCCESS(err); EXPECT_TRUE(m.got_sequence_header); EXPECT_EQ(44100, srs_aac_srates[m.aac_sample_rate]); @@ -2885,22 +2951,20 @@ VOID TEST(KernelAACTest, TransmaxRTMP2AAC) f.error_offset = 6; err = m.write_audio(0, (char*)"\xaf\x01\x00", 3); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { SrsAacTransmuxer m; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); srs_error_t err = m.write_audio(0, (char*)"\xaf\x00", 2); EXPECT_TRUE(ERROR_AAC_DECODE_ERROR == srs_error_code(err)); srs_freep(err); err = m.write_audio(0, (char*)"\xaf\x00\x12\x10", 4); - EXPECT_TRUE(srs_success == err); - srs_freep(err); + HELPER_EXPECT_SUCCESS(err); EXPECT_TRUE(m.got_sequence_header); EXPECT_EQ(44100, srs_aac_srates[m.aac_sample_rate]); @@ -2909,8 +2973,7 @@ VOID TEST(KernelAACTest, TransmaxRTMP2AAC) f.error_offset = 7; err = m.write_audio(0, (char*)"\xaf\x01\x00", 3); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } } @@ -3111,18 +3174,20 @@ VOID TEST(KernelCodecTest, CoverAll) VOID TEST(KernelCodecTest, AVFrame) { + srs_error_t err; + if (true) { SrsAudioFrame f; SrsAudioCodecConfig cc; - EXPECT_TRUE(srs_success == f.initialize(&cc)); + HELPER_EXPECT_SUCCESS(f.initialize(&cc)); EXPECT_TRUE(f.acodec() != NULL); - EXPECT_TRUE(srs_success == f.add_sample((char*)1, 10)); + HELPER_EXPECT_SUCCESS(f.add_sample((char*)1, 10)); EXPECT_TRUE((char*)1 == f.samples[0].bytes); EXPECT_TRUE(10 == f.samples[0].size); EXPECT_TRUE(1 == f.nb_samples); - EXPECT_TRUE(srs_success == f.add_sample((char*)2, 20)); + HELPER_EXPECT_SUCCESS(f.add_sample((char*)2, 20)); EXPECT_TRUE((char*)2 == f.samples[1].bytes); EXPECT_TRUE(20 == f.samples[1].size); EXPECT_TRUE(2 == f.nb_samples); @@ -3131,21 +3196,20 @@ VOID TEST(KernelCodecTest, AVFrame) if (true) { SrsAudioFrame f; for (int i = 0; i < SrsMaxNbSamples; i++) { - EXPECT_TRUE(srs_success == f.add_sample((char*)(int64_t)i, i*10)); + HELPER_EXPECT_SUCCESS(f.add_sample((char*)(int64_t)i, i*10)); } srs_error_t err = f.add_sample((char*)1, 1); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { SrsVideoFrame f; SrsVideoCodecConfig cc; - EXPECT_TRUE(srs_success == f.initialize(&cc)); + HELPER_EXPECT_SUCCESS(f.initialize(&cc)); EXPECT_TRUE(f.vcodec() != NULL); - EXPECT_TRUE(srs_success == f.add_sample((char*)"\x05", 1)); + HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x05", 1)); EXPECT_TRUE(f.has_idr == true); EXPECT_TRUE(f.first_nalu_type == SrsAvcNaluTypeIDR); } @@ -3153,42 +3217,41 @@ VOID TEST(KernelCodecTest, AVFrame) if (true) { SrsVideoFrame f; SrsVideoCodecConfig cc; - EXPECT_TRUE(srs_success == f.initialize(&cc)); + HELPER_EXPECT_SUCCESS(f.initialize(&cc)); EXPECT_TRUE(f.vcodec() != NULL); - EXPECT_TRUE(srs_success == f.add_sample((char*)"\x07", 1)); + HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x07", 1)); EXPECT_TRUE(f.has_sps_pps == true); } if (true) { SrsVideoFrame f; SrsVideoCodecConfig cc; - EXPECT_TRUE(srs_success == f.initialize(&cc)); + HELPER_EXPECT_SUCCESS(f.initialize(&cc)); EXPECT_TRUE(f.vcodec() != NULL); - EXPECT_TRUE(srs_success == f.add_sample((char*)"\x08", 1)); + HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x08", 1)); EXPECT_TRUE(f.has_sps_pps == true); } if (true) { SrsVideoFrame f; SrsVideoCodecConfig cc; - EXPECT_TRUE(srs_success == f.initialize(&cc)); + HELPER_EXPECT_SUCCESS(f.initialize(&cc)); EXPECT_TRUE(f.vcodec() != NULL); - EXPECT_TRUE(srs_success == f.add_sample((char*)"\x09", 1)); + HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x09", 1)); EXPECT_TRUE(f.has_aud == true); } if (true) { SrsVideoFrame f; for (int i = 0; i < SrsMaxNbSamples; i++) { - EXPECT_TRUE(srs_success == f.add_sample((char*)"\x05", 1)); + HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x05", 1)); } srs_error_t err = f.add_sample((char*)"\x05", 1); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } } @@ -3227,31 +3290,33 @@ VOID TEST(KernelCodecTest, IsSequenceHeaderSpecial) VOID TEST(KernelCodecTest, AudioFormat) { + srs_error_t err; + if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); - EXPECT_TRUE(srs_success == f.on_audio(0, NULL, 0)); - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\x00", 0)); - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\x00", 1)); + HELPER_EXPECT_SUCCESS(f.on_audio(0, NULL, 0)); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\x00", 0)); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\x00", 1)); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\x20\x00", 2)); + HELPER_EXPECT_SUCCESS(f.initialize()); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\x20\x00", 2)); EXPECT_TRUE(1 == f.nb_raw); EXPECT_TRUE(0 == f.audio->nb_samples); - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\x20\x00\x00", 3)); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\x20\x00\x00", 3)); EXPECT_TRUE(2 == f.nb_raw); EXPECT_TRUE(1 == f.audio->nb_samples); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\xaf\x00\x12\x10", 4)); + HELPER_EXPECT_SUCCESS(f.initialize()); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\xaf\x00\x12\x10", 4)); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, f.audio->aac_packet_type); EXPECT_EQ(2, f.acodec->aac_channels); EXPECT_EQ(4, f.acodec->aac_sample_rate); @@ -3261,70 +3326,66 @@ VOID TEST(KernelCodecTest, AudioFormat) EXPECT_EQ(SrsAudioSampleRate44100, f.acodec->sound_rate); EXPECT_EQ(SrsAudioSampleBits16bit, f.acodec->sound_size); - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\xaf\x01\x00", 3)); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\xaf\x01\x00", 3)); EXPECT_EQ(SrsAudioAacFrameTraitRawData, f.audio->aac_packet_type); EXPECT_EQ(1, f.audio->nb_samples); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\xaf\x00\x13\x90", 4)); + HELPER_EXPECT_SUCCESS(f.initialize()); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\xaf\x00\x13\x90", 4)); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, f.audio->aac_packet_type); EXPECT_EQ(7, f.acodec->aac_sample_rate); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\xaf\x00\x15\x10", 4)); + HELPER_EXPECT_SUCCESS(f.initialize()); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\xaf\x00\x15\x10", 4)); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, f.audio->aac_packet_type); EXPECT_EQ(10, f.acodec->aac_sample_rate); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\xaf\x01\x00", 3)); + HELPER_EXPECT_SUCCESS(f.initialize()); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\xaf\x01\x00", 3)); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\xaf\x00\x12\x10", 4)); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\xaf\x00\x12\x10", 4)); SrsBuffer b((char*)"\x20", 1); srs_error_t err = f.audio_aac_demux(&b, 0); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\xaf\x00\x12\x10", 4)); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\xaf\x00\x12\x10", 4)); SrsBuffer b((char*)"\x30", 1); srs_error_t err = f.audio_aac_demux(&b, 0); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { SrsFormat f; srs_error_t err = f.on_audio(0, (char*)"\xaf\x00\x12", 3); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { SrsFormat f; srs_error_t err = f.on_audio(0, (char*)"\xaf\x00\x02\x00", 4); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.on_aac_sequence_header((char*)"\x12\x10", 2)); + HELPER_EXPECT_SUCCESS(f.on_aac_sequence_header((char*)"\x12\x10", 2)); EXPECT_EQ(2, f.acodec->aac_channels); EXPECT_EQ(4, f.acodec->aac_sample_rate); EXPECT_EQ(2, f.acodec->aac_object); @@ -3332,8 +3393,8 @@ VOID TEST(KernelCodecTest, AudioFormat) if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); - EXPECT_TRUE(srs_success == f.on_audio(0, (char*)"\xaf\x00\x12\x10", 4)); + HELPER_EXPECT_SUCCESS(f.initialize()); + HELPER_EXPECT_SUCCESS(f.on_audio(0, (char*)"\xaf\x00\x12\x10", 4)); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, f.audio->aac_packet_type); EXPECT_TRUE(f.is_aac_sequence_header()); EXPECT_TRUE(!f.is_avc_sequence_header()); @@ -3346,14 +3407,14 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial) if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); HELPER_EXPECT_FAILED(f.on_video(0, (char*)"\x17", 1)); HELPER_EXPECT_FAILED(f.on_video(0, (char*)"\x27", 1)); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); uint8_t buf[] = { 0x17, // 1, Keyframe; 7, AVC. 0x00, // 0, Sequence header. @@ -3364,7 +3425,7 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial) if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); uint8_t buf[] = { 0x17, // 1, Keyframe; 7, AVC. 0x00, // 0, Sequence header. @@ -3379,7 +3440,7 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial) if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); uint8_t buf[] = { 0x17, // 1, Keyframe; 7, AVC. 0x00, // 0, Sequence header. @@ -3394,7 +3455,7 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial) if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); uint8_t buf[] = { 0x17, // 1, Keyframe; 7, AVC. 0x00, // 0, Sequence header. @@ -3409,7 +3470,7 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial) if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); uint8_t buf[] = { 0x17, // 1, Keyframe; 7, AVC. 0x00, // 0, Sequence header. @@ -3424,7 +3485,7 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial) if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); uint8_t buf[] = { 0x17, // 1, Keyframe; 7, AVC. 0x00, // 0, Sequence header. @@ -3440,7 +3501,7 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial) if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); uint8_t buf[] = { 0x17, // 1, Keyframe; 7, AVC. 0x00, // 0, Sequence header. @@ -3456,7 +3517,7 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial) if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); uint8_t buf[] = { 0x17, // 1, Keyframe; 7, AVC. 0x00, // 0, Sequence header. @@ -3473,25 +3534,26 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial) VOID TEST(KernelCodecTest, VideoFormat) { + srs_error_t err; + if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); - EXPECT_TRUE(srs_success == f.on_video(0, NULL, 0)); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)"\x00", 0)); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)"\x00", 1)); + HELPER_EXPECT_SUCCESS(f.on_video(0, NULL, 0)); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)"\x00", 0)); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)"\x00", 1)); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)"\x57", 1)); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)"\x57", 1)); SrsBuffer b((char*)"\x00", 1); srs_error_t err = f.video_avc_demux(&b, 0); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } uint8_t spspps[] = { @@ -3516,67 +3578,68 @@ VOID TEST(KernelCodecTest, VideoFormat) }; if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)spspps, sizeof(spspps))); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)spspps, sizeof(spspps))); EXPECT_EQ(1, f.video->frame_type); EXPECT_EQ(0, f.video->avc_packet_type); EXPECT_EQ(768, f.vcodec->width); EXPECT_EQ(320, f.vcodec->height); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)rawIBMF, sizeof(rawIBMF))); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)rawIBMF, sizeof(rawIBMF))); EXPECT_EQ(1, f.video->nb_samples); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)rawIBMF, sizeof(rawIBMF))); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)rawIBMF, sizeof(rawIBMF))); EXPECT_EQ(1, f.video->nb_samples); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)spspps, sizeof(spspps))); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)spspps, sizeof(spspps))); EXPECT_EQ(1, f.video->frame_type); EXPECT_EQ(0, f.video->avc_packet_type); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)rawAnnexb, sizeof(rawAnnexb))); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)rawAnnexb, sizeof(rawAnnexb))); EXPECT_EQ(1, f.video->nb_samples); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)rawAnnexb, sizeof(rawAnnexb))); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)rawAnnexb, sizeof(rawAnnexb))); EXPECT_EQ(1, f.video->nb_samples); f.vcodec->payload_format = SrsAvcPayloadFormatAnnexb; - EXPECT_TRUE(srs_success == f.on_video(0, (char*)rawAnnexb, sizeof(rawAnnexb))); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)rawAnnexb, sizeof(rawAnnexb))); EXPECT_EQ(1, f.video->nb_samples); } if (true) { SrsFormat f; - EXPECT_TRUE(srs_success == f.initialize()); + HELPER_EXPECT_SUCCESS(f.initialize()); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)spspps, sizeof(spspps))); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)spspps, sizeof(spspps))); EXPECT_EQ(1, f.video->frame_type); EXPECT_EQ(0, f.video->avc_packet_type); f.vcodec->payload_format = SrsAvcPayloadFormatAnnexb; - EXPECT_TRUE(srs_success == f.on_video(0, (char*)rawIBMF, sizeof(rawIBMF))); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)rawIBMF, sizeof(rawIBMF))); EXPECT_EQ(1, f.video->nb_samples); // If IBMF format parsed, we couldn't parse annexb anymore. // Maybe FFMPEG use annexb format for some packets, then switch to IBMF. srs_error_t err = f.on_video(0, (char*)rawAnnexb, sizeof(rawAnnexb)); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); - EXPECT_TRUE(srs_success == f.on_video(0, (char*)rawIBMF, sizeof(rawIBMF))); + HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)rawIBMF, sizeof(rawIBMF))); EXPECT_EQ(1, f.video->nb_samples); } } VOID TEST(KernelFileTest, FileWriteReader) { + srs_error_t err; + if (true) { SrsFileWriter f; EXPECT_TRUE(!f.is_open()); @@ -3584,16 +3647,16 @@ VOID TEST(KernelFileTest, FileWriteReader) if (true) { SrsFileWriter f; - EXPECT_TRUE(srs_success == f.open("/dev/null")); + HELPER_EXPECT_SUCCESS(f.open("/dev/null")); EXPECT_TRUE(f.is_open()); EXPECT_EQ(0, f.tellg()); ssize_t nwriten = 0; - EXPECT_TRUE(srs_success == f.write((void*)"Hello", 5, &nwriten)); + HELPER_EXPECT_SUCCESS(f.write((void*)"Hello", 5, &nwriten)); EXPECT_EQ(5, nwriten); - EXPECT_TRUE(srs_success == f.lseek(0, SEEK_CUR, NULL)); + HELPER_EXPECT_SUCCESS(f.lseek(0, SEEK_CUR, NULL)); f.seek2(0); EXPECT_EQ(0, f.tellg()); @@ -3601,7 +3664,7 @@ VOID TEST(KernelFileTest, FileWriteReader) if (true) { SrsFileWriter f; - EXPECT_TRUE(srs_success == f.open_append("/dev/null")); + HELPER_EXPECT_SUCCESS(f.open_append("/dev/null")); EXPECT_TRUE(f.is_open()); } @@ -3612,7 +3675,7 @@ VOID TEST(KernelFileTest, FileWriteReader) if (true) { SrsFileReader f; - EXPECT_TRUE(srs_success == f.open("/dev/null")); + HELPER_EXPECT_SUCCESS(f.open("/dev/null")); EXPECT_TRUE(f.is_open()); EXPECT_EQ(0, f.tellg()); EXPECT_EQ(0, f.filesize()); @@ -3625,7 +3688,7 @@ VOID TEST(KernelFileTest, FileWriteReader) if (true) { SrsFileReader f; - EXPECT_TRUE(srs_success == f.open("/dev/null")); + HELPER_EXPECT_SUCCESS(f.open("/dev/null")); char buf[16]; ssize_t nread = 0; @@ -3899,6 +3962,8 @@ VOID TEST(KernelFileTest, ReadWriteCase) VOID TEST(KernelFLVTest, CoverAll) { + srs_error_t err; + if (true) { SrsMessageHeader h; h.message_type = RTMP_MSG_SetChunkSize; @@ -3935,7 +4000,7 @@ VOID TEST(KernelFLVTest, CoverAll) h.initialize_video(10, 30, 20); SrsCommonMessage m; - EXPECT_TRUE(srs_success == m.create(&h, NULL, 0)); + HELPER_EXPECT_SUCCESS(m.create(&h, NULL, 0)); EXPECT_EQ(RTMP_MSG_VideoMessage, m.header.message_type); EXPECT_EQ(10, m.header.payload_length); EXPECT_EQ(20, m.header.stream_id); @@ -3943,7 +4008,7 @@ VOID TEST(KernelFLVTest, CoverAll) EXPECT_EQ(30, m.header.timestamp); SrsSharedPtrMessage s; - EXPECT_TRUE(srs_success == s.create(&m)); + HELPER_EXPECT_SUCCESS(s.create(&m)); EXPECT_TRUE(s.is_av()); EXPECT_TRUE(!s.is_audio()); EXPECT_TRUE(s.is_video()); @@ -3953,16 +4018,16 @@ VOID TEST(KernelFLVTest, CoverAll) if (true) { MockSrsFileWriter f; SrsFlvTransmuxer mux; - EXPECT_TRUE(srs_success == mux.initialize(&f)); + HELPER_EXPECT_SUCCESS(mux.initialize(&f)); SrsMessageHeader h; h.initialize_video(10, 30, 20); SrsSharedPtrMessage m; - EXPECT_TRUE(srs_success == m.create(&h, new char[1], 1)); + HELPER_EXPECT_SUCCESS(m.create(&h, new char[1], 1)); SrsSharedPtrMessage* msgs = &m; - EXPECT_TRUE(srs_success == mux.write_tags(&msgs, 1)); + HELPER_EXPECT_SUCCESS(mux.write_tags(&msgs, 1)); EXPECT_EQ(16, f.tellg()); } @@ -4013,9 +4078,11 @@ VOID TEST(KernelFLVTest, CoverSharedPtrMessage) VOID TEST(KernelLogTest, CoverAll) { + srs_error_t err; + if (true) { ISrsLog l; - EXPECT_TRUE(srs_success == l.initialize()); + HELPER_EXPECT_SUCCESS(l.initialize()); l.reopen(); l.verbose("TAG", 0, "log"); @@ -4033,64 +4100,62 @@ VOID TEST(KernelLogTest, CoverAll) VOID TEST(KernelMp3Test, CoverAll) { + srs_error_t err; + if (true) { MockSrsFileWriter f; - EXPECT_TRUE(srs_success == f.open("")); + HELPER_EXPECT_SUCCESS(f.open("")); SrsMp3Transmuxer m; - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); - EXPECT_TRUE(srs_success == m.write_header()); + HELPER_EXPECT_SUCCESS(m.write_header()); EXPECT_EQ((char)0x49, f.data()[0]); } if (true) { SrsMp3Transmuxer m; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == f.open("")); - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(f.open("")); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); - EXPECT_TRUE(srs_success == m.write_audio(0, (char*)"\x20\x01", 2)); + HELPER_EXPECT_SUCCESS(m.write_audio(0, (char*)"\x20\x01", 2)); EXPECT_EQ((char)0x01, f.data()[0]); } if (true) { SrsMp3Transmuxer m; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == f.open("")); - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(f.open("")); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); srs_error_t err = m.write_audio(0, (char*)"\x30\x01", 2); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); err = m.write_audio(0, (char*)"\x20", 1); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { SrsMp3Transmuxer m; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == f.open("")); - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(f.open("")); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); f.err = srs_error_new(-1, "mock file error"); srs_error_t err = m.write_audio(0, (char*)"\x20\x01", 2); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { SrsMp3Transmuxer m; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == f.open("")); - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(f.open("")); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); f.err = srs_error_new(-1, "mock file error"); srs_error_t err = m.write_header(); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } } @@ -4102,8 +4167,7 @@ VOID TEST(KernelUtilityTest, CoverBitsBufferAll) int32_t v = 0; srs_error_t err = srs_avc_nalu_read_uev(&bb, v); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { @@ -4112,8 +4176,7 @@ VOID TEST(KernelUtilityTest, CoverBitsBufferAll) int32_t v = 0; srs_error_t err = srs_avc_nalu_read_uev(&bb, v); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { @@ -4122,8 +4185,7 @@ VOID TEST(KernelUtilityTest, CoverBitsBufferAll) int32_t v = 0; srs_error_t err = srs_avc_nalu_read_uev(&bb, v); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { @@ -4132,8 +4194,7 @@ VOID TEST(KernelUtilityTest, CoverBitsBufferAll) int8_t v = 0; srs_error_t err = srs_avc_nalu_read_bit(&bb, v); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } } @@ -4174,6 +4235,8 @@ extern int av_toupper(int c); VOID TEST(KernelUtilityTest, CoverTimeUtilityAll) { + srs_error_t err; + _srs_system_time_us_cache = 0; _srs_system_time_startup_time = 0; EXPECT_TRUE(srs_get_system_startup_time() > 0); @@ -4254,7 +4317,7 @@ VOID TEST(KernelUtilityTest, CoverTimeUtilityAll) if (true) { EXPECT_TRUE(srs_path_exists(".")); - EXPECT_TRUE(srs_success == srs_create_dir_recursively(".")); + HELPER_EXPECT_SUCCESS(srs_create_dir_recursively(".")); } if (true) { @@ -4265,6 +4328,8 @@ VOID TEST(KernelUtilityTest, CoverTimeUtilityAll) VOID TEST(KernelTSTest, CoverContextUtility) { + srs_error_t err; + if (true) { EXPECT_STREQ("Reserved", srs_ts_stream2string(SrsTsStreamReserved).c_str()); EXPECT_STREQ("MP3", srs_ts_stream2string(SrsTsStreamAudioMp3).c_str()); @@ -4316,7 +4381,7 @@ VOID TEST(KernelTSTest, CoverContextUtility) SrsBuffer b; int nb_bytes = 0; - EXPECT_TRUE(srs_success == m.dump(&b, &nb_bytes)); + HELPER_EXPECT_SUCCESS(m.dump(&b, &nb_bytes)); EXPECT_EQ(0, nb_bytes); } @@ -4331,7 +4396,7 @@ VOID TEST(KernelTSTest, CoverContextUtility) SrsBuffer b((char*)"\x00\x01\x02\x03", 4); int nb_bytes = 0; - EXPECT_TRUE(srs_success == m.dump(&b, &nb_bytes)); + HELPER_EXPECT_SUCCESS(m.dump(&b, &nb_bytes)); EXPECT_EQ(4, nb_bytes); } @@ -4349,11 +4414,11 @@ VOID TEST(KernelTSTest, CoverContextUtility) SrsBuffer b((char*)"\x00\x01\x02\x03", 4); int nb_bytes = 0; - EXPECT_TRUE(srs_success == m.dump(&b, &nb_bytes)); + HELPER_EXPECT_SUCCESS(m.dump(&b, &nb_bytes)); EXPECT_EQ(4, nb_bytes); b.skip(-4); - EXPECT_TRUE(srs_success == m.dump(&b, &nb_bytes)); + HELPER_EXPECT_SUCCESS(m.dump(&b, &nb_bytes)); EXPECT_EQ(4, nb_bytes); EXPECT_TRUE(m.completed(0)); @@ -4369,11 +4434,11 @@ VOID TEST(KernelTSTest, CoverContextUtility) SrsBuffer b((char*)"\x00\x01\x02\x03", 4); int nb_bytes = 0; - EXPECT_TRUE(srs_success == m.dump(&b, &nb_bytes)); + HELPER_EXPECT_SUCCESS(m.dump(&b, &nb_bytes)); EXPECT_EQ(4, nb_bytes); b.skip(-4); - EXPECT_TRUE(srs_success == m.dump(&b, &nb_bytes)); + HELPER_EXPECT_SUCCESS(m.dump(&b, &nb_bytes)); EXPECT_EQ(4, nb_bytes); EXPECT_TRUE(m.completed(0)); @@ -4426,12 +4491,14 @@ VOID TEST(KernelTSTest, CoverContextUtility) VOID TEST(KernelTSTest, CoverContextEncode) { + srs_error_t err; + SrsTsContext ctx; MockTsHandler h; if (true) { SrsBuffer b; - EXPECT_TRUE(srs_success == ctx.decode(&b, &h)); + HELPER_EXPECT_SUCCESS(ctx.decode(&b, &h)); EXPECT_TRUE(NULL == h.msg); } @@ -4439,16 +4506,14 @@ VOID TEST(KernelTSTest, CoverContextEncode) SrsBuffer b((char*)"\x00", 1); srs_error_t err = ctx.decode(&b, &h); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { SrsBuffer b((char*)"\x00\x00\x00\x00", 4); srs_error_t err = ctx.decode(&b, &h); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { @@ -4456,16 +4521,13 @@ VOID TEST(KernelTSTest, CoverContextEncode) SrsTsMessage m; srs_error_t err = ctx.encode(&f, &m, SrsVideoCodecIdDisabled, SrsAudioCodecIdDisabled); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); err = ctx.encode(&f, &m, SrsVideoCodecIdHEVC, SrsAudioCodecIdOpus); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); err = ctx.encode_pat_pmt(&f, 0, SrsTsStreamReserved, 0, SrsTsStreamReserved); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); } if (true) { @@ -4473,25 +4535,26 @@ VOID TEST(KernelTSTest, CoverContextEncode) SrsTsMessage m; srs_error_t err = ctx.encode_pes(&f, &m, 0x200, SrsTsStreamVideoH264, false); - EXPECT_TRUE(srs_success != err); - srs_freep(err); + HELPER_EXPECT_FAILED(err); - EXPECT_TRUE(srs_success == ctx.encode_pat_pmt(&f, 200, SrsTsStreamVideoH264, 201, SrsTsStreamAudioAAC)); + HELPER_EXPECT_SUCCESS(ctx.encode_pat_pmt(&f, 200, SrsTsStreamVideoH264, 201, SrsTsStreamAudioAAC)); } if (true) { MockSrsFileWriter f; SrsTsMessage m; - EXPECT_TRUE(srs_success == ctx.encode(&f, &m, SrsVideoCodecIdAVC, SrsAudioCodecIdAAC)); + HELPER_EXPECT_SUCCESS(ctx.encode(&f, &m, SrsVideoCodecIdAVC, SrsAudioCodecIdAAC)); m.payload->append("Hello, world!", 13); - EXPECT_TRUE(srs_success == ctx.encode(&f, &m, SrsVideoCodecIdAVC, SrsAudioCodecIdAAC)); + HELPER_EXPECT_SUCCESS(ctx.encode(&f, &m, SrsVideoCodecIdAVC, SrsAudioCodecIdAAC)); } } VOID TEST(KernelTSTest, CoverContextDecode) { + srs_error_t err; + SrsTsContext ctx; MockTsHandler h; @@ -4502,7 +4565,7 @@ VOID TEST(KernelTSTest, CoverContextDecode) 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x30, 0x31, 0x77, 0x7c, 0x43, 0xca, 0xff, 0xff, 0xff }; SrsBuffer b((char*)raw, sizeof(raw)); - EXPECT_TRUE(srs_success == ctx.decode(&b, &h)); + HELPER_EXPECT_SUCCESS(ctx.decode(&b, &h)); } if (true) { @@ -4511,7 +4574,7 @@ VOID TEST(KernelTSTest, CoverContextDecode) 0x00, 0x2a, 0xb1, 0x04, 0xb2, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; SrsBuffer b((char*)raw, sizeof(raw)); - EXPECT_TRUE(srs_success == ctx.decode(&b, &h)); + HELPER_EXPECT_SUCCESS(ctx.decode(&b, &h)); } if (true) { @@ -4520,7 +4583,7 @@ VOID TEST(KernelTSTest, CoverContextDecode) 0x00, 0x1b, 0xe1, 0x00, 0xf0, 0x00, 0x0f, 0xe1, 0x01, 0xf0, 0x00, 0x2f, 0x44, 0xb9, 0x9b, 0xff }; SrsBuffer b((char*)raw, sizeof(raw)); - EXPECT_TRUE(srs_success == ctx.decode(&b, &h)); + HELPER_EXPECT_SUCCESS(ctx.decode(&b, &h)); } if (true) { @@ -4539,15 +4602,17 @@ VOID TEST(KernelTSTest, CoverContextDecode) 0x3d, 0x31, 0x20, 0x72, 0x65, 0x66, 0x3d, 0x33, 0x20, 0x64, 0x65, 0x62 }; SrsBuffer b((char*)raw, sizeof(raw)); - EXPECT_TRUE(srs_success == ctx.decode(&b, &h)); + HELPER_EXPECT_SUCCESS(ctx.decode(&b, &h)); } } VOID TEST(KernelTSTest, CoverTransmuxer) { + srs_error_t err; + SrsTsTransmuxer m; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == m.initialize(&f)); + HELPER_EXPECT_SUCCESS(m.initialize(&f)); if (true) { uint8_t raw[] = { @@ -4556,14 +4621,14 @@ VOID TEST(KernelTSTest, CoverTransmuxer) 0xac, 0xd9, 0x40, 0xc0, 0x29, 0xb0, 0x11, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c }; - EXPECT_TRUE(srs_success == m.write_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(m.write_video(0, (char*)raw, sizeof(raw))); } if (true) { uint8_t raw[] = { 0xaf, 0x00, 0x12, 0x10 }; - EXPECT_TRUE(srs_success == m.write_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(m.write_audio(0, (char*)raw, sizeof(raw))); } if (true) { @@ -4576,7 +4641,7 @@ VOID TEST(KernelTSTest, CoverTransmuxer) 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e }; - EXPECT_TRUE(srs_success == m.write_audio(34, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(m.write_audio(34, (char*)raw, sizeof(raw))); } if (true) { @@ -4592,7 +4657,7 @@ VOID TEST(KernelTSTest, CoverTransmuxer) 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, 0xb2, 0x72, 0x5a }; - EXPECT_TRUE(srs_success == m.write_video(40, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(m.write_video(40, (char*)raw, sizeof(raw))); } } @@ -4611,117 +4676,93 @@ VOID TEST(KernelMP4Test, CoverMP4All) } } -VOID TEST(KernelMP4Test, CoverMP4Codec) +VOID TEST(KernelMP4Test, CoverMP4CodecSingleFrame) { - SrsMp4Encoder enc; + srs_error_t err; + MockSrsFileWriter f; - SrsFormat fmt; - EXPECT_TRUE(srs_success == enc.initialize(&f)); - EXPECT_TRUE(srs_success == fmt.initialize()); - + + // MP4 encoder. if (true) { - uint8_t raw[] = { - 0x17, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x20, 0xff, 0xe1, 0x00, 0x19, 0x67, 0x64, 0x00, 0x20, - 0xac, 0xd9, 0x40, 0xc0, 0x29, 0xb0, 0x11, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, - 0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c - }; - EXPECT_TRUE(srs_success == fmt.on_video(0, (char*)raw, sizeof(raw))); - EXPECT_TRUE(srs_success == enc.write_sample( - NULL, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw - )); + SrsMp4Encoder enc; SrsFormat fmt; + HELPER_EXPECT_SUCCESS(enc.initialize(&f)); + HELPER_EXPECT_SUCCESS(fmt.initialize()); + + if (true) { + uint8_t raw[] = { + 0x17, 0x00, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x20, 0xff, 0xe1, 0x00, 0x19, 0x67, 0x64, 0x00, 0x20, 0xac, 0xd9, 0x40, 0xc0, 0x29, 0xb0, 0x11, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + EXPECT_EQ(768, enc.width); EXPECT_EQ(320, enc.height); + } + + if (true) { + uint8_t raw[] = { + 0xaf, 0x00, 0x12, 0x10 + }; + HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + if (true) { + uint8_t raw[] = { + 0x17, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00, 0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59, 0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13, 0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74, 0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02, 0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8, 0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b, 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, 0xb2, 0x72, 0x5a + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + if (true) { + uint8_t raw[] = { + 0xaf, 0x01, 0x21, 0x11, 0x45, 0x00, 0x14, 0x50, 0x01, 0x46, 0xf3, 0xf1, 0x0a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e + }; + HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + HELPER_EXPECT_SUCCESS(enc.flush()); + //mock_print_mp4(string(f.data(), f.filesize())); } - - if (true) { - uint8_t raw[] = { - 0xaf, 0x00, 0x12, 0x10 - }; - EXPECT_TRUE(srs_success == fmt.on_audio(0, (char*)raw, sizeof(raw))); - EXPECT_TRUE(srs_success == enc.write_sample( - NULL, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw - )); - } - - if (true) { - uint8_t raw[] = { - 0xaf, - 0x01, 0x21, 0x11, 0x45, 0x00, 0x14, 0x50, 0x01, 0x46, 0xf3, 0xf1, 0x0a, 0x5a, 0x5a, 0x5a, 0x5a, - 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, - 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, - 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, - 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, - 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e - }; - EXPECT_TRUE(srs_success == fmt.on_audio(0, (char*)raw, sizeof(raw))); - EXPECT_TRUE(srs_success == enc.write_sample( - NULL, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 34, 34, (uint8_t*)fmt.raw, fmt.nb_raw - )); - } - - if (true) { - uint8_t raw[] = { - 0x27, - 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00, - 0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59, - 0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13, - 0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74, - 0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02, - 0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8, - 0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b, - 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, - 0xb2, 0x72, 0x5a - }; - EXPECT_TRUE(srs_success == fmt.on_video(0, (char*)raw, sizeof(raw))); - EXPECT_TRUE(srs_success == enc.write_sample( - NULL, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 40, 40, (uint8_t*)fmt.raw, fmt.nb_raw - )); - } - - EXPECT_TRUE(srs_success == enc.flush()); - + + // MP4 decoder. if (true) { MockSrsFileReader fr((const char*)f.data(), f.filesize()); - SrsMp4Decoder dec; - EXPECT_TRUE(srs_success == dec.initialize(&fr)); + SrsMp4Decoder dec; HELPER_EXPECT_SUCCESS(dec.initialize(&fr)); - SrsMp4HandlerType ht; - uint16_t ft, ct; - uint32_t dts, pts, nb_sample; - uint8_t* sample; + SrsMp4HandlerType ht; uint16_t ft, ct; uint32_t dts, pts, nb_sample; uint8_t* sample; - EXPECT_TRUE(srs_success == dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); - EXPECT_EQ(0, (int)dts); - EXPECT_EQ(41, nb_sample); - EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); - EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, ct); + // Sequence header. + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(41, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, ct); srs_freepa(sample); - EXPECT_TRUE(srs_success == dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); - EXPECT_EQ(0, (int)dts); - EXPECT_EQ(2, nb_sample); - EXPECT_EQ(SrsMp4HandlerTypeSOUN, ht); - EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, ct); + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(2, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeSOUN, ht); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, ct); srs_freepa(sample); - EXPECT_TRUE(srs_success == dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); - EXPECT_EQ(0, (int)dts); - EXPECT_EQ(87, nb_sample); - EXPECT_EQ(SrsMp4HandlerTypeSOUN, ht); - EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + // Frame group #0 + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(127, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); srs_freepa(sample); - EXPECT_TRUE(srs_success == dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); - EXPECT_EQ(0, (int)dts); - EXPECT_EQ(127, nb_sample); - EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); - EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(87, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeSOUN, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); srs_freepa(sample); } - + + // MP4 box reader. if (true) { - SrsMp4BoxReader br; - MockSrsFileReader fr((const char*)f.data(), f.filesize()); - EXPECT_TRUE(srs_success == br.initialize(&fr)); + SrsMp4BoxReader br; MockSrsFileReader fr((const char*)f.data(), f.filesize()); + HELPER_EXPECT_SUCCESS(br.initialize(&fr)); SrsSimpleStream stream; @@ -4739,13 +4780,203 @@ VOID TEST(KernelMP4Test, CoverMP4Codec) dc.summary = false; box->dumps(ss, dc); - EXPECT_TRUE(srs_success == br.skip(box, &stream)); + HELPER_EXPECT_SUCCESS(br.skip(box, &stream)); srs_freep(box); } } } +VOID TEST(KernelMP4Test, CoverMP4MultipleVideos) +{ + srs_error_t err; + + MockSrsFileWriter f; + + // Encode frames. + // V-A V-V + if (true) { + SrsMp4Encoder enc; SrsFormat fmt; + HELPER_EXPECT_SUCCESS(enc.initialize(&f)); + HELPER_EXPECT_SUCCESS(fmt.initialize()); + + // Sequence header, V-A + if (true) { + uint8_t raw[] = { + 0x17, 0x00, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x20, 0xff, 0xe1, 0x00, 0x19, 0x67, 0x64, 0x00, 0x20, 0xac, 0xd9, 0x40, 0xc0, 0x29, 0xb0, 0x11, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + EXPECT_EQ(768, enc.width); EXPECT_EQ(320, enc.height); + } + + if (true) { + uint8_t raw[] = { + 0xaf, 0x00, 0x12, 0x10 + }; + HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + // Frame group #0, V-V + if (true) { + uint8_t raw[] = { + 0x17, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00, 0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59, 0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13, 0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74, 0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02, 0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8, 0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b, 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, 0xb2, 0x72, 0x5a + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + if (true) { + uint8_t raw[] = { + 0x27, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00, 0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59, 0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13, 0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74, 0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02, 0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8, 0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b, 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, 0xb2, 0x72, 0x5a + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 40, 40, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + // Flush encoder. + HELPER_EXPECT_SUCCESS(enc.flush()); + //mock_print_mp4(string(f.data(), f.filesize())); + } + + // Decode frames. + if (true) { + MockSrsFileReader fr((const char*)f.data(), f.filesize()); + SrsMp4Decoder dec; HELPER_EXPECT_SUCCESS(dec.initialize(&fr)); + + SrsMp4HandlerType ht; uint16_t ft, ct; uint32_t dts, pts, nb_sample; uint8_t* sample; + + // Sequence header. + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(41, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(2, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeSOUN, ht); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + // Frames order by dts asc. + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(127, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(40, (int)dts); EXPECT_EQ(127, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + } +} + +VOID TEST(KernelMP4Test, CoverMP4MultipleCTTs) +{ + srs_error_t err; + + MockSrsFileWriter f; + + // Encode frames. + // V-A V-V + if (true) { + SrsMp4Encoder enc; SrsFormat fmt; + HELPER_EXPECT_SUCCESS(enc.initialize(&f)); + HELPER_EXPECT_SUCCESS(fmt.initialize()); + + // Sequence header, V-A + if (true) { + uint8_t raw[] = { + 0x17, 0x00, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x20, 0xff, 0xe1, 0x00, 0x19, 0x67, 0x64, 0x00, 0x20, 0xac, 0xd9, 0x40, 0xc0, 0x29, 0xb0, 0x11, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + EXPECT_EQ(768, enc.width); EXPECT_EQ(320, enc.height); + } + + if (true) { + uint8_t raw[] = { + 0xaf, 0x00, 0x12, 0x10 + }; + HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + // Frame group #0, V-V-V + if (true) { + uint8_t raw[] = { + 0x17, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00, 0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59, 0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13, 0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74, 0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02, 0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8, 0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b, 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, 0xb2, 0x72, 0x5a + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + if (true) { + uint8_t raw[] = { + 0x27, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00, 0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59, 0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13, 0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74, 0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02, 0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8, 0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b, 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, 0xb2, 0x72, 0x5a + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 40, 80, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + if (true) { + uint8_t raw[] = { + 0x27, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00, 0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59, 0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13, 0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74, 0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02, 0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8, 0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b, 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, 0xb2, 0x72, 0x5a + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 80, 40, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + // Flush encoder. + HELPER_EXPECT_SUCCESS(enc.flush()); + //mock_print_mp4(string(f.data(), f.filesize())); + } + + // Decode frames. + if (true) { + MockSrsFileReader fr((const char*)f.data(), f.filesize()); + SrsMp4Decoder dec; HELPER_EXPECT_SUCCESS(dec.initialize(&fr)); + + SrsMp4HandlerType ht; uint16_t ft, ct; uint32_t dts, pts, nb_sample; uint8_t* sample; + + // Sequence header. + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(41, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(2, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeSOUN, ht); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + // Frames order by dts asc. + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(127, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(40, (int)dts); EXPECT_EQ(80, (int)pts); EXPECT_EQ(127, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(80, (int)dts); EXPECT_EQ(40, (int)pts); EXPECT_EQ(127, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + } +} + uint8_t* mock_copy_bytes(char* data, int size) { uint8_t* cp = new uint8_t[size]; @@ -4755,12 +4986,14 @@ uint8_t* mock_copy_bytes(char* data, int size) VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder) { + srs_error_t err; + SrsMp4M2tsSegmentEncoder enc; MockSrsFileWriter f; - EXPECT_TRUE(srs_success == enc.initialize(&f, 0, 0, 100)); + HELPER_EXPECT_SUCCESS(enc.initialize(&f, 0, 0, 100)); SrsFormat fmt; - EXPECT_TRUE(srs_success == fmt.initialize()); + HELPER_EXPECT_SUCCESS(fmt.initialize()); if (true) { uint8_t raw[] = { @@ -4769,8 +5002,8 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder) 0xac, 0xd9, 0x40, 0xc0, 0x29, 0xb0, 0x11, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c }; - EXPECT_TRUE(srs_success == fmt.on_video(0, (char*)raw, sizeof(raw))); - EXPECT_TRUE(srs_success == enc.write_sample( + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 0, 0, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw )); } @@ -4779,8 +5012,8 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder) uint8_t raw[] = { 0xaf, 0x00, 0x12, 0x10 }; - EXPECT_TRUE(srs_success == fmt.on_audio(0, (char*)raw, sizeof(raw))); - EXPECT_TRUE(srs_success == enc.write_sample( + HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( SrsMp4HandlerTypeSOUN, 0x00, 0, 0, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw )); } @@ -4795,8 +5028,8 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder) 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e }; - EXPECT_TRUE(srs_success == fmt.on_audio(0, (char*)raw, sizeof(raw))); - EXPECT_TRUE(srs_success == enc.write_sample( + HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( SrsMp4HandlerTypeSOUN, 0x00, 34, 34, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw )); } @@ -4814,13 +5047,13 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder) 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, 0xb2, 0x72, 0x5a }; - EXPECT_TRUE(srs_success == fmt.on_video(0, (char*)raw, sizeof(raw))); - EXPECT_TRUE(srs_success == enc.write_sample( + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 40, 40, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw )); } uint64_t dts = 0; - EXPECT_TRUE(srs_success == enc.flush(dts)); + HELPER_EXPECT_SUCCESS(enc.flush(dts)); } From 36236192faf4ccf0f2d19f8980445f6e94be61c5 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 12:00:48 +0800 Subject: [PATCH 02/12] Improve test coverage for mp4 --- trunk/src/utest/srs_utest_kernel.cpp | 116 +++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index 1a2f4c796..aa8f91cc7 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -4977,6 +4977,122 @@ VOID TEST(KernelMP4Test, CoverMP4MultipleCTTs) } } +VOID TEST(KernelMP4Test, CoverMP4MultipleAVs) +{ + srs_error_t err; + + MockSrsFileWriter f; + + // Encode frames. + // V-A V-V + if (true) { + SrsMp4Encoder enc; SrsFormat fmt; + HELPER_EXPECT_SUCCESS(enc.initialize(&f)); + HELPER_EXPECT_SUCCESS(fmt.initialize()); + + // Sequence header, V-A + if (true) { + uint8_t raw[] = { + 0x17, 0x00, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x20, 0xff, 0xe1, 0x00, 0x19, 0x67, 0x64, 0x00, 0x20, 0xac, 0xd9, 0x40, 0xc0, 0x29, 0xb0, 0x11, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + EXPECT_EQ(768, enc.width); EXPECT_EQ(320, enc.height); + } + + if (true) { + uint8_t raw[] = { + 0xaf, 0x00, 0x12, 0x10 + }; + HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + // Frame group #0, V-A-A-V + if (true) { + uint8_t raw[] = { + 0x17, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00, 0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59, 0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13, 0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74, 0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02, 0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8, 0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b, 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, 0xb2, 0x72, 0x5a + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + if (true) { + uint8_t raw[] = { + 0xaf, 0x01, 0x21, 0x11, 0x45, 0x00, 0x14, 0x50, 0x01, 0x46, 0xf3, 0xf1, 0x0a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e + }; + HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + if (true) { + uint8_t raw[] = { + 0xaf, 0x01, 0x21, 0x11, 0x45, 0x00, 0x14, 0x50, 0x01, 0x46, 0xf3, 0xf1, 0x0a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e + }; + HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 20, 20, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + if (true) { + uint8_t raw[] = { + 0x27, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00, 0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59, 0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13, 0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74, 0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02, 0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8, 0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b, 0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82, 0xb2, 0x72, 0x5a + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 40, 40, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + // Flush encoder. + HELPER_EXPECT_SUCCESS(enc.flush()); + //mock_print_mp4(string(f.data(), f.filesize())); + } + + // Decode frames. + if (true) { + MockSrsFileReader fr((const char*)f.data(), f.filesize()); + SrsMp4Decoder dec; HELPER_EXPECT_SUCCESS(dec.initialize(&fr)); + + SrsMp4HandlerType ht; uint16_t ft, ct; uint32_t dts, pts, nb_sample; uint8_t* sample; + + // Sequence header. + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(41, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(2, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeSOUN, ht); EXPECT_EQ(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + // Frames order by dts asc. + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(127, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(0, (int)dts); EXPECT_EQ(87, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeSOUN, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(20, (int)dts); EXPECT_EQ(87, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeSOUN, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + + HELPER_EXPECT_SUCCESS(dec.read_sample(&ht, &ft, &ct, &dts, &pts, &sample, &nb_sample)); + EXPECT_EQ(40, (int)dts); EXPECT_EQ(40, (int)pts); EXPECT_EQ(127, nb_sample); EXPECT_EQ(SrsMp4HandlerTypeVIDE, ht); EXPECT_NE(SrsAudioAacFrameTraitSequenceHeader, ct); + srs_freepa(sample); + } +} + uint8_t* mock_copy_bytes(char* data, int size) { uint8_t* cp = new uint8_t[size]; From a71d93188bbe661d0b1e1b05c6aca576f7067917 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 13:41:19 +0800 Subject: [PATCH 03/12] Improve test coverage for config. --- trunk/src/app/srs_app_config.cpp | 38 +-- trunk/src/app/srs_app_config.hpp | 30 +++ trunk/src/utest/srs_utest_config.cpp | 354 +++++++++++++++++++++++++++ trunk/src/utest/srs_utest_kernel.cpp | 38 +++ 4 files changed, 428 insertions(+), 32 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 1b4db7946..b5e1ca9d8 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -80,36 +80,6 @@ const char* _srs_version = "XCORE-" RTMP_SIG_SRS_SERVER; */ srs_error_t srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine); -/** - * whether the two vector actual equals, for instance, - * srs_vector_actual_equals([0, 1, 2], [0, 1, 2]) ==== true - * srs_vector_actual_equals([0, 1, 2], [2, 1, 0]) ==== true - * srs_vector_actual_equals([0, 1, 2], [0, 2, 1]) ==== true - * srs_vector_actual_equals([0, 1, 2], [0, 1, 2, 3]) ==== false - * srs_vector_actual_equals([1, 2, 3], [0, 1, 2]) ==== false - */ -template -bool srs_vector_actual_equals(const vector& a, const vector& b) -{ - // all elements of a in b. - for (int i = 0; i < (int)a.size(); i++) { - const T& e = a.at(i); - if (::find(b.begin(), b.end(), e) == b.end()) { - return false; - } - } - - // all elements of b in a. - for (int i = 0; i < (int)b.size(); i++) { - const T& e = b.at(i); - if (::find(a.begin(), a.end(), e) == a.end()) { - return false; - } - } - - return true; -} - /** * whether the ch is common space. */ @@ -132,7 +102,8 @@ namespace _srs_internal { srs_freepa(start); } - + + // LCOV_EXCL_START srs_error_t SrsConfigBuffer::fullfill(const char* filename) { srs_error_t err = srs_success; @@ -160,6 +131,7 @@ namespace _srs_internal return err; } + // LCOV_EXCL_STOP bool SrsConfigBuffer::empty() { @@ -413,7 +385,7 @@ srs_error_t srs_config_transform_vhost(SrsConfDirective* root) if (enabled) { SrsConfDirective* mr = publish->get_or_create("mr"); mr->args = enabled->args; - srs_warn("transform: vhost.mr.enabled to vhost.publish.mr.enabled for %s", dir->name.c_str()); + srs_warn("transform: vhost.mr.enabled to vhost.publish.mr for %s", dir->name.c_str()); } SrsConfDirective* latency = conf->get("latency"); @@ -525,6 +497,7 @@ srs_error_t srs_config_transform_vhost(SrsConfDirective* root) return err; } +// LCOV_EXCL_START srs_error_t srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine) { srs_error_t err = srs_success; @@ -626,6 +599,7 @@ srs_error_t srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine return err; } +// LCOV_EXCL_STOP SrsConfDirective::SrsConfDirective() { diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index c5a91740c..602e5e22c 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -46,6 +47,35 @@ class SrsRequest; class SrsJsonArray; class SrsConfDirective; +/** + * whether the two vector actual equals, for instance, + * srs_vector_actual_equals([0, 1, 2], [0, 1, 2]) ==== true + * srs_vector_actual_equals([0, 1, 2], [2, 1, 0]) ==== true + * srs_vector_actual_equals([0, 1, 2], [0, 2, 1]) ==== true + * srs_vector_actual_equals([0, 1, 2], [0, 1, 2, 3]) ==== false + * srs_vector_actual_equals([1, 2, 3], [0, 1, 2]) ==== false + */ +template +bool srs_vector_actual_equals(const std::vector& a, const std::vector& b) +{ + // all elements of a in b. + for (int i = 0; i < (int)a.size(); i++) { + const T& e = a.at(i); + if (std::find(b.begin(), b.end(), e) == b.end()) { + return false; + } + } + + // all elements of b in a. + for (int i = 0; i < (int)b.size(); i++) { + const T& e = b.at(i); + if (std::find(a.begin(), a.end(), e) == a.end()) { + return false; + } + } + + return true; +} namespace _srs_internal { diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 43622c3a7..864637380 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -31,6 +31,7 @@ using namespace std; #include #include #include +#include MockSrsConfigBuffer::MockSrsConfigBuffer(string buf) { @@ -1927,3 +1928,356 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesGlobal) } } +VOID TEST(ConfigUnitTest, VectorEquals) +{ + if (true) { + vector a, b; + a.push_back(0); a.push_back(1); a.push_back(2); + b.push_back(0); b.push_back(1); b.push_back(2); + EXPECT_TRUE(srs_vector_actual_equals(a, b)); + } + + if (true) { + vector a, b; + a.push_back(0); a.push_back(1); a.push_back(2); + b.push_back(2); b.push_back(1); b.push_back(0); + EXPECT_TRUE(srs_vector_actual_equals(a, b)); + } + + if (true) { + vector a, b; + a.push_back(0); a.push_back(1); a.push_back(2); + b.push_back(0); b.push_back(2); b.push_back(1); + EXPECT_TRUE(srs_vector_actual_equals(a, b)); + } + + if (true) { + vector a, b; + a.push_back(0); a.push_back(1); a.push_back(2); + b.push_back(0); b.push_back(1); b.push_back(2); b.push_back(3); + EXPECT_FALSE(srs_vector_actual_equals(a, b)); + } + + if (true) { + vector a, b; + a.push_back(1); a.push_back(2); a.push_back(3); + b.push_back(0); b.push_back(1); b.push_back(2); + EXPECT_FALSE(srs_vector_actual_equals(a, b)); + } +} + +extern bool srs_directive_equals_self(SrsConfDirective* a, SrsConfDirective* b); +extern bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b); +extern bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b, string except); + +VOID TEST(ConfigUnitTest, DirectiveEquals) +{ + EXPECT_TRUE(srs_directive_equals_self(NULL, NULL)); + + if (true) { + SrsConfDirective* a = new SrsConfDirective(); + EXPECT_FALSE(srs_directive_equals_self(a, NULL)); + EXPECT_FALSE(srs_directive_equals_self(NULL, a)); + srs_freep(a); + } + + if (true) { + SrsConfDirective* a = new SrsConfDirective(); + SrsConfDirective* b = a; + EXPECT_TRUE(srs_directive_equals_self(a, b)); + srs_freep(a); + } + + if (true) { + SrsConfDirective* a = new SrsConfDirective(); + a->name = "hls"; + SrsConfDirective* b = new SrsConfDirective(); + b->name = "dvr"; + EXPECT_FALSE(srs_directive_equals_self(a, b)); + srs_freep(a); srs_freep(b); + } + + if (true) { + SrsConfDirective* a = new SrsConfDirective(); + a->directives.push_back(new SrsConfDirective()); + SrsConfDirective* b = new SrsConfDirective(); + EXPECT_FALSE(srs_directive_equals_self(a, b)); + srs_freep(a); srs_freep(b); + } + + if (true) { + SrsConfDirective* a = new SrsConfDirective(); + a->directives.push_back(new SrsConfDirective()); + a->at(0)->name = "hls"; + SrsConfDirective* b = new SrsConfDirective(); + b->directives.push_back(new SrsConfDirective()); + EXPECT_TRUE(srs_directive_equals(a, b, "hls")); + srs_freep(a); srs_freep(b); + } +} + +VOID TEST(ConfigUnitTest, OperatorEquals) +{ + EXPECT_TRUE(srs_config_hls_is_on_error_ignore("ignore")); + EXPECT_FALSE(srs_config_hls_is_on_error_ignore("xxx")); + + EXPECT_TRUE(srs_config_hls_is_on_error_continue("continue")); + EXPECT_FALSE(srs_config_hls_is_on_error_continue("xxx")); + + EXPECT_TRUE(srs_config_ingest_is_file("file")); + EXPECT_FALSE(srs_config_ingest_is_file("xxx")); + + EXPECT_TRUE(srs_config_ingest_is_stream("stream")); + EXPECT_FALSE(srs_config_ingest_is_stream("xxx")); + + EXPECT_TRUE(srs_config_dvr_is_plan_segment("segment")); + EXPECT_FALSE(srs_config_dvr_is_plan_segment("xxx")); + + EXPECT_TRUE(srs_config_dvr_is_plan_session("session")); + EXPECT_FALSE(srs_config_dvr_is_plan_session("xxx")); + + EXPECT_TRUE(srs_stream_caster_is_udp("mpegts_over_udp")); + EXPECT_FALSE(srs_stream_caster_is_udp("xxx")); + + EXPECT_TRUE(srs_stream_caster_is_rtsp("rtsp")); + EXPECT_FALSE(srs_stream_caster_is_rtsp("xxx")); + + EXPECT_TRUE(srs_stream_caster_is_flv("flv")); + EXPECT_FALSE(srs_stream_caster_is_flv("xxx")); + + EXPECT_STREQ("on", srs_config_bool2switch("true").c_str()); + EXPECT_STREQ("off", srs_config_bool2switch("false").c_str()); + EXPECT_STREQ("off", srs_config_bool2switch("xxx").c_str()); +} + +VOID TEST(ConfigUnitTest, ApplyFilter) +{ + EXPECT_TRUE(srs_config_apply_filter(NULL, NULL)); + + if (true) { + SrsConfDirective d; + EXPECT_TRUE(srs_config_apply_filter(&d, NULL)); + } + + if (true) { + SrsConfDirective d; + d.args.push_back("all"); + EXPECT_TRUE(srs_config_apply_filter(&d, NULL)); + } + + if (true) { + SrsConfDirective d; + SrsRequest r; + r.app = "live"; r.stream = "stream"; + d.args.push_back("live/stream"); + EXPECT_TRUE(srs_config_apply_filter(&d, &r)); + } + + if (true) { + SrsConfDirective d; + d.args.push_back("live/stream"); + SrsRequest r; + EXPECT_FALSE(srs_config_apply_filter(&d, &r)); + } +} + +VOID TEST(ConfigUnitTest, TransformForVhost) +{ + srs_error_t err; + + if (true) { + SrsConfDirective root; + root.get_or_create("http_stream"); + + HELPER_ASSERT_SUCCESS(srs_config_transform_vhost(&root)); + + SrsConfDirective* p = root.get("http_server"); + ASSERT_TRUE(p != NULL); + } + + if (true) { + SrsConfDirective root; + SrsConfDirective* vhost = root.get_or_create("vhost"); + if (true) { + vhost->get_or_create("http"); + } + + HELPER_ASSERT_SUCCESS(srs_config_transform_vhost(&root)); + + SrsConfDirective* p = vhost->get("http_static"); + ASSERT_TRUE(p != NULL); + } + + if (true) { + SrsConfDirective root; + SrsConfDirective* vhost = root.get_or_create("vhost"); + if (true) { + SrsConfDirective* p = vhost->get_or_create("http_remux"); + p->get_or_create("hstrs", "on"); + } + + HELPER_ASSERT_SUCCESS(srs_config_transform_vhost(&root)); + + SrsConfDirective* p = vhost->get("http_remux"); + ASSERT_TRUE(p != NULL); + ASSERT_TRUE(p->get("hstrs") == NULL); + } + + if (true) { + SrsConfDirective root; + SrsConfDirective* vhost = root.get_or_create("vhost"); + if (true) { + vhost->get_or_create("refer", "refer-v"); + vhost->get_or_create("refer_play", "refer-play-v"); + vhost->get_or_create("refer_publish", "refer-publish-v"); + } + + HELPER_ASSERT_SUCCESS(srs_config_transform_vhost(&root)); + + SrsConfDirective* p = vhost->get("refer"); + ASSERT_TRUE(p != NULL); + + ASSERT_TRUE(p->get("enabled") != NULL); + EXPECT_STREQ("on", p->get("enabled")->arg0().c_str()); + + ASSERT_TRUE(p->get("all") != NULL); + EXPECT_STREQ("refer-v", p->get("all")->arg0().c_str()); + + ASSERT_TRUE(p->get("play") != NULL); + EXPECT_STREQ("refer-play-v", p->get("play")->arg0().c_str()); + + ASSERT_TRUE(p->get("publish") != NULL); + EXPECT_STREQ("refer-publish-v", p->get("publish")->arg0().c_str()); + } + + if (true) { + SrsConfDirective root; + SrsConfDirective* vhost = root.get_or_create("vhost"); + if (true) { + SrsConfDirective* mr = vhost->get_or_create("mr"); + mr->get_or_create("enabled", "on"); + mr->get_or_create("latency", "100"); + } + + HELPER_ASSERT_SUCCESS(srs_config_transform_vhost(&root)); + + SrsConfDirective* publish = vhost->get("publish"); + ASSERT_TRUE(publish != NULL); + + SrsConfDirective* p = publish->get("mr"); + ASSERT_TRUE(p != NULL); + EXPECT_STREQ("on", p->arg0().c_str()); + + p = publish->get("mr_latency"); + ASSERT_TRUE(p != NULL); + EXPECT_STREQ("100", p->arg0().c_str()); + } + + if (true) { + SrsConfDirective root; + SrsConfDirective* vhost = root.get_or_create("vhost"); + if (true) { + vhost->get_or_create("publish_1stpkt_timeout", "100"); + } + + HELPER_ASSERT_SUCCESS(srs_config_transform_vhost(&root)); + + SrsConfDirective* publish = vhost->get("publish"); + ASSERT_TRUE(publish != NULL); + + SrsConfDirective* p = publish->get("firstpkt_timeout"); + ASSERT_TRUE(p != NULL); + EXPECT_STREQ("100", p->arg0().c_str()); + } + + if (true) { + SrsConfDirective root; + SrsConfDirective* vhost = root.get_or_create("vhost"); + if (true) { + vhost->get_or_create("publish_normal_timeout", "100"); + } + + HELPER_ASSERT_SUCCESS(srs_config_transform_vhost(&root)); + + SrsConfDirective* publish = vhost->get("publish"); + ASSERT_TRUE(publish != NULL); + + SrsConfDirective* p = publish->get("normal_timeout"); + ASSERT_TRUE(p != NULL); + EXPECT_STREQ("100", p->arg0().c_str()); + } + + if (true) { + SrsConfDirective root; + SrsConfDirective* vhost = root.get_or_create("vhost"); + if (true) { + vhost->get_or_create("time_jitter", "on"); + vhost->get_or_create("mix_correct", "on"); + vhost->get_or_create("atc", "on"); + vhost->get_or_create("atc_auto", "on"); + vhost->get_or_create("mw_latency", "on"); + vhost->get_or_create("gop_cache", "on"); + vhost->get_or_create("queue_length", "on"); + vhost->get_or_create("send_min_interval", "on"); + vhost->get_or_create("reduce_sequence_header", "on"); + } + + HELPER_ASSERT_SUCCESS(srs_config_transform_vhost(&root)); + + SrsConfDirective* p = vhost->get("play"); + ASSERT_TRUE(p != NULL); + + ASSERT_TRUE(p->get("time_jitter") != NULL); + ASSERT_TRUE(p->get("mix_correct") != NULL); + ASSERT_TRUE(p->get("atc") != NULL); + ASSERT_TRUE(p->get("atc_auto") != NULL); + ASSERT_TRUE(p->get("mw_latency") != NULL); + ASSERT_TRUE(p->get("gop_cache") != NULL); + ASSERT_TRUE(p->get("queue_length") != NULL); + ASSERT_TRUE(p->get("send_min_interval") != NULL); + ASSERT_TRUE(p->get("reduce_sequence_header") != NULL); + } + + if (true) { + SrsConfDirective root; + SrsConfDirective* vhost = root.get_or_create("vhost"); + if (true) { + vhost->get_or_create("forward", "forward-v"); + } + + HELPER_ASSERT_SUCCESS(srs_config_transform_vhost(&root)); + + SrsConfDirective* p = vhost->get("forward"); + ASSERT_TRUE(p != NULL); + + ASSERT_TRUE(p->get("enabled") != NULL); + EXPECT_STREQ("on", p->get("enabled")->arg0().c_str()); + + ASSERT_TRUE(p->get("destination") != NULL); + EXPECT_STREQ("forward-v", p->get("destination")->arg0().c_str()); + } + + if (true) { + SrsConfDirective root; + SrsConfDirective* vhost = root.get_or_create("vhost"); + if (true) { + vhost->get_or_create("mode", "on"); + vhost->get_or_create("origin", "on"); + vhost->get_or_create("token_traverse", "on"); + vhost->get_or_create("vhost", "on"); + vhost->get_or_create("debug_srs_upnode", "on"); + } + + HELPER_ASSERT_SUCCESS(srs_config_transform_vhost(&root)); + + SrsConfDirective* p = vhost->get("cluster"); + ASSERT_TRUE(p != NULL); + + ASSERT_TRUE(p->get("mode") != NULL); + ASSERT_TRUE(p->get("origin") != NULL); + ASSERT_TRUE(p->get("token_traverse") != NULL); + ASSERT_TRUE(p->get("vhost") != NULL); + ASSERT_TRUE(p->get("debug_srs_upnode") != NULL); + } +} + diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index aa8f91cc7..e73914c13 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -5093,6 +5093,44 @@ VOID TEST(KernelMP4Test, CoverMP4MultipleAVs) } } +VOID TEST(KernelMP4Test, CoverMP4CodecErrorNoFrames) +{ + srs_error_t err; + + MockSrsFileWriter f; + + // MP4 encoder. + if (true) { + SrsMp4Encoder enc; SrsFormat fmt; + HELPER_EXPECT_SUCCESS(enc.initialize(&f)); + HELPER_EXPECT_SUCCESS(fmt.initialize()); + + if (true) { + uint8_t raw[] = { + 0x17, 0x00, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x20, 0xff, 0xe1, 0x00, 0x19, 0x67, 0x64, 0x00, 0x20, 0xac, 0xd9, 0x40, 0xc0, 0x29, 0xb0, 0x11, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c + }; + HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + EXPECT_EQ(768, enc.width); EXPECT_EQ(320, enc.height); + } + + if (true) { + uint8_t raw[] = { + 0xaf, 0x00, 0x12, 0x10 + }; + HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + HELPER_EXPECT_SUCCESS(enc.write_sample( + &fmt, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw + )); + } + + HELPER_ASSERT_FAILED(enc.flush()); + //mock_print_mp4(string(f.data(), f.filesize())); + } +} + uint8_t* mock_copy_bytes(char* data, int size) { uint8_t* cp = new uint8_t[size]; From de87b64f59822b9873afaf11317d88f28f33ce1a Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 14:12:36 +0800 Subject: [PATCH 04/12] Improve test coverage for config. --- trunk/src/app/srs_app_config.cpp | 28 ++-- trunk/src/app/srs_app_config.hpp | 4 +- trunk/src/utest/srs_utest_config.cpp | 210 +++++++++++++++++++++++++++ trunk/src/utest/srs_utest_kernel.cpp | 10 ++ trunk/src/utest/srs_utest_kernel.hpp | 1 + 5 files changed, 232 insertions(+), 21 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index b5e1ca9d8..8ff779870 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -222,6 +222,14 @@ bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b, string excep return true; } +void set_config_directive(SrsConfDirective* parent, string dir, string value) +{ + SrsConfDirective* d = parent->get_or_create(dir); + d->name = dir; + d->args.clear(); + d->args.push_back(value); +} + bool srs_config_hls_is_on_error_ignore(string strategy) { return strategy == "ignore"; @@ -864,6 +872,7 @@ srs_error_t SrsConfDirective::persistence(SrsFileWriter* writer, int level) return err; } +// LCOV_EXCL_START SrsJsonArray* SrsConfDirective::dumps_args() { SrsJsonArray* arr = SrsJsonAny::array(); @@ -893,6 +902,7 @@ SrsJsonAny* SrsConfDirective::dumps_arg0_to_boolean() { return SrsJsonAny::boolean(arg0() == "on"); } +// LCOV_EXCL_STOP // see: ngx_conf_parse srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveType type) @@ -1122,24 +1132,6 @@ bool SrsConfig::is_dolphin() return dolphin; } -void SrsConfig::set_config_directive(SrsConfDirective* parent, string dir, string value) -{ - SrsConfDirective* d = parent->get(dir); - - if (!d) { - d = new SrsConfDirective(); - if (!dir.empty()) { - d->name = dir; - } - parent->directives.push_back(d); - } - - d->args.clear(); - if (!value.empty()) { - d->args.push_back(value); - } -} - void SrsConfig::subscribe(ISrsReloadHandler* handler) { std::vector::iterator it; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 602e5e22c..6bc0b4cf2 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -308,9 +308,7 @@ public: public: // Whether srs is in dolphin mode. virtual bool is_dolphin(); -private: - virtual void set_config_directive(SrsConfDirective* parent, std::string dir, std::string value); -// Reload +// Reload public: // For reload handler to register itself, // when config service do the reload, callback the handler. diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 864637380..b0211540b 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -32,6 +32,7 @@ using namespace std; #include #include #include +#include MockSrsConfigBuffer::MockSrsConfigBuffer(string buf) { @@ -2281,3 +2282,212 @@ VOID TEST(ConfigUnitTest, TransformForVhost) } } +VOID TEST(ConfigUnitTest, DirectiveCopy) +{ + if (true) { + SrsConfDirective d; + d.name = "vhost"; + d.get_or_create("enabled", "on"); + + SrsConfDirective* cp = d.copy(); + ASSERT_TRUE(cp != NULL); + EXPECT_STREQ("vhost", cp->name.c_str()); + ASSERT_TRUE(cp->get("enabled") != NULL); + EXPECT_STREQ("on", cp->get("enabled")->arg0().c_str()); + srs_freep(cp); + } + + if (true) { + SrsConfDirective d; + d.name = "vhost"; + d.get_or_create("enabled", "on"); + + SrsConfDirective* cp = d.copy("enabled"); + ASSERT_TRUE(cp != NULL); + EXPECT_STREQ("vhost", cp->name.c_str()); + ASSERT_TRUE(cp->get("enabled") == NULL); + srs_freep(cp); + } + + if (true) { + SrsConfDirective d; + d.name = "vhost"; + d.get_or_create("enabled", "on"); + d.get_or_create("hls"); + + SrsConfDirective* cp = d.copy("hls"); + ASSERT_TRUE(cp != NULL); + EXPECT_STREQ("vhost", cp->name.c_str()); + ASSERT_TRUE(cp->get("enabled") != NULL); + EXPECT_STREQ("on", cp->get("enabled")->arg0().c_str()); + srs_freep(cp); + } + + if (true) { + SrsConfDirective d; + EXPECT_TRUE(d.arg0().empty()); + EXPECT_TRUE(d.arg1().empty()); + EXPECT_TRUE(d.arg2().empty()); + EXPECT_TRUE(d.arg3().empty()); + } + + if (true) { + SrsConfDirective d; + d.args.push_back("a0"); + EXPECT_STREQ("a0", d.arg0().c_str()); + EXPECT_TRUE(d.arg1().empty()); + EXPECT_TRUE(d.arg2().empty()); + EXPECT_TRUE(d.arg3().empty()); + } + + if (true) { + SrsConfDirective d; + d.args.push_back("a0"); + d.args.push_back("a1"); + EXPECT_STREQ("a0", d.arg0().c_str()); + EXPECT_STREQ("a1", d.arg1().c_str()); + EXPECT_TRUE(d.arg2().empty()); + EXPECT_TRUE(d.arg3().empty()); + } + + if (true) { + SrsConfDirective d; + d.args.push_back("a0"); + d.args.push_back("a1"); + d.args.push_back("a2"); + EXPECT_STREQ("a0", d.arg0().c_str()); + EXPECT_STREQ("a1", d.arg1().c_str()); + EXPECT_STREQ("a2", d.arg2().c_str()); + EXPECT_TRUE(d.arg3().empty()); + } + + if (true) { + SrsConfDirective d; + d.args.push_back("a0"); + d.args.push_back("a1"); + d.args.push_back("a2"); + d.args.push_back("a3"); + EXPECT_STREQ("a0", d.arg0().c_str()); + EXPECT_STREQ("a1", d.arg1().c_str()); + EXPECT_STREQ("a2", d.arg2().c_str()); + EXPECT_STREQ("a3", d.arg3().c_str()); + } + + if (true) { + SrsConfDirective d; + d.set_arg0("a0"); + EXPECT_STREQ("a0", d.arg0().c_str()); + EXPECT_TRUE(d.arg1().empty()); + EXPECT_TRUE(d.arg2().empty()); + EXPECT_TRUE(d.arg3().empty()); + } + + if (true) { + SrsConfDirective d; + d.args.push_back("a0"); + d.set_arg0("a0"); + EXPECT_STREQ("a0", d.arg0().c_str()); + EXPECT_TRUE(d.arg1().empty()); + EXPECT_TRUE(d.arg2().empty()); + EXPECT_TRUE(d.arg3().empty()); + } + + if (true) { + SrsConfDirective d; + d.args.push_back("a1"); + d.set_arg0("a0"); + EXPECT_STREQ("a0", d.arg0().c_str()); + EXPECT_TRUE(d.arg1().empty()); + EXPECT_TRUE(d.arg2().empty()); + EXPECT_TRUE(d.arg3().empty()); + } + + if (true) { + SrsConfDirective d; + + SrsConfDirective* vhost = d.get_or_create("vhost"); + d.remove(vhost); + srs_freep(vhost); + + EXPECT_TRUE(d.get("vhost") == NULL); + } +} + +extern void set_config_directive(SrsConfDirective* parent, string dir, string value); + +VOID TEST(ConfigUnitTest, PersistenceConfig) +{ + srs_error_t err; + + if (true) { + SrsConfDirective d; + MockSrsFileWriter fw; + HELPER_ASSERT_SUCCESS(d.persistence(&fw, 0)); + EXPECT_STREQ("", fw.str().c_str()); + } + + if (true) { + SrsConfDirective d; + d.name = "root"; + d.args.push_back("on"); + + MockSrsFileWriter fw; + HELPER_ASSERT_SUCCESS(d.persistence(&fw, 0)); + EXPECT_STREQ("", fw.str().c_str()); + } + + if (true) { + SrsConfDirective d; + d.get_or_create("global"); + + MockSrsFileWriter fw; + HELPER_ASSERT_SUCCESS(d.persistence(&fw, 0)); + EXPECT_STREQ("global;\n", fw.str().c_str()); + } + + if (true) { + SrsConfDirective d; + d.get_or_create("global", "on"); + + MockSrsFileWriter fw; + HELPER_ASSERT_SUCCESS(d.persistence(&fw, 0)); + EXPECT_STREQ("global on;\n", fw.str().c_str()); + } + + if (true) { + SrsConfDirective d; + SrsConfDirective* p = d.get_or_create("global", "on"); + p->get_or_create("child", "100"); + p->get_or_create("sibling", "101"); + + MockSrsFileWriter fw; + HELPER_ASSERT_SUCCESS(d.persistence(&fw, 0)); + EXPECT_STREQ("global on {\n child 100;\n sibling 101;\n}\n", fw.str().c_str()); + } + + if (true) { + SrsConfDirective d; + SrsConfDirective* p = d.get_or_create("global", "on"); + SrsConfDirective* pp = p->get_or_create("child", "100"); + p->get_or_create("sibling", "101"); + pp->get_or_create("grandson", "200"); + + MockSrsFileWriter fw; + HELPER_ASSERT_SUCCESS(d.persistence(&fw, 0)); + EXPECT_STREQ("global on {\n child 100 {\n grandson 200;\n }\n sibling 101;\n}\n", fw.str().c_str()); + } + + if (true) { + SrsConfDirective d; + set_config_directive(&d, "vhost", "on"); + + ASSERT_TRUE(d.get("vhost") != NULL); + EXPECT_STREQ("on", d.get("vhost")->arg0().c_str()); + + set_config_directive(&d, "vhost", "off"); + + ASSERT_TRUE(d.get("vhost") != NULL); + EXPECT_STREQ("off", d.get("vhost")->arg0().c_str()); + } +} + diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index e73914c13..8f62186cc 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -195,6 +195,16 @@ char* MockSrsFileWriter::data() return uf->_data.bytes(); } +string MockSrsFileWriter::str() +{ + int size = filesize(); + if (size == 0) { + return ""; + } + + return string(data(), size); +} + srs_error_t MockSrsFileWriter::write(void* buf, size_t count, ssize_t* pnwrite) { if (err != srs_success) { diff --git a/trunk/src/utest/srs_utest_kernel.hpp b/trunk/src/utest/srs_utest_kernel.hpp index 6db2b7d35..90efb4ee9 100644 --- a/trunk/src/utest/srs_utest_kernel.hpp +++ b/trunk/src/utest/srs_utest_kernel.hpp @@ -74,6 +74,7 @@ public: virtual int64_t tellg(); virtual int64_t filesize(); virtual char* data(); + virtual string str(); public: virtual srs_error_t write(void* buf, size_t count, ssize_t* pnwrite); virtual srs_error_t lseek(off_t offset, int whence, off_t* seeked); From 7136c7c9b82b9444705fbc492e69176ac3c025b3 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 14:21:24 +0800 Subject: [PATCH 05/12] Improve test coverage for config. --- trunk/src/app/srs_app_config.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 8ff779870..15ea503cc 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -1156,6 +1156,7 @@ void SrsConfig::unsubscribe(ISrsReloadHandler* handler) subscribes.erase(it); } +// LCOV_EXCL_START srs_error_t SrsConfig::reload() { srs_error_t err = srs_success; @@ -1182,6 +1183,7 @@ srs_error_t SrsConfig::reload() return err; } +// LCOV_EXCL_STOP srs_error_t SrsConfig::reload_vhost(SrsConfDirective* old_root) { @@ -1848,6 +1850,7 @@ srs_error_t SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirecti } // see: ngx_get_options +// LCOV_EXCL_START srs_error_t SrsConfig::parse_options(int argc, char** argv) { srs_error_t err = srs_success; @@ -3123,6 +3126,7 @@ srs_error_t SrsConfig::raw_disable_dvr(string vhost, string stream, bool& applie return err; } +// LCOV_EXCL_STOP srs_error_t SrsConfig::do_reload_listen() { @@ -3310,6 +3314,7 @@ string SrsConfig::config() return config_file; } +// LCOV_EXCL_START srs_error_t SrsConfig::parse_argv(int& i, char** argv) { srs_error_t err = srs_success; @@ -3425,6 +3430,7 @@ srs_error_t SrsConfig::parse_file(const char* filename) return err; } +// LCOV_EXCL_STOP srs_error_t SrsConfig::check_config() { @@ -3830,6 +3836,7 @@ srs_error_t SrsConfig::check_normal_config() return err; } +// LCOV_EXCL_START srs_error_t SrsConfig::check_number_connections() { srs_error_t err = srs_success; @@ -3879,6 +3886,7 @@ srs_error_t SrsConfig::check_number_connections() return err; } +// LCOV_EXCL_STOP srs_error_t SrsConfig::parse_buffer(SrsConfigBuffer* buffer) { From 2942955b30b826b6f3903e456c4831abaf3996c0 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 15:49:04 +0800 Subject: [PATCH 06/12] Improve test coverage for config. --- trunk/src/utest/srs_utest_config.cpp | 1182 ++++++++++++++------------ 1 file changed, 658 insertions(+), 524 deletions(-) diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index b0211540b..6c88c6f25 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -97,9 +97,11 @@ VOID TEST(ConfigTest, CheckMacros) VOID TEST(ConfigDirectiveTest, ParseEmpty) { + srs_error_t err; + MockSrsConfigBuffer buf(""); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(0, (int)conf.directives.size()); @@ -107,13 +109,15 @@ VOID TEST(ConfigDirectiveTest, ParseEmpty) VOID TEST(ConfigDirectiveTest, ParseNameOnly) { + srs_error_t err; + MockSrsConfigBuffer buf("winlin;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir = *conf.directives.at(0); EXPECT_STREQ("winlin", dir.name.c_str()); EXPECT_EQ(0, (int)dir.args.size()); @@ -122,13 +126,15 @@ VOID TEST(ConfigDirectiveTest, ParseNameOnly) VOID TEST(ConfigDirectiveTest, ParseNameArg0Only) { + srs_error_t err; + MockSrsConfigBuffer buf("winlin arg0;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir = *conf.directives.at(0); EXPECT_STREQ("winlin", dir.name.c_str()); EXPECT_EQ(1, (int)dir.args.size()); @@ -138,13 +144,15 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg0Only) VOID TEST(ConfigDirectiveTest, ParseNameArg1Only) { + srs_error_t err; + MockSrsConfigBuffer buf("winlin arg0 arg1;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir = *conf.directives.at(0); EXPECT_STREQ("winlin", dir.name.c_str()); EXPECT_EQ(2, (int)dir.args.size()); @@ -155,13 +163,15 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg1Only) VOID TEST(ConfigDirectiveTest, ParseNameArg2Only) { + srs_error_t err; + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir = *conf.directives.at(0); EXPECT_STREQ("winlin", dir.name.c_str()); EXPECT_EQ(3, (int)dir.args.size()); @@ -173,13 +183,15 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2Only) VOID TEST(ConfigDirectiveTest, ParseNameArg2Dir0) { + srs_error_t err; + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2 {dir0;}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir = *conf.directives.at(0); EXPECT_STREQ("winlin", dir.name.c_str()); EXPECT_EQ(3, (int)dir.args.size()); @@ -187,7 +199,7 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2Dir0) EXPECT_STREQ("arg1", dir.arg1().c_str()); EXPECT_STREQ("arg2", dir.arg2().c_str()); EXPECT_EQ(1, (int)dir.directives.size()); - + SrsConfDirective& dir0 = *dir.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(0, (int)dir0.args.size()); @@ -196,13 +208,15 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2Dir0) VOID TEST(ConfigDirectiveTest, ParseNameArg2Dir0NoEmpty) { + srs_error_t err; + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2{dir0;}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir = *conf.directives.at(0); EXPECT_STREQ("winlin", dir.name.c_str()); EXPECT_EQ(3, (int)dir.args.size()); @@ -210,7 +224,7 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2Dir0NoEmpty) EXPECT_STREQ("arg1", dir.arg1().c_str()); EXPECT_STREQ("arg2", dir.arg2().c_str()); EXPECT_EQ(1, (int)dir.directives.size()); - + SrsConfDirective& dir0 = *dir.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(0, (int)dir0.args.size()); @@ -219,13 +233,15 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2Dir0NoEmpty) VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0) { + srs_error_t err; + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2 {dir0 dir_arg0;}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir = *conf.directives.at(0); EXPECT_STREQ("winlin", dir.name.c_str()); EXPECT_EQ(3, (int)dir.args.size()); @@ -233,7 +249,7 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0) EXPECT_STREQ("arg1", dir.arg1().c_str()); EXPECT_STREQ("arg2", dir.arg2().c_str()); EXPECT_EQ(1, (int)dir.directives.size()); - + SrsConfDirective& dir0 = *dir.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); @@ -243,13 +259,15 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0) VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0_Dir0) { + srs_error_t err; + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2 {dir0 dir_arg0 {ddir0;}}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir = *conf.directives.at(0); EXPECT_STREQ("winlin", dir.name.c_str()); EXPECT_EQ(3, (int)dir.args.size()); @@ -257,13 +275,13 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0_Dir0) EXPECT_STREQ("arg1", dir.arg1().c_str()); EXPECT_STREQ("arg2", dir.arg2().c_str()); EXPECT_EQ(1, (int)dir.directives.size()); - + SrsConfDirective& dir0 = *dir.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); EXPECT_STREQ("dir_arg0", dir0.arg0().c_str()); EXPECT_EQ(1, (int)dir0.directives.size()); - + SrsConfDirective& ddir0 = *dir0.directives.at(0); EXPECT_STREQ("ddir0", ddir0.name.c_str()); EXPECT_EQ(0, (int)ddir0.args.size()); @@ -272,13 +290,15 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0_Dir0) VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0_Dir0Arg0) { + srs_error_t err; + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2 {dir0 dir_arg0 {ddir0 ddir_arg0;}}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir = *conf.directives.at(0); EXPECT_STREQ("winlin", dir.name.c_str()); EXPECT_EQ(3, (int)dir.args.size()); @@ -286,13 +306,13 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0_Dir0Arg0) EXPECT_STREQ("arg1", dir.arg1().c_str()); EXPECT_STREQ("arg2", dir.arg2().c_str()); EXPECT_EQ(1, (int)dir.directives.size()); - + SrsConfDirective& dir0 = *dir.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); EXPECT_STREQ("dir_arg0", dir0.arg0().c_str()); EXPECT_EQ(1, (int)dir0.directives.size()); - + SrsConfDirective& ddir0 = *dir0.directives.at(0); EXPECT_STREQ("ddir0", ddir0.name.c_str()); EXPECT_EQ(1, (int)ddir0.args.size()); @@ -302,19 +322,21 @@ VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0_Dir0Arg0) VOID TEST(ConfigDirectiveTest, Parse2SingleDirs) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 arg0;dir1 arg1;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(2, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); EXPECT_STREQ("arg0", dir0.arg0().c_str()); EXPECT_EQ(0, (int)dir0.directives.size()); - + SrsConfDirective& dir1 = *conf.directives.at(1); EXPECT_STREQ("dir1", dir1.name.c_str()); EXPECT_EQ(1, (int)dir1.args.size()); @@ -324,24 +346,26 @@ VOID TEST(ConfigDirectiveTest, Parse2SingleDirs) VOID TEST(ConfigDirectiveTest, ParseSingleComplexDirs) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 arg0;dir1 {dir2 arg2;}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(2, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); EXPECT_STREQ("arg0", dir0.arg0().c_str()); EXPECT_EQ(0, (int)dir0.directives.size()); - + SrsConfDirective& dir1 = *conf.directives.at(1); EXPECT_STREQ("dir1", dir1.name.c_str()); EXPECT_EQ(0, (int)dir1.args.size()); EXPECT_EQ(1, (int)dir1.directives.size()); - + SrsConfDirective& dir2 = *dir1.directives.at(0); EXPECT_STREQ("dir2", dir2.name.c_str()); EXPECT_EQ(1, (int)dir2.args.size()); @@ -351,13 +375,15 @@ VOID TEST(ConfigDirectiveTest, ParseSingleComplexDirs) VOID TEST(ConfigDirectiveTest, ParseStringArgs) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 arg0 \"str_arg\" 100;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(3, (int)dir0.args.size()); @@ -369,13 +395,15 @@ VOID TEST(ConfigDirectiveTest, ParseStringArgs) VOID TEST(ConfigDirectiveTest, ParseStringArgsWithSpace) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 arg0 \"str_arg space\" 100;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(3, (int)dir0.args.size()); @@ -387,13 +415,15 @@ VOID TEST(ConfigDirectiveTest, ParseStringArgsWithSpace) VOID TEST(ConfigDirectiveTest, ParseNumberArgs) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 100 101 102;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(3, (int)dir0.args.size()); @@ -405,13 +435,15 @@ VOID TEST(ConfigDirectiveTest, ParseNumberArgs) VOID TEST(ConfigDirectiveTest, ParseFloatArgs) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 100.01 101.02 102.03;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(3, (int)dir0.args.size()); @@ -423,13 +455,15 @@ VOID TEST(ConfigDirectiveTest, ParseFloatArgs) VOID TEST(ConfigDirectiveTest, ParseComments) { + srs_error_t err; + MockSrsConfigBuffer buf("#commnets\ndir0 arg0;\n#end-comments"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); @@ -439,13 +473,15 @@ VOID TEST(ConfigDirectiveTest, ParseComments) VOID TEST(ConfigDirectiveTest, ParseCommentsInline) { + srs_error_t err; + MockSrsConfigBuffer buf("#commnets\ndir0 arg0;#inline comments\n#end-comments"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); @@ -455,13 +491,15 @@ VOID TEST(ConfigDirectiveTest, ParseCommentsInline) VOID TEST(ConfigDirectiveTest, ParseCommentsInlineWithSpace) { + srs_error_t err; + MockSrsConfigBuffer buf(" #commnets\ndir0 arg0; #inline comments\n #end-comments"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); @@ -471,19 +509,21 @@ VOID TEST(ConfigDirectiveTest, ParseCommentsInlineWithSpace) VOID TEST(ConfigDirectiveTest, ParseCommentsInlinemixed) { + srs_error_t err; + MockSrsConfigBuffer buf("#commnets\ndir0 arg0;#inline comments\n#end-comments\ndir1 arg1;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(2, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); EXPECT_STREQ("arg0", dir0.arg0().c_str()); EXPECT_EQ(0, (int)dir0.directives.size()); - + SrsConfDirective& dir1 = *conf.directives.at(1); EXPECT_STREQ("dir1", dir1.name.c_str()); EXPECT_EQ(1, (int)dir1.args.size()); @@ -493,13 +533,15 @@ VOID TEST(ConfigDirectiveTest, ParseCommentsInlinemixed) VOID TEST(ConfigDirectiveTest, ParseSpecialChars) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 http://www.ossrs.net/api/v1/versions?level=major;"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); @@ -509,13 +551,15 @@ VOID TEST(ConfigDirectiveTest, ParseSpecialChars) VOID TEST(ConfigDirectiveTest, ParseSpecialChars2) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 rtmp://[server]:[port]/[app]/[stream]_[engine];"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(1, (int)dir0.args.size()); @@ -525,48 +569,60 @@ VOID TEST(ConfigDirectiveTest, ParseSpecialChars2) VOID TEST(ConfigDirectiveTest, ParseInvalidNoEndOfDirective) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(&buf)); + HELPER_ASSERT_FAILED(conf.parse(&buf)); } VOID TEST(ConfigDirectiveTest, ParseInvalidNoEndOfSubDirective) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 {"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(&buf)); + HELPER_ASSERT_FAILED(conf.parse(&buf)); } VOID TEST(ConfigDirectiveTest, ParseInvalidNoStartOfSubDirective) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 }"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(&buf)); + HELPER_ASSERT_FAILED(conf.parse(&buf)); } VOID TEST(ConfigDirectiveTest, ParseInvalidEmptyName) { + srs_error_t err; + MockSrsConfigBuffer buf(";"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(&buf)); + HELPER_ASSERT_FAILED(conf.parse(&buf)); } VOID TEST(ConfigDirectiveTest, ParseInvalidEmptyName2) { + srs_error_t err; + MockSrsConfigBuffer buf("{}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(&buf)); + HELPER_ASSERT_FAILED(conf.parse(&buf)); } VOID TEST(ConfigDirectiveTest, ParseInvalidEmptyDirective) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 {}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(0, (int)dir0.args.size()); @@ -575,13 +631,15 @@ VOID TEST(ConfigDirectiveTest, ParseInvalidEmptyDirective) VOID TEST(ConfigDirectiveTest, ParseLine) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 {}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(0, (int)dir0.args.size()); @@ -591,13 +649,15 @@ VOID TEST(ConfigDirectiveTest, ParseLine) VOID TEST(ConfigDirectiveTest, ParseLine2) { + srs_error_t err; + MockSrsConfigBuffer buf("\n\ndir0 {}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(0, (int)dir0.args.size()); @@ -607,19 +667,21 @@ VOID TEST(ConfigDirectiveTest, ParseLine2) VOID TEST(ConfigDirectiveTest, ParseLine3) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 {\n\ndir1 arg0;}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(0, (int)dir0.args.size()); EXPECT_EQ(1, (int)dir0.directives.size()); EXPECT_EQ(1, (int)dir0.conf_line); - + SrsConfDirective& dir1 = *dir0.directives.at(0); EXPECT_STREQ("dir1", dir1.name.c_str()); EXPECT_EQ(1, (int)dir1.args.size()); @@ -630,26 +692,28 @@ VOID TEST(ConfigDirectiveTest, ParseLine3) VOID TEST(ConfigDirectiveTest, ParseLine4) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 {\n\ndir1 \n\narg0;dir2 arg1;}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(0, (int)dir0.args.size()); EXPECT_EQ(2, (int)dir0.directives.size()); EXPECT_EQ(1, (int)dir0.conf_line); - + SrsConfDirective& dir1 = *dir0.directives.at(0); EXPECT_STREQ("dir1", dir1.name.c_str()); EXPECT_EQ(1, (int)dir1.args.size()); EXPECT_STREQ("arg0", dir1.arg0().c_str()); EXPECT_EQ(0, (int)dir1.directives.size()); EXPECT_EQ(3, (int)dir1.conf_line); - + SrsConfDirective& dir2 = *dir0.directives.at(1); EXPECT_STREQ("dir2", dir2.name.c_str()); EXPECT_EQ(1, (int)dir2.args.size()); @@ -660,25 +724,27 @@ VOID TEST(ConfigDirectiveTest, ParseLine4) VOID TEST(ConfigDirectiveTest, ParseLineNormal) { + srs_error_t err; + MockSrsConfigBuffer buf("dir0 {\ndir1 {\ndir2 arg2;\n}\n}"); SrsConfDirective conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); + HELPER_ASSERT_SUCCESS(conf.parse(&buf)); EXPECT_EQ(0, (int)conf.name.length()); EXPECT_EQ(0, (int)conf.args.size()); EXPECT_EQ(1, (int)conf.directives.size()); - + SrsConfDirective& dir0 = *conf.directives.at(0); EXPECT_STREQ("dir0", dir0.name.c_str()); EXPECT_EQ(0, (int)dir0.args.size()); EXPECT_EQ(1, (int)dir0.directives.size()); EXPECT_EQ(1, (int)dir0.conf_line); - + SrsConfDirective& dir1 = *dir0.directives.at(0); EXPECT_STREQ("dir1", dir1.name.c_str()); EXPECT_EQ(0, (int)dir1.args.size()); EXPECT_EQ(1, (int)dir1.directives.size()); EXPECT_EQ(2, (int)dir1.conf_line); - + SrsConfDirective& dir2 = *dir1.directives.at(0); EXPECT_STREQ("dir2", dir2.name.c_str()); EXPECT_EQ(1, (int)dir2.args.size()); @@ -689,15 +755,19 @@ VOID TEST(ConfigDirectiveTest, ParseLineNormal) VOID TEST(ConfigMainTest, ParseEmpty) { + srs_error_t err; + MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse("")); + HELPER_ASSERT_FAILED(conf.parse("")); } VOID TEST(ConfigMainTest, ParseMinConf) { + srs_error_t err; + MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); - + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + vector listens = conf.get_listens(); EXPECT_EQ(1, (int)listens.size()); EXPECT_STREQ("1935", listens.at(0).c_str()); @@ -705,1207 +775,1271 @@ VOID TEST(ConfigMainTest, ParseMinConf) VOID TEST(ConfigMainTest, ParseInvalidDirective) { + srs_error_t err; + MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listens 1935;")); + HELPER_ASSERT_FAILED(conf.parse("listens 1935;")); } VOID TEST(ConfigMainTest, ParseInvalidDirective2) { + srs_error_t err; + MockSrsConfig conf; // check error for user not specified the listen directive. - EXPECT_TRUE(ERROR_SUCCESS != conf.parse("chunk_size 4096;")); + HELPER_ASSERT_FAILED(conf.parse("chunk_size 4096;")); } VOID TEST(ConfigMainTest, CheckConf_listen) { + srs_error_t err; + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listens 1935;")); + HELPER_ASSERT_FAILED(conf.parse("listens 1935;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen 0;")); + HELPER_ASSERT_FAILED(conf.parse("listen 0;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen -1;")); + HELPER_ASSERT_FAILED(conf.parse("listen -1;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen -1935;")); + HELPER_ASSERT_FAILED(conf.parse("listen -1935;")); } } VOID TEST(ConfigMainTest, CheckConf_pid) { + srs_error_t err; + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"pids ./objs/srs.pid;")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"pids ./objs/srs.pid;")); } } VOID TEST(ConfigMainTest, CheckConf_chunk_size) { + srs_error_t err; + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"chunk_size 60000;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size 60000;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"chunk_sizes 60000;")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"chunk_sizes 60000;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"chunk_size 0;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size 0;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"chunk_size 1;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size 1;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"chunk_size 127;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size 127;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"chunk_size -1;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size -1;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"chunk_size -4096;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size -4096;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"chunk_size 65537;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size 65537;")); } } VOID TEST(ConfigMainTest, CheckConf_ff_log_dir) { + srs_error_t err; + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"ff_log_dir ./objs;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"ff_log_dir ./objs;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"ff_log_dirs ./objs;")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"ff_log_dirs ./objs;")); } } VOID TEST(ConfigMainTest, CheckConf_srs_log_level) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"srs_log_level trace;")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"srs_log_levels trace;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"srs_log_level trace;")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"srs_log_levels trace;")); } } VOID TEST(ConfigMainTest, CheckConf_srs_log_file) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"srs_log_file ./objs/srs.log;")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"srs_log_files ./objs/srs.log;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"srs_log_file ./objs/srs.log;")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"srs_log_files ./objs/srs.log;")); } } VOID TEST(ConfigMainTest, CheckConf_daemon) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"daemon on;")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"daemons on;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"daemon on;")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"daemons on;")); } } VOID TEST(ConfigMainTest, CheckConf_heartbeat) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"heartbeat{}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"heartbeats{}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"heartbeat{enabled on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeats{}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"heartbeat{enableds on;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{enabled on;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"heartbeat{interval 9;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeat{enableds on;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"heartbeat{intervals 9;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{interval 9;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"heartbeat{url http://127.0.0.1:8085/api/v1/servers;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeat{intervals 9;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"heartbeat{urls http://127.0.0.1:8085/api/v1/servers;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{url http://127.0.0.1:8085/api/v1/servers;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"heartbeat{device_id 0;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeat{urls http://127.0.0.1:8085/api/v1/servers;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"heartbeat{device_ids 0;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{device_id 0;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"heartbeat{summaries on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeat{device_ids 0;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"heartbeat{summariess on;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{summaries on;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeat{summariess on;}")); } } VOID TEST(ConfigMainTest, CheckConf_http_api) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_api{}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"http_apis{}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"http_api{}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"http_api{enableds on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_apis{}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"http_api{listens 1985;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_api{enableds on;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_api{listens 1985;}")); } } VOID TEST(ConfigMainTest, CheckConf_stats) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"stats{}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"statss{}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"stats{}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"stats{network 0;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"statss{}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"stats{networks 0;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"stats{network 0;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"stats{network -100;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"stats{networks 0;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"stats{network -1;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"stats{network -100;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"stats{disk sda;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"stats{network -1;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"stats{disks sda;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"stats{disk sda;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"stats{disks sda;}")); } } VOID TEST(ConfigMainTest, CheckConf_http_stream) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_stream{}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"http_streams{}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"http_stream{}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"http_stream{enableds on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_streams{}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"http_stream{listens 8080;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_stream{enableds on;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"http_stream{dirs ./objs/nginx/html;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_stream{listens 8080;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_stream{dirs ./objs/nginx/html;}")); } } VOID TEST(ConfigMainTest, CheckConf_vhost) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhosts{}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhosts{}")); } } VOID TEST(ConfigMainTest, CheckConf_vhost_edge) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{mode remote;}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{modes remote;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{mode remote;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{origin 127.0.0.1:1935 localhost:1935;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{modes remote;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{origins 127.0.0.1:1935 localhost:1935;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{origin 127.0.0.1:1935 localhost:1935;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{token_traverse off;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{origins 127.0.0.1:1935 localhost:1935;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{token_traverses off;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{token_traverse off;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{token_traverses off;}")); } } VOID TEST(ConfigMainTest, CheckConf_vhost_dvr) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dvr{}}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{dvrs{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dvr{enabled on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvrs{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{dvr{enableds on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{enabled on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_path ./objs/nginx/html;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{enableds on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_paths ./objs/nginx/html;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_path ./objs/nginx/html;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_plan session;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_paths ./objs/nginx/html;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_plans session;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_plan session;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_duration 30;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_plans session;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_durations 30;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_duration 30;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_wait_keyframe on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_durations 30;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_wait_keyframes on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_wait_keyframe on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dvr{time_jitter full;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_wait_keyframes on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{dvr{time_jitters full;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{time_jitter full;}}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{time_jitters full;}}")); } } VOID TEST(ConfigMainTest, CheckConf_vhost_ingest) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{ingest{}}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{ingests{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{ingest{enabled on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingests{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{ingest{enableds on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest{enabled on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{ingest{input{}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest{enableds on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{ingest{inputs{}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest{input{}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{ingest{ffmpeg ./objs/ffmpeg/bin/ffmpeg;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest{inputs{}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{ingest{ffmpegs ./objs/ffmpeg/bin/ffmpeg;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest{ffmpeg ./objs/ffmpeg/bin/ffmpeg;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{ingest{engine{}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest{ffmpegs ./objs/ffmpeg/bin/ffmpeg;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{ingest{engines{}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest{engine{}}}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest{engines{}}}")); } } VOID TEST(ConfigMainTest, CheckConf_vhost_http) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http{}}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{https{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http{enabled on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{https{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http{enableds on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http{enabled on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http{mount /hls;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http{enableds on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http{mounts /hls;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http{mount /hls;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http{dir ./objs/nginx/html/hls;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http{mounts /hls;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http{dirs ./objs/nginx/html/hls;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http{dir ./objs/nginx/html/hls;}}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http{dirs ./objs/nginx/html/hls;}}")); } } VOID TEST(ConfigMainTest, CheckConf_vhost_hls) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{}}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{hlss{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{enabled on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{hlss{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{hls{enableds on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{enabled on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{hls_path ./objs/nginx/html;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{hls{enableds on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{hls{hls_paths ./objs/nginx/html;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_path ./objs/nginx/html;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{hls_fragment 10;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_paths ./objs/nginx/html;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{hls{hls_fragments 10;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_fragment 10;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{hls_window 60;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_fragments 10;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{hls{hls_windows 60;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_window 60;}}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_windows 60;}}")); } } VOID TEST(ConfigMainTest, CheckConf_hooks) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http_hooks{}}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http_hookss{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http_hooks{enabled on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hookss{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http_hooks{enableds on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{enabled on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_connect http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{enableds on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_connects http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_connect http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_close http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_connects http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_closes http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_close http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_publish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_closes http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_publishs http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_publish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_unpublish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_publishs http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_unpublishs http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_unpublish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_play http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_unpublishs http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_plays http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_play http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_stop http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_plays http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_stops http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_stop http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_stops http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); } } VOID TEST(ConfigMainTest, CheckConf_gop_cache) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{gop_cache off;}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{gop_caches off;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{gop_cache off;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{queue_length 10;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{gop_caches off;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{queue_lengths 10;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{queue_length 10;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{queue_lengths 10;}")); } } VOID TEST(ConfigMainTest, CheckConf_debug_srs_upnode) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{debug_srs_upnode off;}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{debug_srs_upnodes off;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{debug_srs_upnode off;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{debug_srs_upnodes off;}")); } } VOID TEST(ConfigMainTest, CheckConf_refer) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{refer github.com github.io;}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{refers github.com github.io;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{refer github.com github.io;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{refer_publish github.com github.io;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{refers github.com github.io;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{refer_publishs github.com github.io;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{refer_publish github.com github.io;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{refer_play github.com github.io;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{refer_publishs github.com github.io;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{refer_plays github.com github.io;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{refer_play github.com github.io;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{refer_plays github.com github.io;}")); } } VOID TEST(ConfigMainTest, CheckConf_forward) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{forward 127.0.0.1:1936;}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{forwards 127.0.0.1:1936;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{forward 127.0.0.1:1936;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{forwards 127.0.0.1:1936;}")); } } VOID TEST(ConfigMainTest, CheckConf_transcode) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{}}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcodes{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{enabled on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcodes{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{enableds on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{enabled on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{ffmpeg ./objs/ffmpeg/bin/ffmpeg;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{enableds on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{ffmpegs ./objs/ffmpeg/bin/ffmpeg;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{ffmpeg ./objs/ffmpeg/bin/ffmpeg;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{ffmpegs ./objs/ffmpeg/bin/ffmpeg;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engines {}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {enabled on;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engines {}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {enableds on;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {enabled on;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfilter {}}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {enableds on;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfilters {}}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfilter {}}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vcodec libx264;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfilters {}}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vcodecs libx264;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vcodec libx264;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vbitrate 300;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vcodecs libx264;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vbitrates 300;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vbitrate 300;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfps 20;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vbitrates 300;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfpss 20;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfps 20;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vwidth 768;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfpss 20;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vwidths 768;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vwidth 768;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vheight 320;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vwidths 768;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vheights 320;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vheight 320;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vthreads 2;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vheights 320;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vthreadss 2;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vthreads 2;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vprofile baseline;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vthreadss 2;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vprofiles baseline;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vprofile baseline;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vpreset superfast;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vprofiles baseline;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vpresets superfast;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vpreset superfast;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vparams {}}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vpresets superfast;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vparamss {}}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vparams {}}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {acodec libfdk_aac;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vparamss {}}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {acodecs libfdk_aac;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {acodec libfdk_aac;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {abitrate 45;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {acodecs libfdk_aac;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {abitrates 45;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {abitrate 45;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {asample_rate 44100;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {abitrates 45;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {asample_rates 44100;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {asample_rate 44100;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {achannels 2;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {asample_rates 44100;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {achannelss 2;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {achannels 2;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {aparams {}}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {achannelss 2;}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {aparamss {}}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {aparams {}}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {aparamss {}}}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {outputs rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];}}}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {outputs rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];}}}")); } } VOID TEST(ConfigMainTest, CheckConf_bandcheck) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{}}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{bandchecks{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{enabled on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{bandchecks{}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{bandcheck{enableds on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{enabled on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{key \"35c9b402c12a7246868752e2878f7e0e\";}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{enableds on;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{bandcheck{keys \"35c9b402c12a7246868752e2878f7e0e\";}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{key \"35c9b402c12a7246868752e2878f7e0e\";}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{interval 30;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{keys \"35c9b402c12a7246868752e2878f7e0e\";}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{bandcheck{intervals 30;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{interval 30;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{limit_kbps 4000;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{intervals 30;}}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{bandcheck{limit_kbpss 4000;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{limit_kbps 4000;}}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{limit_kbpss 4000;}}")); } } VOID TEST(ConfigMainTest, CheckConf_chunk_size2) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{chunk_size 128;}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{chunk_sizes 128;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size 128;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{chunk_size 127;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{chunk_sizes 128;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{chunk_size 0;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size 127;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{chunk_size -1;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size 0;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{chunk_size -128;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size -1;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{chunk_size 65537;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size -128;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size 65537;}")); } } VOID TEST(ConfigMainTest, CheckConf_jitter) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{time_jitter full;}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{time_jitters full;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{time_jitter full;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{time_jitters full;}")); } } VOID TEST(ConfigMainTest, CheckConf_atc) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{atc on;}")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{atcs on;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{atc on;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{atc_auto on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{atcs on;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{atc_autos on;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{atc_auto on;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{enabled on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{atc_autos on;}")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{enableds on;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{enabled on;}")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{enableds on;}")); } } VOID TEST(ConfigMainTest, CheckConf_pithy_print) { - if (true) { - MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"pithy_print_ms 1000;")); - } + srs_error_t err; if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"pithy_print_mss 1000;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"pithy_print_ms 1000;")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"pithy_print_mss 1000;")); } } VOID TEST(ConfigMainTest, CheckConf_vhost_ingest_id) { + srs_error_t err; + MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{ingest id{}}")); - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{ingest id{} ingest id{}}")); - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{ingest{} ingest{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest id{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest id{} ingest id{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest{} ingest{}}")); } VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) { + srs_error_t err; + MockSrsConfig conf; if (true) { - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{interval 4;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{interval 4;}}")); EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("v")); } if (true) { - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_dash_fragment("")); EXPECT_EQ(150 * SRS_UTIME_SECONDS, conf.get_dash_update_period("")); EXPECT_EQ(300 * SRS_UTIME_SECONDS, conf.get_dash_timeshift("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dash{dash_fragment 4;dash_update_period 40;dash_timeshift 70;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dash{dash_fragment 4;dash_update_period 40;dash_timeshift 70;}}")); EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_dash_fragment("v")); EXPECT_EQ(40 * SRS_UTIME_SECONDS, conf.get_dash_update_period("v")); EXPECT_EQ(70 * SRS_UTIME_SECONDS, conf.get_dash_timeshift("v")); } if (true) { - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(srs_utime_t(9.9 * SRS_UTIME_SECONDS), conf.get_heartbeat_interval()); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"heartbeat{interval 10;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{interval 10;}")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_heartbeat_interval()); } if (true) { - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_pithy_print()); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"pithy_print_ms 20000;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"pithy_print_ms 20000;")); EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_pithy_print()); } if (true) { - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(350 * SRS_UTIME_MILLISECONDS, conf.get_mr_sleep("")); EXPECT_EQ(350 * SRS_UTIME_MILLISECONDS, conf.get_mw_sleep("")); EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_publish_1stpkt_timeout("")); EXPECT_EQ(5 * SRS_UTIME_SECONDS, conf.get_publish_normal_timeout("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{publish{mr_latency 1000; firstpkt_timeout 100; normal_timeout 100;} play{mw_latency 1000;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{publish{mr_latency 1000; firstpkt_timeout 100; normal_timeout 100;} play{mw_latency 1000;}}")); EXPECT_EQ(1000 * SRS_UTIME_MILLISECONDS, conf.get_mr_sleep("v")); EXPECT_EQ(100 * SRS_UTIME_MILLISECONDS, conf.get_publish_1stpkt_timeout("v")); EXPECT_EQ(100 * SRS_UTIME_MILLISECONDS, conf.get_publish_normal_timeout("v")); } if (true) { - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_dvr_duration("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_duration 10;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_duration 10;}}")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_dvr_duration("v")); } if (true) { - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(0, conf.get_hls_dispose("")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_fragment("")); EXPECT_EQ(60 * SRS_UTIME_SECONDS, conf.get_hls_window("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{hls_dispose 10;hls_fragment 20;hls_window 30;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_dispose 10;hls_fragment 20;hls_window 30;}}")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_dispose("v")); EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_hls_fragment("v")); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_hls_window("v")); } if (true) { - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hds_fragment("")); EXPECT_EQ(60 * SRS_UTIME_SECONDS, conf.get_hds_window("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hds{hds_fragment 20;hds_window 30;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hds{hds_fragment 20;hds_window 30;}}")); EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_hds_fragment("v")); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_hds_window("v")); } if (true) { - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_queue_length("")); EXPECT_EQ(0, conf.get_send_min_interval("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{play{queue_length 100;send_min_interval 10;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{play{queue_length 100;send_min_interval 10;}}")); EXPECT_EQ(100 * SRS_UTIME_SECONDS, conf.get_queue_length("v")); EXPECT_EQ(10 * SRS_UTIME_MILLISECONDS, conf.get_send_min_interval("v")); } if (true) { - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(0, conf.get_vhost_http_remux_fast_cache("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{http_remux{fast_cache 10;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_remux{fast_cache 10;}}")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_vhost_http_remux_fast_cache("v")); } } From 146a095b38a31b0867817c2b0d7b15f7e1b43ef7 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 15:52:10 +0800 Subject: [PATCH 07/12] Improve test coverage for config. --- trunk/src/utest/srs_utest_config.cpp | 446 ++++++++++++++------------- 1 file changed, 238 insertions(+), 208 deletions(-) diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 6c88c6f25..6ab803025 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -826,7 +826,7 @@ VOID TEST(ConfigMainTest, CheckConf_pid) if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"pids ./objs/srs.pid;")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "pids ./objs/srs.pid;")); } } @@ -836,42 +836,42 @@ VOID TEST(ConfigMainTest, CheckConf_chunk_size) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size 60000;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "chunk_size 60000;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"chunk_sizes 60000;")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "chunk_sizes 60000;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size 0;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "chunk_size 0;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size 1;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "chunk_size 1;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size 127;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "chunk_size 127;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size -1;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "chunk_size -1;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size -4096;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "chunk_size -4096;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"chunk_size 65537;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "chunk_size 65537;")); } } @@ -881,12 +881,12 @@ VOID TEST(ConfigMainTest, CheckConf_ff_log_dir) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"ff_log_dir ./objs;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "ff_log_dir ./objs;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"ff_log_dirs ./objs;")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "ff_log_dirs ./objs;")); } } @@ -896,12 +896,12 @@ VOID TEST(ConfigMainTest, CheckConf_srs_log_level) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"srs_log_level trace;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srs_log_level trace;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"srs_log_levels trace;")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "srs_log_levels trace;")); } } @@ -911,12 +911,12 @@ VOID TEST(ConfigMainTest, CheckConf_srs_log_file) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"srs_log_file ./objs/srs.log;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srs_log_file ./objs/srs.log;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"srs_log_files ./objs/srs.log;")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "srs_log_files ./objs/srs.log;")); } } @@ -926,12 +926,12 @@ VOID TEST(ConfigMainTest, CheckConf_daemon) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"daemon on;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "daemon on;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"daemons on;")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "daemons on;")); } } @@ -941,62 +941,62 @@ VOID TEST(ConfigMainTest, CheckConf_heartbeat) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "heartbeat{}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeats{}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "heartbeats{}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{enabled on;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "heartbeat{enabled on;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeat{enableds on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "heartbeat{enableds on;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{interval 9;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "heartbeat{interval 9;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeat{intervals 9;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "heartbeat{intervals 9;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{url http://127.0.0.1:8085/api/v1/servers;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "heartbeat{url http://127.0.0.1:8085/api/v1/servers;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeat{urls http://127.0.0.1:8085/api/v1/servers;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "heartbeat{urls http://127.0.0.1:8085/api/v1/servers;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{device_id 0;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "heartbeat{device_id 0;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeat{device_ids 0;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "heartbeat{device_ids 0;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{summaries on;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "heartbeat{summaries on;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"heartbeat{summariess on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "heartbeat{summariess on;}")); } } @@ -1006,22 +1006,22 @@ VOID TEST(ConfigMainTest, CheckConf_http_api) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"http_api{}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "http_api{}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_apis{}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "http_apis{}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_api{enableds on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "http_api{enableds on;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_api{listens 1985;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "http_api{listens 1985;}")); } } @@ -1031,42 +1031,42 @@ VOID TEST(ConfigMainTest, CheckConf_stats) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"stats{}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stats{}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"statss{}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "statss{}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"stats{network 0;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stats{network 0;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"stats{networks 0;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "stats{networks 0;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"stats{network -100;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "stats{network -100;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"stats{network -1;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "stats{network -1;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"stats{disk sda;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stats{disk sda;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"stats{disks sda;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "stats{disks sda;}")); } } @@ -1076,27 +1076,27 @@ VOID TEST(ConfigMainTest, CheckConf_http_stream) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"http_stream{}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "http_stream{}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_streams{}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "http_streams{}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_stream{enableds on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "http_stream{enableds on;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_stream{listens 8080;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "http_stream{listens 8080;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"http_stream{dirs ./objs/nginx/html;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "http_stream{dirs ./objs/nginx/html;}")); } } @@ -1106,12 +1106,12 @@ VOID TEST(ConfigMainTest, CheckConf_vhost) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhosts{}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhosts{}")); } } @@ -1121,32 +1121,32 @@ VOID TEST(ConfigMainTest, CheckConf_vhost_edge) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{mode remote;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{mode remote;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{modes remote;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{modes remote;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{origin 127.0.0.1:1935 localhost:1935;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{origin 127.0.0.1:1935 localhost:1935;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{origins 127.0.0.1:1935 localhost:1935;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{origins 127.0.0.1:1935 localhost:1935;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{token_traverse off;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{token_traverse off;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{token_traverses off;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{token_traverses off;}")); } } @@ -1156,72 +1156,72 @@ VOID TEST(ConfigMainTest, CheckConf_vhost_dvr) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{dvr{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvrs{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{dvrs{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{enabled on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{dvr{enabled on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{enableds on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{dvr{enableds on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_path ./objs/nginx/html;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{dvr{dvr_path ./objs/nginx/html;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_paths ./objs/nginx/html;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{dvr{dvr_paths ./objs/nginx/html;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_plan session;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{dvr{dvr_plan session;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_plans session;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{dvr{dvr_plans session;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_duration 30;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{dvr{dvr_duration 30;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_durations 30;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{dvr{dvr_durations 30;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_wait_keyframe on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{dvr{dvr_wait_keyframe on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_wait_keyframes on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{dvr{dvr_wait_keyframes on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{time_jitter full;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{dvr{time_jitter full;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{dvr{time_jitters full;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{dvr{time_jitters full;}}")); } } @@ -1231,52 +1231,52 @@ VOID TEST(ConfigMainTest, CheckConf_vhost_ingest) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{ingest{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingests{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{ingests{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest{enabled on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{ingest{enabled on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest{enableds on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{ingest{enableds on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest{input{}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{ingest{input{}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest{inputs{}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{ingest{inputs{}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest{ffmpeg ./objs/ffmpeg/bin/ffmpeg;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{ingest{ffmpeg ./objs/ffmpeg/bin/ffmpeg;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest{ffmpegs ./objs/ffmpeg/bin/ffmpeg;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{ingest{ffmpegs ./objs/ffmpeg/bin/ffmpeg;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest{engine{}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{ingest{engine{}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest{engines{}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{ingest{engines{}}}")); } } @@ -1286,42 +1286,42 @@ VOID TEST(ConfigMainTest, CheckConf_vhost_http) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{https{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{https{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http{enabled on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http{enabled on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http{enableds on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http{enableds on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http{mount /hls;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http{mount /hls;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http{mounts /hls;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http{mounts /hls;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http{dir ./objs/nginx/html/hls;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http{dir ./objs/nginx/html/hls;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http{dirs ./objs/nginx/html/hls;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http{dirs ./objs/nginx/html/hls;}}")); } } @@ -1331,52 +1331,52 @@ VOID TEST(ConfigMainTest, CheckConf_vhost_hls) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{hls{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{hlss{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{hlss{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{enabled on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{hls{enabled on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{hls{enableds on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{hls{enableds on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_path ./objs/nginx/html;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{hls{hls_path ./objs/nginx/html;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_paths ./objs/nginx/html;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{hls{hls_paths ./objs/nginx/html;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_fragment 10;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{hls{hls_fragment 10;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_fragments 10;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{hls{hls_fragments 10;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_window 60;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{hls{hls_window 60;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_windows 60;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{hls{hls_windows 60;}}")); } } @@ -1386,82 +1386,82 @@ VOID TEST(ConfigMainTest, CheckConf_hooks) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hookss{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http_hookss{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{enabled on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{enabled on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{enableds on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{enableds on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_connect http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_connect http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_connects http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_connects http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_close http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_close http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_closes http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_closes http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_publish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_publish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_publishs http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_publishs http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_unpublish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_unpublish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_unpublishs http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_unpublishs http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_play http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_play http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_plays http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_plays http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_stop http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_stop http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{http_hooks{on_stops http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{http_hooks{on_stops http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;}}")); } } @@ -1471,22 +1471,22 @@ VOID TEST(ConfigMainTest, CheckConf_gop_cache) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{gop_cache off;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{gop_cache off;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{gop_caches off;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{gop_caches off;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{queue_length 10;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{queue_length 10;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{queue_lengths 10;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{queue_lengths 10;}")); } } @@ -1496,12 +1496,12 @@ VOID TEST(ConfigMainTest, CheckConf_debug_srs_upnode) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{debug_srs_upnode off;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{debug_srs_upnode off;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{debug_srs_upnodes off;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{debug_srs_upnodes off;}")); } } @@ -1511,32 +1511,32 @@ VOID TEST(ConfigMainTest, CheckConf_refer) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{refer github.com github.io;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{refer github.com github.io;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{refers github.com github.io;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{refers github.com github.io;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{refer_publish github.com github.io;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{refer_publish github.com github.io;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{refer_publishs github.com github.io;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{refer_publishs github.com github.io;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{refer_play github.com github.io;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{refer_play github.com github.io;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{refer_plays github.com github.io;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{refer_plays github.com github.io;}")); } } @@ -1546,12 +1546,12 @@ VOID TEST(ConfigMainTest, CheckConf_forward) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{forward 127.0.0.1:1936;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{forward 127.0.0.1:1936;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{forwards 127.0.0.1:1936;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{forwards 127.0.0.1:1936;}")); } } @@ -1561,212 +1561,212 @@ VOID TEST(ConfigMainTest, CheckConf_transcode) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcodes{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcodes{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{enabled on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{enabled on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{enableds on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{enableds on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{ffmpeg ./objs/ffmpeg/bin/ffmpeg;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{ffmpeg ./objs/ffmpeg/bin/ffmpeg;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{ffmpegs ./objs/ffmpeg/bin/ffmpeg;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{ffmpegs ./objs/ffmpeg/bin/ffmpeg;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engines {}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engines {}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {enabled on;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {enabled on;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {enableds on;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {enableds on;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfilter {}}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vfilter {}}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfilters {}}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vfilters {}}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vcodec libx264;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vcodec libx264;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vcodecs libx264;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vcodecs libx264;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vbitrate 300;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vbitrate 300;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vbitrates 300;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vbitrates 300;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfps 20;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vfps 20;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vfpss 20;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vfpss 20;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vwidth 768;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vwidth 768;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vwidths 768;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vwidths 768;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vheight 320;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vheight 320;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vheights 320;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vheights 320;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vthreads 2;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vthreads 2;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vthreadss 2;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vthreadss 2;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vprofile baseline;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vprofile baseline;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vprofiles baseline;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vprofiles baseline;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vpreset superfast;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vpreset superfast;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vpresets superfast;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vpresets superfast;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vparams {}}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vparams {}}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {vparamss {}}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {vparamss {}}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {acodec libfdk_aac;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {acodec libfdk_aac;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {acodecs libfdk_aac;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {acodecs libfdk_aac;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {abitrate 45;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {abitrate 45;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {abitrates 45;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {abitrates 45;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {asample_rate 44100;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {asample_rate 44100;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {asample_rates 44100;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {asample_rates 44100;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {achannels 2;}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {achannels 2;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {achannelss 2;}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {achannelss 2;}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {aparams {}}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {aparams {}}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {aparamss {}}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {aparamss {}}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];}}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];}}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{transcode{engine {outputs rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];}}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{transcode{engine {outputs rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];}}}")); } } @@ -1776,52 +1776,52 @@ VOID TEST(ConfigMainTest, CheckConf_bandcheck) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{bandchecks{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{bandchecks{}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{enabled on;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{enabled on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{enableds on;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{enableds on;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{key \"35c9b402c12a7246868752e2878f7e0e\";}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{key \"35c9b402c12a7246868752e2878f7e0e\";}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{keys \"35c9b402c12a7246868752e2878f7e0e\";}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{keys \"35c9b402c12a7246868752e2878f7e0e\";}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{interval 30;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{interval 30;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{intervals 30;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{intervals 30;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{limit_kbps 4000;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{limit_kbps 4000;}}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{limit_kbpss 4000;}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{limit_kbpss 4000;}}")); } } @@ -1831,37 +1831,37 @@ VOID TEST(ConfigMainTest, CheckConf_chunk_size2) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size 128;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{chunk_size 128;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{chunk_sizes 128;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{chunk_sizes 128;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size 127;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{chunk_size 127;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size 0;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{chunk_size 0;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size -1;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{chunk_size -1;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size -128;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{chunk_size -128;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{chunk_size 65537;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{chunk_size 65537;}")); } } @@ -1871,12 +1871,12 @@ VOID TEST(ConfigMainTest, CheckConf_jitter) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{time_jitter full;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{time_jitter full;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{time_jitters full;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{time_jitters full;}")); } } @@ -1886,32 +1886,32 @@ VOID TEST(ConfigMainTest, CheckConf_atc) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{atc on;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{atc on;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{atcs on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{atcs on;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{atc_auto on;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{atc_auto on;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{atc_autos on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{atc_autos on;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{enabled on;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{enabled on;}")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{enableds on;}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{enableds on;}")); } } @@ -1921,12 +1921,12 @@ VOID TEST(ConfigMainTest, CheckConf_pithy_print) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"pithy_print_ms 1000;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "pithy_print_ms 1000;")); } if (true) { MockSrsConfig conf; - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"pithy_print_mss 1000;")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "pithy_print_mss 1000;")); } } @@ -1935,9 +1935,9 @@ VOID TEST(ConfigMainTest, CheckConf_vhost_ingest_id) srs_error_t err; MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{ingest id{}}")); - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest id{} ingest id{}}")); - HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF"vhost v{ingest{} ingest{}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{ingest id{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{ingest id{} ingest id{}}")); + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "vhost v{ingest{} ingest{}}")); } VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) @@ -1950,7 +1950,7 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("")); - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{bandcheck{interval 4;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{bandcheck{interval 4;}}")); EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("v")); } @@ -1960,7 +1960,7 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) EXPECT_EQ(150 * SRS_UTIME_SECONDS, conf.get_dash_update_period("")); EXPECT_EQ(300 * SRS_UTIME_SECONDS, conf.get_dash_timeshift("")); - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dash{dash_fragment 4;dash_update_period 40;dash_timeshift 70;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{dash{dash_fragment 4;dash_update_period 40;dash_timeshift 70;}}")); EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_dash_fragment("v")); EXPECT_EQ(40 * SRS_UTIME_SECONDS, conf.get_dash_update_period("v")); EXPECT_EQ(70 * SRS_UTIME_SECONDS, conf.get_dash_timeshift("v")); @@ -1970,7 +1970,7 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(srs_utime_t(9.9 * SRS_UTIME_SECONDS), conf.get_heartbeat_interval()); - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"heartbeat{interval 10;}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "heartbeat{interval 10;}")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_heartbeat_interval()); } @@ -1978,7 +1978,7 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_pithy_print()); - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"pithy_print_ms 20000;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "pithy_print_ms 20000;")); EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_pithy_print()); } @@ -1989,7 +1989,7 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_publish_1stpkt_timeout("")); EXPECT_EQ(5 * SRS_UTIME_SECONDS, conf.get_publish_normal_timeout("")); - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{publish{mr_latency 1000; firstpkt_timeout 100; normal_timeout 100;} play{mw_latency 1000;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{publish{mr_latency 1000; firstpkt_timeout 100; normal_timeout 100;} play{mw_latency 1000;}}")); EXPECT_EQ(1000 * SRS_UTIME_MILLISECONDS, conf.get_mr_sleep("v")); EXPECT_EQ(100 * SRS_UTIME_MILLISECONDS, conf.get_publish_1stpkt_timeout("v")); EXPECT_EQ(100 * SRS_UTIME_MILLISECONDS, conf.get_publish_normal_timeout("v")); @@ -1999,7 +1999,7 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_dvr_duration("")); - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{dvr{dvr_duration 10;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{dvr{dvr_duration 10;}}")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_dvr_duration("v")); } @@ -2009,7 +2009,7 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_fragment("")); EXPECT_EQ(60 * SRS_UTIME_SECONDS, conf.get_hls_window("")); - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hls{hls_dispose 10;hls_fragment 20;hls_window 30;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{hls{hls_dispose 10;hls_fragment 20;hls_window 30;}}")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_dispose("v")); EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_hls_fragment("v")); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_hls_window("v")); @@ -2020,7 +2020,7 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hds_fragment("")); EXPECT_EQ(60 * SRS_UTIME_SECONDS, conf.get_hds_window("")); - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{hds{hds_fragment 20;hds_window 30;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{hds{hds_fragment 20;hds_window 30;}}")); EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_hds_fragment("v")); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_hds_window("v")); } @@ -2030,7 +2030,7 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_queue_length("")); EXPECT_EQ(0, conf.get_send_min_interval("")); - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{play{queue_length 100;send_min_interval 10;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{play{queue_length 100;send_min_interval 10;}}")); EXPECT_EQ(100 * SRS_UTIME_SECONDS, conf.get_queue_length("v")); EXPECT_EQ(10 * SRS_UTIME_MILLISECONDS, conf.get_send_min_interval("v")); } @@ -2039,7 +2039,7 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_EQ(0, conf.get_vhost_http_remux_fast_cache("")); - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF"vhost v{http_remux{fast_cache 10;}}")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost v{http_remux{fast_cache 10;}}")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_vhost_http_remux_fast_cache("v")); } } @@ -2625,3 +2625,33 @@ VOID TEST(ConfigUnitTest, PersistenceConfig) } } +VOID TEST(ConfigMainTest, CheckGlobalConfig) +{ + srs_error_t err; + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_TRUE(conf.cwd().empty()); + EXPECT_TRUE(conf.argv().empty()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "daemon on;")); + EXPECT_TRUE(conf.get_daemon()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "daemon off;")); + EXPECT_FALSE(conf.get_daemon()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_TRUE(conf.get_root().empty()); + } +} + From a9dba511ab15b7dccd68ca7f6e6043de632318d6 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 16:04:35 +0800 Subject: [PATCH 08/12] Improve test coverage for config. --- trunk/src/utest/srs_utest_config.cpp | 121 ++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 1 deletion(-) diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 6ab803025..242b11f9e 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -2636,6 +2636,12 @@ VOID TEST(ConfigMainTest, CheckGlobalConfig) EXPECT_TRUE(conf.argv().empty()); } + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_TRUE(conf.get_daemon()); + } + if (true) { MockSrsConfig conf; HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "daemon on;")); @@ -2651,7 +2657,120 @@ VOID TEST(ConfigMainTest, CheckGlobalConfig) if (true) { MockSrsConfig conf; HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); - EXPECT_TRUE(conf.get_root().empty()); + EXPECT_TRUE(conf.get_root() != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_EQ(1000, conf.get_max_connections()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "max_connections 1024;")); + EXPECT_EQ(1024, conf.get_max_connections()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse("listen 1935;")); + EXPECT_EQ(1, conf.get_listens().size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse("listen 1935 1936;")); + EXPECT_EQ(2, conf.get_listens().size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_STREQ("./objs/srs.pid", conf.get_pid_file().c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "pid server.pid;")); + EXPECT_STREQ("server.pid", conf.get_pid_file().c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_pithy_print()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_FALSE(conf.get_utc_time()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "utc_time on;")); + EXPECT_TRUE(conf.get_utc_time()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "utc_time off;")); + EXPECT_FALSE(conf.get_utc_time()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_STREQ("./", conf.get_work_dir().c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "work_dir objs;")); + EXPECT_STREQ("objs", conf.get_work_dir().c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_FALSE(conf.get_asprocess()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "asprocess off;")); + EXPECT_FALSE(conf.get_asprocess()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "asprocess on;")); + EXPECT_TRUE(conf.get_asprocess()); + } +} + +VOID TEST(ConfigMainTest, CheckStreamCaster) +{ + srs_error_t err; + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_EQ(0, conf.get_stream_casters().size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster;")); + EXPECT_EQ(1, conf.get_stream_casters().size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster; stream_caster;")); + EXPECT_EQ(2, conf.get_stream_casters().size()); } } From f7673f6009ba76eab85d4761d81bda35bc530a71 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 16:06:12 +0800 Subject: [PATCH 09/12] Improve test coverage for config. --- trunk/src/utest/srs_utest_config.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 242b11f9e..3444f2a65 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -2746,9 +2746,14 @@ VOID TEST(ConfigMainTest, CheckGlobalConfig) if (true) { MockSrsConfig conf; - HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "asprocess on;")); + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "daemon off; asprocess on;")); EXPECT_TRUE(conf.get_asprocess()); } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "daemon on; asprocess on;")); + } } VOID TEST(ConfigMainTest, CheckStreamCaster) From 0fd0114ee6dd2834ab078459d6f84e6ea08463ae Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 17:14:59 +0800 Subject: [PATCH 10/12] Improve test coverage for config. --- trunk/src/app/srs_app_config.cpp | 6 +- trunk/src/utest/srs_utest_config.cpp | 450 +++++++++++++++++++++++++++ 2 files changed, 453 insertions(+), 3 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 15ea503cc..08f64fdbe 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3892,7 +3892,7 @@ srs_error_t SrsConfig::parse_buffer(SrsConfigBuffer* buffer) { srs_error_t err = srs_success; - // We use a new root to parse buffer, to allow parse multiple times. + // We use a new root to parse buffer, to allow parse multiple times. srs_freep(root); root = new SrsConfDirective(); @@ -4539,7 +4539,7 @@ bool SrsConfig::get_mr_enabled(string vhost) srs_utime_t SrsConfig::get_mr_sleep(string vhost) { - static srs_utime_t DEFAULT = SRS_PERF_MR_SLEEP; + static srs_utime_t DEFAULT = SRS_PERF_MR_SLEEP; SrsConfDirective* conf = get_vhost(vhost); if (!conf) { @@ -4561,7 +4561,7 @@ srs_utime_t SrsConfig::get_mr_sleep(string vhost) srs_utime_t SrsConfig::get_mw_sleep(string vhost) { - static srs_utime_t DEFAULT = SRS_PERF_MW_SLEEP; + static srs_utime_t DEFAULT = SRS_PERF_MW_SLEEP; SrsConfDirective* conf = get_vhost(vhost); if (!conf) { diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 3444f2a65..fa81add36 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -2777,5 +2777,455 @@ VOID TEST(ConfigMainTest, CheckStreamCaster) HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster; stream_caster;")); EXPECT_EQ(2, conf.get_stream_casters().size()); } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster;")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_FALSE(conf.get_stream_caster_enabled(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster {enabled off;}")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_FALSE(conf.get_stream_caster_enabled(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster {enabled on;}")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_TRUE(conf.get_stream_caster_enabled(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster;")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_TRUE(conf.get_stream_caster_output(arr.at(0)).empty()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster {output xxx;}")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_STREQ("xxx", conf.get_stream_caster_output(arr.at(0)).c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster;")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_EQ(0, conf.get_stream_caster_listen(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster {listen 8080;}")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_EQ(8080, conf.get_stream_caster_listen(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster;")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_EQ(0, conf.get_stream_caster_rtp_port_min(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster {rtp_port_min 8080;}")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_EQ(8080, conf.get_stream_caster_rtp_port_min(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster;")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_EQ(0, conf.get_stream_caster_rtp_port_max(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "stream_caster {rtp_port_max 8080;}")); + + vector arr = conf.get_stream_casters(); + ASSERT_EQ(1, arr.size()); + + EXPECT_EQ(8080, conf.get_stream_caster_rtp_port_max(arr.at(0))); + } +} + +VOID TEST(ConfigMainTest, CheckVhostConfig2) +{ + srs_error_t err; + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); + EXPECT_FALSE(conf.get_vhost_enabled("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net;")); + EXPECT_TRUE(conf.get_vhost_enabled("ossrs.net")); + EXPECT_TRUE(conf.get_gop_cache("ossrs.net")); + EXPECT_TRUE(conf.get_debug_srs_upnode("ossrs.net")); + EXPECT_FALSE(conf.get_atc("ossrs.net")); + EXPECT_FALSE(conf.get_atc_auto("ossrs.net")); + EXPECT_EQ(1, conf.get_time_jitter("ossrs.net")); + EXPECT_FALSE(conf.get_mix_correct("ossrs.net")); + EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_queue_length("ossrs.net")); + EXPECT_FALSE(conf.get_refer_enabled("ossrs.net")); + EXPECT_TRUE(conf.get_refer_all("ossrs.net") == NULL); + EXPECT_TRUE(conf.get_refer_play("ossrs.net") == NULL); + EXPECT_TRUE(conf.get_refer_publish("ossrs.net") == NULL); + EXPECT_EQ(0, conf.get_in_ack_size("ossrs.net")); + EXPECT_EQ(2500000, conf.get_out_ack_size("ossrs.net")); + EXPECT_EQ(60000, conf.get_chunk_size("ossrs.net")); + EXPECT_TRUE(conf.get_parse_sps("ossrs.net")); + EXPECT_FALSE(conf.get_mr_enabled("ossrs.net")); + EXPECT_EQ(350 * SRS_UTIME_MILLISECONDS, conf.get_mr_sleep("ossrs.net")); + EXPECT_EQ(350 * SRS_UTIME_MILLISECONDS, conf.get_mw_sleep("ossrs.net")); + EXPECT_FALSE(conf.get_realtime_enabled("ossrs.net")); + EXPECT_FALSE(conf.get_tcp_nodelay("ossrs.net")); + EXPECT_EQ(0, conf.get_send_min_interval("ossrs.net")); + EXPECT_FALSE(conf.get_reduce_sequence_header("ossrs.net")); + EXPECT_EQ(20000000, conf.get_publish_1stpkt_timeout("ossrs.net")); + EXPECT_EQ(5000000, conf.get_publish_normal_timeout("ossrs.net")); + EXPECT_FALSE(conf.get_forward_enabled("ossrs.net")); + EXPECT_TRUE(conf.get_forwards("ossrs.net") == NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{forward {destination xxx;}}")); + EXPECT_TRUE(conf.get_forwards("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{forward {enabled on;}}")); + EXPECT_TRUE(conf.get_forward_enabled("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{publish {normal_timeout 10;}}")); + EXPECT_EQ(10000, conf.get_publish_normal_timeout("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{publish {firstpkt_timeout 10;}}")); + EXPECT_EQ(10000, conf.get_publish_1stpkt_timeout("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{play {reduce_sequence_header on;}}")); + EXPECT_TRUE(conf.get_reduce_sequence_header("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{play {send_min_interval 10;}}")); + EXPECT_EQ(10000, conf.get_send_min_interval("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{tcp_nodelay on;}")); + EXPECT_TRUE(conf.get_tcp_nodelay("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{min_latency on;}")); + EXPECT_TRUE(conf.get_realtime_enabled("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{play{mw_latency 10;}}")); + EXPECT_EQ(10000, conf.get_mw_sleep("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{publish{mr_latency 10;}}")); + EXPECT_EQ(10000, conf.get_mr_sleep("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{publish{mr on;}}")); + EXPECT_TRUE(conf.get_mr_enabled("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{publish{parse_sps off;}}")); + EXPECT_FALSE(conf.get_parse_sps("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{chunk_size 10;}")); + EXPECT_EQ(10, conf.get_chunk_size("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{out_ack_size 10;}")); + EXPECT_EQ(10, conf.get_out_ack_size("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{in_ack_size 10;}")); + EXPECT_EQ(10, conf.get_in_ack_size("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{refer{publish xxx;}}")); + EXPECT_TRUE(conf.get_refer_publish("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{refer{play xxx;}}")); + EXPECT_TRUE(conf.get_refer_play("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{refer{all xxx;}}")); + EXPECT_TRUE(conf.get_refer_all("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{refer{enabled on;}}")); + EXPECT_TRUE(conf.get_refer_enabled("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{play{queue_length 10;}}")); + EXPECT_EQ(10000000, conf.get_queue_length("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{play{mix_correct on;}}")); + EXPECT_TRUE(conf.get_mix_correct("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{play{time_jitter zero;}}")); + EXPECT_EQ(2, conf.get_time_jitter("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{play{atc_auto on;}}")); + EXPECT_TRUE(conf.get_gop_cache("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{play{atc on;}}")); + EXPECT_TRUE(conf.get_gop_cache("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{play{gop_cache off;}}")); + EXPECT_FALSE(conf.get_gop_cache("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net {enabled off;}")); + EXPECT_FALSE(conf.get_vhost_enabled("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net {enabled on;}")); + EXPECT_TRUE(conf.get_vhost_enabled("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{play{gop_cache off;}}")); + EXPECT_FALSE(conf.get_gop_cache("ossrs.net")); + } +} + +VOID TEST(ConfigMainTest, CheckVhostConfig3) +{ + srs_error_t err; + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net;")); + EXPECT_TRUE(conf.get_vhost_http_hooks("ossrs.net") == NULL); + EXPECT_FALSE(conf.get_vhost_http_hooks_enabled("ossrs.net")); + EXPECT_TRUE(conf.get_vhost_on_connect("ossrs.net") == NULL); + EXPECT_TRUE(conf.get_vhost_on_close("ossrs.net") == NULL); + EXPECT_TRUE(conf.get_vhost_on_publish("ossrs.net") == NULL); + EXPECT_TRUE(conf.get_vhost_on_unpublish("ossrs.net") == NULL); + EXPECT_TRUE(conf.get_vhost_on_play("ossrs.net") == NULL); + EXPECT_TRUE(conf.get_vhost_on_stop("ossrs.net") == NULL); + EXPECT_TRUE(conf.get_vhost_on_dvr("ossrs.net") == NULL); + EXPECT_TRUE(conf.get_vhost_on_hls("ossrs.net") == NULL); + EXPECT_TRUE(conf.get_vhost_on_hls_notify("ossrs.net") == NULL); + EXPECT_FALSE(conf.get_bw_check_enabled("ossrs.net")); + EXPECT_TRUE(conf.get_bw_check_key("ossrs.net").empty()); + EXPECT_EQ(30000000, conf.get_bw_check_interval("ossrs.net")); + EXPECT_EQ(1000, conf.get_bw_check_limit_kbps("ossrs.net")); + EXPECT_FALSE(conf.get_vhost_is_edge("ossrs.net")); + EXPECT_TRUE(conf.get_vhost_edge_origin("ossrs.net") == NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{cluster{origin xxx;}}")); + EXPECT_TRUE(conf.get_vhost_edge_origin("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{cluster{mode remote;}}")); + EXPECT_TRUE(conf.get_vhost_is_edge("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{bandcheck{limit_kbps 10;}}")); + EXPECT_EQ(10, conf.get_bw_check_limit_kbps("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{bandcheck{interval 10;}}")); + EXPECT_EQ(10000, conf.get_bw_check_interval("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{bandcheck{key xxx;}}")); + EXPECT_FALSE(conf.get_bw_check_key("ossrs.net").empty()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{bandcheck{enabled on;}}")); + EXPECT_TRUE(conf.get_bw_check_enabled("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_hls_notify xxx;}}")); + EXPECT_TRUE(conf.get_vhost_on_hls_notify("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_hls xxx;}}")); + EXPECT_TRUE(conf.get_vhost_on_hls("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_dvr xxx;}}")); + EXPECT_TRUE(conf.get_vhost_on_dvr("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_stop xxx;}}")); + EXPECT_TRUE(conf.get_vhost_on_stop("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_play xxx;}}")); + EXPECT_TRUE(conf.get_vhost_on_play("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_unpublish xxx;}}")); + EXPECT_TRUE(conf.get_vhost_on_unpublish("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_publish xxx;}}")); + EXPECT_TRUE(conf.get_vhost_on_publish("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_close xxx;}}")); + EXPECT_TRUE(conf.get_vhost_on_close("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{on_connect xxx;}}")); + EXPECT_TRUE(conf.get_vhost_on_connect("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks{enabled on;}}")); + EXPECT_TRUE(conf.get_vhost_http_hooks_enabled("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{http_hooks;}")); + EXPECT_TRUE(conf.get_vhost_http_hooks("ossrs.net") != NULL); + } } From 4848d3ab91ce2427e4d1e9c55ee4b4814aafa750 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 17:15:21 +0800 Subject: [PATCH 11/12] Improve test coverage for config. --- trunk/src/utest/srs_utest_config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index fa81add36..2a2231ecd 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -3147,7 +3147,7 @@ VOID TEST(ConfigMainTest, CheckVhostConfig3) if (true) { MockSrsConfig conf; HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{bandcheck{interval 10;}}")); - EXPECT_EQ(10000, conf.get_bw_check_interval("ossrs.net")); + EXPECT_EQ(10000000, conf.get_bw_check_interval("ossrs.net")); } if (true) { From 45aa3257227afffe9ed9cd7148ed13fb03899602 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 1 Jan 2020 21:01:14 +0800 Subject: [PATCH 12/12] Improve test coverage for config. --- trunk/src/app/srs_app_config.cpp | 16 +- trunk/src/kernel/srs_kernel_codec.cpp | 10 +- trunk/src/utest/srs_utest_config.cpp | 249 ++++++++++++++++++++++++++ 3 files changed, 266 insertions(+), 9 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 08f64fdbe..026ac8801 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -5231,7 +5231,9 @@ vector SrsConfig::get_engine_perfile(SrsConfDirective* conf) } perfile.push_back(srs_prefix_underscores_ifno(option->name)); - perfile.push_back(option->arg0()); + if (!option->arg0().empty()) { + perfile.push_back(option->arg0()); + } } return perfile; @@ -5273,7 +5275,9 @@ vector SrsConfig::get_engine_vfilter(SrsConfDirective* conf) } vfilter.push_back(srs_prefix_underscores_ifno(filter->name)); - vfilter.push_back(filter->arg0()); + if (!filter->arg0().empty()) { + vfilter.push_back(filter->arg0()); + } } return vfilter; @@ -5427,7 +5431,9 @@ vector SrsConfig::get_engine_vparams(SrsConfDirective* conf) } vparams.push_back(srs_prefix_underscores_ifno(filter->name)); - vparams.push_back(filter->arg0()); + if (!filter->arg0().empty()) { + vparams.push_back(filter->arg0()); + } } return vparams; @@ -5517,7 +5523,9 @@ vector SrsConfig::get_engine_aparams(SrsConfDirective* conf) } aparams.push_back(srs_prefix_underscores_ifno(filter->name)); - aparams.push_back(filter->arg0()); + if (!filter->arg0().empty()) { + aparams.push_back(filter->arg0()); + } } return aparams; diff --git a/trunk/src/kernel/srs_kernel_codec.cpp b/trunk/src/kernel/srs_kernel_codec.cpp index 6d0cb0dcd..a0b11f424 100644 --- a/trunk/src/kernel/srs_kernel_codec.cpp +++ b/trunk/src/kernel/srs_kernel_codec.cpp @@ -1195,24 +1195,24 @@ srs_error_t SrsFormat::audio_aac_demux(SrsBuffer* stream, int64_t timestamp) int8_t sound_size = (sound_format >> 1) & 0x01; int8_t sound_rate = (sound_format >> 2) & 0x03; sound_format = (sound_format >> 4) & 0x0f; - + SrsAudioCodecId codec_id = (SrsAudioCodecId)sound_format; acodec->id = codec_id; - + acodec->sound_type = (SrsAudioChannels)sound_type; acodec->sound_rate = (SrsAudioSampleRate)sound_rate; acodec->sound_size = (SrsAudioSampleBits)sound_size; - + // we support h.264+mp3 for hls. if (codec_id == SrsAudioCodecIdMP3) { return srs_error_new(ERROR_HLS_TRY_MP3, "try mp3"); } - + // only support aac if (codec_id != SrsAudioCodecIdAAC) { return srs_error_new(ERROR_HLS_DECODE_ERROR, "not supported codec %d", codec_id); } - + if (!stream->require(1)) { return srs_error_new(ERROR_HLS_DECODE_ERROR, "aac decode aac_packet_type"); } diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 2a2231ecd..0466c1538 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -3124,6 +3124,48 @@ VOID TEST(ConfigMainTest, CheckVhostConfig3) EXPECT_EQ(1000, conf.get_bw_check_limit_kbps("ossrs.net")); EXPECT_FALSE(conf.get_vhost_is_edge("ossrs.net")); EXPECT_TRUE(conf.get_vhost_edge_origin("ossrs.net") == NULL); + EXPECT_FALSE(conf.get_vhost_edge_token_traverse("ossrs.net")); + EXPECT_STREQ("[vhost]", conf.get_vhost_edge_transform_vhost("ossrs.net").c_str()); + EXPECT_FALSE(conf.get_vhost_origin_cluster("ossrs.net")); + EXPECT_EQ(0, conf.get_vhost_coworkers("ossrs.net").size()); + EXPECT_FALSE(conf.get_security_enabled("ossrs.net")); + EXPECT_TRUE(conf.get_security_rules("ossrs.net") == NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{security{enabled on;}}")); + EXPECT_TRUE(conf.get_security_rules("ossrs.net") != NULL); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{security{enabled on;}}")); + EXPECT_TRUE(conf.get_security_enabled("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{cluster{coworkers xxx;}}")); + EXPECT_EQ(1, conf.get_vhost_coworkers("ossrs.net").size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{cluster{origin_cluster on;}}")); + EXPECT_TRUE(conf.get_vhost_origin_cluster("ossrs.net")); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{cluster{vhost xxx;}}")); + EXPECT_FALSE(conf.get_vhost_edge_transform_vhost("ossrs.net").empty()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{cluster{token_traverse on;}}")); + EXPECT_TRUE(conf.get_vhost_edge_token_traverse("ossrs.net")); } if (true) { @@ -3229,3 +3271,210 @@ VOID TEST(ConfigMainTest, CheckVhostConfig3) } } +VOID TEST(ConfigMainTest, CheckVhostConfig4) +{ + srs_error_t err; + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net;")); + EXPECT_TRUE(conf.get_transcode("ossrs.net", "") == NULL); + EXPECT_FALSE(conf.get_transcode_enabled(conf.get_transcode("ossrs.net", ""))); + EXPECT_TRUE(conf.get_transcode_ffmpeg(conf.get_transcode("ossrs.net", "")).empty()); + EXPECT_EQ(0, conf.get_transcode_engines(conf.get_transcode("ossrs.net", "")).size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{output xxx;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_STREQ("xxx", conf.get_engine_output(arr.at(0)).c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{oformat flv;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_STREQ("flv", conf.get_engine_oformat(arr.at(0)).c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{aparams {i;}}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1, conf.get_engine_aparams(arr.at(0)).size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{achannels 1000;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1000, conf.get_engine_achannels(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{asample_rate 1000;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1000, conf.get_engine_asample_rate(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{abitrate 1000;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1000, conf.get_engine_abitrate(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{acodec aac;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_STREQ("aac", conf.get_engine_acodec(arr.at(0)).c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vparams {t;}}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1, conf.get_engine_vparams(arr.at(0)).size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vpreset main;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_STREQ("main", conf.get_engine_vpreset(arr.at(0)).c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vprofile main;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_STREQ("main", conf.get_engine_vprofile(arr.at(0)).c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vthreads 1000;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1000, conf.get_engine_vthreads(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vheight 1000;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1000, conf.get_engine_vheight(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vwidth 1000;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1000, conf.get_engine_vwidth(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vfps 1000;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1000, conf.get_engine_vfps(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vbitrate 1000;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1000, conf.get_engine_vbitrate(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vcodec x264;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_STREQ("x264", conf.get_engine_vcodec(arr.at(0)).c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vfilter {i;}}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1, conf.get_engine_vfilter(arr.at(0)).size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{vfilter {i logo.png;}}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(2, conf.get_engine_vfilter(arr.at(0)).size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{iformat mp4;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_STREQ("mp4", conf.get_engine_iformat(arr.at(0)).c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{perfile {re;}}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_EQ(1, conf.get_engine_perfile(arr.at(0)).size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine{enabled on;}}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + EXPECT_TRUE(conf.get_engine_enabled(arr.at(0))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{engine;}}")); + vector arr = conf.get_transcode_engines(conf.get_transcode("ossrs.net", "xxx")); + ASSERT_EQ(1, arr.size()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{ffmpeg xxx;}}")); + EXPECT_STREQ("xxx", conf.get_transcode_ffmpeg(conf.get_transcode("ossrs.net", "xxx")).c_str()); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx{enabled on;}}")); + EXPECT_TRUE(conf.get_transcode_enabled(conf.get_transcode("ossrs.net", "xxx"))); + } + + if (true) { + MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "vhost ossrs.net{transcode xxx;}")); + EXPECT_TRUE(conf.get_transcode("ossrs.net", "xxx") != NULL); + } +} +