File tree Expand file tree Collapse file tree 3 files changed +50
-3
lines changed
Expand file tree Collapse file tree 3 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -33,9 +33,18 @@ add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
3333 ${CMAKE_CURRENT_BINARY_DIR} /googletest-build
3434 EXCLUDE_FROM_ALL )
3535
36- add_executable (circularbuffer_int circularbuffer_int .cpp)
37- target_link_libraries (circularbuffer_int
36+ add_executable (int_buffer int_buffer .cpp)
37+ target_link_libraries (int_buffer
3838 circularbuffer
3939 gtest_main
4040 )
41- add_test (NAME test_circularbuffer_int COMMAND circularbuffer_int)
41+ add_test (NAME test_int_buffer COMMAND int_buffer)
42+
43+ add_executable (string_buffer string_buffer.cpp)
44+ target_link_libraries (string_buffer
45+ circularbuffer
46+ gtest_main
47+ )
48+ add_test (NAME test_string_buffer COMMAND string_buffer)
49+
50+
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ TEST_F(CircularBufferTest, PushAndPopTest){
8080 test.push_back (i);
8181 EXPECT_EQ (TEST_BUFFER_SIZE, test.size ());
8282 EXPECT_EQ (test.size (), test.capacity ());
83+
8384 for (int i=0 ; i<TEST_BUFFER_SIZE - 1 ; i++)
8485 test.pop_front ();
8586 EXPECT_EQ (1 , test.size ());
Original file line number Diff line number Diff line change 1+ #include " circular_buffer.h"
2+ #include < iostream>
3+ #include < string.h>
4+ #include " gtest/gtest.h"
5+
6+ #define TEST_BUFFER_SIZE 100
7+
8+ class CircularBufferTest : public ::testing::Test{
9+
10+ protected:
11+
12+ CircularBuffer<std::string> test{TEST_BUFFER_SIZE};
13+
14+ };
15+
16+ TEST_F (CircularBufferTest, CapacityTest){
17+ EXPECT_EQ (TEST_BUFFER_SIZE, test.capacity ());
18+ EXPECT_FALSE (test.capacity () == 0 );
19+ }
20+
21+ TEST_F (CircularBufferTest, EmptyTest){
22+ EXPECT_TRUE (test.empty ());
23+ test.push_back (" string 1" );
24+ test.push_back (" string 2" );
25+ EXPECT_FALSE (test.empty ());
26+ test.pop_front ();
27+ test.pop_front ();
28+ EXPECT_TRUE (test.empty ());
29+ for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
30+ test.push_back (" string" + std::to_string (i));
31+ EXPECT_FALSE (test.empty ());
32+
33+ for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
34+ test.pop_front ();
35+ EXPECT_TRUE (test.empty ());
36+ }
37+
You can’t perform that action at this time.
0 commit comments