-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathtest_publishOnChangeRateLimit.cpp
61 lines (53 loc) · 2.22 KB
/
test_publishOnChangeRateLimit.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
/*
Copyright (c) 2019 Arduino. All rights reserved.
*/
/**************************************************************************************
INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <util/CBORTestUtil.h>
/**************************************************************************************
TEST CODE
**************************************************************************************/
SCENARIO("An Arduino cloud property is published on value change but the update rate is limited", "[ArduinoCloudThing::publishOnChange]")
{
PropertyContainer property_container;
CloudInt test = 0;
int const MIN_DELTA = 0;
unsigned long const MIN_TIME_BETWEEN_UPDATES_ms = 500; /* No updates faster than 500 ms */
addPropertyToContainer(property_container, test, "test", Permission::ReadWrite).publishOnChange(MIN_DELTA, MIN_TIME_BETWEEN_UPDATES_ms);
WHEN("t = 0 ms, min time between updates = 500 ms, property not modified, 1st call to 'encode'") {
set_millis(0);
THEN("'encode' should encode the property") {
REQUIRE(cbor::encode(property_container).size() != 0);
WHEN("t = 499 ms, property modified") {
test++;
set_millis(499);
THEN("'encode' should not encode any property") {
REQUIRE(cbor::encode(property_container).size() == 0);
WHEN("t = 500 ms, property modified") {
test++;
set_millis(500);
THEN("'encode' should encode the property") {
REQUIRE(cbor::encode(property_container).size() != 0);
WHEN("t = 999 ms, property modified") {
test++;
set_millis(999);
THEN("'encode' should not encode any property") {
REQUIRE(cbor::encode(property_container).size() == 0);
WHEN("t = 1000 ms, property modified") {
test++;
set_millis(1000);
THEN("'encode' should encode the property") {
REQUIRE(cbor::encode(property_container).size() != 0);
}
}
}
}
}
}
}
}
}
}
}