Skip to content

Commit e3245de

Browse files
committed
Add test case for CloudFloat
1 parent c383fd7 commit e3245de

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

extras/test/src/test_CloudFloat.cpp

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

0 commit comments

Comments
 (0)