MCPcopy Create free account
hub / github.com/apache/brpc / TEST

Function TEST

test/bounded_queue_unittest.cc:26–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24namespace {
25
26TEST(BoundedQueueTest, sanity) {
27 const int N = 36;
28 char storage[N * sizeof(int)];
29 butil::BoundedQueue<int> q(storage, sizeof(storage), butil::NOT_OWN_STORAGE);
30 ASSERT_EQ(0ul, q.size());
31 ASSERT_TRUE(q.empty());
32 ASSERT_TRUE(NULL == q.top());
33 ASSERT_TRUE(NULL == q.bottom());
34 for (int i = 1; i <= N; ++i) {
35 if (i % 2 == 0) {
36 ASSERT_TRUE(q.push(i));
37 } else {
38 int* p = q.push();
39 ASSERT_TRUE(p);
40 *p = i;
41 }
42 ASSERT_EQ((size_t)i, q.size());
43 ASSERT_EQ(1, *q.top());
44 ASSERT_EQ(i, *q.bottom());
45 }
46 ASSERT_FALSE(q.push(N+1));
47 ASSERT_FALSE(q.push_top(N+1));
48 ASSERT_EQ((size_t)N, q.size());
49 ASSERT_FALSE(q.empty());
50 ASSERT_TRUE(q.full());
51
52 for (int i = 1; i <= N; ++i) {
53 ASSERT_EQ(i, *q.top());
54 ASSERT_EQ(N, *q.bottom());
55 if (i % 2 == 0) {
56 int tmp = 0;
57 ASSERT_TRUE(q.pop(&tmp));
58 ASSERT_EQ(tmp, i);
59 } else {
60 ASSERT_TRUE(q.pop());
61 }
62 ASSERT_EQ((size_t)(N-i), q.size());
63 }
64 ASSERT_EQ(0ul, q.size());
65 ASSERT_TRUE(q.empty());
66 ASSERT_FALSE(q.full());
67 ASSERT_FALSE(q.pop());
68
69 for (int i = 1; i <= N; ++i) {
70 if (i % 2 == 0) {
71 ASSERT_TRUE(q.push_top(i));
72 } else {
73 int* p = q.push_top();
74 ASSERT_TRUE(p);
75 *p = i;
76 }
77 ASSERT_EQ((size_t)i, q.size());
78 ASSERT_EQ(i, *q.top());
79 ASSERT_EQ(1, *q.bottom());
80 }
81 ASSERT_FALSE(q.push(N+1));
82 ASSERT_FALSE(q.push_top(N+1));
83 ASSERT_EQ((size_t)N, q.size());

Callers

nothing calls this directly

Calls 9

topMethod · 0.80
bottomMethod · 0.80
push_topMethod · 0.80
pop_bottomMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
pushMethod · 0.45
fullMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected