@@ -294,23 +294,57 @@ TEST_F(CircularBufferTest, BeginIteratorTest){
294
294
CircularBuffer<std::string>::const_iterator const_it = test_buff.begin ();
295
295
for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
296
296
EXPECT_EQ (*(const_it++), " string" + std::to_string (i));
297
+ // test out of bounds
298
+ try {
299
+ *it = " test_string" ;
300
+ FAIL () << " Expected std::out_of_range error" ;
301
+ }
302
+ catch (const std::out_of_range& err){
303
+ EXPECT_EQ (err.what (), std::string (" Index is out of Range of buffer size" ));
304
+ }
305
+
306
+ try {
307
+ std::string out_of_bound = *(const_it);
308
+ FAIL () << " Expected std::out_of_range error" ;
309
+ }
310
+ catch (const std::out_of_range& err){
311
+ EXPECT_EQ (err.what (), std::string (" Index is out of Range of buffer size" ));
312
+ }
297
313
}
298
314
315
+
299
316
TEST_F (CircularBufferTest, EndIteratorTest){
300
317
// create full buffer
301
318
for (int i=0 ; i<TEST_BUFFER_SIZE; i++)
302
319
test_buff.push_back (" string" + std::to_string (i));
303
- // test last element with iterator
304
- CircularBuffer<std::string>::iterator it = test_buff.end ();
305
- EXPECT_EQ (*(--it), " string99" );
306
- // access with begin iterator
320
+
321
+ CircularBuffer<std::string>::iterator it = test_buff.end ();
322
+ // access with end iterator
307
323
for (int i = TEST_BUFFER_SIZE-1 ; i>=0 ; i--)
308
- EXPECT_EQ (*(it-- ), " string" + std::to_string (i));
324
+ EXPECT_EQ (*(--it ), " string" + std::to_string (i));
309
325
310
- // access with const begin iterator
326
+ // access with const end iterator
311
327
CircularBuffer<std::string>::const_iterator const_it = test_buff.end ();
312
328
for (int i = TEST_BUFFER_SIZE-1 ; i>=0 ; i--)
313
329
EXPECT_EQ (*(--const_it), " string" + std::to_string (i));
330
+
331
+ // test out of bounds
332
+ try {
333
+ *(--it) = " test_string" ;
334
+ FAIL () << " Expected std::out_of_range error" ;
335
+ }
336
+ catch (const std::out_of_range& err){
337
+ EXPECT_EQ (err.what (), std::string (" Index is out of Range of buffer size" ));
338
+ }
339
+
340
+ try {
341
+ std::string out_of_bound = *(--const_it);
342
+ FAIL () << " Expected std::out_of_range error" ;
343
+ }
344
+ catch (const std::out_of_range& err){
345
+ EXPECT_EQ (err.what (), std::string (" Index is out of Range of buffer size" ));
346
+ }
347
+
314
348
}
315
349
316
350
@@ -324,3 +358,6 @@ TEST_F(CircularBufferTest, EndIteratorTest){
324
358
325
359
326
360
361
+
362
+
363
+
0 commit comments