diff --git a/trunk/configure b/trunk/configure index ae7eac9f6..774922538 100755 --- a/trunk/configure +++ b/trunk/configure @@ -517,8 +517,7 @@ fi # # utest, the unit-test cases of srs, base on gtest1.6 MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_handshake" - "srs_utest_buffer" "srs_utest_protocol" "srs_utest_kernel" - "srs_utest_core") + "srs_utest_protocol" "srs_utest_kernel" "srs_utest_core") ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot}) ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile}) MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index f1583d3bc..3aab75d41 100755 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -114,8 +114,6 @@ file ..\utest\srs_utest.cpp, ..\utest\srs_utest_amf0.hpp, ..\utest\srs_utest_amf0.cpp, - ..\utest\srs_utest_buffer.hpp, - ..\utest\srs_utest_buffer.cpp, ..\utest\srs_utest_core.hpp, ..\utest\srs_utest_core.cpp, ..\utest\srs_utest_handshake.hpp, diff --git a/trunk/src/utest/srs_utest_buffer.cpp b/trunk/src/utest/srs_utest_buffer.cpp deleted file mode 100644 index cb141c931..000000000 --- a/trunk/src/utest/srs_utest_buffer.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* -The MIT License (MIT) - -Copyright (c) 2013-2014 winlin - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#include - -#include -#include - -MockBufferReader::MockBufferReader(const char* data) -{ - str = data; -} - -MockBufferReader::~MockBufferReader() -{ -} - -int MockBufferReader::read(void* buf, size_t size, ssize_t* nread) -{ - int len = srs_min(str.length(), size); - - memcpy(buf, str.data(), len); - - if (nread) { - *nread = len; - } - - return ERROR_SUCCESS; -} - -VOID TEST(BufferTest, DefaultObject) -{ - SrsBuffer b; - - EXPECT_EQ(0, b.length()); - EXPECT_EQ(NULL, b.bytes()); -} - -VOID TEST(BufferTest, AppendBytes) -{ - SrsBuffer b; - - char winlin[] = "winlin"; - b.append(winlin, strlen(winlin)); - EXPECT_EQ((int)strlen(winlin), b.length()); - ASSERT_TRUE(NULL != b.bytes()); - EXPECT_EQ('w', b.bytes()[0]); - EXPECT_EQ('n', b.bytes()[5]); - - b.append(winlin, strlen(winlin)); - EXPECT_EQ(2 * (int)strlen(winlin), b.length()); - ASSERT_TRUE(NULL != b.bytes()); - EXPECT_EQ('w', b.bytes()[0]); - EXPECT_EQ('n', b.bytes()[5]); - EXPECT_EQ('w', b.bytes()[6]); - EXPECT_EQ('n', b.bytes()[11]); -} - -VOID TEST(BufferTest, EraseBytes) -{ - SrsBuffer b; - - b.erase(0); - b.erase(-1); - EXPECT_EQ(0, b.length()); - - char winlin[] = "winlin"; - b.append(winlin, strlen(winlin)); - b.erase(b.length()); - EXPECT_EQ(0, b.length()); - - b.erase(0); - b.erase(-1); - EXPECT_EQ(0, b.length()); - - b.append(winlin, strlen(winlin)); - b.erase(1); - EXPECT_EQ(5, b.length()); - EXPECT_EQ('i', b.bytes()[0]); - EXPECT_EQ('n', b.bytes()[4]); - - b.erase(2); - EXPECT_EQ(3, b.length()); - EXPECT_EQ('l', b.bytes()[0]); - EXPECT_EQ('n', b.bytes()[2]); - - b.erase(0); - b.erase(-1); - EXPECT_EQ(3, b.length()); - - b.erase(3); - EXPECT_EQ(0, b.length()); -} - -VOID TEST(BufferTest, Grow) -{ - SrsBuffer b; - MockBufferReader r("winlin"); - - b.grow(&r, 1); - EXPECT_EQ(6, b.length()); - EXPECT_EQ('w', b.bytes()[0]); - - b.grow(&r, 3); - EXPECT_EQ(6, b.length()); - EXPECT_EQ('n', b.bytes()[2]); - - b.grow(&r, 100); - EXPECT_EQ(102, b.length()); - EXPECT_EQ('l', b.bytes()[99]); -} diff --git a/trunk/src/utest/srs_utest_buffer.hpp b/trunk/src/utest/srs_utest_buffer.hpp deleted file mode 100644 index 6281d0f4b..000000000 --- a/trunk/src/utest/srs_utest_buffer.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* -The MIT License (MIT) - -Copyright (c) 2013-2014 winlin - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef SRS_UTEST_BUFFER_HPP -#define SRS_UTEST_BUFFER_HPP - -/* -#include -*/ -#include - -#include -#include - -class MockBufferReader: public ISrsBufferReader -{ -private: - std::string str; -public: - MockBufferReader(const char* data); - virtual ~MockBufferReader(); -public: - virtual int read(void* buf, size_t size, ssize_t* nread); -}; - -#endif diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index f6d9cb26a..18c8d51ce 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -176,6 +176,110 @@ void MockSrsFileReader::mock_reset_offset() offset = 0; } +MockBufferReader::MockBufferReader(const char* data) +{ + str = data; +} + +MockBufferReader::~MockBufferReader() +{ +} + +int MockBufferReader::read(void* buf, size_t size, ssize_t* nread) +{ + int len = srs_min(str.length(), size); + + memcpy(buf, str.data(), len); + + if (nread) { + *nread = len; + } + + return ERROR_SUCCESS; +} + +VOID TEST(BufferTest, DefaultObject) +{ + SrsBuffer b; + + EXPECT_EQ(0, b.length()); + EXPECT_EQ(NULL, b.bytes()); +} + +VOID TEST(BufferTest, AppendBytes) +{ + SrsBuffer b; + + char winlin[] = "winlin"; + b.append(winlin, strlen(winlin)); + EXPECT_EQ((int)strlen(winlin), b.length()); + ASSERT_TRUE(NULL != b.bytes()); + EXPECT_EQ('w', b.bytes()[0]); + EXPECT_EQ('n', b.bytes()[5]); + + b.append(winlin, strlen(winlin)); + EXPECT_EQ(2 * (int)strlen(winlin), b.length()); + ASSERT_TRUE(NULL != b.bytes()); + EXPECT_EQ('w', b.bytes()[0]); + EXPECT_EQ('n', b.bytes()[5]); + EXPECT_EQ('w', b.bytes()[6]); + EXPECT_EQ('n', b.bytes()[11]); +} + +VOID TEST(BufferTest, EraseBytes) +{ + SrsBuffer b; + + b.erase(0); + b.erase(-1); + EXPECT_EQ(0, b.length()); + + char winlin[] = "winlin"; + b.append(winlin, strlen(winlin)); + b.erase(b.length()); + EXPECT_EQ(0, b.length()); + + b.erase(0); + b.erase(-1); + EXPECT_EQ(0, b.length()); + + b.append(winlin, strlen(winlin)); + b.erase(1); + EXPECT_EQ(5, b.length()); + EXPECT_EQ('i', b.bytes()[0]); + EXPECT_EQ('n', b.bytes()[4]); + + b.erase(2); + EXPECT_EQ(3, b.length()); + EXPECT_EQ('l', b.bytes()[0]); + EXPECT_EQ('n', b.bytes()[2]); + + b.erase(0); + b.erase(-1); + EXPECT_EQ(3, b.length()); + + b.erase(3); + EXPECT_EQ(0, b.length()); +} + +VOID TEST(BufferTest, Grow) +{ + SrsBuffer b; + MockBufferReader r("winlin"); + + b.grow(&r, 1); + EXPECT_EQ(6, b.length()); + EXPECT_EQ('w', b.bytes()[0]); + + b.grow(&r, 3); + EXPECT_EQ(6, b.length()); + EXPECT_EQ('n', b.bytes()[2]); + + b.grow(&r, 100); + EXPECT_EQ(102, b.length()); + EXPECT_EQ('l', b.bytes()[99]); +} + /** * test the codec, * whether H.264 keyframe diff --git a/trunk/src/utest/srs_utest_kernel.hpp b/trunk/src/utest/srs_utest_kernel.hpp index 0038d5ed8..773f11880 100644 --- a/trunk/src/utest/srs_utest_kernel.hpp +++ b/trunk/src/utest/srs_utest_kernel.hpp @@ -31,6 +31,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include + +class MockBufferReader: public ISrsBufferReader +{ +private: + std::string str; +public: + MockBufferReader(const char* data); + virtual ~MockBufferReader(); +public: + virtual int read(void* buf, size_t size, ssize_t* nread); +}; class MockSrsFileWriter : public SrsFileWriter {