forked from Haivision/srt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_threadname.cpp
More file actions
63 lines (51 loc) · 1.51 KB
/
test_threadname.cpp
File metadata and controls
63 lines (51 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <algorithm>
#include <string>
#include "gtest/gtest.h"
#include "hvu_threadname.h"
using namespace hvu;
TEST(ThreadName, GetSet)
{
std::string name("getset");
char buf[ThreadName::BUFSIZE * 2];
memset(buf, 'a', sizeof(buf));
ASSERT_EQ(ThreadName::get(buf), true);
// ensure doesn't write out-of-range
size_t max = ThreadName::BUFSIZE - 1;
ASSERT_LE(strlen(buf), max);
if (ThreadName::DUMMY_IMPL)
return;
ASSERT_EQ(ThreadName::set(name), true);
memset(buf, 'a', sizeof(buf));
ASSERT_EQ(ThreadName::get(buf), true);
ASSERT_EQ(buf, name);
}
TEST(ThreadName, AutoReset)
{
const std::string old_name("old");
std::string new_name("new-name");
if (ThreadName::DUMMY_IMPL)
{
// just make sure the API is correct
ThreadName t(std::string("test"));
return;
}
ASSERT_EQ(ThreadName::set(old_name), true);
std::string name;
ASSERT_EQ(ThreadName::get(name), true);
ASSERT_EQ(name, old_name);
{
ThreadName threadName(new_name);
ASSERT_EQ(ThreadName::get(name), true);
ASSERT_EQ(name, new_name);
}
ASSERT_EQ(ThreadName::get(name), true);
ASSERT_EQ(name, old_name);
{
new_name.resize(std::max<size_t>(512, ThreadName::BUFSIZE * 2), 'z');
ThreadName threadName(new_name);
ASSERT_EQ(ThreadName::get(name), true);
ASSERT_EQ(new_name.compare(0, name.size(), name), 0);
}
ASSERT_EQ(ThreadName::get(name), true);
ASSERT_EQ(name, old_name);
}