File tree 3 files changed +37
-2
lines changed
3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ void CanMsgRingbuffer::enqueue(CanMsg const & msg)
40
40
41
41
_buf[_head] = msg;
42
42
_head = next (_head);
43
- _num_elems++ ;
43
+ _num_elems = _num_elems + 1 ;
44
44
}
45
45
46
46
CanMsg CanMsgRingbuffer::dequeue ()
@@ -50,7 +50,7 @@ CanMsg CanMsgRingbuffer::dequeue()
50
50
51
51
CanMsg const msg = _buf[_tail];
52
52
_tail = next (_tail);
53
- _num_elems-- ;
53
+ _num_elems = _num_elems - 1 ;
54
54
55
55
return msg;
56
56
}
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ set(TEST_SRCS
33
33
src/CanMsg/test_isStandardId.cpp
34
34
src/CanMsg/test_operator_assignment.cpp
35
35
src/CanMsg/test_printTo.cpp
36
+ src/CanMsgRingbuffer/test_available.cpp
36
37
src/Common/test_makeWord.cpp
37
38
src/Common/test_map.cpp
38
39
src/Common/test_max.cpp
@@ -104,6 +105,7 @@ set(TEST_SRCS
104
105
105
106
set (TEST_DUT_SRCS
106
107
../api/CanMsg.cpp
108
+ ../api/CanMsgRingbuffer.cpp
107
109
../api/Common.cpp
108
110
../api/IPAddress.cpp
109
111
../api/String .cpp
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2020 Arduino. All rights reserved.
3
+ */
4
+
5
+ /* *************************************************************************************
6
+ * INCLUDE
7
+ **************************************************************************************/
8
+
9
+ #include < catch.hpp>
10
+
11
+ #include < CanMsgRingbuffer.h>
12
+
13
+ /* *************************************************************************************
14
+ * TEST CODE
15
+ **************************************************************************************/
16
+
17
+ TEST_CASE (" 'available' should return 0 for empty CanMsg ring buffer" , " [CanMsgRingbuffer-available-01]" )
18
+ {
19
+ arduino::CanMsgRingbuffer ringbuffer;
20
+ REQUIRE (ringbuffer.available () == 0 );
21
+ }
22
+
23
+ TEST_CASE (" 'available' should return number of elements in CanMsg ringbuffer" , " [CanMsgRingbuffer-available-02]" )
24
+ {
25
+ arduino::CanMsgRingbuffer ringbuffer;
26
+ arduino::CanMsg msg;
27
+ ringbuffer.enqueue (msg);
28
+ REQUIRE (ringbuffer.available () == 1 );
29
+ ringbuffer.enqueue (msg);
30
+ REQUIRE (ringbuffer.available () == 2 );
31
+ ringbuffer.dequeue ();
32
+ REQUIRE (ringbuffer.available () == 1 );
33
+ }
You can’t perform that action at this time.
0 commit comments