Skip to content

Commit d8d0b6a

Browse files
committed
Fix deprecated volatile access in CanMsgRingbuffer + testcase
1 parent 60b64bc commit d8d0b6a

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

api/CanMsgRingbuffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void CanMsgRingbuffer::enqueue(CanMsg const & msg)
4040

4141
_buf[_head] = msg;
4242
_head = next(_head);
43-
_num_elems++;
43+
_num_elems = _num_elems + 1;
4444
}
4545

4646
CanMsg CanMsgRingbuffer::dequeue()
@@ -50,7 +50,7 @@ CanMsg CanMsgRingbuffer::dequeue()
5050

5151
CanMsg const msg = _buf[_tail];
5252
_tail = next(_tail);
53-
_num_elems--;
53+
_num_elems = _num_elems - 1;
5454

5555
return msg;
5656
}

test/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(TEST_SRCS
3333
src/CanMsg/test_isStandardId.cpp
3434
src/CanMsg/test_operator_assignment.cpp
3535
src/CanMsg/test_printTo.cpp
36+
src/CanMsgRingbuffer/test_available.cpp
3637
src/Common/test_makeWord.cpp
3738
src/Common/test_map.cpp
3839
src/Common/test_max.cpp
@@ -104,6 +105,7 @@ set(TEST_SRCS
104105

105106
set(TEST_DUT_SRCS
106107
../api/CanMsg.cpp
108+
../api/CanMsgRingbuffer.cpp
107109
../api/Common.cpp
108110
../api/IPAddress.cpp
109111
../api/String.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
 (0)