From b095c157208028c70c89475d0d68ed2b6b2b1195 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 30 Aug 2020 11:55:18 +0800 Subject: [PATCH] Fix utest fail --- trunk/src/utest/srs_utest_app.cpp | 10 +++++---- trunk/src/utest/srs_utest_rtc.cpp | 2 +- trunk/src/utest/srs_utest_service.cpp | 31 ++++++++++++++++++++------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/trunk/src/utest/srs_utest_app.cpp b/trunk/src/utest/srs_utest_app.cpp index e04a859de..010ed4272 100644 --- a/trunk/src/utest/srs_utest_app.cpp +++ b/trunk/src/utest/srs_utest_app.cpp @@ -92,7 +92,8 @@ public: // Quit without error. bool quit; public: - MockCoroutineHandler() : trd(NULL), err(srs_success), cid("0"), quit(false) { + MockCoroutineHandler() : trd(NULL), err(srs_success), quit(false) { + cid.set_value("0"); running = srs_cond_new(); exited = srs_cond_new(); } @@ -220,16 +221,17 @@ VOID TEST(AppCoroutineTest, Cycle) if (true) { MockCoroutineHandler ch; - SrsSTCoroutine sc("test", &ch, SrsContextId("250")); + SrsContextId cid; + SrsSTCoroutine sc("test", &ch, cid.set_value("250")); ch.trd = ≻ - EXPECT_TRUE(!sc.cid().compare(SrsContextId("250"))); + EXPECT_TRUE(!sc.cid().compare(cid)); EXPECT_TRUE(srs_success == sc.start()); EXPECT_TRUE(srs_success == sc.pull()); // After running, the cid in cycle should equal to the thread. srs_cond_timedwait(ch.running, 100 * SRS_UTIME_MILLISECONDS); - EXPECT_TRUE(!ch.cid.compare(SrsContextId("250"))); + EXPECT_TRUE(!ch.cid.compare(cid)); } if (true) { diff --git a/trunk/src/utest/srs_utest_rtc.cpp b/trunk/src/utest/srs_utest_rtc.cpp index d7d850dba..2a00be08b 100644 --- a/trunk/src/utest/srs_utest_rtc.cpp +++ b/trunk/src/utest/srs_utest_rtc.cpp @@ -1183,7 +1183,7 @@ VOID TEST(KernelRTCTest, DefaultTrackStatus) // Enable it by publisher. if (true) { - SrsRtcConnection s(NULL, SrsContextId()); SrsRtcPublishStream publish(&s); + SrsRtcConnection s(NULL, SrsContextId()); SrsRtcPublishStream publish(&s, SrsContextId()); SrsRtcAudioRecvTrack* audio; SrsRtcVideoRecvTrack *video; if (true) { diff --git a/trunk/src/utest/srs_utest_service.cpp b/trunk/src/utest/srs_utest_service.cpp index 9f075e477..75e33b546 100644 --- a/trunk/src/utest/srs_utest_service.cpp +++ b/trunk/src/utest/srs_utest_service.cpp @@ -1382,19 +1382,34 @@ VOID TEST(TCPServerTest, ContextUtility) if (true) { SrsThreadContext ctx; - EXPECT_TRUE(!ctx.set_id(SrsContextId("100")).compare(SrsContextId("100"))); - EXPECT_TRUE(!ctx.set_id(SrsContextId("1000")).compare(SrsContextId("1000"))); - EXPECT_TRUE(!ctx.get_id().compare(SrsContextId("1000"))); + if (true) { + SrsContextId cid; + EXPECT_TRUE(!ctx.set_id(cid.set_value("100")).compare(cid)); + } + if (true) { + SrsContextId cid; + EXPECT_TRUE(!ctx.set_id(cid.set_value("1000")).compare(cid)); + } + if (true) { + SrsContextId cid; + EXPECT_TRUE(!ctx.get_id().compare(cid.set_value("1000"))); + } ctx.clear_cid(); - EXPECT_TRUE(!ctx.set_id(SrsContextId("100")).compare(SrsContextId("100"))); + if (true) { + SrsContextId cid; + EXPECT_TRUE(!ctx.set_id(cid.set_value("100")).compare(cid)); + } } + SrsContextId cid; + cid.set_value("100"); + int base_size = 0; if (true) { errno = 0; int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0); - ASSERT_TRUE(srs_log_header(buf, 1024, true, true, "SRS", SrsContextId("100"), "Trace", &size)); + ASSERT_TRUE(srs_log_header(buf, 1024, true, true, "SRS", cid, "Trace", &size)); base_size = size; EXPECT_TRUE(base_size > 0); } @@ -1402,21 +1417,21 @@ VOID TEST(TCPServerTest, ContextUtility) if (true) { errno = 0; int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0); - ASSERT_TRUE(srs_log_header(buf, 1024, false, true, "SRS", SrsContextId("100"), "Trace", &size)); + ASSERT_TRUE(srs_log_header(buf, 1024, false, true, "SRS", cid, "Trace", &size)); EXPECT_EQ(base_size, size); } if (true) { errno = 0; int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0); - ASSERT_TRUE(srs_log_header(buf, 1024, false, true, NULL, SrsContextId("100"), "Trace", &size)); + ASSERT_TRUE(srs_log_header(buf, 1024, false, true, NULL, cid, "Trace", &size)); EXPECT_EQ(base_size - 5, size); } if (true) { errno = 0; int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0); - ASSERT_TRUE(srs_log_header(buf, 1024, false, false, NULL, SrsContextId("100"), "Trace", &size)); + ASSERT_TRUE(srs_log_header(buf, 1024, false, false, NULL, cid, "Trace", &size)); EXPECT_EQ(base_size - 8, size); }