diff --git a/trunk/src/core/srs_core.cpp b/trunk/src/core/srs_core.cpp index 8f409f4ec..539f4e267 100644 --- a/trunk/src/core/srs_core.cpp +++ b/trunk/src/core/srs_core.cpp @@ -37,6 +37,12 @@ _SrsContextId::_SrsContextId(const _SrsContextId& cp) v_ = cp.v_; } +_SrsContextId& _SrsContextId::operator=(const _SrsContextId& cp) +{ + v_ = cp.v_; + return *this; +} + _SrsContextId::~_SrsContextId() { } diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index a68549697..bb983c2af 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -125,6 +125,7 @@ public: _SrsContextId(); _SrsContextId(std::string v); _SrsContextId(const _SrsContextId& cp); + _SrsContextId& operator=(const _SrsContextId& cp); virtual ~_SrsContextId(); public: const char* c_str() const; diff --git a/trunk/src/utest/srs_utest.cpp b/trunk/src/utest/srs_utest.cpp index 9d8678518..20a691a15 100644 --- a/trunk/src/utest/srs_utest.cpp +++ b/trunk/src/utest/srs_utest.cpp @@ -137,3 +137,47 @@ VOID TEST(SampleTest, StringEQTest) EXPECT_STREQ("100", str.c_str()); } +class MockSrsContextId +{ +public: + MockSrsContextId() { + bind_ = NULL; + } + MockSrsContextId(const MockSrsContextId& cp){ + bind_ = NULL; + if (cp.bind_) { + bind_ = cp.bind_->copy(); + } + } + MockSrsContextId& operator= (const MockSrsContextId& cp) { + srs_freep(bind_); + if (cp.bind_) { + bind_ = cp.bind_->copy(); + } + return *this; + } + virtual ~MockSrsContextId() { + srs_freep(bind_); + } +public: + MockSrsContextId* copy() const { + MockSrsContextId* cp = new MockSrsContextId(); + if (bind_) { + cp->bind_ = bind_->copy(); + } + return cp; + } +private: + MockSrsContextId* bind_; +}; + +VOID TEST(SampleTest, ContextTest) +{ + MockSrsContextId cid; + cid.bind_ = new MockSrsContextId(); + + static std::map cache; + cache[0] = cid; + cache[0] = cid; +} +