From 4cf7a3417dcf813d0423a5a45a6b5f114363d884 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 8 Apr 2024 17:12:04 +0200 Subject: [PATCH] Add writeOnDemand testcase --- extras/test/CMakeLists.txt | 1 + extras/test/src/test_writeOnDemand.cpp | 38 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 extras/test/src/test_writeOnDemand.cpp diff --git a/extras/test/CMakeLists.txt b/extras/test/CMakeLists.txt index 8e514890..c330afd1 100644 --- a/extras/test/CMakeLists.txt +++ b/extras/test/CMakeLists.txt @@ -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 diff --git a/extras/test/src/test_writeOnDemand.cpp b/extras/test/src/test_writeOnDemand.cpp new file mode 100644 index 00000000..5bd0c378 --- /dev/null +++ b/extras/test/src/test_writeOnDemand.cpp @@ -0,0 +1,38 @@ +/* + Copyright (c) 2019 Arduino. All rights reserved. +*/ + +/************************************************************************************** + INCLUDE + **************************************************************************************/ + +#include + +#include + +#include +#include + +/************************************************************************************** + 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); +}