refine utest, move the mock io to handshake where actually use it.
正在显示
4 个修改的文件
包含
91 行增加
和
91 行删除
| @@ -36,67 +36,6 @@ ISrsThreadContext* _srs_context = new ISrsThreadContext(); | @@ -36,67 +36,6 @@ ISrsThreadContext* _srs_context = new ISrsThreadContext(); | ||
| 36 | SrsConfig* _srs_config = NULL; | 36 | SrsConfig* _srs_config = NULL; |
| 37 | SrsServer* _srs_server = NULL; | 37 | SrsServer* _srs_server = NULL; |
| 38 | 38 | ||
| 39 | -MockEmptyIO::MockEmptyIO() | ||
| 40 | -{ | ||
| 41 | -} | ||
| 42 | - | ||
| 43 | -MockEmptyIO::~MockEmptyIO() | ||
| 44 | -{ | ||
| 45 | -} | ||
| 46 | - | ||
| 47 | -bool MockEmptyIO::is_never_timeout(int64_t /*timeout_us*/) | ||
| 48 | -{ | ||
| 49 | - return true; | ||
| 50 | -} | ||
| 51 | - | ||
| 52 | -int MockEmptyIO::read_fully(void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/) | ||
| 53 | -{ | ||
| 54 | - return ERROR_SUCCESS; | ||
| 55 | -} | ||
| 56 | - | ||
| 57 | -int MockEmptyIO::write(void* /*buf*/, size_t /*size*/, ssize_t* /*nwrite*/) | ||
| 58 | -{ | ||
| 59 | - return ERROR_SUCCESS; | ||
| 60 | -} | ||
| 61 | - | ||
| 62 | -void MockEmptyIO::set_recv_timeout(int64_t /*timeout_us*/) | ||
| 63 | -{ | ||
| 64 | -} | ||
| 65 | - | ||
| 66 | -int64_t MockEmptyIO::get_recv_timeout() | ||
| 67 | -{ | ||
| 68 | - return -1; | ||
| 69 | -} | ||
| 70 | - | ||
| 71 | -int64_t MockEmptyIO::get_recv_bytes() | ||
| 72 | -{ | ||
| 73 | - return -1; | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | -void MockEmptyIO::set_send_timeout(int64_t /*timeout_us*/) | ||
| 77 | -{ | ||
| 78 | -} | ||
| 79 | - | ||
| 80 | -int64_t MockEmptyIO::get_send_timeout() | ||
| 81 | -{ | ||
| 82 | - return 0; | ||
| 83 | -} | ||
| 84 | - | ||
| 85 | -int64_t MockEmptyIO::get_send_bytes() | ||
| 86 | -{ | ||
| 87 | - return 0; | ||
| 88 | -} | ||
| 89 | - | ||
| 90 | -int MockEmptyIO::writev(const iovec */*iov*/, int /*iov_size*/, ssize_t* /*nwrite*/) | ||
| 91 | -{ | ||
| 92 | - return ERROR_SUCCESS; | ||
| 93 | -} | ||
| 94 | - | ||
| 95 | -int MockEmptyIO::read(void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/) | ||
| 96 | -{ | ||
| 97 | - return ERROR_SUCCESS; | ||
| 98 | -} | ||
| 99 | - | ||
| 100 | // basic test and samples. | 39 | // basic test and samples. |
| 101 | VOID TEST(SampleTest, FastSampleInt64Test) | 40 | VOID TEST(SampleTest, FastSampleInt64Test) |
| 102 | { | 41 | { |
| @@ -49,34 +49,4 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -49,34 +49,4 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 49 | // * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual): Tests that two double values are almost equal. | 49 | // * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual): Tests that two double values are almost equal. |
| 50 | // * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): Tests that v1 and v2 are within the given distance to each other. | 50 | // * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): Tests that v1 and v2 are within the given distance to each other. |
| 51 | 51 | ||
| 52 | -#include <srs_protocol_io.hpp> | ||
| 53 | - | ||
| 54 | -class MockEmptyIO : public ISrsProtocolReaderWriter | ||
| 55 | -{ | ||
| 56 | -public: | ||
| 57 | - MockEmptyIO(); | ||
| 58 | - virtual ~MockEmptyIO(); | ||
| 59 | -// for protocol | ||
| 60 | -public: | ||
| 61 | - virtual bool is_never_timeout(int64_t timeout_us); | ||
| 62 | -// for handshake. | ||
| 63 | -public: | ||
| 64 | - virtual int read_fully(void* buf, size_t size, ssize_t* nread); | ||
| 65 | - virtual int write(void* buf, size_t size, ssize_t* nwrite); | ||
| 66 | -// for protocol | ||
| 67 | -public: | ||
| 68 | - virtual void set_recv_timeout(int64_t timeout_us); | ||
| 69 | - virtual int64_t get_recv_timeout(); | ||
| 70 | - virtual int64_t get_recv_bytes(); | ||
| 71 | -// for protocol | ||
| 72 | -public: | ||
| 73 | - virtual void set_send_timeout(int64_t timeout_us); | ||
| 74 | - virtual int64_t get_send_timeout(); | ||
| 75 | - virtual int64_t get_send_bytes(); | ||
| 76 | - virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite); | ||
| 77 | -// for protocol/amf0/msg-codec | ||
| 78 | -public: | ||
| 79 | - virtual int read(void* buf, size_t size, ssize_t* nread); | ||
| 80 | -}; | ||
| 81 | - | ||
| 82 | #endif | 52 | #endif |
| @@ -26,6 +26,67 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -26,6 +26,67 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 26 | #include <srs_core_autofree.hpp> | 26 | #include <srs_core_autofree.hpp> |
| 27 | #include <srs_protocol_utility.hpp> | 27 | #include <srs_protocol_utility.hpp> |
| 28 | 28 | ||
| 29 | +MockEmptyIO::MockEmptyIO() | ||
| 30 | +{ | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +MockEmptyIO::~MockEmptyIO() | ||
| 34 | +{ | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +bool MockEmptyIO::is_never_timeout(int64_t /*timeout_us*/) | ||
| 38 | +{ | ||
| 39 | + return true; | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +int MockEmptyIO::read_fully(void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/) | ||
| 43 | +{ | ||
| 44 | + return ERROR_SUCCESS; | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +int MockEmptyIO::write(void* /*buf*/, size_t /*size*/, ssize_t* /*nwrite*/) | ||
| 48 | +{ | ||
| 49 | + return ERROR_SUCCESS; | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +void MockEmptyIO::set_recv_timeout(int64_t /*timeout_us*/) | ||
| 53 | +{ | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +int64_t MockEmptyIO::get_recv_timeout() | ||
| 57 | +{ | ||
| 58 | + return -1; | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +int64_t MockEmptyIO::get_recv_bytes() | ||
| 62 | +{ | ||
| 63 | + return -1; | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +void MockEmptyIO::set_send_timeout(int64_t /*timeout_us*/) | ||
| 67 | +{ | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +int64_t MockEmptyIO::get_send_timeout() | ||
| 71 | +{ | ||
| 72 | + return 0; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +int64_t MockEmptyIO::get_send_bytes() | ||
| 76 | +{ | ||
| 77 | + return 0; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +int MockEmptyIO::writev(const iovec */*iov*/, int /*iov_size*/, ssize_t* /*nwrite*/) | ||
| 81 | +{ | ||
| 82 | + return ERROR_SUCCESS; | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +int MockEmptyIO::read(void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/) | ||
| 86 | +{ | ||
| 87 | + return ERROR_SUCCESS; | ||
| 88 | +} | ||
| 89 | + | ||
| 29 | #ifdef SRS_AUTO_SSL | 90 | #ifdef SRS_AUTO_SSL |
| 30 | 91 | ||
| 31 | // verify the sha256 | 92 | // verify the sha256 |
| @@ -36,4 +36,34 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -36,4 +36,34 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 36 | using namespace srs; | 36 | using namespace srs; |
| 37 | #endif | 37 | #endif |
| 38 | 38 | ||
| 39 | +#include <srs_protocol_io.hpp> | ||
| 40 | + | ||
| 41 | +class MockEmptyIO : public ISrsProtocolReaderWriter | ||
| 42 | +{ | ||
| 43 | +public: | ||
| 44 | + MockEmptyIO(); | ||
| 45 | + virtual ~MockEmptyIO(); | ||
| 46 | +// for protocol | ||
| 47 | +public: | ||
| 48 | + virtual bool is_never_timeout(int64_t timeout_us); | ||
| 49 | +// for handshake. | ||
| 50 | +public: | ||
| 51 | + virtual int read_fully(void* buf, size_t size, ssize_t* nread); | ||
| 52 | + virtual int write(void* buf, size_t size, ssize_t* nwrite); | ||
| 53 | +// for protocol | ||
| 54 | +public: | ||
| 55 | + virtual void set_recv_timeout(int64_t timeout_us); | ||
| 56 | + virtual int64_t get_recv_timeout(); | ||
| 57 | + virtual int64_t get_recv_bytes(); | ||
| 58 | +// for protocol | ||
| 59 | +public: | ||
| 60 | + virtual void set_send_timeout(int64_t timeout_us); | ||
| 61 | + virtual int64_t get_send_timeout(); | ||
| 62 | + virtual int64_t get_send_bytes(); | ||
| 63 | + virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite); | ||
| 64 | +// for protocol/amf0/msg-codec | ||
| 65 | +public: | ||
| 66 | + virtual int read(void* buf, size_t size, ssize_t* nread); | ||
| 67 | +}; | ||
| 68 | + | ||
| 39 | #endif | 69 | #endif |
-
请 注册 或 登录 后发表评论