From 11e77ea8b9af8bbc8d1ad2c154167d5e7a12ffc0 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 9 Apr 2024 08:50:09 +0200 Subject: [PATCH] Add writeOnChange testcase --- extras/test/CMakeLists.txt | 1 + extras/test/src/test_writeOnChange.cpp | 33 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 extras/test/src/test_writeOnChange.cpp diff --git a/extras/test/CMakeLists.txt b/extras/test/CMakeLists.txt index c330afd1..2588c27c 100644 --- a/extras/test/CMakeLists.txt +++ b/extras/test/CMakeLists.txt @@ -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 diff --git a/extras/test/src/test_writeOnChange.cpp b/extras/test/src/test_writeOnChange.cpp new file mode 100644 index 00000000..0896bbdf --- /dev/null +++ b/extras/test/src/test_writeOnChange.cpp @@ -0,0 +1,33 @@ +/* + Copyright (c) 2019 Arduino. All rights reserved. +*/ + +/************************************************************************************** + INCLUDE + **************************************************************************************/ + +#include + +#include + +#include +#include + +/************************************************************************************** + 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); +}