Skip to content

Commit

Permalink
Add writeOnDemand testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Apr 8, 2024
1 parent 896249b commit 4cf7a34
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions extras/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set(TEST_SRCS
src/test_publishOnChangeRateLimit.cpp
src/test_readOnly.cpp
src/test_writeOnly.cpp
src/test_writeOnDemand.cpp
)

set(TEST_UTIL_SRCS
Expand Down
38 changes: 38 additions & 0 deletions extras/test/src/test_writeOnDemand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright (c) 2019 Arduino. All rights reserved.
*/

/**************************************************************************************
INCLUDE
**************************************************************************************/

#include <catch.hpp>

#include <util/CBORTestUtil.h>

#include <CBORDecoder.h>
#include <PropertyContainer.h>

/**************************************************************************************
TEST CODE
**************************************************************************************/

SCENARIO("An Arduino cloud property is marked 'write on demand'", "[ArduinoCloudThing::decode]")
{
PropertyContainer property_container;

CloudInt test = 0;
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).writeOnDemand();

/* [{0: "test", 2: 7}] = 81 A2 00 64 74 65 73 74 02 07 */
uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0x07};
int const payload_length = sizeof(payload) / sizeof(uint8_t);
CBORDecoder::decode(property_container, payload, payload_length);

REQUIRE(test == 0);

Property* p = getProperty(property_container, "test");
p->fromCloudToLocal();

REQUIRE(test == 7);
}

0 comments on commit 4cf7a34

Please sign in to comment.