正在显示
12 个修改的文件
包含
151 行增加
和
42 行删除
| @@ -489,7 +489,8 @@ fi | @@ -489,7 +489,8 @@ fi | ||
| 489 | # | 489 | # |
| 490 | # utest, the unit-test cases of srs, base on gtest1.6 | 490 | # utest, the unit-test cases of srs, base on gtest1.6 |
| 491 | MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_protocol" | 491 | MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_protocol" |
| 492 | - "srs_utest_kernel" "srs_utest_core" "srs_utest_config") | 492 | + "srs_utest_kernel" "srs_utest_core" "srs_utest_config" |
| 493 | + "srs_utest_reload") | ||
| 493 | ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot}) | 494 | ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot}) |
| 494 | ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile}) | 495 | ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile}) |
| 495 | MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") | 496 | MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") |
| @@ -86,7 +86,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -86,7 +86,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 86 | // so we remove the srs_freepa utility. | 86 | // so we remove the srs_freepa utility. |
| 87 | 87 | ||
| 88 | /** | 88 | /** |
| 89 | -* disable copy constructor of class | 89 | +* disable copy constructor of class, |
| 90 | +* to avoid the memory leak or corrupt by copy instance. | ||
| 90 | */ | 91 | */ |
| 91 | #define disable_default_copy(className)\ | 92 | #define disable_default_copy(className)\ |
| 92 | private:\ | 93 | private:\ |
| @@ -101,6 +101,11 @@ int main(int argc, char** argv) | @@ -101,6 +101,11 @@ int main(int argc, char** argv) | ||
| 101 | srs_trace("arm tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN); | 101 | srs_trace("arm tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN); |
| 102 | #endif | 102 | #endif |
| 103 | 103 | ||
| 104 | + /** | ||
| 105 | + * we do nothing in the constructor of server, | ||
| 106 | + * and use initialize to create members, set hooks for instance the reload handler, | ||
| 107 | + * all initialize will done in this stage. | ||
| 108 | + */ | ||
| 104 | if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) { | 109 | if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) { |
| 105 | return ret; | 110 | return ret; |
| 106 | } | 111 | } |
| @@ -125,6 +125,8 @@ file | @@ -125,6 +125,8 @@ file | ||
| 125 | ..\utest\srs_utest_kernel.cpp, | 125 | ..\utest\srs_utest_kernel.cpp, |
| 126 | ..\utest\srs_utest_protocol.hpp, | 126 | ..\utest\srs_utest_protocol.hpp, |
| 127 | ..\utest\srs_utest_protocol.cpp, | 127 | ..\utest\srs_utest_protocol.cpp, |
| 128 | + ..\utest\srs_utest_reload.hpp, | ||
| 129 | + ..\utest\srs_utest_reload.cpp, | ||
| 128 | research readonly separator, | 130 | research readonly separator, |
| 129 | ..\..\research\librtmp\srs_bandwidth_check.c, | 131 | ..\..\research\librtmp\srs_bandwidth_check.c, |
| 130 | ..\..\research\librtmp\srs_detect_rtmp.c, | 132 | ..\..\research\librtmp\srs_detect_rtmp.c, |
| @@ -140,4 +142,3 @@ file | @@ -140,4 +142,3 @@ file | ||
| 140 | mainconfig | 142 | mainconfig |
| 141 | "" = "MAIN"; | 143 | "" = "MAIN"; |
| 142 | 144 | ||
| 143 | - |
| @@ -33,6 +33,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -33,6 +33,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 33 | 33 | ||
| 34 | #include <srs_app_log.hpp> | 34 | #include <srs_app_log.hpp> |
| 35 | 35 | ||
| 36 | +// enable all utest. | ||
| 37 | +#if 1 | ||
| 38 | + #define ENABLE_UTEST_AMF0 | ||
| 39 | + #define ENABLE_UTEST_CONFIG | ||
| 40 | + #define ENABLE_UTEST_CORE | ||
| 41 | + #define ENABLE_UTEST_KERNEL | ||
| 42 | + #define ENABLE_UTEST_PROTOCOL | ||
| 43 | + #define ENABLE_UTEST_RELOAD | ||
| 44 | +#endif | ||
| 45 | + | ||
| 46 | +// disable some for fast dev, compile and startup. | ||
| 47 | +#if 1 | ||
| 48 | + #undef ENABLE_UTEST_AMF0 | ||
| 49 | + #undef ENABLE_UTEST_CONFIG | ||
| 50 | + #undef ENABLE_UTEST_CORE | ||
| 51 | + #undef ENABLE_UTEST_KERNEL | ||
| 52 | + #undef ENABLE_UTEST_PROTOCOL | ||
| 53 | + #undef ENABLE_UTEST_RELOAD | ||
| 54 | +#endif | ||
| 55 | + | ||
| 36 | // we add an empty macro for upp to show the smart tips. | 56 | // we add an empty macro for upp to show the smart tips. |
| 37 | #define VOID | 57 | #define VOID |
| 38 | 58 |
| @@ -22,6 +22,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -22,6 +22,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | */ | 22 | */ |
| 23 | #include <srs_utest_amf0.hpp> | 23 | #include <srs_utest_amf0.hpp> |
| 24 | 24 | ||
| 25 | +#ifdef ENABLE_UTEST_AMF0 | ||
| 26 | + | ||
| 25 | #include <string> | 27 | #include <string> |
| 26 | using namespace std; | 28 | using namespace std; |
| 27 | 29 | ||
| @@ -1269,3 +1271,5 @@ VOID TEST(ProtocolAMF0Test, ObjectEcmaStrict) | @@ -1269,3 +1271,5 @@ VOID TEST(ProtocolAMF0Test, ObjectEcmaStrict) | ||
| 1269 | EXPECT_EQ(0, arr3->to_ecma_array()->count()); | 1271 | EXPECT_EQ(0, arr3->to_ecma_array()->count()); |
| 1270 | } | 1272 | } |
| 1271 | 1273 | ||
| 1274 | +#endif | ||
| 1275 | + |
| @@ -29,6 +29,47 @@ using namespace std; | @@ -29,6 +29,47 @@ using namespace std; | ||
| 29 | #include <srs_kernel_error.hpp> | 29 | #include <srs_kernel_error.hpp> |
| 30 | #include <srs_app_source.hpp> | 30 | #include <srs_app_source.hpp> |
| 31 | 31 | ||
| 32 | +MockSrsConfigBuffer::MockSrsConfigBuffer(string buf) | ||
| 33 | +{ | ||
| 34 | + // read all. | ||
| 35 | + int filesize = (int)buf.length(); | ||
| 36 | + | ||
| 37 | + if (filesize <= 0) { | ||
| 38 | + return; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + // create buffer | ||
| 42 | + pos = last = start = new char[filesize]; | ||
| 43 | + end = start + filesize; | ||
| 44 | + | ||
| 45 | + memcpy(start, buf.data(), filesize); | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +MockSrsConfigBuffer::~MockSrsConfigBuffer() | ||
| 49 | +{ | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +int MockSrsConfigBuffer::fullfill(const char* /*filename*/) | ||
| 53 | +{ | ||
| 54 | + return ERROR_SUCCESS; | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +MockSrsConfig::MockSrsConfig() | ||
| 58 | +{ | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +MockSrsConfig::~MockSrsConfig() | ||
| 62 | +{ | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +int MockSrsConfig::parse(string buf) | ||
| 66 | +{ | ||
| 67 | + MockSrsConfigBuffer buffer(buf); | ||
| 68 | + return parse_buffer(&buffer); | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +#ifdef ENABLE_UTEST_CONFIG | ||
| 72 | + | ||
| 32 | #define _MIN_OK_CONF "listen 1935; " | 73 | #define _MIN_OK_CONF "listen 1935; " |
| 33 | 74 | ||
| 34 | // full.conf | 75 | // full.conf |
| @@ -993,45 +1034,6 @@ std::string __full_conf = "" | @@ -993,45 +1034,6 @@ std::string __full_conf = "" | ||
| 993 | "} \n" | 1034 | "} \n" |
| 994 | ; | 1035 | ; |
| 995 | 1036 | ||
| 996 | -MockSrsConfigBuffer::MockSrsConfigBuffer(string buf) | ||
| 997 | -{ | ||
| 998 | - // read all. | ||
| 999 | - int filesize = (int)buf.length(); | ||
| 1000 | - | ||
| 1001 | - if (filesize <= 0) { | ||
| 1002 | - return; | ||
| 1003 | - } | ||
| 1004 | - | ||
| 1005 | - // create buffer | ||
| 1006 | - pos = last = start = new char[filesize]; | ||
| 1007 | - end = start + filesize; | ||
| 1008 | - | ||
| 1009 | - memcpy(start, buf.data(), filesize); | ||
| 1010 | -} | ||
| 1011 | - | ||
| 1012 | -MockSrsConfigBuffer::~MockSrsConfigBuffer() | ||
| 1013 | -{ | ||
| 1014 | -} | ||
| 1015 | - | ||
| 1016 | -int MockSrsConfigBuffer::fullfill(const char* /*filename*/) | ||
| 1017 | -{ | ||
| 1018 | - return ERROR_SUCCESS; | ||
| 1019 | -} | ||
| 1020 | - | ||
| 1021 | -MockSrsConfig::MockSrsConfig() | ||
| 1022 | -{ | ||
| 1023 | -} | ||
| 1024 | - | ||
| 1025 | -MockSrsConfig::~MockSrsConfig() | ||
| 1026 | -{ | ||
| 1027 | -} | ||
| 1028 | - | ||
| 1029 | -int MockSrsConfig::parse(string buf) | ||
| 1030 | -{ | ||
| 1031 | - MockSrsConfigBuffer buffer(buf); | ||
| 1032 | - return parse_buffer(&buffer); | ||
| 1033 | -} | ||
| 1034 | - | ||
| 1035 | VOID TEST(ConfigTest, CheckMacros) | 1037 | VOID TEST(ConfigTest, CheckMacros) |
| 1036 | { | 1038 | { |
| 1037 | #ifndef SRS_CONSTS_LOCALHOST | 1039 | #ifndef SRS_CONSTS_LOCALHOST |
| @@ -5452,3 +5454,5 @@ VOID TEST(ConfigMainTest, CheckConf_pithy_print) | @@ -5452,3 +5454,5 @@ VOID TEST(ConfigMainTest, CheckConf_pithy_print) | ||
| 5452 | } | 5454 | } |
| 5453 | } | 5455 | } |
| 5454 | 5456 | ||
| 5457 | +#endif | ||
| 5458 | + |
| @@ -22,6 +22,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -22,6 +22,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | */ | 22 | */ |
| 23 | #include <srs_utest_core.hpp> | 23 | #include <srs_utest_core.hpp> |
| 24 | 24 | ||
| 25 | +#ifdef ENABLE_UTEST_CORE | ||
| 26 | + | ||
| 25 | using namespace std; | 27 | using namespace std; |
| 26 | 28 | ||
| 27 | #include <srs_core_autofree.hpp> | 29 | #include <srs_core_autofree.hpp> |
| @@ -67,3 +69,5 @@ VOID TEST(CoreMacroseTest, Check) | @@ -67,3 +69,5 @@ VOID TEST(CoreMacroseTest, Check) | ||
| 67 | #endif | 69 | #endif |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 72 | +#endif | ||
| 73 | + |
| @@ -199,6 +199,8 @@ int MockBufferReader::read(void* buf, size_t size, ssize_t* nread) | @@ -199,6 +199,8 @@ int MockBufferReader::read(void* buf, size_t size, ssize_t* nread) | ||
| 199 | return ERROR_SUCCESS; | 199 | return ERROR_SUCCESS; |
| 200 | } | 200 | } |
| 201 | 201 | ||
| 202 | +#ifdef ENABLE_UTEST_KERNEL | ||
| 203 | + | ||
| 202 | VOID TEST(KernelBufferTest, DefaultObject) | 204 | VOID TEST(KernelBufferTest, DefaultObject) |
| 203 | { | 205 | { |
| 204 | SrsBuffer b; | 206 | SrsBuffer b; |
| @@ -1510,3 +1512,5 @@ VOID TEST(KernelUtilityTest, UtilityString) | @@ -1510,3 +1512,5 @@ VOID TEST(KernelUtilityTest, UtilityString) | ||
| 1510 | EXPECT_TRUE(srs_string_ends_with("Hello", "lo")); | 1512 | EXPECT_TRUE(srs_string_ends_with("Hello", "lo")); |
| 1511 | } | 1513 | } |
| 1512 | 1514 | ||
| 1515 | +#endif | ||
| 1516 | + |
| @@ -203,6 +203,8 @@ int MockBufferIO::read(void* buf, size_t size, ssize_t* nread) | @@ -203,6 +203,8 @@ int MockBufferIO::read(void* buf, size_t size, ssize_t* nread) | ||
| 203 | return ERROR_SUCCESS; | 203 | return ERROR_SUCCESS; |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | +#ifdef ENABLE_UTEST_PROTOCOL | ||
| 207 | + | ||
| 206 | #ifdef SRS_AUTO_SSL | 208 | #ifdef SRS_AUTO_SSL |
| 207 | 209 | ||
| 208 | // verify the sha256 | 210 | // verify the sha256 |
| @@ -5598,4 +5600,5 @@ VOID TEST(ProtocolRTMPTest, RTMPHandshakeBytes) | @@ -5598,4 +5600,5 @@ VOID TEST(ProtocolRTMPTest, RTMPHandshakeBytes) | ||
| 5598 | EXPECT_TRUE(bytes.s0s1s2 != NULL); | 5600 | EXPECT_TRUE(bytes.s0s1s2 != NULL); |
| 5599 | } | 5601 | } |
| 5600 | 5602 | ||
| 5603 | +#endif | ||
| 5601 | 5604 |
trunk/src/utest/srs_utest_reload.cpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#include <srs_utest_reload.hpp> | ||
| 25 | + | ||
| 26 | +#ifdef ENABLE_UTEST_RELOAD | ||
| 27 | + | ||
| 28 | +#endif | ||
| 29 | + |
trunk/src/utest/srs_utest_reload.hpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_UTEST_RELOAD_HPP | ||
| 25 | +#define SRS_UTEST_RELOAD_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_utest_reload.hpp> | ||
| 29 | +*/ | ||
| 30 | +#include <srs_core.hpp> | ||
| 31 | + | ||
| 32 | +#endif | ||
| 33 | + |
-
请 注册 或 登录 后发表评论