mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine utest
This commit is contained in:
parent
c10671cbb3
commit
58561b9f76
4 changed files with 77 additions and 29 deletions
|
@ -34,12 +34,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <srs_core.hpp>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <string>
|
||||
|
||||
#include <srs_app_log.hpp>
|
||||
|
||||
// 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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue