1+ /*
2+ Copyright (c) 2019 Arduino. All rights reserved.
3+ */
4+
5+ /* *************************************************************************************
6+ INCLUDE
7+ **************************************************************************************/
8+
9+ #include < catch.hpp>
10+
11+ #include < util/CBORTestUtil.h>
12+ #include < ArduinoCloudThing.h>
13+
14+ /* *************************************************************************************
15+ TEST CODE
16+ **************************************************************************************/
17+
18+ /* ***********************************************************************************/
19+ SCENARIO (" Arduino Cloud Properties " , " [ArduinoCloudThing::CloudColor]" ) {
20+ WHEN (" Set invalid color HSB" ) {
21+ GIVEN (" CloudProtocol::V2" ) {
22+
23+
24+ CloudColor color_test = CloudColor (0.0 , 0.0 , 0.0 );
25+
26+ Color value_color_test = color_test.getValue ();
27+ REQUIRE (value_color_test.setColorHSB (500.0 , 20.0 , 30.0 ) == false );
28+
29+ }
30+ }
31+
32+ WHEN (" Set and Get different RGB colors" ) {
33+ GIVEN (" CloudProtocol::V2" ) {
34+
35+ uint8_t r, g, b;
36+
37+ CloudColor color_test = CloudColor (0.0 , 0.0 , 0.0 );
38+
39+ Color value_color_test = color_test.getValue ();
40+
41+ value_color_test.setColorRGB (128 , 64 , 64 );
42+ value_color_test.getRGB (r, g, b);
43+
44+ REQUIRE (r == 128 );
45+ REQUIRE (g == 64 );
46+ REQUIRE (b == 64 );
47+
48+ value_color_test.setColorRGB (126 , 128 , 64 );
49+ value_color_test.getRGB (r, g, b);
50+
51+ REQUIRE (r == 126 );
52+ REQUIRE (g == 128 );
53+ REQUIRE (b == 64 );
54+
55+ value_color_test.setColorRGB (64 , 128 , 64 );
56+ value_color_test.getRGB (r, g, b);
57+
58+ REQUIRE (r == 64 );
59+ REQUIRE (g == 128 );
60+ REQUIRE (b == 64 );
61+
62+ value_color_test.setColorRGB (64 , 64 , 128 );
63+ value_color_test.getRGB (r, g, b);
64+
65+ REQUIRE (r == 64 );
66+ REQUIRE (g == 64 );
67+ REQUIRE (b == 128 );
68+
69+ value_color_test.setColorRGB (255 , 0 , 255 );
70+ value_color_test.getRGB (r, g, b);
71+
72+ REQUIRE (r == 255 );
73+ REQUIRE (g == 0 );
74+ REQUIRE (b == 255 );
75+
76+ value_color_test.setColorRGB (0 , 0 , 0 );
77+ value_color_test.getRGB (r, g, b);
78+
79+ REQUIRE (r == 0 );
80+ REQUIRE (g == 0 );
81+ REQUIRE (b == 0 );
82+
83+ value_color_test.setColorRGB (50 , 100 , 20 );
84+ value_color_test.getRGB (r, g, b);
85+
86+ REQUIRE (r == 50 );
87+ REQUIRE (g == 100 );
88+ REQUIRE (b == 20 );
89+
90+ value_color_test.setColorRGB (20 , 50 , 70 );
91+ value_color_test.getRGB (r, g, b);
92+
93+ REQUIRE (r == 20 );
94+ REQUIRE (g == 50 );
95+ REQUIRE (b == 70 );
96+
97+ }
98+ }
99+
100+ WHEN (" Set HSB colors and get RGB" ) {
101+ GIVEN (" CloudProtocol::V2" ) {
102+ bool verify;
103+ uint8_t r, g, b;
104+
105+ CloudColor color_test = CloudColor (0.0 , 0.0 , 0.0 );
106+
107+ Color value_color_test = color_test.getValue ();
108+
109+ value_color_test.setColorHSB (240 , 50 , 50 );
110+ value_color_test.getRGB (r, g, b);
111+ verify = r == 64 && g == 64 && b == 128 ;
112+
113+ REQUIRE (verify);
114+
115+ value_color_test.setColorHSB (120 , 50 , 50 );
116+ value_color_test.getRGB (r, g, b);
117+ verify = r == 64 && g == 128 && b == 64 ;
118+
119+ REQUIRE (verify);
120+
121+ }
122+ }
123+ }
0 commit comments