diff --git a/trunk/src/utest/srs_utest_protostack.cpp b/trunk/src/utest/srs_utest_protostack.cpp index f0f2cd200..3c26e3452 100644 --- a/trunk/src/utest/srs_utest_protostack.cpp +++ b/trunk/src/utest/srs_utest_protostack.cpp @@ -22,7 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include -using namespace std; +#include #include #include @@ -36,6 +36,8 @@ using namespace std; #include #include +using namespace std; + class MockErrorPacket : public SrsPacket { protected: @@ -75,3 +77,75 @@ VOID TEST(ProtoStackTest, PacketEncode) } } +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()); + } +} +