diff --git a/trunk/configure b/trunk/configure index 5c35087c4..aacaaf83b 100755 --- a/trunk/configure +++ b/trunk/configure @@ -489,7 +489,8 @@ fi # # utest, the unit-test cases of srs, base on gtest1.6 MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_protocol" - "srs_utest_kernel" "srs_utest_core" "srs_utest_config") + "srs_utest_kernel" "srs_utest_core" "srs_utest_config" + "srs_utest_reload") ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot}) ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile}) MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index b6a81236c..2c7a595c9 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -86,7 +86,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // so we remove the srs_freepa utility. /** -* disable copy constructor of class +* disable copy constructor of class, +* to avoid the memory leak or corrupt by copy instance. */ #define disable_default_copy(className)\ private:\ diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 113251d62..fdd0b0dbe 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -101,6 +101,11 @@ int main(int argc, char** argv) srs_trace("arm tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN); #endif + /** + * we do nothing in the constructor of server, + * and use initialize to create members, set hooks for instance the reload handler, + * all initialize will done in this stage. + */ if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) { return ret; } diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index f725ba037..63c2cfa74 100755 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -125,6 +125,8 @@ file ..\utest\srs_utest_kernel.cpp, ..\utest\srs_utest_protocol.hpp, ..\utest\srs_utest_protocol.cpp, + ..\utest\srs_utest_reload.hpp, + ..\utest\srs_utest_reload.cpp, research readonly separator, ..\..\research\librtmp\srs_bandwidth_check.c, ..\..\research\librtmp\srs_detect_rtmp.c, @@ -140,4 +142,3 @@ file mainconfig "" = "MAIN"; - diff --git a/trunk/src/utest/srs_utest.hpp b/trunk/src/utest/srs_utest.hpp index db7639de1..32a7de829 100644 --- a/trunk/src/utest/srs_utest.hpp +++ b/trunk/src/utest/srs_utest.hpp @@ -33,6 +33,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +// enable all utest. +#if 1 + #define ENABLE_UTEST_AMF0 + #define ENABLE_UTEST_CONFIG + #define ENABLE_UTEST_CORE + #define ENABLE_UTEST_KERNEL + #define ENABLE_UTEST_PROTOCOL + #define ENABLE_UTEST_RELOAD +#endif + +// disable some for fast dev, compile and startup. +#if 1 + #undef ENABLE_UTEST_AMF0 + #undef ENABLE_UTEST_CONFIG + #undef ENABLE_UTEST_CORE + #undef ENABLE_UTEST_KERNEL + #undef ENABLE_UTEST_PROTOCOL + #undef ENABLE_UTEST_RELOAD +#endif + // we add an empty macro for upp to show the smart tips. #define VOID diff --git a/trunk/src/utest/srs_utest_amf0.cpp b/trunk/src/utest/srs_utest_amf0.cpp index 98c88dfd8..009a5dfba 100644 --- a/trunk/src/utest/srs_utest_amf0.cpp +++ b/trunk/src/utest/srs_utest_amf0.cpp @@ -22,6 +22,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#ifdef ENABLE_UTEST_AMF0 + #include using namespace std; @@ -1269,3 +1271,5 @@ VOID TEST(ProtocolAMF0Test, ObjectEcmaStrict) EXPECT_EQ(0, arr3->to_ecma_array()->count()); } +#endif + diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 6f8c961b4..c7d0c677e 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -29,6 +29,47 @@ using namespace std; #include #include +MockSrsConfigBuffer::MockSrsConfigBuffer(string buf) +{ + // read all. + int filesize = (int)buf.length(); + + if (filesize <= 0) { + return; + } + + // create buffer + pos = last = start = new char[filesize]; + end = start + filesize; + + memcpy(start, buf.data(), filesize); +} + +MockSrsConfigBuffer::~MockSrsConfigBuffer() +{ +} + +int MockSrsConfigBuffer::fullfill(const char* /*filename*/) +{ + return ERROR_SUCCESS; +} + +MockSrsConfig::MockSrsConfig() +{ +} + +MockSrsConfig::~MockSrsConfig() +{ +} + +int MockSrsConfig::parse(string buf) +{ + MockSrsConfigBuffer buffer(buf); + return parse_buffer(&buffer); +} + +#ifdef ENABLE_UTEST_CONFIG + #define _MIN_OK_CONF "listen 1935; " // full.conf @@ -993,45 +1034,6 @@ std::string __full_conf = "" "} \n" ; -MockSrsConfigBuffer::MockSrsConfigBuffer(string buf) -{ - // read all. - int filesize = (int)buf.length(); - - if (filesize <= 0) { - return; - } - - // create buffer - pos = last = start = new char[filesize]; - end = start + filesize; - - memcpy(start, buf.data(), filesize); -} - -MockSrsConfigBuffer::~MockSrsConfigBuffer() -{ -} - -int MockSrsConfigBuffer::fullfill(const char* /*filename*/) -{ - return ERROR_SUCCESS; -} - -MockSrsConfig::MockSrsConfig() -{ -} - -MockSrsConfig::~MockSrsConfig() -{ -} - -int MockSrsConfig::parse(string buf) -{ - MockSrsConfigBuffer buffer(buf); - return parse_buffer(&buffer); -} - VOID TEST(ConfigTest, CheckMacros) { #ifndef SRS_CONSTS_LOCALHOST @@ -5452,3 +5454,5 @@ VOID TEST(ConfigMainTest, CheckConf_pithy_print) } } +#endif + diff --git a/trunk/src/utest/srs_utest_core.cpp b/trunk/src/utest/srs_utest_core.cpp index 60ad82bb1..6b1e43bc0 100644 --- a/trunk/src/utest/srs_utest_core.cpp +++ b/trunk/src/utest/srs_utest_core.cpp @@ -22,6 +22,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#ifdef ENABLE_UTEST_CORE + using namespace std; #include @@ -67,3 +69,5 @@ VOID TEST(CoreMacroseTest, Check) #endif } +#endif + diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index e11d01854..166981cc8 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -199,6 +199,8 @@ int MockBufferReader::read(void* buf, size_t size, ssize_t* nread) return ERROR_SUCCESS; } +#ifdef ENABLE_UTEST_KERNEL + VOID TEST(KernelBufferTest, DefaultObject) { SrsBuffer b; @@ -1510,3 +1512,5 @@ VOID TEST(KernelUtilityTest, UtilityString) EXPECT_TRUE(srs_string_ends_with("Hello", "lo")); } +#endif + diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index 281d7d783..77e545d31 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -203,6 +203,8 @@ int MockBufferIO::read(void* buf, size_t size, ssize_t* nread) return ERROR_SUCCESS; } +#ifdef ENABLE_UTEST_PROTOCOL + #ifdef SRS_AUTO_SSL // verify the sha256 @@ -5598,4 +5600,5 @@ VOID TEST(ProtocolRTMPTest, RTMPHandshakeBytes) EXPECT_TRUE(bytes.s0s1s2 != NULL); } +#endif diff --git a/trunk/src/utest/srs_utest_reload.cpp b/trunk/src/utest/srs_utest_reload.cpp new file mode 100644 index 000000000..e157fee96 --- /dev/null +++ b/trunk/src/utest/srs_utest_reload.cpp @@ -0,0 +1,29 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013-2014 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 + +#ifdef ENABLE_UTEST_RELOAD + +#endif + diff --git a/trunk/src/utest/srs_utest_reload.hpp b/trunk/src/utest/srs_utest_reload.hpp new file mode 100644 index 000000000..c035caaae --- /dev/null +++ b/trunk/src/utest/srs_utest_reload.hpp @@ -0,0 +1,33 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013-2014 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. +*/ + +#ifndef SRS_UTEST_RELOAD_HPP +#define SRS_UTEST_RELOAD_HPP + +/* +#include +*/ +#include + +#endif +