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