1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00
srs/trunk/src/utest/srs_utest_protostack.cpp

1268 lines
37 KiB
C++
Raw Normal View History

2019-10-23 01:26:10 +00:00
/*
The MIT License (MIT)
Copyright (c) 2013-2019 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_protostack.hpp>
2019-10-28 00:41:49 +00:00
#include <srs_utest_protocol.hpp>
2019-10-23 01:26:10 +00:00
#include <srs_kernel_error.hpp>
#include <srs_core_autofree.hpp>
#include <srs_protocol_utility.hpp>
#include <srs_rtmp_msg_array.hpp>
#include <srs_rtmp_stack.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_app_st.hpp>
#include <srs_protocol_amf0.hpp>
#include <srs_rtmp_stack.hpp>
#include <srs_service_http_conn.hpp>
2019-10-25 00:18:21 +00:00
#include <srs_kernel_buffer.hpp>
2019-10-23 01:26:10 +00:00
2019-10-28 00:41:49 +00:00
using namespace std;
2019-11-05 02:17:06 +00:00
class MockPacket : public SrsPacket
2019-10-23 01:26:10 +00:00
{
2019-11-05 02:17:06 +00:00
public:
int size;
public:
MockPacket() {
size = 0;
}
virtual ~MockPacket() {
}
2019-10-25 00:18:21 +00:00
protected:
virtual int get_size() {
2019-11-05 02:17:06 +00:00
return size;
2019-10-25 00:18:21 +00:00
}
};
2019-11-05 02:17:06 +00:00
class MockPacket2 : public MockPacket
2019-11-05 01:55:45 +00:00
{
2019-11-05 02:17:06 +00:00
public:
char* payload;
public:
MockPacket2() {
payload = NULL;
}
virtual ~MockPacket2() {
srs_freep(payload);
}
2019-11-05 01:55:45 +00:00
virtual srs_error_t encode(int& size, char*& payload) {
2019-11-05 02:17:06 +00:00
size = this->size;
payload = this->payload;
this->payload = NULL;
2019-11-05 01:55:45 +00:00
return srs_success;
}
};
2019-10-25 00:18:21 +00:00
VOID TEST(ProtoStackTest, PacketEncode)
{
srs_error_t err;
int size;
char* payload;
if (true) {
2019-11-05 02:17:06 +00:00
MockPacket pkt;
pkt.size = 1024;
2019-10-25 00:18:21 +00:00
HELPER_EXPECT_FAILED(pkt.encode(size, payload));
}
if (true) {
2019-11-05 02:17:06 +00:00
MockPacket pkt;
pkt.size = 1024;
2019-10-25 00:18:21 +00:00
SrsBuffer b;
HELPER_EXPECT_FAILED(pkt.decode(&b));
}
if (true) {
SrsPacket pkt;
EXPECT_EQ(0, pkt.get_prefer_cid());
EXPECT_EQ(0, pkt.get_message_type());
EXPECT_EQ(0, pkt.get_size());
}
if (true) {
2019-11-05 02:17:06 +00:00
MockPacket pkt;
pkt.size = 1024;
2019-10-25 00:18:21 +00:00
EXPECT_EQ(1024, pkt.get_size());
}
2019-10-23 01:26:10 +00:00
}
2019-10-28 00:41:49 +00:00
VOID TEST(ProtoStackTest, ManualFlush)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
// Always response ACK message.
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
// Default is auto response.
HELPER_EXPECT_SUCCESS(p.response_acknowledgement_message());
EXPECT_EQ(12+4, io.out_buffer.length());
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
// Always response ACK message.
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
p.set_auto_response(true);
HELPER_EXPECT_SUCCESS(p.response_acknowledgement_message());
EXPECT_EQ(12+4, io.out_buffer.length());
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
// Always response ACK message.
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
// When not auto response, need to flush it manually.
p.set_auto_response(false);
HELPER_EXPECT_SUCCESS(p.response_acknowledgement_message());
EXPECT_EQ(0, io.out_buffer.length());
HELPER_EXPECT_SUCCESS(p.manual_response_flush());
EXPECT_EQ(12+4, io.out_buffer.length());
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
// Always response ACK message.
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
HELPER_EXPECT_SUCCESS(p.response_ping_message(1024));
EXPECT_EQ(12+6, io.out_buffer.length());
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
// Always response ACK message.
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
// When not auto response, need to flush it manually.
p.set_auto_response(false);
HELPER_EXPECT_SUCCESS(p.response_ping_message(1024));
EXPECT_EQ(0, io.out_buffer.length());
HELPER_EXPECT_SUCCESS(p.manual_response_flush());
EXPECT_EQ(12+6, io.out_buffer.length());
}
2019-10-28 00:57:11 +00:00
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
// Always response ACK message.
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
// When not auto response, need to flush it manually.
p.set_auto_response(false);
HELPER_EXPECT_SUCCESS(p.response_ping_message(1024));
EXPECT_EQ(0, io.out_buffer.length());
// If not flushed, the packets will be destroyed.
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
p.set_recv_buffer(0);
p.set_recv_buffer(131072 * 10);
p.set_merge_read(true, NULL);
p.set_merge_read(false, NULL);
}
2019-10-28 00:41:49 +00:00
}
2019-11-05 01:55:45 +00:00
VOID TEST(ProtoStackTest, SendPacketsError)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
2019-11-05 02:17:06 +00:00
MockPacket* pkt = new MockPacket();
pkt->size = 1024;
2019-11-05 01:55:45 +00:00
HELPER_EXPECT_FAILED(p.send_and_free_packet(pkt, 1));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsPacket* pkt = new SrsPacket();
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 1));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
2019-11-05 02:17:06 +00:00
MockPacket2* pkt = new MockPacket2();
pkt->size = 1024;
2019-11-05 01:55:45 +00:00
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 1));
}
2019-11-05 06:00:00 +00:00
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsCommonMessage pkt;
pkt.header.initialize_audio(200, 1000, 1);
pkt.create_payload(256);
pkt.size = 256;
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
msg->create(&pkt);
SrsAutoFree(SrsSharedPtrMessage, msg);
SrsSharedPtrMessage* msgs[10240];
for (int i = 0; i < 10240; i++) {
msgs[i] = msg->copy();
}
io.out_err = srs_error_new(1, "fail");
HELPER_EXPECT_FAILED(p.send_and_free_messages(msgs, 10240, 1));
}
2019-11-05 02:17:06 +00:00
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
2019-11-05 06:00:00 +00:00
// Always response ACK message.
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
// When not auto response, need to flush it manually.
p.set_auto_response(false);
HELPER_EXPECT_SUCCESS(p.response_acknowledgement_message());
EXPECT_EQ(0, io.out_buffer.length());
io.out_err = srs_error_new(1, "fail");
HELPER_EXPECT_FAILED(p.manual_response_flush());
2019-11-05 02:17:06 +00:00
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
MockPacket2* pkt = new MockPacket2();
pkt->size = 16;
pkt->payload = new char[16];
io.out_err = srs_error_new(1, "fail");
HELPER_EXPECT_FAILED(p.send_and_free_packet(pkt, 1));
}
}
2019-11-05 06:00:00 +00:00
VOID TEST(ProtoStackTest, SendHugePacket)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
MockPacket2* pkt = new MockPacket2();
pkt->size = 1024;
pkt->payload = new char[1024];
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 1));
}
}
2019-10-29 02:02:03 +00:00
VOID TEST(ProtoStackTest, SendZeroMessages)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
HELPER_EXPECT_SUCCESS(p.send_and_free_message(NULL, 0));
}
2019-11-04 01:31:30 +00:00
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
HELPER_EXPECT_SUCCESS(p.send_and_free_message(msg, 1));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsSharedPtrMessage* msgs[1024];
for (int i = 0; i < 1024; i++) {
msgs[i] = new SrsSharedPtrMessage();
}
HELPER_EXPECT_SUCCESS(p.send_and_free_messages(msgs, 1024, 0));
}
}
VOID TEST(ProtoStackTest, HugeMessages)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsCommonMessage pkt;
pkt.header.initialize_audio(200, 1000, 1);
pkt.create_payload(256);
pkt.size = 256;
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
msg->create(&pkt);
HELPER_EXPECT_SUCCESS(p.send_and_free_message(msg, 1));
EXPECT_EQ(269, io.out_buffer.length());
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsCommonMessage pkt;
pkt.header.initialize_audio(200, 1000, 1);
pkt.create_payload(256);
pkt.size = 256;
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
msg->create(&pkt);
SrsAutoFree(SrsSharedPtrMessage, msg);
SrsSharedPtrMessage* msgs[1024];
for (int i = 0; i < 1024; i++) {
msgs[i] = msg->copy();
}
HELPER_EXPECT_SUCCESS(p.send_and_free_messages(msgs, 1024, 1));
EXPECT_EQ(269*1024, io.out_buffer.length());
}
2019-11-05 02:31:21 +00:00
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsCommonMessage pkt;
pkt.header.initialize_audio(200, 1000, 1);
pkt.create_payload(256);
pkt.size = 256;
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
msg->create(&pkt);
SrsAutoFree(SrsSharedPtrMessage, msg);
SrsSharedPtrMessage* msgs[10240];
for (int i = 0; i < 10240; i++) {
msgs[i] = msg->copy();
}
HELPER_EXPECT_SUCCESS(p.send_and_free_messages(msgs, 10240, 1));
EXPECT_EQ(269*10240, io.out_buffer.length());
}
2019-10-29 02:02:03 +00:00
}
2019-11-05 01:55:45 +00:00
VOID TEST(ProtoStackTest, DecodeMessages)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
// AMF0 message with 1B should fail.
SrsCommonMessage msg;
msg.header.initialize_amf0_script(1, 1);
msg.create_payload(1);
msg.size = 1;
SrsPacket* pkt;
HELPER_EXPECT_FAILED(p.decode_message(&msg, &pkt));
}
}
2019-11-08 01:26:57 +00:00
VOID TEST(ProtoStackTest, OnDecodeMessages)
{
srs_error_t err;
2019-11-22 04:06:15 +00:00
SrsSimpleStream bytes;
2019-11-08 01:26:57 +00:00
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsSetChunkSizePacket* pkt = new SrsSetChunkSizePacket();
pkt->chunk_size = 0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 1));
2019-11-22 04:06:15 +00:00
bytes.append(&io.out_buffer);
2019-11-08 01:26:57 +00:00
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
// Always response ACK message.
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
SrsCommonMessage* msg;
2019-11-22 04:06:15 +00:00
io.in_buffer.append(&bytes);
2019-11-08 01:26:57 +00:00
HELPER_EXPECT_FAILED(p.recv_message(&msg));
srs_freep(msg);
}
}
2019-11-19 10:18:43 +00:00
SrsCommonMessage* _create_amf0(char* bytes, int size, int stream_id)
2019-11-19 03:47:31 +00:00
{
SrsCommonMessage* msg = new SrsCommonMessage();
msg->header.initialize_amf0_script(size, stream_id);
msg->create_payload(size);
memcpy(msg->payload, bytes, size);
msg->size = size;
return msg;
}
VOID TEST(ProtoStackTest, OnDecodeMessages2)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x01, 's', 0x00, 0,0,0,0,0,0,0,0, 0x03,0,0,9};
2019-11-19 10:18:43 +00:00
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
2019-11-19 03:47:31 +00:00
SrsAutoFree(SrsCommonMessage, msg);
msg->header.message_type = RTMP_MSG_AMF3CommandMessage;
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
SrsCallPacket* call = (SrsCallPacket*)pkt;
EXPECT_STREQ("s", call->command_name.c_str());
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x01, 's'};
2019-11-19 10:18:43 +00:00
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
2019-11-19 03:47:31 +00:00
SrsAutoFree(SrsCommonMessage, msg);
msg->header.message_type = RTMP_MSG_AMF3CommandMessage;
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
2019-11-19 10:18:43 +00:00
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x00};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
msg->header.message_type = 0xff;
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 0x01, 's'};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
msg->header.message_type = RTMP_MSG_AMF0DataMessage;
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
}
}
VOID TEST(ProtoStackTest, OnDecodeMessages3)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
2019-11-20 03:05:56 +00:00
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t'};
2019-11-19 10:18:43 +00:00
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
msg->header.message_type = RTMP_MSG_AMF0DataMessage;
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
2019-11-20 03:05:56 +00:00
// Decode the response failed, no transaction ID was set by request.
2019-11-19 10:18:43 +00:00
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
2019-11-20 03:05:56 +00:00
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x07, '_','r','e','s','u','l','t'};
2019-11-19 10:18:43 +00:00
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
2019-11-20 03:14:02 +00:00
msg->header.message_type = RTMP_MSG_AMF3DataMessage;
2019-11-19 10:18:43 +00:00
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
2019-11-20 03:05:56 +00:00
// Decode the response failed, no transaction ID was set by request.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
2019-11-20 03:14:02 +00:00
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
2019-11-20 03:05:56 +00:00
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
2019-11-20 03:14:02 +00:00
msg->header.message_type = RTMP_MSG_AMF3CommandMessage;
2019-11-20 03:05:56 +00:00
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Decode the response failed, no transaction ID was set by request.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsConnectAppPacket* request = new SrsConnectAppPacket();
request->transaction_id = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the response packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsCreateStreamPacket* request = new SrsCreateStreamPacket();
request->transaction_id = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the response packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsFMLEStartPacket* request = SrsFMLEStartPacket::create_FC_publish("livestream");
request->transaction_id = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the response packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsFMLEStartPacket* request = SrsFMLEStartPacket::create_release_stream("livestream");
request->transaction_id = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the response packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsFMLEStartPacket* request = SrsFMLEStartPacket::create_release_stream("livestream");
request->command_name = RTMP_AMF0_COMMAND_UNPUBLISH;
request->transaction_id = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
2019-11-20 03:14:02 +00:00
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the response packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsFMLEStartPacket* request = new SrsFMLEStartPacket();
request->command_name = "srs";
request->transaction_id = 0.0;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(request, 1));
2019-11-20 03:05:56 +00:00
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the response packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
}
VOID TEST(ProtoStackTest, OnDecodeMessages4)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 0x07, 'c','o','n','n','e','c','t', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 12, 'c','r','e','a','t','e','S','t','r','e','a','m', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 4, 'p','l','a','y', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 5, 'p','a','u','s','e', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 13, 'r','e','l','e','a','s','e','S','t','r','e','a','m', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 9, 'F','C','P','u','b','l','i','s','h', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 7, 'p','u','b','l','i','s','h', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 11, 'F','C','U','n','p','u','b','l','i','s','h', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 13, '@','s','e','t','D','a','t','a','F','r','a','m','e', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 10, 'o','n','M','e','t','a','D','a','t','a', 03,0,0,9};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 22, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','F','i','n','i','s','h','e','d', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 21, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','P','l','a','y','i','n','g', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 24, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','P','u','b','l','i','s','h','i','n','g', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 31, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','a','r','t','i','n','g','P','l','a','y','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 34, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','a','r','t','i','n','g','P','u','b','l','i','s','h','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 28, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','a','r','t','P','l','a','y','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 31, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','a','r','t','P','u','b','l','i','s','h','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 30, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','o','p','p','e','d','P','l','a','y','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 27, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','o','p','P','l','a','y','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 30, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','o','p','P','u','b','l','i','s','h','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 33, 'o','n','S','r','s','B','a','n','d','C','h','e','c','k','S','t','o','p','p','e','d','P','u','b','l','i','s','h','B','y','t','e','s', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 17, 'f','i','n','a','l','C','l','i','e','n','t','P','a','c','k','e','t', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 11, 'c','l','o','s','e','S','t','r','e','a','m', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x02, 0x00, 3, 's','r','s', 0x00,0,0,0,0,0,0,0,0};
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
msg->header.message_type = RTMP_MSG_AMF0CommandMessage;
SrsAutoFree(SrsCommonMessage, msg);
SrsPacket* pkt;
SrsAutoFree(SrsPacket, pkt);
// Without enough data, it fail when decoding the request packet.
2019-11-19 10:18:43 +00:00
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
}
2019-11-19 03:47:31 +00:00
}
2019-11-20 06:08:53 +00:00
VOID TEST(ProtoStackTest, RecvMessage)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x01, 0x00, 0x00};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x00, 0x00};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x00};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
}
VOID TEST(ProtoStackTest, RecvMessage2)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
p.in_chunk_size = 3;
uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
uint8_t bytes2[] = {0x43, 0,0,0, 0,0,5, 0, 0,0,0,0, 1,2,3};
io.in_buffer.append((char*)bytes2, sizeof(bytes2));
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x03};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x43, 0,0,0, 0,0,0, 0};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
}
VOID TEST(ProtoStackTest, RecvMessage3)
{
if (true) {
SrsRequest req;
req.ip = "10.11.12.13";
SrsRequest* cp = req.copy();
EXPECT_STREQ("10.11.12.13", cp->ip.c_str());
srs_freep(cp);
}
if (true) {
SrsRequest req;
req.ip = "10.11.12.13";
SrsAmf0Object* obj = SrsAmf0Any::object();
obj->set("id", SrsAmf0Any::str("srs"));
req.args = obj;
SrsRequest* cp = req.copy();
EXPECT_STREQ("10.11.12.13", cp->ip.c_str());
SrsAmf0Object* cpa = dynamic_cast<SrsAmf0Object*>(cp->args);
SrsAmf0Any* cps = cpa->ensure_property_string("id");
EXPECT_STREQ("srs", cps->to_str().c_str());
srs_freep(cp);
}
if (true) {
SrsRequest req;
EXPECT_STREQ("//", req.get_stream_url().c_str());
}
if (true) {
SrsRequest req;
EXPECT_STREQ("", req.schema.c_str());
req.as_http();
EXPECT_STREQ("http", req.schema.c_str());
}
if (true) {
SrsResponse res;
EXPECT_EQ(1, res.stream_id);
}
if (true) {
EXPECT_STREQ("Play", srs_client_type_string(SrsRtmpConnPlay).c_str());
EXPECT_STREQ("flash-publish", srs_client_type_string(SrsRtmpConnFlashPublish).c_str());
EXPECT_STREQ("fmle-publish", srs_client_type_string(SrsRtmpConnFMLEPublish).c_str());
EXPECT_STREQ("haivision-publish", srs_client_type_string(SrsRtmpConnHaivisionPublish).c_str());
EXPECT_STREQ("Unknown", srs_client_type_string(SrsRtmpConnType(0x0f)).c_str());
EXPECT_TRUE(srs_client_type_is_publish(SrsRtmpConnFlashPublish));
EXPECT_TRUE(srs_client_type_is_publish(SrsRtmpConnFMLEPublish));
EXPECT_TRUE(srs_client_type_is_publish(SrsRtmpConnHaivisionPublish));
EXPECT_FALSE(srs_client_type_is_publish(SrsRtmpConnPlay));
}
}
2019-11-22 04:06:15 +00:00
VOID TEST(ProtoStackTest, RecvMessage4)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsSetChunkSizePacket* pkt = new SrsSetChunkSizePacket();
pkt->chunk_size = 256;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 0));
io.in_buffer.append(&io.out_buffer);
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
EXPECT_EQ(256, p.out_chunk_size);
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsUserControlPacket* pkt = new SrsUserControlPacket();
pkt->event_type = SrcPCUCSetBufferLength;
pkt->extra_data = 256;
HELPER_EXPECT_SUCCESS(p.send_and_free_packet(pkt, 0));
io.in_buffer.append(&io.out_buffer);
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
EXPECT_EQ(256, p.in_buffer_length);
}
}