Skip to content

Commit

Permalink
Add writeOnChange testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Apr 9, 2024
1 parent 4cf7a34 commit 11e77ea
Show file tree
Hide file tree
Showing 2 changed files with 34 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 @@ -42,6 +42,7 @@ set(TEST_SRCS
src/test_readOnly.cpp
src/test_writeOnly.cpp
src/test_writeOnDemand.cpp
src/test_writeOnChange.cpp
)

set(TEST_UTIL_SRCS
Expand Down
33 changes: 33 additions & 0 deletions extras/test/src/test_writeOnChange.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
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 change'", "[ArduinoCloudThing::decode]")
{
PropertyContainer property_container;

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

/* [{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 == 7);
}

0 comments on commit 11e77ea

Please sign in to comment.