diff --git a/trunk/src/rtmp/srs_protocol_amf0.hpp b/trunk/src/rtmp/srs_protocol_amf0.hpp index 7ee3f5576..06cceb4c3 100644 --- a/trunk/src/rtmp/srs_protocol_amf0.hpp +++ b/trunk/src/rtmp/srs_protocol_amf0.hpp @@ -60,6 +60,10 @@ public: virtual bool is_object_eof(); virtual bool is_ecma_array(); public: + /** + * get the string of any when is_string() indicates true. + * user must ensure the type is a string, or assert failed. + */ virtual std::string to_str(); public: virtual int size() = 0; diff --git a/trunk/src/utest/srs_utest_amf0.cpp b/trunk/src/utest/srs_utest_amf0.cpp index a309a85fc..9df0db4be 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 +#include + VOID TEST(AMF0Test, Size) { // size of elem @@ -259,3 +261,24 @@ VOID TEST(AMF0Test, Size) EXPECT_EQ(size, SrsAmf0Size::array(&o)); } } + +VOID TEST(AMF0Test, AnyElem) +{ + SrsAmf0Any* o = NULL; + + // string + if (true) { + o = SrsAmf0Any::str(); + SrsAutoFree(SrsAmf0Any, o, false); + EXPECT_TRUE(NULL != o); + EXPECT_TRUE(o->is_string()); + EXPECT_STREQ("", o->to_str().c_str()); + } + if (true) { + o = SrsAmf0Any::str("winlin"); + SrsAutoFree(SrsAmf0Any, o, false); + EXPECT_TRUE(NULL != o); + EXPECT_TRUE(o->is_string()); + EXPECT_STREQ("winlin", o->to_str().c_str()); + } +}