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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 0 deletions
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
Lines changed: 33 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy