Skip to content

Integrate ArduinoCloudThing with ArduinoIoTCloud #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 179 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
d74745e
ArduinoCloud base
May 19, 2016
4b16668
Correct typos
facchinm Jul 1, 2016
f6af0a6
remove loop cycle, otherwise if wifi connection drops code get stuck
Jul 21, 2016
ffafb20
removed debug prints
Jul 21, 2016
7720f97
wrong comment
Jul 21, 2016
189592c
modified example and removed useless delay
Jul 22, 2016
2d73d59
Merge pull request #2 from facchinm/typos
lorenzoromagnoli Jul 27, 2016
6b6ccec
start new branch with cbor and stuff
facchinm Jan 25, 2018
af18ef1
Almost working on SAMD
facchinm Jan 26, 2018
00cca22
bundle dependencies
facchinm Jan 26, 2018
2c41a33
Change CBOR library (this one uses maps)
facchinm Jan 26, 2018
86f53b7
use composition to add functionalities
facchinm Feb 16, 2018
e388049
Fix encoding
facchinm Feb 16, 2018
ebaa1ab
Library is now ArduinoCloudThing
facchinm Feb 16, 2018
ea5aefe
use external buffer on poll()
facchinm Feb 16, 2018
3797b91
make decode() public
facchinm Feb 16, 2018
32e8d8d
Make permission field composable too
facchinm Feb 21, 2018
e18c499
Fix write-only properties
facchinm Feb 22, 2018
5e92f67
setPermission should return ArduinoCloudPropertyGeneric& to allow com…
facchinm May 30, 2018
fccc594
Improve stringification
facchinm May 30, 2018
4f31436
Fixed memory leak in CborArray, fixed ssize_t, #define CBOR_INT_T int
Jun 27, 2018
4f04358
Merge pull request #1 from bcmi-labs/hotfix/memoryleak
facchinm Jun 27, 2018
cd341c6
Remove evil NAME_OF macro
facchinm Jun 27, 2018
2cf58e5
Add printinfo debug function
facchinm Jun 27, 2018
57d63fd
Remove hardcoded DEBUG_MEMORY define
facchinm Jun 27, 2018
c226bde
Pass external buffer size explicitely
facchinm Jun 27, 2018
b60bafc
Proposal: add minimumDelta API
facchinm Jul 3, 2018
71ed28e
Replace ArduinoCBOR with TinyCBOR
facchinm Aug 21, 2018
d94fb00
Squash #2 and fixup String and types handling
facchinm Aug 21, 2018
9d7cd84
Restore "v" as key for value
facchinm Aug 24, 2018
fe468ab
Instantiate shadow on addProperty
facchinm Aug 24, 2018
f4c0ef3
Start adding unit tests
facchinm Aug 24, 2018
3f8cfbc
add writeOnly test
facchinm Aug 24, 2018
dd14625
Fix delta stuff
facchinm Aug 24, 2018
188e4f9
Proposal: fix map and array length
facchinm Aug 27, 2018
89b8f07
Remove composition APIs
facchinm Sep 3, 2018
c3df6f4
add minDelta to all function signatures
facchinm Sep 7, 2018
d5edc24
overload addProperty(float...double)
facchinm Sep 7, 2018
f646f9c
Revert "overload addProperty(float...double)"
facchinm Sep 7, 2018
c79748b
Fix callback not being populated
facchinm Sep 7, 2018
d6e90f5
Handle errors in cbor_value_advance
facchinm Sep 10, 2018
1d504ca
restored CBOR decode function
Sid23 Sep 11, 2018
873f91d
Updated the ArduinoCloudThing library: added getType method for prope…
Sid23 Sep 11, 2018
5080d9d
Updated poll and addPropertyReal
Sid23 Sep 11, 2018
892861a
Updated int shadow_property assignment, modified test (all passed), b…
Sid23 Sep 11, 2018
0d1f285
Update status property assignment and fixed tests
Sid23 Sep 12, 2018
b5c6a5f
Added some decode tests
Sid23 Sep 12, 2018
8c4dd38
fix integer type into a double
Sep 25, 2018
0a6ff99
Extracting class ArduinoCloudPropertyGeneric into separate header file
aentinger Oct 13, 2018
862fdd7
Extracting ArduinoCloudProperty class into dedicated header file
aentinger Oct 13, 2018
292f8b2
Extracting template function implementation into .ipp file
aentinger Oct 13, 2018
4783768
Rearranging function order a bit so that functions o similiar functio…
aentinger Oct 13, 2018
7583551
Using functions canRead/canWrite inside template functions
aentinger Oct 13, 2018
727d721
Using keyword 'override' with virtual functions in order to allow the…
aentinger Oct 13, 2018
baa438e
Adding const qualifiers in order to allow the compiler to identify me…
aentinger Oct 13, 2018
6b6f79a
Initialisation of all properties take place within ctor class Arduino…
aentinger Oct 13, 2018
78836fa
Moving common class members up into the base class ArduinoCloudProper…
aentinger Oct 14, 2018
04a1f58
Moving functions canWrite and canRead up into the base class - they d…
aentinger Oct 14, 2018
ff820ec
Moving comparison operator up in base class module and out of the cla…
aentinger Oct 14, 2018
9583053
Moving function shouldBeUpdated as well as member variable _last_upda…
aentinger Oct 14, 2018
a1da1a6
Moving function 'append' to base class and implementing function appe…
aentinger Oct 14, 2018
cd6ff59
long _last_updated no longer needs to be protected but can be private…
aentinger Oct 14, 2018
66d3ac0
Function canRead must no longer be virtual
aentinger Oct 14, 2018
2701c75
Separating runtime polymorphism (virtual) from static polymorphism (t…
aentinger Oct 14, 2018
13ee571
Separating runtime polymorphism (virtual) from static polymorphism (t…
aentinger Oct 14, 2018
f1fedbb
Separating runtime polymorphism (virtual) from static polymorphism (t…
aentinger Oct 14, 2018
db525fd
Separating runtime polymorphism (virtual) from static polymorphism (t…
aentinger Oct 14, 2018
8323f89
Method 'shouldBeUpdated' can also be 'const'
aentinger Oct 14, 2018
8589955
Adding template class ArduinoCloudProperty which should replace the r…
aentinger Oct 15, 2018
6e04616
Replacing runtime-polymorphism implementation spread over different f…
aentinger Oct 15, 2018
cf6a2a5
Fixing a couple of bugs in the new refactored implementation - now al…
aentinger Oct 15, 2018
3caca6d
Make the methods onUpdate/publishOnChange/publishEvery composable by …
aentinger Oct 16, 2018
e3e98b9
Rewriting ArduinoCloudPropertyContainer in order to provide a conside…
aentinger Oct 16, 2018
bbc50a4
Adding new update policy OnChangeRateLimited where data is published …
aentinger Oct 16, 2018
ebf8eb0
Simplifying configuration via composition and adding const qualifiers…
aentinger Oct 17, 2018
f1f47c4
Extracting ArduinoCloudProperty template implementation into *.ipp file
aentinger Oct 17, 2018
07b21c0
Extracting usage isWritableMethodByCloud method into 'decode' method …
aentinger Oct 17, 2018
555fc24
Removing no longer needed variable propId
aentinger Oct 17, 2018
b28c0d7
Renaming method 'poll' to 'encode' to better reflect what it is doing…
aentinger Oct 17, 2018
721e47f
Bugfix - Corrected wrong order in subtraction in test code
aentinger Oct 17, 2018
89ff0a5
Changing name of method 'addProperty' to 'addPropertyReal' in order t…
aentinger Oct 18, 2018
df0c632
Renaming milliseconds to millis wherever used as an variable appendix
aentinger Oct 20, 2018
220b846
Fixing some typos as suggested by the pull request comments made by A…
aentinger Oct 25, 2018
a10d9c0
Reducing the overall payload size by replacing the string key with a …
aentinger Nov 15, 2018
c7ac378
Squashing multiple commits concerning the refactoring of the test code
aentinger Nov 15, 2018
b378673
Of course the conversion from cbor half float also needs to be fixed …
aentinger Nov 16, 2018
a790330
Implementing first draft of state machine based CBOR decoding
aentinger Dec 12, 2018
35082a6
More simplification of the CBOR parser - but not guaranteed to work i…
aentinger Dec 12, 2018
b3d2ff2
Adding minimal 'Arduino.h' file which stubs the required methods in o…
aentinger Dec 18, 2018
f980cfb
Support for CloudProtocol::V1/V2 implemented for boolean values
aentinger Dec 18, 2018
ce885d1
Adding 'encode' test for int property
aentinger Dec 18, 2018
bf40b74
Implementing test and production code for encoding float properties f…
aentinger Dec 18, 2018
1627d56
Implementation of first draft of encode complete
aentinger Jan 7, 2019
d860700
Since we do have a definite 'end' state of the do while loop we can s…
aentinger Jan 7, 2019
bcb6360
Supporting both encoding protocols for String
aentinger Jan 22, 2019
18ddbe6
Fixing bug when decoding multiple strings
aentinger Jan 23, 2019
14401a0
Adding method 'getInitialMinDeltaPropertyValue' which provides the in…
aentinger Jan 23, 2019
f74487a
Adding decoding implementation for CloudProtocol::V2
aentinger Jan 24, 2019
661abb4
Adding implementation and test code for decoding a base tag property
aentinger Feb 4, 2019
9e2a63e
Adding implementation and test code for decoding a base time map entry
aentinger Feb 4, 2019
d570fe4
Refactoring state machine for better readability
aentinger Feb 4, 2019
5533454
Extracting all state code into dedicated functions for better readabi…
aentinger Feb 5, 2019
c6b176e
Rearranging function ordering for better readability
aentinger Feb 5, 2019
350d61f
Rewriting parser in such way that the order of the map entries is no …
aentinger Feb 5, 2019
ff214f8
In case of a unkown map key we now just advance to the next map key i…
aentinger Feb 5, 2019
41fb58c
Implementing parsing for base version
aentinger Feb 5, 2019
3374ec1
Making sure the map data is reset when entering a new map
aentinger Feb 5, 2019
ef597e1
Bugfix: Parsing BaseTime regardless if its a double or an int
aentinger Feb 5, 2019
20c1f43
Bugfix - taking into account that the CBOR library might collapse any…
aentinger Feb 5, 2019
ee503e4
Bugfix - All numeric data types are excepted for BaseTime and Time
aentinger Feb 5, 2019
dcbd179
Bugfix + test code - if a property is manipulated in its onChange cal…
aentinger Feb 5, 2019
f11f9a9
Added license
cmaglie Feb 6, 2019
b3fc51f
Disable assert for target build (#15)
aentinger Feb 8, 2019
f47d0f2
Add automatically decode for V1 and V2 cloud protocol
Feb 8, 2019
8b6a40f
Change protocol in encode from V1 to V2
Feb 8, 2019
92360bb
Add some comments to explain which protocol version the decode will use
Feb 8, 2019
cbe49da
Removing enum class CloudProtocol since the 'decode' function decodes…
aentinger Feb 12, 2019
c6899ed
Reapplying changes of PR #11 (refactoring) (8d773a4) ... (#20)
aentinger Feb 12, 2019
e4a610d
Implementation of the shadow Thing feature on the device
ilcato Feb 8, 2019
6cd2b0b
fixing ArduinoCloudProperty<T>::isChangedLocally() return type
ilcato Feb 8, 2019
8810cbc
definition of sychronization callback moved into ArduinoCloudThing, t…
ilcato Feb 19, 2019
0f0b1a4
Fixed cbor decod for negative ints. Added specific unit test.
Feb 20, 2019
e314621
Refactoring reset map data
Feb 20, 2019
8272275
Reanme of the standard sync callbacks.
ilcato Feb 21, 2019
335c16e
Incorporating changes suggested by @per1234.
per1234 Feb 25, 2019
230f66d
Apply suggestions from @per1234 code review
per1234 Feb 26, 2019
c2d041e
Complete removal of SenML V1 protocol (string based keys)
ilcato Mar 22, 2019
bc34d24
Removed unused internal state property
ilcato Mar 25, 2019
31ef291
Auto format code
per1234 Apr 9, 2019
9ac82d0
Manually improve some formatting left ugly by the auto format
per1234 Apr 9, 2019
95fa08d
Object properties implementation
ilcato Mar 2, 2019
476a56c
Multi value properties implementation
mirkokurt Apr 9, 2019
563f6c1
AStyle formatting
mirkokurt Apr 29, 2019
e7e94dd
Improve test coverage
mirkokurt Apr 29, 2019
c338a3e
Incorporating changes suggested by @lxrobotics
ilcato May 2, 2019
cf355c4
Fix CloudColor assignment operator
ilcato May 8, 2019
e8b8275
Fix compiler warnings
aentinger May 20, 2019
3fb6bc8
Presetting variable next_state with defined value so as to not leave …
aentinger May 21, 2019
0e2f786
Fixed memory leak during the decode of a cbor message
mirkokurt May 27, 2019
ff7b2c9
Correcting semantic usage of overloaded CloudLocation::operator
aentinger Aug 2, 2019
9dd4b36
Types for home automation
ilcato Jun 13, 2019
c557001
Automation types rename
ilcato Jun 14, 2019
ebeb82a
Added home automation types
ilcato Jun 18, 2019
d2153d3
Fixed style formatting
ilcato Jun 18, 2019
5067fa9
Manage the SWI attribute on behalf of the widget
ilcato Aug 7, 2019
3fe305e
Fixed DimmeredLight
ilcato Aug 7, 2019
061268e
Fixed formatting error
ilcato Aug 7, 2019
bdb7bfa
Added tests for home automation types
mirkokurt Aug 19, 2019
e1a17e4
Fix automation types
ilcato Aug 27, 2019
8d93e57
Add getters and setters to automation types
Oct 24, 2019
4cc870c
removed dependency lib examples
Oct 28, 2019
aa06c8b
Fix dimmed typo
Oct 28, 2019
66c8933
Merge pull request #44 from arduino-libraries/remove_examples
Oct 28, 2019
10acd4f
First draft TV type support
ilcato Nov 7, 2019
bf0c66b
Fixed formatting
ilcato Nov 7, 2019
eef2689
Implement @lxrobotics suggestions
ilcato Nov 12, 2019
dc7562b
Fixed missing reference to new type
ilcato Nov 13, 2019
c4ffeef
Use base integer type
ilcato Nov 13, 2019
6185636
Update local timestamp after setting values
Dec 11, 2019
279a98e
Add setters for tv switch, mute and volume
Dec 11, 2019
c221d09
fix_boolean_management (#49)
ilcato Dec 16, 2019
b389995
LoRa support (#48)
mirkokurt Dec 16, 2019
12fc6bb
Fix CloudTelevision volume setter name
per1234 Jan 15, 2020
8fe1fac
Adding a function to register a callback function for retrieving a gl…
aentinger Feb 25, 2020
f9b5a13
Removal of hidden dependency to RTCZero which is used to retrieve a e…
aentinger Feb 27, 2020
abb0d0d
Moving all ArduinoCloudThing code into folder 'cbor'
aentinger Jun 3, 2020
fd428e2
Merge branch 'master' of /home/alex/projects/arduino/tmp/ArduinoCloud…
aentinger Jun 3, 2020
088c2b6
Moving pulled in cbor folder from ArduinoCloudThing into src
aentinger Jun 3, 2020
c9edb04
Remove ArduinoCloudThing from the list of dependencies
aentinger Jun 3, 2020
faf2b7e
Remove ArduinoCloudThing from the list of automatically installed lib…
aentinger Jun 3, 2020
4c2c5d5
Replacing absolute with relative inclusions which are necessary now t…
aentinger Jun 3, 2020
b216a9c
Adding latest test code of ArduinoCloudThing
aentinger Jun 3, 2020
46193a0
Fixing test cases (CBOR encoded byte-array was not consistent with sy…
aentinger Jun 3, 2020
caed2b6
Excluding the library director containing the SingleLinkedList as wel…
aentinger Jun 3, 2020
c9d7d27
Moving utility/test helper files into subfolder include/util and src/…
aentinger Jun 4, 2020
1d8d99a
Renaming OTATestData.h/.cpp to OTATestDataGenerator.h/.cpp
aentinger Jun 4, 2020
ca3e6a1
Renaming TestUtil to CBORTestUtil and encapsulating its methods in th…
aentinger Jun 4, 2020
ca37b6c
Renaming OTATestDataGenerator.h/.cpp into OTATestUtil.h/.cpp and enca…
aentinger Jun 4, 2020
d47720f
Refactoring CMakeLists.txt by introducing variables holding the vario…
aentinger Jun 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

env:
# libraries to install for all boards
UNIVERSAL_LIBRARIES: '"ArduinoCloudThing" "Arduino_ConnectionHandler" "Arduino_DebugUtils" "ArduinoMqttClient"'
UNIVERSAL_LIBRARIES: '"Arduino_ConnectionHandler" "Arduino_DebugUtils" "ArduinoMqttClient"'
# sketch paths to compile (recursive) for all boards
UNIVERSAL_SKETCH_PATHS: '"examples/ArduinoIoTCloud-Advanced" "examples/ArduinoIoTCloud-Basic" "examples/utility/ArduinoIoTCloud_Travis_CI"'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
cd "$BUILD_PATH"
sudo apt-get --assume-yes install lcov > /dev/null
lcov --directory . --capture --output-file coverage.info
lcov --quiet --remove coverage.info '*/extras/test/*' '/usr/*' --output-file coverage.info
lcov --quiet --remove coverage.info '*/extras/test/*' '/usr/*' '*/src/cbor/lib/*' --output-file coverage.info
lcov --list coverage.info

- name: Upload coverage report to Codecov
Expand Down
52 changes: 48 additions & 4 deletions extras/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project(testArduinoIoTCloud)
##########################################################################

include_directories(include)
include_directories(../../src/cbor)
include_directories(../../src/utility/ota)
include_directories(external/catch/v2.12.1/include)
include_directories(external/fakeit/v2.0.5/include)
Expand All @@ -21,14 +22,57 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

##########################################################################

set(TEST_TARGET testArduinoIoTCloud)
set(TEST_TARGET ${CMAKE_PROJECT_NAME})

##########################################################################

set(TEST_SRCS
src/test_main.cpp
src/test_OTALogic.cpp
src/OTATestData.cpp

src/test_addPropertyReal.cpp
src/test_callback.cpp
src/test_CloudColor.cpp
src/test_CloudLocation.cpp
src/test_decode.cpp
src/test_encode.cpp
src/test_publishEvery.cpp
src/test_publishOnChange.cpp
src/test_publishOnChangeRateLimit.cpp
src/test_readOnly.cpp
src/test_writeOnly.cpp
)

set(TEST_UTIL_SRCS
src/util/CBORTestUtil.cpp
src/util/OTATestUtil.cpp
)

set(TEST_DUT_SRCS
../../src/utility/ota/crc.cpp
../../src/utility/ota/OTALogic.cpp

../../src/cbor/ArduinoCloudThing.cpp
../../src/cbor/ArduinoCloudProperty.cpp
../../src/cbor/lib/tinycbor/src/cborencoder.c
../../src/cbor/lib/tinycbor/src/cborencoder_close_container_checked.c
../../src/cbor/lib/tinycbor/src/cborerrorstrings.c
../../src/cbor/lib/tinycbor/src/cborparser.c
../../src/cbor/lib/tinycbor/src/cborparser_dup_string.c
../../src/cbor/lib/tinycbor/src/cborpretty.c
../../src/cbor/lib/tinycbor/src/cborpretty_stdio.c
../../src/cbor/lib/tinycbor/src/cbortojson.c
../../src/cbor/lib/tinycbor/src/cborvalidation.c
../../src/cbor/lib/tinycbor/src/open_memstream.c
)

##########################################################################

set(TEST_TARGET_SRCS
src/Arduino.cpp
src/test_main.cpp
${TEST_SRCS}
${TEST_UTIL_SRCS}
${TEST_DUT_SRCS}
)

##########################################################################
Expand All @@ -43,7 +87,7 @@ set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage")

add_executable(
${TEST_TARGET}
${TEST_SRCS}
${TEST_TARGET_SRCS}
)

##########################################################################
Expand Down
27 changes: 27 additions & 0 deletions extras/test/include/Arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright (c) 2019 Arduino. All rights reserved.
*/

#ifndef TEST_ARDUINO_H_
#define TEST_ARDUINO_H_

/******************************************************************************
INCLUDE
******************************************************************************/

#include <string>

/******************************************************************************
TYPEDEF
******************************************************************************/

typedef std::string String;

/******************************************************************************
FUNCTION PROTOTYPES
******************************************************************************/

void set_millis(unsigned long const millis);
unsigned long millis();

#endif /* TEST_ARDUINO_H_ */
36 changes: 36 additions & 0 deletions extras/test/include/util/CBORTestUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright (c) 2019 Arduino. All rights reserved.
*/

#ifndef INCLUDE_CBOR_TESTUTIL_H_
#define INCLUDE_CBOR_TESTUTIL_H_

/**************************************************************************************
INCLUDE
**************************************************************************************/

#include <ArduinoCloudThing.h>

#include <vector>

/**************************************************************************************
NAMESPACE
**************************************************************************************/

namespace cbor
{

/**************************************************************************************
PROTOTYPES
**************************************************************************************/

std::vector<uint8_t> encode(ArduinoCloudThing & thing, bool lightPayload = false);
void print(std::vector<uint8_t> const & vect);

/**************************************************************************************
NAMESPACE
**************************************************************************************/

} /* cbor */

#endif /* INCLUDE_CBOR_TESTUTIL_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
* Copyright (c) 2020 Arduino. All rights reserved.
*/

#ifndef OTA_TEST_DATA_H_
#define OTA_TEST_DATA_H_
#ifndef OTA_TEST_DATA_GENERATOR_H_
#define OTA_TEST_DATA_GENERATOR_H_

/**************************************************************************************
INCLUDE
**************************************************************************************/

#include <stdint.h>

/**************************************************************************************
NAMESPACE
**************************************************************************************/

namespace ota
{

/**************************************************************************************
TYPEDEF
**************************************************************************************/
Expand All @@ -33,5 +40,10 @@ union OTAData
void generate_valid_ota_data(OTAData & ota_data);
void generate_invalid_ota_data_crc_wrong(OTAData & ota_data);

/**************************************************************************************
NAMESPACE
**************************************************************************************/

} /* ota */

#endif /* OTA_TEST_DATA_H_ */
#endif /* OTA_TEST_DATA_GENERATOR_H_ */
27 changes: 27 additions & 0 deletions extras/test/src/Arduino.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright (c) 2019 Arduino. All rights reserved.
*/

/******************************************************************************
INCLUDE
******************************************************************************/

#include <Arduino.h>

/******************************************************************************
GLOBAL VARIABLES
******************************************************************************/

static unsigned long current_millis = 0;

/******************************************************************************
PUBLIC FUNCTIONS
******************************************************************************/

void set_millis(unsigned long const millis) {
current_millis = millis;
}

unsigned long millis() {
return current_millis;
}
123 changes: 123 additions & 0 deletions extras/test/src/test_CloudColor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);

}
}
}
Loading