@@ -253,13 +253,14 @@ void test_input_exceeds_capacity_push_2_pop_1_complex_type()
253
253
}
254
254
}
255
255
256
- /* Test circular buffer - test pop(), empty(), full(), size() after CircularBuffer creation.
256
+ /* Test circular buffer - test pop(), peek(), empty(), full(), size() after CircularBuffer creation.
257
257
*
258
258
* Given is a circular buffer.
259
259
* When circular buffer is created.
260
260
* Then circular buffer is empty:
261
261
* - empty() returns true,
262
262
* - pop() function returns false,
263
+ * - peek() function returns false,
263
264
* - full() function returns false,
264
265
* - size() function returns 0,
265
266
*
@@ -271,6 +272,7 @@ void test_pop_empty_full_size_after_creation()
271
272
272
273
TEST_ASSERT_TRUE (cb.empty ());
273
274
TEST_ASSERT_FALSE (cb.pop (data));
275
+ TEST_ASSERT_FALSE (cb.peek (data));
274
276
TEST_ASSERT_FALSE (cb.full ());
275
277
TEST_ASSERT_EQUAL (0 , cb.size ());
276
278
}
@@ -411,6 +413,35 @@ void test_counter_type_buffer_size()
411
413
TEST_ASSERT_EQUAL (100 , data);
412
414
}
413
415
416
+ /* Test circular buffer - peek should not update buffer data.
417
+ *
418
+ * When circular buffer peek operation is performed along with
419
+ * push and pop, it should not update the buffer data elements.
420
+ * Elements read using pop/peek operation should match.
421
+ *
422
+ */
423
+ void test_peek_no_pop ()
424
+ {
425
+ CircularBuffer<int , 3 , unsigned char > cb;
426
+ int data = 0 ;
427
+ int peek_data = 0 ;
428
+
429
+ for (uint32_t i = 0 ; i < 3 ; i++) {
430
+ data = (0xAA + i);
431
+ cb.push (data);
432
+ cb.peek (peek_data);
433
+ TEST_ASSERT_EQUAL (i + 1 , cb.size ());
434
+ }
435
+
436
+ for (uint32_t i = 0 ; i < 3 ; i++) {
437
+ TEST_ASSERT_TRUE (cb.peek (peek_data));
438
+ TEST_ASSERT_EQUAL (0xAA + i, peek_data);
439
+ TEST_ASSERT_TRUE (cb.pop (data));
440
+ TEST_ASSERT_EQUAL (0xAA + i, data);
441
+ TEST_ASSERT_EQUAL (3 - i - 1 , cb.size ());
442
+ }
443
+ }
444
+
414
445
utest::v1::status_t greentea_failure_handler (const Case *const source, const failure_t reason)
415
446
{
416
447
greentea_case_failure_abort_handler (source, reason);
@@ -446,13 +477,15 @@ Case cases[] = {
446
477
447
478
Case (" reset() clears the buffer." , test_reset<uint32_t , 5 >, greentea_failure_handler),
448
479
449
- Case (" Test pop(), empty(), full(), size() after CircularBuffer creation." ,
480
+ Case (" Test pop(), peek(), empty(), full(), size() after CircularBuffer creation." ,
450
481
test_pop_empty_full_size_after_creation, greentea_failure_handler),
451
482
452
483
Case (" Test CounterType/BufferSize boarder case." , test_counter_type_buffer_size, greentea_failure_handler),
453
484
454
485
Case (" Input exceeds capacity(5) push 2, pop 1 - complex type." ,
455
486
test_input_exceeds_capacity_push_2_pop_1_complex_type<5 , unsigned short >, greentea_failure_handler),
487
+
488
+ Case (" peek() return data without popping the element." , test_peek_no_pop, greentea_failure_handler),
456
489
};
457
490
458
491
utest::v1::status_t greentea_test_setup (const size_t number_of_cases)
0 commit comments