mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
merge buffer to kernel utest
This commit is contained in:
parent
1e395e7c10
commit
b13fd5112b
6 changed files with 117 additions and 180 deletions
3
trunk/configure
vendored
3
trunk/configure
vendored
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 <srs_utest_buffer.hpp>
|
||||
|
||||
#include <srs_kernel_error.hpp>
|
||||
#include <srs_kernel_utility.hpp>
|
||||
|
||||
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]);
|
||||
}
|
|
@ -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 <srs_utest_buffer.hpp>
|
||||
*/
|
||||
#include <srs_utest.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <srs_kernel_buffer.hpp>
|
||||
|
||||
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
|
|
@ -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
|
||||
|
|
|
@ -31,6 +31,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <string>
|
||||
#include <srs_kernel_file.hpp>
|
||||
#include <srs_kernel_buffer.hpp>
|
||||
|
||||
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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue