Skip to content

Commit 6fef724

Browse files
committed
Add test for CloudWrapperFloat
1 parent 256c3a8 commit 6fef724

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

Diff for: extras/test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ set(TEST_SRCS
6767
src/test_callback.cpp
6868
src/test_CloudColor.cpp
6969
src/test_CloudFloat.cpp
70+
src/test_CloudWrapperFloat.cpp
7071
src/test_CloudLocation.cpp
7172
src/test_CloudSchedule.cpp
7273
src/test_decode.cpp

Diff for: extras/test/src/test_CloudWrapperFloat.cpp

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
Copyright (c) 2019 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch2/catch_test_macros.hpp>
10+
11+
#include <CBORDecoder.h>
12+
13+
#include <property/types/CloudWrapperFloat.h>
14+
15+
/**************************************************************************************
16+
TEST CODE
17+
**************************************************************************************/
18+
19+
SCENARIO("Arduino Cloud Properties ", "[ArduinoCloudThing::CloudWrapperFloat]")
20+
{
21+
WHEN("NAN value from cloud is received")
22+
{
23+
PropertyContainer property_container;
24+
float value = 2.0f;
25+
CloudWrapperFloat prop(value);
26+
prop.writeOnDemand();
27+
addPropertyToContainer(property_container, prop, "test", Permission::ReadWrite);
28+
29+
/* [{0: "test", 2: NaN}] = 81A200647465737402F97E00 */
30+
uint8_t const payload[] = { 0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x7E, 0x00 };
31+
int const payload_length = sizeof(payload) / sizeof(uint8_t);
32+
CBORDecoder::decode(property_container, payload, payload_length);
33+
34+
REQUIRE(prop.isDifferentFromCloud() == true);
35+
}
36+
37+
WHEN("Local value is NAN")
38+
{
39+
PropertyContainer property_container;
40+
float value = NAN;
41+
CloudWrapperFloat prop(value);
42+
prop.writeOnDemand();
43+
addPropertyToContainer(property_container, prop, "test", Permission::ReadWrite);
44+
45+
/* [{0: "test", 2: 1.5}] = 81A200647465737402F93E00 */
46+
uint8_t const payload[] = { 0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x3E, 0x00 };
47+
int const payload_length = sizeof(payload) / sizeof(uint8_t);
48+
CBORDecoder::decode(property_container, payload, payload_length);
49+
50+
REQUIRE(prop.isDifferentFromCloud() == true);
51+
}
52+
53+
WHEN("both, the local and the cloud values are NaN")
54+
{
55+
PropertyContainer property_container;
56+
float value = NAN;
57+
CloudWrapperFloat prop(value);
58+
prop.writeOnDemand();
59+
addPropertyToContainer(property_container, prop, "test", Permission::ReadWrite);
60+
61+
/* [{0: "test", 2: NaN}] = 81A200647465737402F97E00 */
62+
uint8_t const payload[] = { 0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x7E, 0x00 };
63+
int const payload_length = sizeof(payload) / sizeof(uint8_t);
64+
CBORDecoder::decode(property_container, payload, payload_length);
65+
66+
REQUIRE(prop.isDifferentFromCloud() == false);
67+
}
68+
69+
WHEN("the local and cloud values are the same")
70+
{
71+
PropertyContainer property_container;
72+
float value = 1.5f;
73+
CloudWrapperFloat prop(value);
74+
prop.writeOnDemand();
75+
addPropertyToContainer(property_container, prop, "test", Permission::ReadWrite);
76+
77+
/* [{0: "test", 2: 1.5}] = 81A200647465737402F93E00 */
78+
uint8_t const payload[] = { 0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x3E, 0x00 };
79+
int const payload_length = sizeof(payload) / sizeof(uint8_t);
80+
CBORDecoder::decode(property_container, payload, payload_length);
81+
82+
REQUIRE(prop.isDifferentFromCloud() == false);
83+
}
84+
85+
WHEN("the local and the cloud values differ")
86+
{
87+
PropertyContainer property_container;
88+
float value = 1.0f;
89+
CloudWrapperFloat prop(value);
90+
prop.writeOnDemand();
91+
addPropertyToContainer(property_container, prop, "test", Permission::ReadWrite);
92+
93+
/* [{0: "test", 2: 1.5}] = 81A200647465737402F97E00 */
94+
uint8_t const payload[] = { 0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x7E, 0x00 };
95+
int const payload_length = sizeof(payload) / sizeof(uint8_t);
96+
CBORDecoder::decode(property_container, payload, payload_length);
97+
98+
REQUIRE(prop.isDifferentFromCloud() == true);
99+
}
100+
101+
WHEN("the local value differs by 0.25 from the cloud value")
102+
{
103+
PropertyContainer property_container;
104+
float value = 1.0f;
105+
CloudWrapperFloat prop(value);
106+
prop.writeOnDemand();
107+
addPropertyToContainer(property_container, prop, "test", Permission::ReadWrite);
108+
109+
/* [{0: "test", 2: 1.5}] = 81A200647465737402F97E00 */
110+
uint8_t const payload[] = { 0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xF9, 0x7E, 0x00 };
111+
int const payload_length = sizeof(payload) / sizeof(uint8_t);
112+
CBORDecoder::decode(property_container, payload, payload_length);
113+
prop.publishOnChange(0.25f, 0); // 0.25 min delta
114+
115+
REQUIRE(prop.isDifferentFromCloud() == true);
116+
}
117+
118+
}

0 commit comments

Comments
 (0)