Fix utest failed.
This commit is contained in:
parent
6846f8e893
commit
1606c3d713
|
|
@ -119,6 +119,12 @@ else
|
|||
srs_undefine_macro "SRS_UTEST" $SRS_AUTO_HEADERS_H
|
||||
fi
|
||||
|
||||
if [[ $SRS_FORCE_PUBLIC4UTEST == YES ]]; then
|
||||
srs_define_macro "SRS_FORCE_PUBLIC4UTEST" $SRS_AUTO_HEADERS_H
|
||||
else
|
||||
srs_undefine_macro "SRS_FORCE_PUBLIC4UTEST" $SRS_AUTO_HEADERS_H
|
||||
fi
|
||||
|
||||
# whatever the FFMPEG tools, if transcode and ingest specified,
|
||||
# srs always compile the FFMPEG tool stub which used to start the FFMPEG process.
|
||||
if [[ $SRS_FFMPEG_STUB == YES ]]; then
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ SRS_CXX14=NO
|
|||
SRS_BACKTRACE=YES
|
||||
SRS_NGINX=NO
|
||||
SRS_UTEST=NO
|
||||
SRS_FORCE_PUBLIC4UTEST=NO
|
||||
# Always enable the bellow features.
|
||||
SRS_STREAM_CASTER=YES
|
||||
SRS_INGEST=YES
|
||||
|
|
@ -598,6 +599,13 @@ function apply_auto_options() {
|
|||
SRS_CXX11=NO
|
||||
fi
|
||||
|
||||
# When utest is enabled, automatically enable SRS_FORCE_PUBLIC4UTEST to make private members public
|
||||
# This ensures consistent class layout between production code and utest code with AddressSanitizer
|
||||
if [[ $SRS_UTEST == YES ]]; then
|
||||
echo "Enable SRS_FORCE_PUBLIC4UTEST for utest to make private members public."
|
||||
SRS_FORCE_PUBLIC4UTEST=YES
|
||||
fi
|
||||
|
||||
# Force disable C++14 always - C++98 compatibility is required
|
||||
if [[ $SRS_CXX14 != NO ]]; then
|
||||
echo "Warning: C++14 support has been disabled. Forcing C++98 compatibility mode."
|
||||
|
|
|
|||
9
trunk/configure
vendored
9
trunk/configure
vendored
|
|
@ -384,12 +384,15 @@ if [[ $SRS_UTEST == YES ]]; then
|
|||
"srs_utest_coworkers" "srs_utest_pithy_print" "srs_utest_kernel3" "srs_utest_protocol4"
|
||||
"srs_utest_protocol3" "srs_utest_app" "srs_utest_app2" "srs_utest_app3" "srs_utest_app4"
|
||||
"srs_utest_app5" "srs_utest_app6" "srs_utest_app7" "srs_utest_app8" "srs_utest_app9"
|
||||
"srs_utest_app10" "srs_utest_app11" "srs_utest_app12" "srs_utest_app13" "srs_utest_app14"
|
||||
"srs_utest_app15" "srs_utest_app16" "srs_utest_app17")
|
||||
"srs_utest_app10" "srs_utest_app11" "srs_utest_app15" "srs_utest_app16"
|
||||
"srs_utest_app17")
|
||||
# Always include SRT utest
|
||||
MODULE_FILES+=("srs_utest_srt")
|
||||
if [[ $SRS_GB28181 == YES ]]; then
|
||||
MODULE_FILES+=("srs_utest_gb28181")
|
||||
MODULE_FILES+=("srs_utest_gb28181" "srs_utest_app14")
|
||||
fi
|
||||
if [[ $SRS_RTSP == YES ]]; then
|
||||
MODULE_FILES+=("srs_utest_app12" "srs_utest_app13")
|
||||
fi
|
||||
ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot} ${LibSSLRoot} ${LibSrtpRoot})
|
||||
if [[ $SRS_FFMPEG_FIT == YES ]]; then
|
||||
|
|
|
|||
|
|
@ -12,13 +12,17 @@
|
|||
#include <srs_app_dvr.hpp>
|
||||
#include <srs_app_ffmpeg.hpp>
|
||||
#include <srs_app_fragment.hpp>
|
||||
#ifdef SRS_GB28181
|
||||
#include <srs_app_gb28181.hpp>
|
||||
#endif
|
||||
#include <srs_app_ingest.hpp>
|
||||
#include <srs_app_listener.hpp>
|
||||
#include <srs_app_rtc_conn.hpp>
|
||||
#include <srs_app_rtmp_conn.hpp>
|
||||
#include <srs_app_rtmp_source.hpp>
|
||||
#ifdef SRS_RTSP
|
||||
#include <srs_app_rtsp_source.hpp>
|
||||
#endif
|
||||
#include <srs_app_st.hpp>
|
||||
#include <srs_kernel_file.hpp>
|
||||
#include <srs_kernel_flv.hpp>
|
||||
|
|
|
|||
|
|
@ -894,7 +894,7 @@ srs_error_t SrsRtmpConn::publishing(SrsSharedPtr<SrsLiveSource> source)
|
|||
// @see: https://github.com/ossrs/srs/issues/237
|
||||
SrsPublishRecvThread rtrd(rtmp_, req, srs_netfd_fileno(transport_->fd()), 0, this, source, _srs_context->get_id());
|
||||
rtrd.assemble();
|
||||
|
||||
|
||||
err = do_publishing(source, &rtrd);
|
||||
rtrd.stop();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ using namespace std;
|
|||
#include <srs_app_config.hpp>
|
||||
#include <srs_app_factory.hpp>
|
||||
#include <srs_app_http_hooks.hpp>
|
||||
#ifdef SRS_RTSP
|
||||
#include <srs_app_rtsp_source.hpp>
|
||||
#endif
|
||||
#include <srs_app_security.hpp>
|
||||
#include <srs_app_st.hpp>
|
||||
#include <srs_app_statistic.hpp>
|
||||
|
|
@ -27,7 +29,9 @@ using namespace std;
|
|||
#include <srs_kernel_log.hpp>
|
||||
#include <srs_kernel_pithy_print.hpp>
|
||||
#include <srs_kernel_rtc_rtp.hpp>
|
||||
#ifdef SRS_RTSP
|
||||
#include <srs_protocol_rtsp_stack.hpp>
|
||||
#endif
|
||||
#include <srs_protocol_st.hpp>
|
||||
#include <srs_protocol_utility.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,14 @@
|
|||
// The macros generated by configure script.
|
||||
#include <srs_auto_headers.hpp>
|
||||
|
||||
// When utest is enabled, make all private and protected members public for testing.
|
||||
// This ensures consistent class layout between production code and utest code with AddressSanitizer.
|
||||
// The macro is automatically enabled when --utest=on is specified in configure.
|
||||
#ifdef SRS_FORCE_PUBLIC4UTEST
|
||||
#define private public
|
||||
#define protected public
|
||||
#endif
|
||||
|
||||
// To convert macro values to string.
|
||||
// @see https://gcc.gnu.org/onlinedocs/cpp/Stringification.html#Stringification
|
||||
#define SRS_INTERNAL_STR(v) #v
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@
|
|||
// @see https://stackoverflow.com/questions/47839718/sstream-redeclared-with-public-access-compiler-error
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// Public all private and protected members.
|
||||
#define private public
|
||||
#define protected public
|
||||
// Note: The #define private public and #define protected public are now handled in srs_core.hpp
|
||||
// when SRS_FORCE_PUBLIC4UTEST is enabled (automatically enabled when --utest=on is specified).
|
||||
// This ensures consistent class layout between production code and utest code with AddressSanitizer.
|
||||
|
||||
/*
|
||||
#include <srs_utest.hpp>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@
|
|||
using namespace std;
|
||||
|
||||
#include <srs_app_rtc_source.hpp>
|
||||
#ifdef SRS_RTSP
|
||||
#include <srs_app_rtsp_source.hpp>
|
||||
#endif
|
||||
#include <srs_app_srt_source.hpp>
|
||||
#include <srs_core_autofree.hpp>
|
||||
#include <srs_kernel_buffer.hpp>
|
||||
|
|
@ -1613,6 +1615,7 @@ VOID TEST(SrsSrtSourceTest, OnPacketDistribution)
|
|||
// Note: mock_bridge will be freed by source destructor
|
||||
}
|
||||
|
||||
#ifdef SRS_RTSP
|
||||
// Test SrsRtspConsumer enqueue and update_source_id
|
||||
// This test covers the major use scenario: enqueueing RTP packets and signaling waiting threads
|
||||
VOID TEST(SrsRtspConsumerTest, EnqueueAndUpdateSourceId)
|
||||
|
|
@ -3549,3 +3552,4 @@ VOID TEST(SrsRtspVideoSendTrackTest, OnRtpActiveTrackWithPTConversion)
|
|||
EXPECT_EQ(180000, (int)mock_conn.last_packet_->header_.get_timestamp());
|
||||
EXPECT_TRUE(mock_conn.last_packet_->header_.get_marker());
|
||||
}
|
||||
#endif // SRS_RTSP
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
*/
|
||||
#include <srs_utest.hpp>
|
||||
|
||||
#ifdef SRS_RTSP
|
||||
#include <srs_app_rtsp_conn.hpp>
|
||||
#endif
|
||||
#include <srs_app_stream_bridge.hpp>
|
||||
#include <srs_protocol_rtmp_stack.hpp>
|
||||
#include <srs_utest_app6.hpp>
|
||||
|
|
|
|||
|
|
@ -3214,6 +3214,7 @@ ISrsDvrSegmenter *MockDvrAppFactory::create_dvr_mp4_segmenter()
|
|||
return segmenter;
|
||||
}
|
||||
|
||||
#ifdef SRS_GB28181
|
||||
ISrsGbMediaTcpConn *MockDvrAppFactory::create_gb_media_tcp_conn()
|
||||
{
|
||||
return NULL;
|
||||
|
|
@ -3223,6 +3224,7 @@ ISrsGbSession *MockDvrAppFactory::create_gb_session()
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
ISrsInitMp4 *MockDvrAppFactory::create_init_mp4()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@
|
|||
#include <srs_app_factory.hpp>
|
||||
#include <srs_app_rtc_source.hpp>
|
||||
#include <srs_app_rtmp_conn.hpp>
|
||||
#ifdef SRS_RTSP
|
||||
#include <srs_app_rtsp_conn.hpp>
|
||||
#include <srs_app_rtsp_source.hpp>
|
||||
#endif
|
||||
#include <srs_app_statistic.hpp>
|
||||
#include <srs_kernel_balance.hpp>
|
||||
#include <srs_kernel_flv.hpp>
|
||||
|
|
@ -29,7 +31,9 @@
|
|||
#include <srs_protocol_json.hpp>
|
||||
#include <srs_protocol_rtmp_conn.hpp>
|
||||
#include <srs_protocol_rtmp_stack.hpp>
|
||||
#ifdef SRS_RTSP
|
||||
#include <srs_protocol_rtsp_stack.hpp>
|
||||
#endif
|
||||
#include <srs_utest_app12.hpp>
|
||||
#include <srs_utest_app6.hpp>
|
||||
|
||||
|
|
@ -636,8 +640,10 @@ public:
|
|||
virtual ISrsMp4Encoder *create_mp4_encoder();
|
||||
virtual ISrsDvrSegmenter *create_dvr_flv_segmenter();
|
||||
virtual ISrsDvrSegmenter *create_dvr_mp4_segmenter();
|
||||
#ifdef SRS_GB28181
|
||||
virtual ISrsGbMediaTcpConn *create_gb_media_tcp_conn();
|
||||
virtual ISrsGbSession *create_gb_session();
|
||||
#endif
|
||||
virtual ISrsInitMp4 *create_init_mp4();
|
||||
virtual ISrsFragmentWindow *create_fragment_window();
|
||||
virtual ISrsFragmentedMp4 *create_fragmented_mp4();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@
|
|||
using namespace std;
|
||||
|
||||
#include <srs_app_config.hpp>
|
||||
#ifdef SRS_GB28181
|
||||
#include <srs_app_gb28181.hpp>
|
||||
#endif
|
||||
#include <srs_app_listener.hpp>
|
||||
#include <srs_app_rtc_conn.hpp>
|
||||
#include <srs_app_rtc_network.hpp>
|
||||
|
|
@ -830,84 +832,6 @@ void MockGbSessionForMediaConn::reset()
|
|||
on_media_transport_called_ = false;
|
||||
}
|
||||
|
||||
// Mock ISrsResourceManager implementation
|
||||
MockResourceManagerForBindSession::MockResourceManagerForBindSession()
|
||||
{
|
||||
session_to_return_ = NULL;
|
||||
}
|
||||
|
||||
MockResourceManagerForBindSession::~MockResourceManagerForBindSession()
|
||||
{
|
||||
}
|
||||
|
||||
srs_error_t MockResourceManagerForBindSession::start()
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
bool MockResourceManagerForBindSession::empty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t MockResourceManagerForBindSession::size()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::add(ISrsResource *conn, bool *exists)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::add_with_id(const std::string &id, ISrsResource *conn)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::add_with_fast_id(uint64_t id, ISrsResource *conn)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::add_with_name(const std::string & /*name*/, ISrsResource * /*conn*/)
|
||||
{
|
||||
}
|
||||
|
||||
ISrsResource *MockResourceManagerForBindSession::at(int index)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ISrsResource *MockResourceManagerForBindSession::find_by_id(std::string id)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ISrsResource *MockResourceManagerForBindSession::find_by_fast_id(uint64_t id)
|
||||
{
|
||||
return session_to_return_;
|
||||
}
|
||||
|
||||
ISrsResource *MockResourceManagerForBindSession::find_by_name(std::string /*name*/)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::remove(ISrsResource *c)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::subscribe(ISrsDisposingHandler *h)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::unsubscribe(ISrsDisposingHandler *h)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::reset()
|
||||
{
|
||||
session_to_return_ = NULL;
|
||||
}
|
||||
|
||||
// Test SrsGbMediaTcpConn::on_ps_pack - covers the major use scenario:
|
||||
// 1. Media connection receives PS pack with messages
|
||||
// 2. Connection state changes from disconnected to connected
|
||||
|
|
@ -2440,6 +2364,7 @@ SrsDvrMp4Segmenter *MockAppFactoryForGbPublish::create_dvr_mp4_segmenter()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef SRS_GB28181
|
||||
ISrsGbMediaTcpConn *MockAppFactoryForGbPublish::create_gb_media_tcp_conn()
|
||||
{
|
||||
return NULL;
|
||||
|
|
@ -2452,6 +2377,7 @@ ISrsGbSession *MockAppFactoryForGbPublish::create_gb_session()
|
|||
mock_gb_session_ = new MockGbSessionForApiPublish();
|
||||
return session;
|
||||
}
|
||||
#endif
|
||||
|
||||
ISrsInitMp4 *MockAppFactoryForGbPublish::create_init_mp4()
|
||||
{
|
||||
|
|
@ -3064,39 +2990,6 @@ void MockRtcConnectionForUdpNetwork::reset()
|
|||
on_rtcp_called_ = false;
|
||||
}
|
||||
|
||||
// Mock ISrsEphemeralDelta implementation
|
||||
MockEphemeralDelta::MockEphemeralDelta()
|
||||
{
|
||||
in_bytes_ = 0;
|
||||
out_bytes_ = 0;
|
||||
}
|
||||
|
||||
MockEphemeralDelta::~MockEphemeralDelta()
|
||||
{
|
||||
}
|
||||
|
||||
void MockEphemeralDelta::add_delta(int64_t in, int64_t out)
|
||||
{
|
||||
in_bytes_ += in;
|
||||
out_bytes_ += out;
|
||||
}
|
||||
|
||||
void MockEphemeralDelta::remark(int64_t *in, int64_t *out)
|
||||
{
|
||||
if (in)
|
||||
*in = in_bytes_;
|
||||
if (out)
|
||||
*out = out_bytes_;
|
||||
in_bytes_ = 0;
|
||||
out_bytes_ = 0;
|
||||
}
|
||||
|
||||
void MockEphemeralDelta::reset()
|
||||
{
|
||||
in_bytes_ = 0;
|
||||
out_bytes_ = 0;
|
||||
}
|
||||
|
||||
// Test SrsRtcUdpNetwork initialization and DTLS handling
|
||||
VOID TEST(RtcUdpNetworkTest, InitializeAndHandleDtls)
|
||||
{
|
||||
|
|
@ -3444,90 +3337,6 @@ void MockResourceManagerForUdpNetwork::reset()
|
|||
fast_id_map_.clear();
|
||||
}
|
||||
|
||||
// Mock ISrsUdpMuxSocket implementation
|
||||
MockUdpMuxSocket::MockUdpMuxSocket()
|
||||
{
|
||||
sendto_error_ = srs_success;
|
||||
sendto_called_count_ = 0;
|
||||
last_sendto_size_ = 0;
|
||||
peer_ip_ = "192.168.1.100";
|
||||
peer_port_ = 5000;
|
||||
peer_id_ = "192.168.1.100:5000";
|
||||
fast_id_ = 0;
|
||||
data_ = NULL;
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
MockUdpMuxSocket::~MockUdpMuxSocket()
|
||||
{
|
||||
srs_freep(sendto_error_);
|
||||
data_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t MockUdpMuxSocket::sendto(void *data, int size, srs_utime_t timeout)
|
||||
{
|
||||
sendto_called_count_++;
|
||||
last_sendto_size_ = size;
|
||||
return srs_error_copy(sendto_error_);
|
||||
}
|
||||
|
||||
std::string MockUdpMuxSocket::get_peer_ip() const
|
||||
{
|
||||
return peer_ip_;
|
||||
}
|
||||
|
||||
int MockUdpMuxSocket::get_peer_port() const
|
||||
{
|
||||
return peer_port_;
|
||||
}
|
||||
|
||||
std::string MockUdpMuxSocket::peer_id()
|
||||
{
|
||||
return peer_id_;
|
||||
}
|
||||
|
||||
uint64_t MockUdpMuxSocket::fast_id()
|
||||
{
|
||||
return fast_id_;
|
||||
}
|
||||
|
||||
SrsUdpMuxSocket *MockUdpMuxSocket::copy_sendonly()
|
||||
{
|
||||
// Return self for testing purposes - in real implementation this creates a copy
|
||||
return (SrsUdpMuxSocket *)this;
|
||||
}
|
||||
|
||||
int MockUdpMuxSocket::recvfrom(srs_utime_t timeout)
|
||||
{
|
||||
// Mock implementation - return the size of data received
|
||||
return size_;
|
||||
}
|
||||
|
||||
char *MockUdpMuxSocket::data()
|
||||
{
|
||||
// Mock implementation - return the data buffer
|
||||
return data_;
|
||||
}
|
||||
|
||||
int MockUdpMuxSocket::size()
|
||||
{
|
||||
// Mock implementation - return the size of data
|
||||
return size_;
|
||||
}
|
||||
|
||||
void MockUdpMuxSocket::reset()
|
||||
{
|
||||
srs_freep(sendto_error_);
|
||||
sendto_called_count_ = 0;
|
||||
last_sendto_size_ = 0;
|
||||
}
|
||||
|
||||
void MockUdpMuxSocket::set_sendto_error(srs_error_t err)
|
||||
{
|
||||
srs_freep(sendto_error_);
|
||||
sendto_error_ = srs_error_copy(err);
|
||||
}
|
||||
|
||||
// Test SrsRtcUdpNetwork STUN binding request handling
|
||||
VOID TEST(RtcUdpNetworkTest, HandleStunBindingRequest)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@
|
|||
#include <srs_app_config.hpp>
|
||||
#include <srs_app_dvr.hpp>
|
||||
#include <srs_app_factory.hpp>
|
||||
#ifdef SRS_GB28181
|
||||
#include <srs_app_gb28181.hpp>
|
||||
#endif
|
||||
#include <srs_app_server.hpp>
|
||||
#include <srs_protocol_http_client.hpp>
|
||||
#include <srs_protocol_http_stack.hpp>
|
||||
|
|
@ -177,23 +179,6 @@ public:
|
|||
void reset();
|
||||
};
|
||||
|
||||
// Mock ISrsEphemeralDelta for testing SrsRtcUdpNetwork
|
||||
class MockEphemeralDelta : public ISrsEphemeralDelta
|
||||
{
|
||||
public:
|
||||
int64_t in_bytes_;
|
||||
int64_t out_bytes_;
|
||||
|
||||
public:
|
||||
MockEphemeralDelta();
|
||||
virtual ~MockEphemeralDelta();
|
||||
|
||||
public:
|
||||
virtual void add_delta(int64_t in, int64_t out);
|
||||
virtual void remark(int64_t *in, int64_t *out);
|
||||
void reset();
|
||||
};
|
||||
|
||||
// Mock ISrsIpListener for testing SrsGbListener::initialize
|
||||
class MockIpListener : public ISrsIpListener
|
||||
{
|
||||
|
|
@ -307,34 +292,6 @@ public:
|
|||
void reset();
|
||||
};
|
||||
|
||||
// Mock ISrsResourceManager for testing SrsGbMediaTcpConn::bind_session
|
||||
class MockResourceManagerForBindSession : public ISrsResourceManager
|
||||
{
|
||||
public:
|
||||
ISrsResource *session_to_return_;
|
||||
|
||||
public:
|
||||
MockResourceManagerForBindSession();
|
||||
virtual ~MockResourceManagerForBindSession();
|
||||
|
||||
public:
|
||||
virtual srs_error_t start();
|
||||
virtual bool empty();
|
||||
virtual size_t size();
|
||||
virtual void add(ISrsResource *conn, bool *exists = NULL);
|
||||
virtual void add_with_id(const std::string &id, ISrsResource *conn);
|
||||
virtual void add_with_fast_id(uint64_t id, ISrsResource *conn);
|
||||
virtual void add_with_name(const std::string &name, ISrsResource *conn);
|
||||
virtual ISrsResource *at(int index);
|
||||
virtual ISrsResource *find_by_id(std::string id);
|
||||
virtual ISrsResource *find_by_fast_id(uint64_t id);
|
||||
virtual ISrsResource *find_by_name(std::string name);
|
||||
virtual void remove(ISrsResource *c);
|
||||
virtual void subscribe(ISrsDisposingHandler *h);
|
||||
virtual void unsubscribe(ISrsDisposingHandler *h);
|
||||
void reset();
|
||||
};
|
||||
|
||||
// Mock ISrsBasicRtmpClient for testing SrsGbMuxer
|
||||
class MockGbRtmpClient : public ISrsBasicRtmpClient
|
||||
{
|
||||
|
|
@ -628,8 +585,10 @@ public:
|
|||
virtual ISrsMp4Encoder *create_mp4_encoder();
|
||||
virtual SrsDvrFlvSegmenter *create_dvr_flv_segmenter();
|
||||
virtual SrsDvrMp4Segmenter *create_dvr_mp4_segmenter();
|
||||
#ifdef SRS_GB28181
|
||||
virtual ISrsGbMediaTcpConn *create_gb_media_tcp_conn();
|
||||
virtual ISrsGbSession *create_gb_session();
|
||||
#endif
|
||||
virtual ISrsInitMp4 *create_init_mp4();
|
||||
virtual ISrsFragmentWindow *create_fragment_window();
|
||||
virtual ISrsFragmentedMp4 *create_fragmented_mp4();
|
||||
|
|
@ -744,40 +703,6 @@ public:
|
|||
void reset();
|
||||
};
|
||||
|
||||
// Mock ISrsUdpMuxSocket for testing SrsRtcUdpNetwork STUN handling
|
||||
class MockUdpMuxSocket : public ISrsUdpMuxSocket
|
||||
{
|
||||
public:
|
||||
srs_error_t sendto_error_;
|
||||
int sendto_called_count_;
|
||||
int last_sendto_size_;
|
||||
std::string peer_ip_;
|
||||
int peer_port_;
|
||||
std::string peer_id_;
|
||||
uint64_t fast_id_;
|
||||
char *data_;
|
||||
int size_;
|
||||
|
||||
public:
|
||||
MockUdpMuxSocket();
|
||||
virtual ~MockUdpMuxSocket();
|
||||
|
||||
public:
|
||||
virtual srs_error_t sendto(void *data, int size, srs_utime_t timeout);
|
||||
virtual std::string get_peer_ip() const;
|
||||
virtual int get_peer_port() const;
|
||||
virtual std::string peer_id();
|
||||
virtual uint64_t fast_id();
|
||||
virtual SrsUdpMuxSocket *copy_sendonly();
|
||||
virtual int recvfrom(srs_utime_t timeout);
|
||||
virtual char *data();
|
||||
virtual int size();
|
||||
|
||||
public:
|
||||
void reset();
|
||||
void set_sendto_error(srs_error_t err);
|
||||
};
|
||||
|
||||
// Mock ISrsProtocolReadWriter for testing SrsRtcTcpNetwork write operations
|
||||
class MockProtocolReadWriterForTcpNetwork : public ISrsProtocolReadWriter
|
||||
{
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ VOID TEST(UdpListenerTest, ListenAndReceivePacket)
|
|||
}
|
||||
|
||||
// Wait a bit for the listener to receive and process the packet
|
||||
srs_usleep(30 * SRS_UTIME_MILLISECONDS);
|
||||
srs_usleep(50 * SRS_UTIME_MILLISECONDS);
|
||||
|
||||
// Verify that the mock handler received the packet
|
||||
EXPECT_TRUE(mock_handler->on_udp_packet_called_);
|
||||
|
|
@ -1536,6 +1536,7 @@ ISrsFlvDecoder *MockAppFactoryForIngester::create_flv_decoder()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef SRS_RTSP
|
||||
ISrsRtspSendTrack *MockAppFactoryForIngester::create_rtsp_audio_send_track(ISrsRtspConnection *session, SrsRtcTrackDescription *track_desc)
|
||||
{
|
||||
return NULL;
|
||||
|
|
@ -1545,6 +1546,7 @@ ISrsRtspSendTrack *MockAppFactoryForIngester::create_rtsp_video_send_track(ISrsR
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
ISrsFlvTransmuxer *MockAppFactoryForIngester::create_flv_transmuxer()
|
||||
{
|
||||
|
|
@ -1566,6 +1568,7 @@ ISrsDvrSegmenter *MockAppFactoryForIngester::create_dvr_mp4_segmenter()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef SRS_GB28181
|
||||
ISrsGbMediaTcpConn *MockAppFactoryForIngester::create_gb_media_tcp_conn()
|
||||
{
|
||||
return NULL;
|
||||
|
|
@ -1575,6 +1578,7 @@ ISrsGbSession *MockAppFactoryForIngester::create_gb_session()
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
ISrsInitMp4 *MockAppFactoryForIngester::create_init_mp4()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -537,14 +537,18 @@ public:
|
|||
virtual ISrsHttpClient *create_http_client();
|
||||
virtual ISrsFileReader *create_http_file_reader(ISrsHttpResponseReader *r);
|
||||
virtual ISrsFlvDecoder *create_flv_decoder();
|
||||
#ifdef SRS_RTSP
|
||||
virtual ISrsRtspSendTrack *create_rtsp_audio_send_track(ISrsRtspConnection *session, SrsRtcTrackDescription *track_desc);
|
||||
virtual ISrsRtspSendTrack *create_rtsp_video_send_track(ISrsRtspConnection *session, SrsRtcTrackDescription *track_desc);
|
||||
#endif
|
||||
virtual ISrsFlvTransmuxer *create_flv_transmuxer();
|
||||
virtual ISrsMp4Encoder *create_mp4_encoder();
|
||||
virtual ISrsDvrSegmenter *create_dvr_flv_segmenter();
|
||||
virtual ISrsDvrSegmenter *create_dvr_mp4_segmenter();
|
||||
#ifdef SRS_GB28181
|
||||
virtual ISrsGbMediaTcpConn *create_gb_media_tcp_conn();
|
||||
virtual ISrsGbSession *create_gb_session();
|
||||
#endif
|
||||
virtual ISrsInitMp4 *create_init_mp4();
|
||||
virtual ISrsFragmentWindow *create_fragment_window();
|
||||
virtual ISrsFragmentedMp4 *create_fragmented_mp4();
|
||||
|
|
|
|||
|
|
@ -3035,7 +3035,7 @@ VOID TEST(QueueRecvThreadTest, BasicQueueOperations)
|
|||
// Queue should have one message
|
||||
EXPECT_FALSE(queue_thread->empty());
|
||||
EXPECT_EQ(1, queue_thread->size());
|
||||
EXPECT_TRUE(queue_thread->interrupted()); // interrupted() returns true when queue is not empty
|
||||
EXPECT_TRUE(queue_thread->interrupted()); // interrupted() returns true when queue is not empty
|
||||
|
||||
// Test 3: Consume second message
|
||||
SrsRtmpCommonMessage *msg2 = new SrsRtmpCommonMessage();
|
||||
|
|
@ -3088,12 +3088,12 @@ VOID TEST(QueueRecvThreadTest, BasicQueueOperations)
|
|||
// Test 8: Test on_start() and on_stop() - verify set_auto_response is called
|
||||
queue_thread->on_start();
|
||||
EXPECT_TRUE(mock_rtmp->set_auto_response_called_);
|
||||
EXPECT_FALSE(mock_rtmp->auto_response_value_); // Should be set to false
|
||||
EXPECT_FALSE(mock_rtmp->auto_response_value_); // Should be set to false
|
||||
|
||||
mock_rtmp->reset();
|
||||
queue_thread->on_stop();
|
||||
EXPECT_TRUE(mock_rtmp->set_auto_response_called_);
|
||||
EXPECT_TRUE(mock_rtmp->auto_response_value_); // Should be set to true
|
||||
EXPECT_TRUE(mock_rtmp->auto_response_value_); // Should be set to true
|
||||
}
|
||||
|
||||
// Test SrsPublishRecvThread basic operations
|
||||
|
|
@ -3105,7 +3105,7 @@ VOID TEST(PublishRecvThreadTest, BasicOperations)
|
|||
// Create mock dependencies
|
||||
SrsUniquePtr<MockRtmpServerForQueueRecvThread> mock_rtmp(new MockRtmpServerForQueueRecvThread());
|
||||
SrsUniquePtr<MockSrsRequest> mock_req(new MockSrsRequest("__defaultVhost__", "live", "test_stream"));
|
||||
SrsSharedPtr<SrsLiveSource> mock_source; // NULL is fine for this test
|
||||
SrsSharedPtr<SrsLiveSource> mock_source; // NULL is fine for this test
|
||||
|
||||
// Create SrsPublishRecvThread (without starting the actual recv thread)
|
||||
SrsUniquePtr<SrsPublishRecvThread> publish_thread(new SrsPublishRecvThread(
|
||||
|
|
|
|||
|
|
@ -17,6 +17,201 @@ using namespace std;
|
|||
#include <srs_protocol_sdp.hpp>
|
||||
#include <srs_utest_app2.hpp>
|
||||
|
||||
// Mock ISrsResourceManager implementation
|
||||
MockResourceManagerForBindSession::MockResourceManagerForBindSession()
|
||||
{
|
||||
session_to_return_ = NULL;
|
||||
}
|
||||
|
||||
MockResourceManagerForBindSession::~MockResourceManagerForBindSession()
|
||||
{
|
||||
}
|
||||
|
||||
srs_error_t MockResourceManagerForBindSession::start()
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
bool MockResourceManagerForBindSession::empty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t MockResourceManagerForBindSession::size()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::add(ISrsResource *conn, bool *exists)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::add_with_id(const std::string &id, ISrsResource *conn)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::add_with_fast_id(uint64_t id, ISrsResource *conn)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::add_with_name(const std::string & /*name*/, ISrsResource * /*conn*/)
|
||||
{
|
||||
}
|
||||
|
||||
ISrsResource *MockResourceManagerForBindSession::at(int index)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ISrsResource *MockResourceManagerForBindSession::find_by_id(std::string id)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ISrsResource *MockResourceManagerForBindSession::find_by_fast_id(uint64_t id)
|
||||
{
|
||||
return session_to_return_;
|
||||
}
|
||||
|
||||
ISrsResource *MockResourceManagerForBindSession::find_by_name(std::string /*name*/)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::remove(ISrsResource *c)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::subscribe(ISrsDisposingHandler *h)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::unsubscribe(ISrsDisposingHandler *h)
|
||||
{
|
||||
}
|
||||
|
||||
void MockResourceManagerForBindSession::reset()
|
||||
{
|
||||
session_to_return_ = NULL;
|
||||
}
|
||||
|
||||
// Mock ISrsEphemeralDelta implementation
|
||||
MockEphemeralDelta::MockEphemeralDelta()
|
||||
{
|
||||
in_bytes_ = 0;
|
||||
out_bytes_ = 0;
|
||||
}
|
||||
|
||||
MockEphemeralDelta::~MockEphemeralDelta()
|
||||
{
|
||||
}
|
||||
|
||||
void MockEphemeralDelta::add_delta(int64_t in, int64_t out)
|
||||
{
|
||||
in_bytes_ += in;
|
||||
out_bytes_ += out;
|
||||
}
|
||||
|
||||
void MockEphemeralDelta::remark(int64_t *in, int64_t *out)
|
||||
{
|
||||
if (in)
|
||||
*in = in_bytes_;
|
||||
if (out)
|
||||
*out = out_bytes_;
|
||||
in_bytes_ = 0;
|
||||
out_bytes_ = 0;
|
||||
}
|
||||
|
||||
void MockEphemeralDelta::reset()
|
||||
{
|
||||
in_bytes_ = 0;
|
||||
out_bytes_ = 0;
|
||||
}
|
||||
|
||||
// Mock ISrsUdpMuxSocket implementation
|
||||
MockUdpMuxSocket::MockUdpMuxSocket()
|
||||
{
|
||||
sendto_error_ = srs_success;
|
||||
sendto_called_count_ = 0;
|
||||
last_sendto_size_ = 0;
|
||||
peer_ip_ = "192.168.1.100";
|
||||
peer_port_ = 5000;
|
||||
peer_id_ = "192.168.1.100:5000";
|
||||
fast_id_ = 0;
|
||||
data_ = NULL;
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
MockUdpMuxSocket::~MockUdpMuxSocket()
|
||||
{
|
||||
srs_freep(sendto_error_);
|
||||
data_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t MockUdpMuxSocket::sendto(void *data, int size, srs_utime_t timeout)
|
||||
{
|
||||
sendto_called_count_++;
|
||||
last_sendto_size_ = size;
|
||||
return srs_error_copy(sendto_error_);
|
||||
}
|
||||
|
||||
std::string MockUdpMuxSocket::get_peer_ip() const
|
||||
{
|
||||
return peer_ip_;
|
||||
}
|
||||
|
||||
int MockUdpMuxSocket::get_peer_port() const
|
||||
{
|
||||
return peer_port_;
|
||||
}
|
||||
|
||||
std::string MockUdpMuxSocket::peer_id()
|
||||
{
|
||||
return peer_id_;
|
||||
}
|
||||
|
||||
uint64_t MockUdpMuxSocket::fast_id()
|
||||
{
|
||||
return fast_id_;
|
||||
}
|
||||
|
||||
SrsUdpMuxSocket *MockUdpMuxSocket::copy_sendonly()
|
||||
{
|
||||
// Return self for testing purposes - in real implementation this creates a copy
|
||||
return (SrsUdpMuxSocket *)this;
|
||||
}
|
||||
|
||||
int MockUdpMuxSocket::recvfrom(srs_utime_t timeout)
|
||||
{
|
||||
// Mock implementation - return the size of data received
|
||||
return size_;
|
||||
}
|
||||
|
||||
char *MockUdpMuxSocket::data()
|
||||
{
|
||||
// Mock implementation - return the data buffer
|
||||
return data_;
|
||||
}
|
||||
|
||||
int MockUdpMuxSocket::size()
|
||||
{
|
||||
// Mock implementation - return the size of data
|
||||
return size_;
|
||||
}
|
||||
|
||||
void MockUdpMuxSocket::reset()
|
||||
{
|
||||
srs_freep(sendto_error_);
|
||||
sendto_called_count_ = 0;
|
||||
last_sendto_size_ = 0;
|
||||
}
|
||||
|
||||
void MockUdpMuxSocket::set_sendto_error(srs_error_t err)
|
||||
{
|
||||
srs_freep(sendto_error_);
|
||||
sendto_error_ = srs_error_copy(err);
|
||||
}
|
||||
|
||||
// Mock DTLS implementation
|
||||
MockDtls::MockDtls()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,6 +25,85 @@
|
|||
#include <srs_utest_app2.hpp>
|
||||
#include <srs_utest_protocol3.hpp>
|
||||
|
||||
// Mock ISrsResourceManager for testing SrsGbMediaTcpConn::bind_session
|
||||
class MockResourceManagerForBindSession : public ISrsResourceManager
|
||||
{
|
||||
public:
|
||||
ISrsResource *session_to_return_;
|
||||
|
||||
public:
|
||||
MockResourceManagerForBindSession();
|
||||
virtual ~MockResourceManagerForBindSession();
|
||||
|
||||
public:
|
||||
virtual srs_error_t start();
|
||||
virtual bool empty();
|
||||
virtual size_t size();
|
||||
virtual void add(ISrsResource *conn, bool *exists = NULL);
|
||||
virtual void add_with_id(const std::string &id, ISrsResource *conn);
|
||||
virtual void add_with_fast_id(uint64_t id, ISrsResource *conn);
|
||||
virtual void add_with_name(const std::string &name, ISrsResource *conn);
|
||||
virtual ISrsResource *at(int index);
|
||||
virtual ISrsResource *find_by_id(std::string id);
|
||||
virtual ISrsResource *find_by_fast_id(uint64_t id);
|
||||
virtual ISrsResource *find_by_name(std::string name);
|
||||
virtual void remove(ISrsResource *c);
|
||||
virtual void subscribe(ISrsDisposingHandler *h);
|
||||
virtual void unsubscribe(ISrsDisposingHandler *h);
|
||||
void reset();
|
||||
};
|
||||
|
||||
// Mock ISrsEphemeralDelta for testing SrsRtcUdpNetwork
|
||||
class MockEphemeralDelta : public ISrsEphemeralDelta
|
||||
{
|
||||
public:
|
||||
int64_t in_bytes_;
|
||||
int64_t out_bytes_;
|
||||
|
||||
public:
|
||||
MockEphemeralDelta();
|
||||
virtual ~MockEphemeralDelta();
|
||||
|
||||
public:
|
||||
virtual void add_delta(int64_t in, int64_t out);
|
||||
virtual void remark(int64_t *in, int64_t *out);
|
||||
void reset();
|
||||
};
|
||||
|
||||
// Mock ISrsUdpMuxSocket for testing SrsRtcUdpNetwork STUN handling
|
||||
class MockUdpMuxSocket : public ISrsUdpMuxSocket
|
||||
{
|
||||
public:
|
||||
srs_error_t sendto_error_;
|
||||
int sendto_called_count_;
|
||||
int last_sendto_size_;
|
||||
std::string peer_ip_;
|
||||
int peer_port_;
|
||||
std::string peer_id_;
|
||||
uint64_t fast_id_;
|
||||
char *data_;
|
||||
int size_;
|
||||
|
||||
public:
|
||||
MockUdpMuxSocket();
|
||||
virtual ~MockUdpMuxSocket();
|
||||
|
||||
public:
|
||||
virtual srs_error_t sendto(void *data, int size, srs_utime_t timeout);
|
||||
virtual std::string get_peer_ip() const;
|
||||
virtual int get_peer_port() const;
|
||||
virtual std::string peer_id();
|
||||
virtual uint64_t fast_id();
|
||||
virtual SrsUdpMuxSocket *copy_sendonly();
|
||||
virtual int recvfrom(srs_utime_t timeout);
|
||||
virtual char *data();
|
||||
virtual int size();
|
||||
|
||||
public:
|
||||
void reset();
|
||||
void set_sendto_error(srs_error_t err);
|
||||
};
|
||||
|
||||
// Mock DTLS implementation for testing SrsSecurityTransport
|
||||
class MockDtls : public ISrsDtls
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ using namespace std;
|
|||
#include <srs_protocol_protobuf.hpp>
|
||||
#include <srs_protocol_rtmp_msg_array.hpp>
|
||||
#include <srs_protocol_rtmp_stack.hpp>
|
||||
#ifdef SRS_RTSP
|
||||
#include <srs_protocol_rtsp_stack.hpp>
|
||||
#endif
|
||||
#include <srs_protocol_utility.hpp>
|
||||
|
||||
#include <srs_protocol_sdp.hpp>
|
||||
|
|
|
|||
|
|
@ -700,7 +700,7 @@ VOID TEST(SourceLockTest, RtcSourceManager_FetchNonExistent)
|
|||
// Fetch non-existent source should return NULL
|
||||
SrsSharedPtr<SrsRtcSource> source = manager.fetch(&req);
|
||||
EXPECT_TRUE(source.get() == NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SRS_RTSP
|
||||
typedef MockOtherSourceAsyncCreator<SrsRtspSourceManager, SrsRtspSource> MockRtspSourceAsyncCreator;
|
||||
|
|
@ -814,4 +814,4 @@ VOID TEST(SourceLockTest, RtspSourceManager_BasicFunctionality)
|
|||
HELPER_EXPECT_SUCCESS(manager.fetch_or_create(&req, source2));
|
||||
EXPECT_EQ(source.get(), source2.get());
|
||||
}
|
||||
#endif
|
||||
#endif // SRS_RTSP
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user