Skip to content

Commit 4cf7a34

Browse files
committed
Add writeOnDemand testcase
1 parent 896249b commit 4cf7a34

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

extras/test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ set(TEST_SRCS
4141
src/test_publishOnChangeRateLimit.cpp
4242
src/test_readOnly.cpp
4343
src/test_writeOnly.cpp
44+
src/test_writeOnDemand.cpp
4445
)
4546

4647
set(TEST_UTIL_SRCS
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright (c) 2019 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <util/CBORTestUtil.h>
12+
13+
#include <CBORDecoder.h>
14+
#include <PropertyContainer.h>
15+
16+
/**************************************************************************************
17+
TEST CODE
18+
**************************************************************************************/
19+
20+
SCENARIO("An Arduino cloud property is marked 'write on demand'", "[ArduinoCloudThing::decode]")
21+
{
22+
PropertyContainer property_container;
23+
24+
CloudInt test = 0;
25+
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).writeOnDemand();
26+
27+
/* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */
28+
uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07};
29+
int const payload_length = sizeof(payload) / sizeof(uint8_t);
30+
CBORDecoder::decode(property_container, payload, payload_length);
31+
32+
REQUIRE(test == 0);
33+
34+
Property* p = getProperty(property_container, "test");
35+
p->fromCloudToLocal();
36+
37+
REQUIRE(test == 7);
38+
}

0 commit comments

Comments
 (0)