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