Skip to content

Commit 6db4c11

Browse files
authored
Removing obsolete identifier CloudProtocol::V2 from test code (and rearranging code to reestablish a good looking base) (arduino-libraries#162)
1 parent 33bde4b commit 6db4c11

13 files changed

+1081
-1138
lines changed

extras/test/src/Arduino.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ static unsigned long current_millis = 0;
1818
PUBLIC FUNCTIONS
1919
******************************************************************************/
2020

21-
void set_millis(unsigned long const millis) {
21+
void set_millis(unsigned long const millis)
22+
{
2223
current_millis = millis;
2324
}
2425

25-
unsigned long millis() {
26+
unsigned long millis()
27+
{
2628
return current_millis;
2729
}

extras/test/src/test_CloudColor.cpp

+67-76
Original file line numberDiff line numberDiff line change
@@ -16,109 +16,100 @@
1616
TEST CODE
1717
**************************************************************************************/
1818

19-
/************************************************************************************/
20-
SCENARIO("Arduino Cloud Properties ", "[ArduinoCloudThing::CloudColor]") {
21-
WHEN("Set invalid color HSB") {
22-
GIVEN("CloudProtocol::V2") {
23-
24-
25-
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
26-
27-
Color value_color_test = color_test.getValue();
28-
REQUIRE(value_color_test.setColorHSB(500.0, 20.0, 30.0) == false);
29-
30-
}
19+
SCENARIO("Arduino Cloud Properties ", "[ArduinoCloudThing::CloudColor]")
20+
{
21+
WHEN("Set invalid color HSB")
22+
{
23+
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
24+
25+
Color value_color_test = color_test.getValue();
26+
REQUIRE(value_color_test.setColorHSB(500.0, 20.0, 30.0) == false);
3127
}
3228

33-
WHEN("Set and Get different RGB colors") {
34-
GIVEN("CloudProtocol::V2") {
29+
WHEN("Set and Get different RGB colors")
30+
{
31+
uint8_t r, g, b;
3532

36-
uint8_t r, g, b;
33+
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
3734

38-
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
35+
Color value_color_test = color_test.getValue();
3936

40-
Color value_color_test = color_test.getValue();
37+
value_color_test.setColorRGB(128, 64, 64);
38+
value_color_test.getRGB(r, g, b);
4139

42-
value_color_test.setColorRGB(128, 64, 64);
43-
value_color_test.getRGB(r, g, b);
40+
REQUIRE(r == 128);
41+
REQUIRE(g == 64);
42+
REQUIRE(b == 64);
4443

45-
REQUIRE(r == 128);
46-
REQUIRE(g == 64);
47-
REQUIRE(b == 64);
44+
value_color_test.setColorRGB(126, 128, 64);
45+
value_color_test.getRGB(r, g, b);
4846

49-
value_color_test.setColorRGB(126, 128, 64);
50-
value_color_test.getRGB(r, g, b);
47+
REQUIRE(r == 126);
48+
REQUIRE(g == 128);
49+
REQUIRE(b == 64);
5150

52-
REQUIRE(r == 126);
53-
REQUIRE(g == 128);
54-
REQUIRE(b == 64);
51+
value_color_test.setColorRGB(64, 128, 64);
52+
value_color_test.getRGB(r, g, b);
5553

56-
value_color_test.setColorRGB(64, 128, 64);
57-
value_color_test.getRGB(r, g, b);
54+
REQUIRE(r == 64);
55+
REQUIRE(g == 128);
56+
REQUIRE(b == 64);
5857

59-
REQUIRE(r == 64);
60-
REQUIRE(g == 128);
61-
REQUIRE(b == 64);
58+
value_color_test.setColorRGB(64, 64, 128);
59+
value_color_test.getRGB(r, g, b);
6260

63-
value_color_test.setColorRGB(64, 64, 128);
64-
value_color_test.getRGB(r, g, b);
61+
REQUIRE(r == 64);
62+
REQUIRE(g == 64);
63+
REQUIRE(b == 128);
6564

66-
REQUIRE(r == 64);
67-
REQUIRE(g == 64);
68-
REQUIRE(b == 128);
65+
value_color_test.setColorRGB(255, 0, 255);
66+
value_color_test.getRGB(r, g, b);
6967

70-
value_color_test.setColorRGB(255, 0, 255);
71-
value_color_test.getRGB(r, g, b);
68+
REQUIRE(r == 255);
69+
REQUIRE(g == 0);
70+
REQUIRE(b == 255);
7271

73-
REQUIRE(r == 255);
74-
REQUIRE(g == 0);
75-
REQUIRE(b == 255);
72+
value_color_test.setColorRGB(0, 0, 0);
73+
value_color_test.getRGB(r, g, b);
7674

77-
value_color_test.setColorRGB(0, 0, 0);
78-
value_color_test.getRGB(r, g, b);
75+
REQUIRE(r == 0);
76+
REQUIRE(g == 0);
77+
REQUIRE(b == 0);
7978

80-
REQUIRE(r == 0);
81-
REQUIRE(g == 0);
82-
REQUIRE(b == 0);
79+
value_color_test.setColorRGB(50, 100, 20);
80+
value_color_test.getRGB(r, g, b);
8381

84-
value_color_test.setColorRGB(50, 100, 20);
85-
value_color_test.getRGB(r, g, b);
82+
REQUIRE(r == 50);
83+
REQUIRE(g == 100);
84+
REQUIRE(b == 20);
8685

87-
REQUIRE(r == 50);
88-
REQUIRE(g == 100);
89-
REQUIRE(b == 20);
86+
value_color_test.setColorRGB(20, 50, 70);
87+
value_color_test.getRGB(r, g, b);
9088

91-
value_color_test.setColorRGB(20, 50, 70);
92-
value_color_test.getRGB(r, g, b);
93-
94-
REQUIRE(r == 20);
95-
REQUIRE(g == 50);
96-
REQUIRE(b == 70);
97-
98-
}
89+
REQUIRE(r == 20);
90+
REQUIRE(g == 50);
91+
REQUIRE(b == 70);
9992
}
10093

101-
WHEN("Set HSB colors and get RGB") {
102-
GIVEN("CloudProtocol::V2") {
103-
bool verify;
104-
uint8_t r, g, b;
105-
106-
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
94+
WHEN("Set HSB colors and get RGB")
95+
{
96+
bool verify;
97+
uint8_t r, g, b;
10798

108-
Color value_color_test = color_test.getValue();
99+
CloudColor color_test = CloudColor(0.0, 0.0, 0.0);
109100

110-
value_color_test.setColorHSB(240, 50, 50);
111-
value_color_test.getRGB(r, g, b);
112-
verify = r == 64 && g == 64 && b == 128;
101+
Color value_color_test = color_test.getValue();
113102

114-
REQUIRE(verify);
103+
value_color_test.setColorHSB(240, 50, 50);
104+
value_color_test.getRGB(r, g, b);
105+
verify = r == 64 && g == 64 && b == 128;
115106

116-
value_color_test.setColorHSB(120, 50, 50);
117-
value_color_test.getRGB(r, g, b);
118-
verify = r == 64 && g == 128 && b == 64;
107+
REQUIRE(verify);
119108

120-
REQUIRE(verify);
109+
value_color_test.setColorHSB(120, 50, 50);
110+
value_color_test.getRGB(r, g, b);
111+
verify = r == 64 && g == 128 && b == 64;
121112

122-
}
113+
REQUIRE(verify);
123114
}
124115
}

extras/test/src/test_CloudLocation.cpp

+31-14
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
TEST CODE
1515
**************************************************************************************/
1616

17-
SCENARIO("Tesing cloud type 'Location' Ctor", "[Location::Location]") {
18-
WHEN("A Location(1.0f, 2.0f) is being instantiated") {
17+
SCENARIO("Tesing cloud type 'Location' Ctor", "[Location::Location]")
18+
{
19+
WHEN("A Location(1.0f, 2.0f) is being instantiated")
20+
{
1921
Location loc(1.0f, 2.0f);
2022
THEN("The member variable 'lat' should be 1.0f") {
2123
REQUIRE(loc.lat == 1.0f);
@@ -28,11 +30,14 @@ SCENARIO("Tesing cloud type 'Location' Ctor", "[Location::Location]") {
2830

2931
/**************************************************************************************/
3032

31-
SCENARIO("Tesing cloud type 'Location' assignment operator", "[Location::operator =]") {
33+
SCENARIO("Tesing cloud type 'Location' assignment operator", "[Location::operator =]")
34+
{
3235
Location loc1(1.0f, 2.0f),
3336
loc2(3.0f, 4.0f);
3437
loc1 = loc2;
35-
WHEN("One location is assigned to the other") {
38+
39+
WHEN("One location is assigned to the other")
40+
{
3641
THEN("The coordinates of the second location should be assigned to the first") {
3742
REQUIRE(loc1.lat == 3.0f);
3843
REQUIRE(loc1.lon == 4.0f);
@@ -42,11 +47,14 @@ SCENARIO("Tesing cloud type 'Location' assignment operator", "[Location::operato
4247

4348
/**************************************************************************************/
4449

45-
SCENARIO("Tesing cloud type 'Location' operator -", "[Location::operator -]") {
50+
SCENARIO("Tesing cloud type 'Location' operator -", "[Location::operator -]")
51+
{
4652
Location loc1(1.0f, 2.0f),
4753
loc2(3.0f, 4.0f);
4854
Location loc3 = loc1 - loc2;
49-
WHEN("One location is subtracted from the other") {
55+
56+
WHEN("One location is subtracted from the other")
57+
{
5058
THEN("The result should be calculated according the rule lon3 = lon1 - lon2, lat3 = lat1 - lat2") {
5159
REQUIRE(loc3.lat == loc1.lat - loc2.lat);
5260
REQUIRE(loc3.lon == loc1.lon - loc2.lon);
@@ -56,17 +64,21 @@ SCENARIO("Tesing cloud type 'Location' operator -", "[Location::operator -]") {
5664

5765
/**************************************************************************************/
5866

59-
SCENARIO("Tesing cloud type 'Location' comparison operator ==", "[Location::operator ==]") {
67+
SCENARIO("Tesing cloud type 'Location' comparison operator ==", "[Location::operator ==]")
68+
{
6069
Location loc1(1.0f, 2.0f),
6170
loc2(3.0f, 4.0f),
6271
loc3(1.0f, 2.0f);
63-
WHEN("Two locations are identical (lat as well as lon)") {
72+
73+
WHEN("Two locations are identical (lat as well as lon)")
74+
{
6475
THEN("The comparison operation should return true") {
6576
REQUIRE((loc1 == loc3) == true);
6677
}
6778
}
6879

69-
WHEN("Two locations are not identical (either lat or lon do not match)") {
80+
WHEN("Two locations are not identical (either lat or lon do not match)")
81+
{
7082
THEN("The comparison operation should return false") {
7183
REQUIRE((loc1 == loc2) == false);
7284
}
@@ -75,17 +87,21 @@ SCENARIO("Tesing cloud type 'Location' comparison operator ==", "[Location::oper
7587

7688
/**************************************************************************************/
7789

78-
SCENARIO("Tesing cloud type 'Location' comparison operator !=", "[Location::operator !=]") {
90+
SCENARIO("Tesing cloud type 'Location' comparison operator !=", "[Location::operator !=]")
91+
{
7992
Location loc1(1.0f, 2.0f),
8093
loc2(3.0f, 4.0f),
8194
loc3(1.0f, 2.0f);
82-
WHEN("Two locations are identical (lat as well as lon)") {
95+
96+
WHEN("Two locations are identical (lat as well as lon)")
97+
{
8398
THEN("The comparison operation should return false") {
8499
REQUIRE((loc1 != loc3) == false);
85100
}
86101
}
87102

88-
WHEN("Two locations are not identical (either lat or lon do not match)") {
103+
WHEN("Two locations are not identical (either lat or lon do not match)")
104+
{
89105
THEN("The comparison operation should return true") {
90106
REQUIRE((loc1 != loc2) == true);
91107
}
@@ -94,9 +110,10 @@ SCENARIO("Tesing cloud type 'Location' comparison operator !=", "[Location::oper
94110

95111
/**************************************************************************************/
96112

97-
SCENARIO("Tesing cloud type 'Location' function distance for calculating euclidean 2d distance between two points", "[Location::distance]") {
113+
SCENARIO("Tesing cloud type 'Location' function distance for calculating euclidean 2d distance between two points", "[Location::distance]")
114+
{
98115
Location loc1(0.0f, 0.0f),
99116
loc2(1.0f, 1.0f);
100117

101118
REQUIRE(Location::distance(loc1, loc2) == sqrt(2.0f));
102-
}
119+
}

extras/test/src/test_addPropertyReal.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
TEST CODE
2020
**************************************************************************************/
2121

22-
SCENARIO("The same arduino cloud properties are added multiple times", "[ArduinoCloudThing::addPropertyToContainer]") {
23-
WHEN("The same bool property is added multiple times") {
22+
SCENARIO("The same arduino cloud properties are added multiple times", "[ArduinoCloudThing::addPropertyToContainer]")
23+
{
24+
WHEN("The same bool property is added multiple times")
25+
{
2426
PropertyContainer property_container;
2527

2628
CloudBool bool_property = false;
@@ -34,7 +36,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino
3436

3537
/**************************************************************************************/
3638

37-
WHEN("the same int property is added multiple times") {
39+
WHEN("the same int property is added multiple times")
40+
{
3841
PropertyContainer property_container;
3942

4043
CloudInt int_property = 1;
@@ -49,7 +52,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino
4952

5053
/**************************************************************************************/
5154

52-
WHEN("the same float property is added multiple times") {
55+
WHEN("the same float property is added multiple times")
56+
{
5357
PropertyContainer property_container;
5458

5559
CloudFloat float_property = 1.0f;
@@ -64,7 +68,8 @@ SCENARIO("The same arduino cloud properties are added multiple times", "[Arduino
6468

6569
/**************************************************************************************/
6670

67-
WHEN("the same String property is added multiple times") {
71+
WHEN("the same String property is added multiple times")
72+
{
6873
PropertyContainer property_container;
6974

7075
CloudString str_property;

0 commit comments

Comments
 (0)