Fix context string ID bug

pull/1830/head
winlin 5 years ago
parent 83ce78a015
commit 7627c290c9

@ -129,3 +129,11 @@ VOID TEST(SampleTest, FastSampleMacrosTest)
EXPECT_NEAR(10, 15, 5);
}
VOID TEST(SampleTest, StringEQTest)
{
string str = "100";
EXPECT_TRUE("100" == str);
EXPECT_EQ("100", str);
EXPECT_STREQ("100", str.c_str());
}

@ -36,7 +36,7 @@ VOID TEST(AppCoroutineTest, Dummy)
SrsDummyCoroutine dc;
if (true) {
EXPECT_EQ(0, dc.cid());
EXPECT_EQ("", dc.cid());
srs_error_t err = dc.pull();
EXPECT_TRUE(err != srs_success);
@ -52,7 +52,7 @@ VOID TEST(AppCoroutineTest, Dummy)
if (true) {
dc.stop();
EXPECT_EQ(0, dc.cid());
EXPECT_EQ("", dc.cid());
srs_error_t err = dc.pull();
EXPECT_TRUE(err != srs_success);
@ -68,7 +68,7 @@ VOID TEST(AppCoroutineTest, Dummy)
if (true) {
dc.interrupt();
EXPECT_EQ(0, dc.cid());
EXPECT_EQ("", dc.cid());
srs_error_t err = dc.pull();
EXPECT_TRUE(err != srs_success);
@ -92,7 +92,7 @@ public:
// Quit without error.
bool quit;
public:
MockCoroutineHandler() : trd(NULL), err(srs_success), cid(0), quit(false) {
MockCoroutineHandler() : trd(NULL), err(srs_success), cid("0"), quit(false) {
running = srs_cond_new();
exited = srs_cond_new();
}
@ -128,12 +128,12 @@ VOID TEST(AppCoroutineTest, StartStop)
MockCoroutineHandler ch;
SrsSTCoroutine sc("test", &ch);
ch.trd = ≻
EXPECT_EQ(0, sc.cid());
EXPECT_EQ("", sc.cid());
// Thread stop after created.
sc.stop();
EXPECT_EQ(0, sc.cid());
EXPECT_EQ("", sc.cid());
srs_error_t err = sc.pull();
EXPECT_TRUE(srs_success != err);
@ -151,13 +151,13 @@ VOID TEST(AppCoroutineTest, StartStop)
MockCoroutineHandler ch;
SrsSTCoroutine sc("test", &ch);
ch.trd = ≻
EXPECT_EQ(0, sc.cid());
EXPECT_EQ("", sc.cid());
EXPECT_TRUE(srs_success == sc.start());
EXPECT_TRUE(srs_success == sc.pull());
srs_cond_timedwait(ch.running, 100 * SRS_UTIME_MILLISECONDS);
EXPECT_TRUE(sc.cid() > 0);
EXPECT_TRUE(!sc.cid().empty());
// Thread stop after started.
sc.stop();
@ -178,7 +178,7 @@ VOID TEST(AppCoroutineTest, StartStop)
MockCoroutineHandler ch;
SrsSTCoroutine sc("test", &ch);
ch.trd = ≻
EXPECT_EQ(0, sc.cid());
EXPECT_EQ("", sc.cid());
EXPECT_TRUE(srs_success == sc.start());
EXPECT_TRUE(srs_success == sc.pull());
@ -220,16 +220,16 @@ VOID TEST(AppCoroutineTest, Cycle)
if (true) {
MockCoroutineHandler ch;
SrsSTCoroutine sc("test", &ch, 250);
SrsSTCoroutine sc("test", &ch, "250");
ch.trd = ≻
EXPECT_EQ(250, sc.cid());
EXPECT_TRUE("250" == sc.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_EQ(250, ch.cid);
EXPECT_TRUE("250" == ch.cid);
}
if (true) {

@ -4106,9 +4106,9 @@ VOID TEST(KernelLogTest, CoverAll)
l.error("TAG", "0", "log");
ISrsThreadContext ctx;
ctx.set_id(10);
EXPECT_EQ("0", ctx.get_id());
EXPECT_EQ("0", ctx.generate_id());
ctx.set_id("10");
EXPECT_EQ("", ctx.get_id());
EXPECT_EQ("", ctx.generate_id());
}
}

@ -782,7 +782,7 @@ class MockOnCycleThread : public ISrsCoroutineHandler
public:
SrsSTCoroutine trd;
srs_cond_t cond;
MockOnCycleThread() : trd("mock", this, 0) {
MockOnCycleThread() : trd("mock", this, "0") {
cond = srs_cond_new();
};
virtual ~MockOnCycleThread() {
@ -822,7 +822,7 @@ class MockOnCycleThread2 : public ISrsCoroutineHandler
public:
SrsSTCoroutine trd;
srs_mutex_t lock;
MockOnCycleThread2() : trd("mock", this, 0) {
MockOnCycleThread2() : trd("mock", this, "0") {
lock = srs_mutex_new();
};
virtual ~MockOnCycleThread2() {
@ -863,7 +863,7 @@ class MockOnCycleThread3 : public ISrsCoroutineHandler
public:
SrsSTCoroutine trd;
srs_netfd_t fd;
MockOnCycleThread3() : trd("mock", this, 0) {
MockOnCycleThread3() : trd("mock", this, "0") {
fd = NULL;
};
virtual ~MockOnCycleThread3() {
@ -1116,7 +1116,7 @@ class MockOnCycleThread4 : public ISrsCoroutineHandler
public:
SrsSTCoroutine trd;
srs_netfd_t fd;
MockOnCycleThread4() : trd("mock", this, 0) {
MockOnCycleThread4() : trd("mock", this, "0") {
fd = NULL;
};
virtual ~MockOnCycleThread4() {
@ -1268,18 +1268,18 @@ VOID TEST(TCPServerTest, ContextUtility)
if (true) {
SrsThreadContext ctx;
EXPECT_EQ("0", ctx.set_id("100"));
EXPECT_EQ("100", ctx.set_id("1000"));
EXPECT_EQ("1000", ctx.get_id());
EXPECT_TRUE("" == ctx.set_id("100"));
EXPECT_TRUE("100" == ctx.set_id("1000"));
EXPECT_TRUE("1000" == ctx.get_id());
ctx.clear_cid();
EXPECT_EQ("0", ctx.set_id("100"));
EXPECT_TRUE("" == ctx.set_id("100"));
}
int base_size = 0;
if (true) {
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
ASSERT_TRUE(srs_log_header(buf, 1024, true, true, "SRS", 100, "Trace", &size));
ASSERT_TRUE(srs_log_header(buf, 1024, true, true, "SRS", "100", "Trace", &size));
base_size = size;
EXPECT_TRUE(base_size > 0);
}

Loading…
Cancel
Save