-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathtest_CloudColor.cpp
123 lines (85 loc) · 2.97 KB
/
test_CloudColor.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
113
114
115
116
117
118
119
120
121
122
123
/*
Copyright (c) 2019 Arduino. All rights reserved.
*/
/**************************************************************************************
INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <util/CBORTestUtil.h>
#include <ArduinoCloudThing.h>
/**************************************************************************************
TEST CODE
**************************************************************************************/
/************************************************************************************/
SCENARIO("Arduino Cloud Properties ", "[ArduinoCloudThing::CloudColor]") {
WHEN("Set invalid color HSB") {
GIVEN("CloudProtocol::V2") {
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
Color value_color_test = color_test.getValue();
REQUIRE(value_color_test.setColorHSB(500.0, 20.0, 30.0) == false);
}
}
WHEN("Set and Get different RGB colors") {
GIVEN("CloudProtocol::V2") {
uint8_t r, g, b;
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
Color value_color_test = color_test.getValue();
value_color_test.setColorRGB(128, 64, 64);
value_color_test.getRGB(r, g, b);
REQUIRE(r == 128);
REQUIRE(g == 64);
REQUIRE(b == 64);
value_color_test.setColorRGB(126, 128, 64);
value_color_test.getRGB(r, g, b);
REQUIRE(r == 126);
REQUIRE(g == 128);
REQUIRE(b == 64);
value_color_test.setColorRGB(64, 128, 64);
value_color_test.getRGB(r, g, b);
REQUIRE(r == 64);
REQUIRE(g == 128);
REQUIRE(b == 64);
value_color_test.setColorRGB(64, 64, 128);
value_color_test.getRGB(r, g, b);
REQUIRE(r == 64);
REQUIRE(g == 64);
REQUIRE(b == 128);
value_color_test.setColorRGB(255, 0, 255);
value_color_test.getRGB(r, g, b);
REQUIRE(r == 255);
REQUIRE(g == 0);
REQUIRE(b == 255);
value_color_test.setColorRGB(0, 0, 0);
value_color_test.getRGB(r, g, b);
REQUIRE(r == 0);
REQUIRE(g == 0);
REQUIRE(b == 0);
value_color_test.setColorRGB(50, 100, 20);
value_color_test.getRGB(r, g, b);
REQUIRE(r == 50);
REQUIRE(g == 100);
REQUIRE(b == 20);
value_color_test.setColorRGB(20, 50, 70);
value_color_test.getRGB(r, g, b);
REQUIRE(r == 20);
REQUIRE(g == 50);
REQUIRE(b == 70);
}
}
WHEN("Set HSB colors and get RGB") {
GIVEN("CloudProtocol::V2") {
bool verify;
uint8_t r, g, b;
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
Color value_color_test = color_test.getValue();
value_color_test.setColorHSB(240, 50, 50);
value_color_test.getRGB(r, g, b);
verify = r == 64 && g == 64 && b == 128;
REQUIRE(verify);
value_color_test.setColorHSB(120, 50, 50);
value_color_test.getRGB(r, g, b);
verify = r == 64 && g == 128 && b == 64;
REQUIRE(verify);
}
}
}