1 #include <gtest/gtest.h>
4 #include <boost/thread.hpp>
7 TEST(SharedQueueTest, emptyOnConstuct) {
11 ASSERT_TRUE(sq.
empty());
14 TEST(SharedQueueTest, notEmptyAfterPush) {
19 ASSERT_FALSE(sq.
empty());
22 TEST(SharedQueueTest, notEmptyAfterPushMultiple) {
26 for (
int i = 0; i < 5; ++i) {
33 ASSERT_FALSE(sq.
empty());
36 TEST(SharedQueueTest, emptyAfterPushAndPop) {
41 ASSERT_FALSE(sq.
empty());
46 ASSERT_TRUE(sq.
empty());
49 TEST(SharedQueueTest, pushFrontPop) {
52 for (
int i = 0; i < 5; ++i) {
56 for (
int i = 0; i < 5; ++i) {
57 ASSERT_EQ(i, sq.
front());
61 for (
int i = 0; i < 5; ++i) {
65 for (
int i = 0; i < 5; ++i) {
70 ASSERT_TRUE(sq.
empty());
71 ASSERT_EQ(0, sq.
size());
74 TEST(SharedQueueTest, copy) {
78 for (
int i = 0; i < 5; ++i) {
84 ASSERT_FALSE(sq1.
empty());
85 ASSERT_EQ(5, sq1.
size());
87 for (
int i = 0; i < 5; ++i) {
92 ASSERT_TRUE(sq1.
empty());
93 ASSERT_EQ(0, sq1.
size());
97 ASSERT_FALSE(sq0.
empty());
98 ASSERT_EQ(5, sq0.
size());
101 TEST(SharedQueueTest, copyConstruct) {
104 for (
int i = 0; i < 5; ++i) {
110 ASSERT_FALSE(sq1.
empty());
111 ASSERT_EQ(5, sq1.
size());
113 for (
int i = 0; i < 5; ++i) {
118 ASSERT_TRUE(sq1.
empty());
119 ASSERT_EQ(0, sq1.
size());
123 ASSERT_FALSE(sq0.
empty());
124 ASSERT_EQ(5, sq0.
size());
127 TEST(SharedQueueTest, pushConstCopyFront) {
130 for (
int i = 0; i < 5; ++i) {
137 ASSERT_FALSE(sq.
empty());
138 ASSERT_EQ(5, sq.
size());
140 const int &front = csq.
front();
144 TEST(SharedQueueTest, pushPopSize) {
147 for (
int i = 0; i < 5; ++i) {
149 ASSERT_EQ(i + 1, sq.
size());
152 ASSERT_EQ(5, sq.
size());
154 for (
int i = 0; i < 5; ++i) {
155 ASSERT_EQ(5 - i, sq.
size());
160 TEST(SharedQueueTest, pushMultipleSize) {
164 for (
int i = 0; i < 5; ++i) {
169 ASSERT_EQ(5, sq.
size());
173 for (
int i = 0; i < 100; ++i) {
175 ASSERT_FALSE(sq->
empty());
176 ASSERT_EQ(i, sq->
front());
181 TEST(SharedQueueTest, pushFrontPopThreaded) {
184 for (
int i = 0; i < 100; ++i) {
188 boost::thread popThread = boost::thread(
pop_thread, &sq);
192 ASSERT_TRUE(sq.
empty());
193 ASSERT_EQ(0, sq.
size());
196 int main(
int argc,
char **argv) {
197 testing::InitGoogleTest(&argc, argv);
198 return RUN_ALL_TESTS();