diff --git a/CMakeLists.txt b/CMakeLists.txt
index 02789de..279cf3a 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,15 @@
-cmake_minimum_required(VERSION 2.8.3)
-project(hueplusplus)
+cmake_minimum_required(VERSION 3.2)
+
+if(${CMAKE_VERSION} VERSION_LESS 3.11)
+ cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
+else()
+ cmake_policy(VERSION 3.11)
+endif()
+
+# Add cmake dir to module path, so Find*.cmake can be found
+set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
+
+project(hueplusplus LANGUAGES CXX)
# options to set
option(hueplusplus_TESTS "Build tests" OFF)
diff --git a/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in
old mode 100755
new mode 100644
index 4c07dc7..4c07dc7
--- a/cmake_uninstall.cmake.in
+++ b/cmake/cmake_uninstall.cmake.in
diff --git a/hueplusplus/hueplusplus-config.cmake.in b/cmake/hueplusplus-config.cmake.in
old mode 100755
new mode 100644
index dc1490f..dc1490f
--- a/hueplusplus/hueplusplus-config.cmake.in
+++ b/cmake/hueplusplus-config.cmake.in
diff --git a/extern b/extern
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/extern
diff --git a/hueplusplus/include/BaseHttpHandler.h b/include/hueplusplus/BaseHttpHandler.h
index 22d29c6..db0fe55 100644
--- a/hueplusplus/include/BaseHttpHandler.h
+++ b/include/hueplusplus/BaseHttpHandler.h
@@ -1,175 +1,175 @@
-/**
- \file BaseHttpHandler.h
- Copyright Notice\n
- Copyright (C) 2020 Jan Rogall - developer\n
- Copyright (C) 2020 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#ifndef _BASE_HTTPHANDLER_H
-#define _BASE_HTTPHANDLER_H
-
-#include
-#include
-#include
-#include
-
-#include "IHttpHandler.h"
-
-#include "json/json.hpp"
-
-//! Base class for classes that handle http requests and multicast requests
-class BaseHttpHandler : public IHttpHandler
-{
-public:
- //! \brief Virtual dtor
- virtual ~BaseHttpHandler() = default;
-
- //! \brief Send a message to a specified host and return the body of the response.
- //!
- //! \param msg The message that should sent to the specified address
- //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
- //! \param port Optional port the request is sent to, default is 80
- //! \return The body of the response of the host as a string
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- std::string sendGetHTTPBody(const std::string& msg, const std::string& adr, int port = 80) const override;
-
- //! \brief Send a HTTP request with the given method to the specified host and return the body of the response.
- //!
- //! \param method HTTP method type e.g. GET, HEAD, POST, PUT, DELETE, ...
- //! \param uri Uniform Resource Identifier in the request
- //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
- //! \param body Request body, may be empty
- //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
- //! \param port Optional port the request is sent to, default is 80
- //! \return Body of the response of the host
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- std::string sendHTTPRequest(const std::string& method, const std::string& uri, const std::string& contentType,
- const std::string& body, const std::string& adr, int port = 80) const override;
-
- //! \brief Send a HTTP GET request to the specified host and return the body of the response.
- //!
- //! \param uri Uniform Resource Identifier in the request
- //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
- //! \param body Request body, may be empty
- //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
- //! \param port Optional port the request is sent to, default is 80
- //! that specifies the port to which the request is sent to. Default is 80
- //! \return Body of the response of the host
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- std::string GETString(const std::string& uri, const std::string& contentType, const std::string& body,
- const std::string& adr, int port = 80) const override;
-
- //! \brief Send a HTTP POST request to the specified host and return the body of the response.
- //!
- //! \param uri Uniform Resource Identifier in the request
- //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
- //! \param body Request body, may be empty
- //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
- //! \param port Optional port the request is sent to, default is 80
- //! that specifies the port to which the request is sent to. Default is 80
- //! \return Body of the response of the host
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- std::string POSTString(const std::string& uri, const std::string& contentType, const std::string& body,
- const std::string& adr, int port = 80) const override;
-
- //! \brief Send a HTTP PUT request to the specified host and return the body of the response.
- //!
- //! \param uri Uniform Resource Identifier in the request
- //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
- //! \param body Request body, may be empty
- //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
- //! \param port Optional port the request is sent to, default is 80
- //! that specifies the port to which the request is sent to. Default is 80
- //! \return Body of the response of the host
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- std::string PUTString(const std::string& uri, const std::string& contentType, const std::string& body,
- const std::string& adr, int port = 80) const override;
-
- //! \brief Send a HTTP DELETE request to the specified host and return the body of the response.
- //!
- //! \param uri Uniform Resource Identifier in the request
- //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
- //! \param body Request body, may be empty
- //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
- //! \param port Optional port the request is sent to, default is 80
- //! that specifies the port to which the request is sent to. Default is 80
- //! \return Body of the response of the host
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- std::string DELETEString(const std::string& uri, const std::string& contentType, const std::string& body,
- const std::string& adr, int port = 80) const override;
-
- //! \brief Send a HTTP GET request to the specified host and return the body of the response parsed as JSON.
- //!
- //! \param uri Uniform Resource Identifier in the request
- //! \param body Request body, may be empty
- //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
- //! \param port Optional port the request is sent to, default is 80
- //! \return Parsed body of the response of the host
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- //! \throws nlohmann::json::parse_error when the body could not be parsed
- nlohmann::json GETJson(
- const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
-
- //! \brief Send a HTTP POST request to the specified host and return the body of the response parsed as JSON.
- //!
- //! \param uri Uniform Resource Identifier in the request
- //! \param body Request body, may be empty
- //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
- //! \param port Optional port the request is sent to, default is 80
- //! \return Parsed body of the response of the host
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- //! \throws nlohmann::json::parse_error when the body could not be parsed
- nlohmann::json POSTJson(
- const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
-
- //! \brief Send a HTTP PUT request to the specified host and return the body of the response parsed as JSON.
- //!
- //! \param uri Uniform Resource Identifier in the request
- //! \param body Request body, may be empty
- //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
- //! \param port Optional port the request is sent to, default is 80
- //! \return Parsed body of the response of the host
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- //! \throws nlohmann::json::parse_error when the body could not be parsed
- nlohmann::json PUTJson(
- const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
-
- //! \brief Send a HTTP DELETE request to the specified host and return the body of the response parsed as JSON.
- //!
- //! \param uri Uniform Resource Identifier in the request
- //! \param body Request body, may be empty
- //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
- //! \param port Optional port the request is sent to, default is 80
- //! \return Parsed body of the response of the host
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- //! \throws nlohmann::json::parse_error when the body could not be parsed
- nlohmann::json DELETEJson(
- const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
-};
-
-#endif
+/**
+ \file BaseHttpHandler.h
+ Copyright Notice\n
+ Copyright (C) 2020 Jan Rogall - developer\n
+ Copyright (C) 2020 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+**/
+
+#ifndef _BASE_HTTPHANDLER_H
+#define _BASE_HTTPHANDLER_H
+
+#include
+#include
+#include
+#include
+
+#include "IHttpHandler.h"
+
+#include "json/json.hpp"
+
+//! Base class for classes that handle http requests and multicast requests
+class BaseHttpHandler : public IHttpHandler
+{
+public:
+ //! \brief Virtual dtor
+ virtual ~BaseHttpHandler() = default;
+
+ //! \brief Send a message to a specified host and return the body of the response.
+ //!
+ //! \param msg The message that should sent to the specified address
+ //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
+ //! \param port Optional port the request is sent to, default is 80
+ //! \return The body of the response of the host as a string
+ //! \throws std::system_error when system or socket operations fail
+ //! \throws HueException when response contained no body
+ std::string sendGetHTTPBody(const std::string& msg, const std::string& adr, int port = 80) const override;
+
+ //! \brief Send a HTTP request with the given method to the specified host and return the body of the response.
+ //!
+ //! \param method HTTP method type e.g. GET, HEAD, POST, PUT, DELETE, ...
+ //! \param uri Uniform Resource Identifier in the request
+ //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
+ //! \param body Request body, may be empty
+ //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
+ //! \param port Optional port the request is sent to, default is 80
+ //! \return Body of the response of the host
+ //! \throws std::system_error when system or socket operations fail
+ //! \throws HueException when response contained no body
+ std::string sendHTTPRequest(const std::string& method, const std::string& uri, const std::string& contentType,
+ const std::string& body, const std::string& adr, int port = 80) const override;
+
+ //! \brief Send a HTTP GET request to the specified host and return the body of the response.
+ //!
+ //! \param uri Uniform Resource Identifier in the request
+ //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
+ //! \param body Request body, may be empty
+ //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
+ //! \param port Optional port the request is sent to, default is 80
+ //! that specifies the port to which the request is sent to. Default is 80
+ //! \return Body of the response of the host
+ //! \throws std::system_error when system or socket operations fail
+ //! \throws HueException when response contained no body
+ std::string GETString(const std::string& uri, const std::string& contentType, const std::string& body,
+ const std::string& adr, int port = 80) const override;
+
+ //! \brief Send a HTTP POST request to the specified host and return the body of the response.
+ //!
+ //! \param uri Uniform Resource Identifier in the request
+ //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
+ //! \param body Request body, may be empty
+ //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
+ //! \param port Optional port the request is sent to, default is 80
+ //! that specifies the port to which the request is sent to. Default is 80
+ //! \return Body of the response of the host
+ //! \throws std::system_error when system or socket operations fail
+ //! \throws HueException when response contained no body
+ std::string POSTString(const std::string& uri, const std::string& contentType, const std::string& body,
+ const std::string& adr, int port = 80) const override;
+
+ //! \brief Send a HTTP PUT request to the specified host and return the body of the response.
+ //!
+ //! \param uri Uniform Resource Identifier in the request
+ //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
+ //! \param body Request body, may be empty
+ //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
+ //! \param port Optional port the request is sent to, default is 80
+ //! that specifies the port to which the request is sent to. Default is 80
+ //! \return Body of the response of the host
+ //! \throws std::system_error when system or socket operations fail
+ //! \throws HueException when response contained no body
+ std::string PUTString(const std::string& uri, const std::string& contentType, const std::string& body,
+ const std::string& adr, int port = 80) const override;
+
+ //! \brief Send a HTTP DELETE request to the specified host and return the body of the response.
+ //!
+ //! \param uri Uniform Resource Identifier in the request
+ //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
+ //! \param body Request body, may be empty
+ //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
+ //! \param port Optional port the request is sent to, default is 80
+ //! that specifies the port to which the request is sent to. Default is 80
+ //! \return Body of the response of the host
+ //! \throws std::system_error when system or socket operations fail
+ //! \throws HueException when response contained no body
+ std::string DELETEString(const std::string& uri, const std::string& contentType, const std::string& body,
+ const std::string& adr, int port = 80) const override;
+
+ //! \brief Send a HTTP GET request to the specified host and return the body of the response parsed as JSON.
+ //!
+ //! \param uri Uniform Resource Identifier in the request
+ //! \param body Request body, may be empty
+ //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
+ //! \param port Optional port the request is sent to, default is 80
+ //! \return Parsed body of the response of the host
+ //! \throws std::system_error when system or socket operations fail
+ //! \throws HueException when response contained no body
+ //! \throws nlohmann::json::parse_error when the body could not be parsed
+ nlohmann::json GETJson(
+ const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
+
+ //! \brief Send a HTTP POST request to the specified host and return the body of the response parsed as JSON.
+ //!
+ //! \param uri Uniform Resource Identifier in the request
+ //! \param body Request body, may be empty
+ //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
+ //! \param port Optional port the request is sent to, default is 80
+ //! \return Parsed body of the response of the host
+ //! \throws std::system_error when system or socket operations fail
+ //! \throws HueException when response contained no body
+ //! \throws nlohmann::json::parse_error when the body could not be parsed
+ nlohmann::json POSTJson(
+ const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
+
+ //! \brief Send a HTTP PUT request to the specified host and return the body of the response parsed as JSON.
+ //!
+ //! \param uri Uniform Resource Identifier in the request
+ //! \param body Request body, may be empty
+ //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
+ //! \param port Optional port the request is sent to, default is 80
+ //! \return Parsed body of the response of the host
+ //! \throws std::system_error when system or socket operations fail
+ //! \throws HueException when response contained no body
+ //! \throws nlohmann::json::parse_error when the body could not be parsed
+ nlohmann::json PUTJson(
+ const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
+
+ //! \brief Send a HTTP DELETE request to the specified host and return the body of the response parsed as JSON.
+ //!
+ //! \param uri Uniform Resource Identifier in the request
+ //! \param body Request body, may be empty
+ //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
+ //! \param port Optional port the request is sent to, default is 80
+ //! \return Parsed body of the response of the host
+ //! \throws std::system_error when system or socket operations fail
+ //! \throws HueException when response contained no body
+ //! \throws nlohmann::json::parse_error when the body could not be parsed
+ nlohmann::json DELETEJson(
+ const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
+};
+
+#endif
diff --git a/hueplusplus/include/BrightnessStrategy.h b/include/hueplusplus/BrightnessStrategy.h
old mode 100755
new mode 100644
index 1c12704..1c12704
--- a/hueplusplus/include/BrightnessStrategy.h
+++ b/include/hueplusplus/BrightnessStrategy.h
diff --git a/hueplusplus/include/ColorHueStrategy.h b/include/hueplusplus/ColorHueStrategy.h
old mode 100755
new mode 100644
index 7d40d8a..7d40d8a
--- a/hueplusplus/include/ColorHueStrategy.h
+++ b/include/hueplusplus/ColorHueStrategy.h
diff --git a/hueplusplus/include/ColorTemperatureStrategy.h b/include/hueplusplus/ColorTemperatureStrategy.h
old mode 100755
new mode 100644
index 37be4fe..37be4fe
--- a/hueplusplus/include/ColorTemperatureStrategy.h
+++ b/include/hueplusplus/ColorTemperatureStrategy.h
diff --git a/hueplusplus/include/ExtendedColorHueStrategy.h b/include/hueplusplus/ExtendedColorHueStrategy.h
old mode 100755
new mode 100644
index 000418f..000418f
--- a/hueplusplus/include/ExtendedColorHueStrategy.h
+++ b/include/hueplusplus/ExtendedColorHueStrategy.h
diff --git a/hueplusplus/include/ExtendedColorTemperatureStrategy.h b/include/hueplusplus/ExtendedColorTemperatureStrategy.h
old mode 100755
new mode 100644
index e24137c..e24137c
--- a/hueplusplus/include/ExtendedColorTemperatureStrategy.h
+++ b/include/hueplusplus/ExtendedColorTemperatureStrategy.h
diff --git a/hueplusplus/include/Hue.h b/include/hueplusplus/Hue.h
index 1aa8360..1aa8360 100644
--- a/hueplusplus/include/Hue.h
+++ b/include/hueplusplus/Hue.h
diff --git a/hueplusplus/include/HueCommandAPI.h b/include/hueplusplus/HueCommandAPI.h
index 7bd9895..7bd9895 100644
--- a/hueplusplus/include/HueCommandAPI.h
+++ b/include/hueplusplus/HueCommandAPI.h
diff --git a/hueplusplus/include/HueConfig.h b/include/hueplusplus/HueConfig.h
old mode 100755
new mode 100644
index de5c069..de5c069
--- a/hueplusplus/include/HueConfig.h
+++ b/include/hueplusplus/HueConfig.h
diff --git a/hueplusplus/include/HueException.h b/include/hueplusplus/HueException.h
index fafb7cc..fafb7cc 100644
--- a/hueplusplus/include/HueException.h
+++ b/include/hueplusplus/HueException.h
diff --git a/hueplusplus/include/HueExceptionMacro.h b/include/hueplusplus/HueExceptionMacro.h
index 80ffaeb..80ffaeb 100644
--- a/hueplusplus/include/HueExceptionMacro.h
+++ b/include/hueplusplus/HueExceptionMacro.h
diff --git a/hueplusplus/include/HueLight.h b/include/hueplusplus/HueLight.h
index 0bd20ca..0bd20ca 100644
--- a/hueplusplus/include/HueLight.h
+++ b/include/hueplusplus/HueLight.h
diff --git a/hueplusplus/include/IHttpHandler.h b/include/hueplusplus/IHttpHandler.h
old mode 100755
new mode 100644
index edcb6be..edcb6be
--- a/hueplusplus/include/IHttpHandler.h
+++ b/include/hueplusplus/IHttpHandler.h
diff --git a/hueplusplus/include/LinHttpHandler.h b/include/hueplusplus/LinHttpHandler.h
old mode 100755
new mode 100644
index 5717d4c..5717d4c
--- a/hueplusplus/include/LinHttpHandler.h
+++ b/include/hueplusplus/LinHttpHandler.h
diff --git a/hueplusplus/include/SimpleBrightnessStrategy.h b/include/hueplusplus/SimpleBrightnessStrategy.h
old mode 100755
new mode 100644
index 59df71a..59df71a
--- a/hueplusplus/include/SimpleBrightnessStrategy.h
+++ b/include/hueplusplus/SimpleBrightnessStrategy.h
diff --git a/hueplusplus/include/SimpleColorHueStrategy.h b/include/hueplusplus/SimpleColorHueStrategy.h
old mode 100755
new mode 100644
index c963ef2..c963ef2
--- a/hueplusplus/include/SimpleColorHueStrategy.h
+++ b/include/hueplusplus/SimpleColorHueStrategy.h
diff --git a/hueplusplus/include/SimpleColorTemperatureStrategy.h b/include/hueplusplus/SimpleColorTemperatureStrategy.h
old mode 100755
new mode 100644
index 484c081..484c081
--- a/hueplusplus/include/SimpleColorTemperatureStrategy.h
+++ b/include/hueplusplus/SimpleColorTemperatureStrategy.h
diff --git a/hueplusplus/include/UPnP.h b/include/hueplusplus/UPnP.h
old mode 100755
new mode 100644
index 01e75a9..01e75a9
--- a/hueplusplus/include/UPnP.h
+++ b/include/hueplusplus/UPnP.h
diff --git a/hueplusplus/include/Units.h b/include/hueplusplus/Units.h
index ff24330..ff24330 100644
--- a/hueplusplus/include/Units.h
+++ b/include/hueplusplus/Units.h
diff --git a/hueplusplus/include/Utils.h b/include/hueplusplus/Utils.h
index 96cff7c..96cff7c 100644
--- a/hueplusplus/include/Utils.h
+++ b/include/hueplusplus/Utils.h
diff --git a/hueplusplus/include/WinHttpHandler.h b/include/hueplusplus/WinHttpHandler.h
index e5c92dc..e5c92dc 100644
--- a/hueplusplus/include/WinHttpHandler.h
+++ b/include/hueplusplus/WinHttpHandler.h
diff --git a/hueplusplus/include/json/json.hpp b/include/json/json.hpp
index 06da815..06da815 100644
--- a/hueplusplus/include/json/json.hpp
+++ b/include/json/json.hpp
diff --git a/hueplusplus/BaseHttpHandler.cpp b/src/BaseHttpHandler.cpp
index f0cd07d..f0cd07d 100644
--- a/hueplusplus/BaseHttpHandler.cpp
+++ b/src/BaseHttpHandler.cpp
diff --git a/hueplusplus/CMakeLists.txt b/src/CMakeLists.txt
old mode 100755
new mode 100644
index 608e2ad..63cd756
--- a/hueplusplus/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -36,21 +36,11 @@ if(ESP_PLATFORM)
)
endif()
-
-# Set global includes BEFORE adding any targets for legacy CMake versions
-if(CMAKE_VERSION VERSION_LESS 2.8.12)
- include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
- include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/json")
-endif()
-
-
# hueplusplus shared library
add_library(hueplusplusshared SHARED ${hueplusplus_SOURCES})
set_property(TARGET hueplusplusshared PROPERTY CXX_STANDARD 14)
set_property(TARGET hueplusplusshared PROPERTY CXX_EXTENSIONS OFF)
-if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_include_directories(hueplusplusshared PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
-endif()
+target_include_directories(hueplusplusshared PUBLIC $ $)
install(TARGETS hueplusplusshared DESTINATION lib)
# hueplusplus static library
@@ -58,9 +48,7 @@ add_library(hueplusplusstatic STATIC ${hueplusplus_SOURCES})
set_property(TARGET hueplusplusstatic PROPERTY CXX_STANDARD 14)
set_property(TARGET hueplusplusstatic PROPERTY CXX_EXTENSIONS OFF)
install(TARGETS hueplusplusstatic DESTINATION lib)
-if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_include_directories(hueplusplusstatic PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
-endif()
+target_include_directories(hueplusplusstatic PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
install(FILES ${hueplusplus_HEADERS} DESTINATION include/hueplusplus)
# Export the package for use from the build-tree
diff --git a/hueplusplus/ExtendedColorHueStrategy.cpp b/src/ExtendedColorHueStrategy.cpp
old mode 100755
new mode 100644
index 6199855..6199855
--- a/hueplusplus/ExtendedColorHueStrategy.cpp
+++ b/src/ExtendedColorHueStrategy.cpp
diff --git a/hueplusplus/ExtendedColorTemperatureStrategy.cpp b/src/ExtendedColorTemperatureStrategy.cpp
index 202096a..202096a 100644
--- a/hueplusplus/ExtendedColorTemperatureStrategy.cpp
+++ b/src/ExtendedColorTemperatureStrategy.cpp
diff --git a/hueplusplus/Hue.cpp b/src/Hue.cpp
index d088f4e..d088f4e 100644
--- a/hueplusplus/Hue.cpp
+++ b/src/Hue.cpp
diff --git a/hueplusplus/HueCommandAPI.cpp b/src/HueCommandAPI.cpp
index b818d44..b818d44 100644
--- a/hueplusplus/HueCommandAPI.cpp
+++ b/src/HueCommandAPI.cpp
diff --git a/hueplusplus/HueException.cpp b/src/HueException.cpp
index d54f6c7..d54f6c7 100644
--- a/hueplusplus/HueException.cpp
+++ b/src/HueException.cpp
diff --git a/hueplusplus/HueLight.cpp b/src/HueLight.cpp
index dc705ff..dc705ff 100644
--- a/hueplusplus/HueLight.cpp
+++ b/src/HueLight.cpp
diff --git a/hueplusplus/LinHttpHandler.cpp b/src/LinHttpHandler.cpp
old mode 100755
new mode 100644
index c8f7132..c8f7132
--- a/hueplusplus/LinHttpHandler.cpp
+++ b/src/LinHttpHandler.cpp
diff --git a/hueplusplus/SimpleBrightnessStrategy.cpp b/src/SimpleBrightnessStrategy.cpp
index d0d00ac..d0d00ac 100644
--- a/hueplusplus/SimpleBrightnessStrategy.cpp
+++ b/src/SimpleBrightnessStrategy.cpp
diff --git a/hueplusplus/SimpleColorHueStrategy.cpp b/src/SimpleColorHueStrategy.cpp
index 86c5ee4..86c5ee4 100644
--- a/hueplusplus/SimpleColorHueStrategy.cpp
+++ b/src/SimpleColorHueStrategy.cpp
diff --git a/hueplusplus/SimpleColorTemperatureStrategy.cpp b/src/SimpleColorTemperatureStrategy.cpp
index 8dac10f..8dac10f 100644
--- a/hueplusplus/SimpleColorTemperatureStrategy.cpp
+++ b/src/SimpleColorTemperatureStrategy.cpp
diff --git a/hueplusplus/UPnP.cpp b/src/UPnP.cpp
old mode 100755
new mode 100644
index 1d5b349..1d5b349
--- a/hueplusplus/UPnP.cpp
+++ b/src/UPnP.cpp
diff --git a/hueplusplus/Utils.cpp b/src/Utils.cpp
index 2b55488..2b55488 100644
--- a/hueplusplus/Utils.cpp
+++ b/src/Utils.cpp
diff --git a/hueplusplus/WinHttpHandler.cpp b/src/WinHttpHandler.cpp
old mode 100755
new mode 100644
index 23a53cf..23a53cf
--- a/hueplusplus/WinHttpHandler.cpp
+++ b/src/WinHttpHandler.cpp
diff --git a/hueplusplus/test/CMakeLists.txt b/src/test/CMakeLists.txt
old mode 100755
new mode 100644
index 8106d3d..353171f
--- a/hueplusplus/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -1,109 +1,109 @@
-# Set cmake cxx standard to 14
-set(CMAKE_CXX_STANDARD 14)
-
-# Download and unpack googletest at configure time
-configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
-execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} .
- RESULT_VARIABLE result
- WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download"
-)
-if(result)
- message(FATAL_ERROR "CMake step for googletest failed: ${result}")
-endif()
-execute_process(COMMAND "${CMAKE_COMMAND}" --build .
- RESULT_VARIABLE result
- WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download"
-)
-if(result)
- message(FATAL_ERROR "Build step for googletest failed: ${result}")
-endif()
-
-# Prevent overriding the parent project's compiler/linker
-# settings on Windows
-set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
-
-# Add googletest directly to our build. This defines
-# the gtest and gtest_main targets.
-add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src EXCLUDE_FROM_ALL
- ${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL
-)
-
-# The gtest/gtest_main targets carry header search path
-# dependencies automatically when using CMake 2.8.11 or
-# later. Otherwise we have to add them here ourselves.
-if (CMAKE_VERSION VERSION_LESS 2.8.11)
- include_directories("${gtest_SOURCE_DIR}/include" EXCLUDE_FROM_ALL)
-endif()
-
-# define all test sources
-set(TEST_SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/test_BaseHttpHandler.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_ExtendedColorHueStrategy.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_ExtendedColorTemperatureStrategy.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_Hue.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_HueLight.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_HueCommandAPI.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_Main.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleBrightnessStrategy.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleColorHueStrategy.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleColorTemperatureStrategy.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_UPnP.cpp
-)
-
-# test executable
-add_executable(test_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES})
-target_link_libraries(test_HuePlusPlus gtest gmock)
-target_include_directories(test_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS})
-target_include_directories(test_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR})
-set_property(TARGET test_HuePlusPlus PROPERTY CXX_STANDARD 14)
-set_property(TARGET test_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF)
-set_property(TARGET gmock PROPERTY CXX_STANDARD 14)
-set_property(TARGET gtest PROPERTY CXX_STANDARD 14)
-# add custom target to make it simple to run the tests
-add_custom_target("unittest"
- # Run the executable
- COMMAND test_HuePlusPlus
- # Depends on test_HuePlusPlus
- DEPENDS test_HuePlusPlus
-)
-
-# Check for coverage test prerequisites
-find_program( GCOV_PATH gcov )
-find_program( LCOV_PATH lcov )
-
-if(LCOV_PATH AND GCOV_PATH)
- # GCov
- include(CodeCoverage.cmake)
- add_executable(testcov_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES})
- target_link_libraries(testcov_HuePlusPlus gtest gmock)
- # prevent Main.cpp from defining main()
- target_compile_definitions(testcov_HuePlusPlus PUBLIC MAIN_CPP_NO_MAIN_FUNCTION)
- target_include_directories(testcov_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS})
- target_include_directories(testcov_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR})
- set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_STANDARD 14)
- set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF)
- # this will be already done by APPEND_COVERAGE_COMPILER_FLAGS()
- #set_target_properties(
- # testcov_HuePlusPlus PROPERTIES
- # COMPILE_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage"
- #)
- # Normally this would be -lgcov, but on mac only -Lgcov works
- #set_target_properties(
- # testcov_HuePlusPlus PROPERTIES
- # LINK_FLAGS "-O0 -g -Lgcov -fprofile-arcs -ftest-coverage"
- #)
- # exclude some special files we do not want to profile
- set(COVERAGE_EXCLUDES
- '/usr/*' # unix
- '*/hueplusplus/build/*'
- '*/json*'
- '*/test/*'
- '*/v1/*' # iOS
- )
- APPEND_COVERAGE_COMPILER_FLAGS()
- SETUP_TARGET_FOR_COVERAGE(
- NAME "coveragetest"
- EXECUTABLE testcov_HuePlusPlus
- DEPENDENCIES testcov_HuePlusPlus
- )
-endif()
+# Set cmake cxx standard to 14
+set(CMAKE_CXX_STANDARD 14)
+
+# Download and unpack googletest at configure time
+configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
+execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} .
+ RESULT_VARIABLE result
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download"
+)
+if(result)
+ message(FATAL_ERROR "CMake step for googletest failed: ${result}")
+endif()
+execute_process(COMMAND "${CMAKE_COMMAND}" --build .
+ RESULT_VARIABLE result
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download"
+)
+if(result)
+ message(FATAL_ERROR "Build step for googletest failed: ${result}")
+endif()
+
+# Prevent overriding the parent project's compiler/linker
+# settings on Windows
+set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+
+# Add googletest directly to our build. This defines
+# the gtest and gtest_main targets.
+add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src EXCLUDE_FROM_ALL
+ ${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL
+)
+
+# The gtest/gtest_main targets carry header search path
+# dependencies automatically when using CMake 2.8.11 or
+# later. Otherwise we have to add them here ourselves.
+if (CMAKE_VERSION VERSION_LESS 2.8.11)
+ include_directories("${gtest_SOURCE_DIR}/include" EXCLUDE_FROM_ALL)
+endif()
+
+# define all test sources
+set(TEST_SOURCES
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_BaseHttpHandler.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_ExtendedColorHueStrategy.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_ExtendedColorTemperatureStrategy.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_Hue.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_HueLight.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_HueCommandAPI.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_Main.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleBrightnessStrategy.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleColorHueStrategy.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleColorTemperatureStrategy.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_UPnP.cpp
+)
+
+# test executable
+add_executable(test_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES})
+target_link_libraries(test_HuePlusPlus gtest gmock)
+target_include_directories(test_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS})
+target_include_directories(test_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR})
+set_property(TARGET test_HuePlusPlus PROPERTY CXX_STANDARD 14)
+set_property(TARGET test_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF)
+set_property(TARGET gmock PROPERTY CXX_STANDARD 14)
+set_property(TARGET gtest PROPERTY CXX_STANDARD 14)
+# add custom target to make it simple to run the tests
+add_custom_target("unittest"
+ # Run the executable
+ COMMAND test_HuePlusPlus
+ # Depends on test_HuePlusPlus
+ DEPENDS test_HuePlusPlus
+)
+
+# Check for coverage test prerequisites
+find_program( GCOV_PATH gcov )
+find_program( LCOV_PATH lcov )
+
+if(LCOV_PATH AND GCOV_PATH)
+ # GCov
+ include(CodeCoverage.cmake)
+ add_executable(testcov_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES})
+ target_link_libraries(testcov_HuePlusPlus gtest gmock)
+ # prevent Main.cpp from defining main()
+ target_compile_definitions(testcov_HuePlusPlus PUBLIC MAIN_CPP_NO_MAIN_FUNCTION)
+ target_include_directories(testcov_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS})
+ target_include_directories(testcov_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR})
+ set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_STANDARD 14)
+ set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF)
+ # this will be already done by APPEND_COVERAGE_COMPILER_FLAGS()
+ #set_target_properties(
+ # testcov_HuePlusPlus PROPERTIES
+ # COMPILE_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage"
+ #)
+ # Normally this would be -lgcov, but on mac only -Lgcov works
+ #set_target_properties(
+ # testcov_HuePlusPlus PROPERTIES
+ # LINK_FLAGS "-O0 -g -Lgcov -fprofile-arcs -ftest-coverage"
+ #)
+ # exclude some special files we do not want to profile
+ set(COVERAGE_EXCLUDES
+ '/usr/*' # unix
+ '*/hueplusplus/build/*'
+ '*/json*'
+ '*/test/*'
+ '*/v1/*' # iOS
+ )
+ APPEND_COVERAGE_COMPILER_FLAGS()
+ SETUP_TARGET_FOR_COVERAGE(
+ NAME "coveragetest"
+ EXECUTABLE testcov_HuePlusPlus
+ DEPENDENCIES testcov_HuePlusPlus
+ )
+endif()
diff --git a/hueplusplus/test/CMakeLists.txt.in b/src/test/CMakeLists.txt.in
old mode 100755
new mode 100644
index 257b755..4c67ef5
--- a/hueplusplus/test/CMakeLists.txt.in
+++ b/src/test/CMakeLists.txt.in
@@ -1,15 +1,15 @@
-cmake_minimum_required(VERSION 2.8.2)
-
-project(googletest-download NONE)
-
-include(ExternalProject)
-ExternalProject_Add(googletest
- GIT_REPOSITORY https://github.com/google/googletest.git
- GIT_TAG master
- SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
- BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
- CONFIGURE_COMMAND ""
- BUILD_COMMAND ""
- INSTALL_COMMAND ""
- TEST_COMMAND ""
-)
+cmake_minimum_required(VERSION 2.8.2)
+
+project(googletest-download NONE)
+
+include(ExternalProject)
+ExternalProject_Add(googletest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG master
+ SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
+ BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ TEST_COMMAND ""
+)
diff --git a/hueplusplus/test/CodeCoverage.cmake b/src/test/CodeCoverage.cmake
old mode 100755
new mode 100644
index 8687a27..8971d78
--- a/hueplusplus/test/CodeCoverage.cmake
+++ b/src/test/CodeCoverage.cmake
@@ -1,234 +1,234 @@
-# Copyright (c) 2012 - 2017, Lars Bilke
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors
-# may be used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-# CHANGES:
-#
-# 2012-01-31, Lars Bilke
-# - Enable Code Coverage
-#
-# 2013-09-17, Joakim Söderberg
-# - Added support for Clang.
-# - Some additional usage instructions.
-#
-# 2016-02-03, Lars Bilke
-# - Refactored functions to use named parameters
-#
-# 2017-06-02, Lars Bilke
-# - Merged with modified version from github.com/ufz/ogs
-#
-#
-# USAGE:
-#
-# 1. Copy this file into your cmake modules path.
-#
-# 2. Add the following line to your CMakeLists.txt:
-# include(CodeCoverage)
-#
-# 3. Append necessary compiler flags:
-# APPEND_COVERAGE_COMPILER_FLAGS()
-#
-# 4. If you need to exclude additional directories from the report, specify them
-# using the COVERAGE_EXCLUDES variable before calling SETUP_TARGET_FOR_COVERAGE.
-# Example:
-# set(COVERAGE_EXCLUDES 'dir1/*' 'dir2/*')
-#
-# 5. Use the functions described below to create a custom make target which
-# runs your test executable and produces a code coverage report.
-#
-# 6. Build a Debug build:
-# cmake -DCMAKE_BUILD_TYPE=Debug ..
-# make
-# make my_coverage_target
-#
-
-include(CMakeParseArguments)
-
-# Check prereqs
-find_program( GCOV_PATH gcov )
-find_program( LCOV_PATH lcov )
-find_program( GENHTML_PATH genhtml )
-find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)
-find_program( SIMPLE_PYTHON_EXECUTABLE python )
-
-if(NOT GCOV_PATH)
- message(FATAL_ERROR "gcov not found! Aborting...")
-endif() # NOT GCOV_PATH
-
-if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
- if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
- message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
- endif()
-elseif(NOT CMAKE_COMPILER_IS_GNUCXX)
- message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
-endif()
-
-set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage"
- CACHE INTERNAL "")
-
-set(CMAKE_CXX_FLAGS_COVERAGE
- ${COVERAGE_COMPILER_FLAGS}
- CACHE STRING "Flags used by the C++ compiler during coverage builds."
- FORCE )
-set(CMAKE_C_FLAGS_COVERAGE
- ${COVERAGE_COMPILER_FLAGS}
- CACHE STRING "Flags used by the C compiler during coverage builds."
- FORCE )
-set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
- ""
- CACHE STRING "Flags used for linking binaries during coverage builds."
- FORCE )
-set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
- ""
- CACHE STRING "Flags used by the shared libraries linker during coverage builds."
- FORCE )
-mark_as_advanced(
- CMAKE_CXX_FLAGS_COVERAGE
- CMAKE_C_FLAGS_COVERAGE
- CMAKE_EXE_LINKER_FLAGS_COVERAGE
- CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
-
-if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
- message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
-endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
-
-if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- link_libraries(gcov)
-else()
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
-endif()
-
-# Defines a target for running and collection code coverage information
-# Builds dependencies, runs the given executable and outputs reports.
-# NOTE! The executable should always have a ZERO as exit code otherwise
-# the coverage generation will not complete.
-#
-# SETUP_TARGET_FOR_COVERAGE(
-# NAME testrunner_coverage # New target name
-# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
-# DEPENDENCIES testrunner # Dependencies to build first
-# )
-function(SETUP_TARGET_FOR_COVERAGE)
-
- set(options NONE)
- set(oneValueArgs NAME)
- set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
- cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
- if(NOT LCOV_PATH)
- message(FATAL_ERROR "lcov not found! Aborting...")
- endif() # NOT LCOV_PATH
-
- if(NOT GENHTML_PATH)
- message(FATAL_ERROR "genhtml not found! Aborting...")
- endif() # NOT GENHTML_PATH
-
- # Setup target
- add_custom_target(${Coverage_NAME}
-
- # Cleanup lcov
- COMMAND ${LCOV_PATH} --directory . --zerocounters
-
- # Run tests
- COMMAND ${Coverage_EXECUTABLE}
-
- # Capturing lcov counters and generating report
- COMMAND ${LCOV_PATH} --directory . --capture --output-file ${Coverage_NAME}.info
- COMMAND ${LCOV_PATH} --remove ${Coverage_NAME}.info ${COVERAGE_EXCLUDES} --output-file ${Coverage_NAME}.info.cleaned
- COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${Coverage_NAME}.info.cleaned
- COMMAND ${CMAKE_COMMAND} -E remove ${Coverage_NAME}.info ${Coverage_NAME}.info.cleaned
-
- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
- DEPENDS ${Coverage_DEPENDENCIES}
- COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
- )
-
- # Show info where to find the report
- add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
- COMMAND ;
- COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
- )
-
-endfunction() # SETUP_TARGET_FOR_COVERAGE
-
-# Defines a target for running and collection code coverage information
-# Builds dependencies, runs the given executable and outputs reports.
-# NOTE! The executable should always have a ZERO as exit code otherwise
-# the coverage generation will not complete.
-#
-# SETUP_TARGET_FOR_COVERAGE_COBERTURA(
-# NAME ctest_coverage # New target name
-# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
-# DEPENDENCIES executable_target # Dependencies to build first
-# )
-function(SETUP_TARGET_FOR_COVERAGE_COBERTURA)
-
- set(options NONE)
- set(oneValueArgs NAME)
- set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
- cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
- if(NOT SIMPLE_PYTHON_EXECUTABLE)
- message(FATAL_ERROR "python not found! Aborting...")
- endif() # NOT SIMPLE_PYTHON_EXECUTABLE
-
- if(NOT GCOVR_PATH)
- message(FATAL_ERROR "gcovr not found! Aborting...")
- endif() # NOT GCOVR_PATH
-
- # Combine excludes to several -e arguments
- set(COBERTURA_EXCLUDES "")
- foreach(EXCLUDE ${COVERAGE_EXCLUDES})
- set(COBERTURA_EXCLUDES "-e ${EXCLUDE} ${COBERTURA_EXCLUDES}")
- endforeach()
-
- add_custom_target(${Coverage_NAME}
-
- # Run tests
- ${Coverage_EXECUTABLE}
-
- # Running gcovr
- COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} ${COBERTURA_EXCLUDES}
- -o ${Coverage_NAME}.xml
- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
- DEPENDS ${Coverage_DEPENDENCIES}
- COMMENT "Running gcovr to produce Cobertura code coverage report."
- )
-
- # Show info where to find the report
- add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
- COMMAND ;
- COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml."
- )
-
-endfunction() # SETUP_TARGET_FOR_COVERAGE_COBERTURA
-
-function(APPEND_COVERAGE_COMPILER_FLAGS)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
- message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
-endfunction() # APPEND_COVERAGE_COMPILER_FLAGS
+# Copyright (c) 2012 - 2017, Lars Bilke
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors
+# may be used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# CHANGES:
+#
+# 2012-01-31, Lars Bilke
+# - Enable Code Coverage
+#
+# 2013-09-17, Joakim Söderberg
+# - Added support for Clang.
+# - Some additional usage instructions.
+#
+# 2016-02-03, Lars Bilke
+# - Refactored functions to use named parameters
+#
+# 2017-06-02, Lars Bilke
+# - Merged with modified version from github.com/ufz/ogs
+#
+#
+# USAGE:
+#
+# 1. Copy this file into your cmake modules path.
+#
+# 2. Add the following line to your CMakeLists.txt:
+# include(CodeCoverage)
+#
+# 3. Append necessary compiler flags:
+# APPEND_COVERAGE_COMPILER_FLAGS()
+#
+# 4. If you need to exclude additional directories from the report, specify them
+# using the COVERAGE_EXCLUDES variable before calling SETUP_TARGET_FOR_COVERAGE.
+# Example:
+# set(COVERAGE_EXCLUDES 'dir1/*' 'dir2/*')
+#
+# 5. Use the functions described below to create a custom make target which
+# runs your test executable and produces a code coverage report.
+#
+# 6. Build a Debug build:
+# cmake -DCMAKE_BUILD_TYPE=Debug ..
+# make
+# make my_coverage_target
+#
+
+include(CMakeParseArguments)
+
+# Check prereqs
+find_program( GCOV_PATH gcov )
+find_program( LCOV_PATH lcov )
+find_program( GENHTML_PATH genhtml )
+find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)
+find_program( SIMPLE_PYTHON_EXECUTABLE python )
+
+if(NOT GCOV_PATH)
+ message(FATAL_ERROR "gcov not found! Aborting...")
+endif() # NOT GCOV_PATH
+
+if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
+ if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
+ message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
+ endif()
+elseif(NOT CMAKE_COMPILER_IS_GNUCXX)
+ message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
+endif()
+
+set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage"
+ CACHE INTERNAL "")
+
+set(CMAKE_CXX_FLAGS_COVERAGE
+ ${COVERAGE_COMPILER_FLAGS}
+ CACHE STRING "Flags used by the C++ compiler during coverage builds."
+ FORCE )
+set(CMAKE_C_FLAGS_COVERAGE
+ ${COVERAGE_COMPILER_FLAGS}
+ CACHE STRING "Flags used by the C compiler during coverage builds."
+ FORCE )
+set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
+ ""
+ CACHE STRING "Flags used for linking binaries during coverage builds."
+ FORCE )
+set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
+ ""
+ CACHE STRING "Flags used by the shared libraries linker during coverage builds."
+ FORCE )
+mark_as_advanced(
+ CMAKE_CXX_FLAGS_COVERAGE
+ CMAKE_C_FLAGS_COVERAGE
+ CMAKE_EXE_LINKER_FLAGS_COVERAGE
+ CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
+
+if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
+ message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
+endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
+
+if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ link_libraries(gcov)
+else()
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
+endif()
+
+# Defines a target for running and collection code coverage information
+# Builds dependencies, runs the given executable and outputs reports.
+# NOTE! The executable should always have a ZERO as exit code otherwise
+# the coverage generation will not complete.
+#
+# SETUP_TARGET_FOR_COVERAGE(
+# NAME testrunner_coverage # New target name
+# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
+# DEPENDENCIES testrunner # Dependencies to build first
+# )
+function(SETUP_TARGET_FOR_COVERAGE)
+
+ set(options NONE)
+ set(oneValueArgs NAME)
+ set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
+ cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if(NOT LCOV_PATH)
+ message(FATAL_ERROR "lcov not found! Aborting...")
+ endif() # NOT LCOV_PATH
+
+ if(NOT GENHTML_PATH)
+ message(FATAL_ERROR "genhtml not found! Aborting...")
+ endif() # NOT GENHTML_PATH
+
+ # Setup target
+ add_custom_target(${Coverage_NAME}
+
+ # Cleanup lcov
+ COMMAND ${LCOV_PATH} --directory . --zerocounters
+
+ # Run tests
+ COMMAND ${Coverage_EXECUTABLE}
+
+ # Capturing lcov counters and generating report
+ COMMAND ${LCOV_PATH} --directory . --capture --output-file ${Coverage_NAME}.info
+ COMMAND ${LCOV_PATH} --remove ${Coverage_NAME}.info ${COVERAGE_EXCLUDES} --output-file ${Coverage_NAME}.info.cleaned
+ COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${Coverage_NAME}.info.cleaned
+ COMMAND ${CMAKE_COMMAND} -E remove ${Coverage_NAME}.info ${Coverage_NAME}.info.cleaned
+
+ WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
+ DEPENDS ${Coverage_DEPENDENCIES}
+ COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
+ )
+
+ # Show info where to find the report
+ add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
+ COMMAND ;
+ COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
+ )
+
+endfunction() # SETUP_TARGET_FOR_COVERAGE
+
+# Defines a target for running and collection code coverage information
+# Builds dependencies, runs the given executable and outputs reports.
+# NOTE! The executable should always have a ZERO as exit code otherwise
+# the coverage generation will not complete.
+#
+# SETUP_TARGET_FOR_COVERAGE_COBERTURA(
+# NAME ctest_coverage # New target name
+# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
+# DEPENDENCIES executable_target # Dependencies to build first
+# )
+function(SETUP_TARGET_FOR_COVERAGE_COBERTURA)
+
+ set(options NONE)
+ set(oneValueArgs NAME)
+ set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
+ cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if(NOT SIMPLE_PYTHON_EXECUTABLE)
+ message(FATAL_ERROR "python not found! Aborting...")
+ endif() # NOT SIMPLE_PYTHON_EXECUTABLE
+
+ if(NOT GCOVR_PATH)
+ message(FATAL_ERROR "gcovr not found! Aborting...")
+ endif() # NOT GCOVR_PATH
+
+ # Combine excludes to several -e arguments
+ set(COBERTURA_EXCLUDES "")
+ foreach(EXCLUDE ${COVERAGE_EXCLUDES})
+ set(COBERTURA_EXCLUDES "-e ${EXCLUDE} ${COBERTURA_EXCLUDES}")
+ endforeach()
+
+ add_custom_target(${Coverage_NAME}
+
+ # Run tests
+ ${Coverage_EXECUTABLE}
+
+ # Running gcovr
+ COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} ${COBERTURA_EXCLUDES}
+ -o ${Coverage_NAME}.xml
+ WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
+ DEPENDS ${Coverage_DEPENDENCIES}
+ COMMENT "Running gcovr to produce Cobertura code coverage report."
+ )
+
+ # Show info where to find the report
+ add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
+ COMMAND ;
+ COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml."
+ )
+
+endfunction() # SETUP_TARGET_FOR_COVERAGE_COBERTURA
+
+function(APPEND_COVERAGE_COMPILER_FLAGS)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
+ message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
+endfunction() # APPEND_COVERAGE_COMPILER_FLAGS
diff --git a/hueplusplus/test/mocks/mock_BaseHttpHandler.h b/src/test/mocks/mock_BaseHttpHandler.h
old mode 100755
new mode 100644
index 867a344..867a344
--- a/hueplusplus/test/mocks/mock_BaseHttpHandler.h
+++ b/src/test/mocks/mock_BaseHttpHandler.h
diff --git a/hueplusplus/test/mocks/mock_HttpHandler.h b/src/test/mocks/mock_HttpHandler.h
old mode 100755
new mode 100644
index 1527753..e30e6d6
--- a/hueplusplus/test/mocks/mock_HttpHandler.h
+++ b/src/test/mocks/mock_HttpHandler.h
@@ -1,78 +1,78 @@
-/**
- \file mock_HttpHandler.h
- Copyright Notice\n
- Copyright (C) 2017 Jan Rogall - developer\n
- Copyright (C) 2017 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#ifndef _MOCK_HTTPHANDLER_H
-#define _MOCK_HTTPHANDLER_H
-
-#include
-#include
-
-#include
-
-#include "../hueplusplus/include/IHttpHandler.h"
-#include "../hueplusplus/include/json/json.hpp"
-
-//! Mock Class
-class MockHttpHandler : public IHttpHandler
-{
-public:
- MOCK_CONST_METHOD3(send, std::string(const std::string& msg, const std::string& adr, int port));
-
- MOCK_CONST_METHOD3(sendGetHTTPBody, std::string(const std::string& msg, const std::string& adr, int port));
-
- MOCK_CONST_METHOD4(
- sendMulticast, std::vector(const std::string& msg, const std::string& adr, int port, int timeout));
-
- MOCK_CONST_METHOD6(sendHTTPRequest,
- std::string(const std::string& method, const std::string& uri, const std::string& content_type,
- const std::string& body, const std::string& adr, int port));
-
- MOCK_CONST_METHOD5(GETString,
- std::string(const std::string& uri, const std::string& content_type, const std::string& body,
- const std::string& adr, int port));
-
- MOCK_CONST_METHOD5(POSTString,
- std::string(const std::string& uri, const std::string& content_type, const std::string& body,
- const std::string& adr, int port));
-
- MOCK_CONST_METHOD5(PUTString,
- std::string(const std::string& uri, const std::string& content_type, const std::string& body,
- const std::string& adr, int port));
-
- MOCK_CONST_METHOD5(DELETEString,
- std::string(const std::string& uri, const std::string& content_type, const std::string& body,
- const std::string& adr, int port));
-
- MOCK_CONST_METHOD4(
- GETJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port));
-
- MOCK_CONST_METHOD4(
- POSTJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port));
-
- MOCK_CONST_METHOD4(
- PUTJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port));
-
- MOCK_CONST_METHOD4(DELETEJson,
- nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port));
-};
-
-#endif
+/**
+ \file mock_HttpHandler.h
+ Copyright Notice\n
+ Copyright (C) 2017 Jan Rogall - developer\n
+ Copyright (C) 2017 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+**/
+
+#ifndef _MOCK_HTTPHANDLER_H
+#define _MOCK_HTTPHANDLER_H
+
+#include
+#include
+
+#include
+
+#include "../hueplusplus/include/IHttpHandler.h"
+#include "../hueplusplus/include/json/json.hpp"
+
+//! Mock Class
+class MockHttpHandler : public IHttpHandler
+{
+public:
+ MOCK_CONST_METHOD3(send, std::string(const std::string& msg, const std::string& adr, int port));
+
+ MOCK_CONST_METHOD3(sendGetHTTPBody, std::string(const std::string& msg, const std::string& adr, int port));
+
+ MOCK_CONST_METHOD4(
+ sendMulticast, std::vector(const std::string& msg, const std::string& adr, int port, int timeout));
+
+ MOCK_CONST_METHOD6(sendHTTPRequest,
+ std::string(const std::string& method, const std::string& uri, const std::string& content_type,
+ const std::string& body, const std::string& adr, int port));
+
+ MOCK_CONST_METHOD5(GETString,
+ std::string(const std::string& uri, const std::string& content_type, const std::string& body,
+ const std::string& adr, int port));
+
+ MOCK_CONST_METHOD5(POSTString,
+ std::string(const std::string& uri, const std::string& content_type, const std::string& body,
+ const std::string& adr, int port));
+
+ MOCK_CONST_METHOD5(PUTString,
+ std::string(const std::string& uri, const std::string& content_type, const std::string& body,
+ const std::string& adr, int port));
+
+ MOCK_CONST_METHOD5(DELETEString,
+ std::string(const std::string& uri, const std::string& content_type, const std::string& body,
+ const std::string& adr, int port));
+
+ MOCK_CONST_METHOD4(
+ GETJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port));
+
+ MOCK_CONST_METHOD4(
+ POSTJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port));
+
+ MOCK_CONST_METHOD4(
+ PUTJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port));
+
+ MOCK_CONST_METHOD4(DELETEJson,
+ nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port));
+};
+
+#endif
diff --git a/hueplusplus/test/mocks/mock_HueLight.h b/src/test/mocks/mock_HueLight.h
index c265823..9932adb 100644
--- a/hueplusplus/test/mocks/mock_HueLight.h
+++ b/src/test/mocks/mock_HueLight.h
@@ -1,134 +1,134 @@
-/**
- \file mock_HueLight.h
- Copyright Notice\n
- Copyright (C) 2017 Jan Rogall - developer\n
- Copyright (C) 2017 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#ifndef _MOCK_HUE_LIGHT_H
-#define _MOCK_HUE_LIGHT_H
-
-#include
-#include
-
-#include
-
-#include "../hueplusplus/include/HueLight.h"
-#include "../hueplusplus/include/json/json.hpp"
-#include "../testhelper.h"
-
-//! Mock Class
-class MockHueLight : public HueLight
-{
-public:
- MockHueLight(std::shared_ptr handler)
- : HueLight(1, HueCommandAPI(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler)) {};
-
- nlohmann::json& getState() { return state; };
-
- MOCK_METHOD1(On, bool(uint8_t transition));
-
- MOCK_METHOD1(Off, bool(uint8_t transition));
-
- MOCK_METHOD0(isOn, bool());
-
- MOCK_CONST_METHOD0(isOn, bool());
-
- MOCK_CONST_METHOD0(getId, int());
-
- MOCK_CONST_METHOD0(getType, std::string());
-
- MOCK_METHOD0(getName, std::string());
-
- MOCK_CONST_METHOD0(getName, std::string());
-
- MOCK_CONST_METHOD0(getModelId, std::string());
-
- MOCK_CONST_METHOD0(getUId, std::string());
-
- MOCK_CONST_METHOD0(getManufacturername, std::string());
-
- MOCK_CONST_METHOD0(getLuminaireUId, std::string());
-
- MOCK_METHOD0(getSwVersion, std::string());
-
- MOCK_CONST_METHOD0(getSwVersion, std::string());
-
- MOCK_METHOD1(setName, bool(std::string& name));
-
- MOCK_CONST_METHOD0(getColorType, ColorType());
-
- MOCK_CONST_METHOD0(hasBrightnessControl, bool());
-
- MOCK_CONST_METHOD0(hasTemperatureControl, bool());
-
- MOCK_CONST_METHOD0(hasColorControl, bool());
-
- MOCK_METHOD2(setBrightness, bool(unsigned int bri, uint8_t transition));
-
- MOCK_CONST_METHOD0(getBrightness, unsigned int());
-
- MOCK_METHOD0(getBrightness, unsigned int());
-
- MOCK_METHOD2(setColorTemperature, bool(unsigned int mired, uint8_t transition));
-
- MOCK_CONST_METHOD0(getColorTemperature, unsigned int());
-
- MOCK_METHOD0(getColorTemperature, unsigned int());
-
- MOCK_METHOD2(setColorHue, bool(uint16_t hue, uint8_t transition));
-
- MOCK_METHOD2(setColorSaturation, bool(uint8_t sat, uint8_t transition));
-
- MOCK_METHOD3(setColorHueSaturation, bool(uint16_t hue, uint8_t sat, uint8_t transition));
-
- MOCK_CONST_METHOD0(getColorHueSaturation, std::pair());
-
- MOCK_METHOD0(getColorHueSaturation, std::pair());
-
- MOCK_METHOD3(setColorXY, bool(float x, float y, uint8_t transition));
-
- MOCK_CONST_METHOD0(getColorXY, std::pair());
-
- MOCK_METHOD0(getColorXY, std::pair());
-
- MOCK_METHOD4(setColorRGB, bool(uint8_t r, uint8_t g, uint8_t b, uint8_t transition));
-
- MOCK_METHOD0(alert, bool());
-
- MOCK_METHOD1(alertTemperature, bool(unsigned int mired));
-
- MOCK_METHOD2(alertHueSaturation, bool(uint16_t hue, uint8_t sat));
-
- MOCK_METHOD2(alertXY, bool(float x, float y));
-
- MOCK_METHOD3(alertRGB, bool(uint8_t r, uint8_t g, uint8_t b));
-
- MOCK_METHOD1(setColorLoop, bool(bool on));
-
- MOCK_METHOD1(OnNoRefresh, bool(uint8_t transition));
-
- MOCK_METHOD1(OffNoRefresh, bool(uint8_t transition));
-
- MOCK_METHOD3(
- SendPutRequest, nlohmann::json(const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo));
-
- MOCK_METHOD0(refreshState, void());
-};
-
-#endif
+/**
+ \file mock_HueLight.h
+ Copyright Notice\n
+ Copyright (C) 2017 Jan Rogall - developer\n
+ Copyright (C) 2017 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+**/
+
+#ifndef _MOCK_HUE_LIGHT_H
+#define _MOCK_HUE_LIGHT_H
+
+#include
+#include
+
+#include
+
+#include "../hueplusplus/include/HueLight.h"
+#include "../hueplusplus/include/json/json.hpp"
+#include "../testhelper.h"
+
+//! Mock Class
+class MockHueLight : public HueLight
+{
+public:
+ MockHueLight(std::shared_ptr handler)
+ : HueLight(1, HueCommandAPI(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler)) {};
+
+ nlohmann::json& getState() { return state; };
+
+ MOCK_METHOD1(On, bool(uint8_t transition));
+
+ MOCK_METHOD1(Off, bool(uint8_t transition));
+
+ MOCK_METHOD0(isOn, bool());
+
+ MOCK_CONST_METHOD0(isOn, bool());
+
+ MOCK_CONST_METHOD0(getId, int());
+
+ MOCK_CONST_METHOD0(getType, std::string());
+
+ MOCK_METHOD0(getName, std::string());
+
+ MOCK_CONST_METHOD0(getName, std::string());
+
+ MOCK_CONST_METHOD0(getModelId, std::string());
+
+ MOCK_CONST_METHOD0(getUId, std::string());
+
+ MOCK_CONST_METHOD0(getManufacturername, std::string());
+
+ MOCK_CONST_METHOD0(getLuminaireUId, std::string());
+
+ MOCK_METHOD0(getSwVersion, std::string());
+
+ MOCK_CONST_METHOD0(getSwVersion, std::string());
+
+ MOCK_METHOD1(setName, bool(std::string& name));
+
+ MOCK_CONST_METHOD0(getColorType, ColorType());
+
+ MOCK_CONST_METHOD0(hasBrightnessControl, bool());
+
+ MOCK_CONST_METHOD0(hasTemperatureControl, bool());
+
+ MOCK_CONST_METHOD0(hasColorControl, bool());
+
+ MOCK_METHOD2(setBrightness, bool(unsigned int bri, uint8_t transition));
+
+ MOCK_CONST_METHOD0(getBrightness, unsigned int());
+
+ MOCK_METHOD0(getBrightness, unsigned int());
+
+ MOCK_METHOD2(setColorTemperature, bool(unsigned int mired, uint8_t transition));
+
+ MOCK_CONST_METHOD0(getColorTemperature, unsigned int());
+
+ MOCK_METHOD0(getColorTemperature, unsigned int());
+
+ MOCK_METHOD2(setColorHue, bool(uint16_t hue, uint8_t transition));
+
+ MOCK_METHOD2(setColorSaturation, bool(uint8_t sat, uint8_t transition));
+
+ MOCK_METHOD3(setColorHueSaturation, bool(uint16_t hue, uint8_t sat, uint8_t transition));
+
+ MOCK_CONST_METHOD0(getColorHueSaturation, std::pair());
+
+ MOCK_METHOD0(getColorHueSaturation, std::pair());
+
+ MOCK_METHOD3(setColorXY, bool(float x, float y, uint8_t transition));
+
+ MOCK_CONST_METHOD0(getColorXY, std::pair());
+
+ MOCK_METHOD0(getColorXY, std::pair());
+
+ MOCK_METHOD4(setColorRGB, bool(uint8_t r, uint8_t g, uint8_t b, uint8_t transition));
+
+ MOCK_METHOD0(alert, bool());
+
+ MOCK_METHOD1(alertTemperature, bool(unsigned int mired));
+
+ MOCK_METHOD2(alertHueSaturation, bool(uint16_t hue, uint8_t sat));
+
+ MOCK_METHOD2(alertXY, bool(float x, float y));
+
+ MOCK_METHOD3(alertRGB, bool(uint8_t r, uint8_t g, uint8_t b));
+
+ MOCK_METHOD1(setColorLoop, bool(bool on));
+
+ MOCK_METHOD1(OnNoRefresh, bool(uint8_t transition));
+
+ MOCK_METHOD1(OffNoRefresh, bool(uint8_t transition));
+
+ MOCK_METHOD3(
+ SendPutRequest, nlohmann::json(const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo));
+
+ MOCK_METHOD0(refreshState, void());
+};
+
+#endif
diff --git a/hueplusplus/test/test_BaseHttpHandler.cpp b/src/test/test_BaseHttpHandler.cpp
old mode 100755
new mode 100644
index 0790343..89583fd
--- a/hueplusplus/test/test_BaseHttpHandler.cpp
+++ b/src/test/test_BaseHttpHandler.cpp
@@ -1,237 +1,237 @@
-/**
- \file test_BaseHttpHandler.cpp
- Copyright Notice\n
- Copyright (C) 2017 Jan Rogall - developer\n
- Copyright (C) 2017 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#include
-#include
-
-#include
-#include
-
-#include "testhelper.h"
-
-#include "../include/json/json.hpp"
-#include "mocks/mock_BaseHttpHandler.h"
-#include "../include/HueException.h"
-
-TEST(BaseHttpHandler, sendGetHTTPBody)
-{
- using namespace ::testing;
- MockBaseHttpHandler handler;
-
- EXPECT_CALL(handler, send("testmsg", "192.168.2.1", 90))
- .Times(AtLeast(2))
- .WillOnce(Return(""))
- .WillRepeatedly(Return("\r\n\r\ntestreply"));
-
- EXPECT_THROW(handler.sendGetHTTPBody("testmsg", "192.168.2.1", 90), HueException);
- EXPECT_EQ("testreply", handler.sendGetHTTPBody("testmsg", "192.168.2.1", 90));
-}
-
-TEST(BaseHttpHandler, sendHTTPRequest)
-{
- using namespace ::testing;
- MockBaseHttpHandler handler;
-
- EXPECT_CALL(handler,
- send("GET UrI HTTP/1.0\r\nContent-Type: "
- "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n",
- "192.168.2.1", 90))
- .Times(AtLeast(2))
- .WillOnce(Return(""))
- .WillRepeatedly(Return("\r\n\r\ntestreply"));
-
- EXPECT_THROW(handler.sendHTTPRequest("GET", "UrI", "text/html", "body", "192.168.2.1", 90), HueException);
- EXPECT_EQ("testreply", handler.sendHTTPRequest("GET", "UrI", "text/html", "body", "192.168.2.1", 90));
-}
-
-TEST(BaseHttpHandler, GETString)
-{
- using namespace ::testing;
- MockBaseHttpHandler handler;
-
- EXPECT_CALL(handler,
- send("GET UrI HTTP/1.0\r\nContent-Type: "
- "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n",
- "192.168.2.1", 90))
- .Times(AtLeast(2))
- .WillOnce(Return(""))
- .WillRepeatedly(Return("\r\n\r\ntestreply"));
-
- EXPECT_THROW(handler.GETString("UrI", "text/html", "body", "192.168.2.1", 90), HueException);
- EXPECT_EQ("testreply", handler.GETString("UrI", "text/html", "body", "192.168.2.1", 90));
-}
-
-TEST(BaseHttpHandler, POSTString)
-{
- using namespace ::testing;
- MockBaseHttpHandler handler;
-
- EXPECT_CALL(handler,
- send("POST UrI HTTP/1.0\r\nContent-Type: "
- "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n",
- "192.168.2.1", 90))
- .Times(AtLeast(2))
- .WillOnce(Return(""))
- .WillRepeatedly(Return("\r\n\r\ntestreply"));
-
- EXPECT_THROW(handler.POSTString("UrI", "text/html", "body", "192.168.2.1", 90), HueException);
- EXPECT_EQ("testreply", handler.POSTString("UrI", "text/html", "body", "192.168.2.1", 90));
-}
-
-TEST(BaseHttpHandler, PUTString)
-{
- using namespace ::testing;
- MockBaseHttpHandler handler;
-
- EXPECT_CALL(handler,
- send("PUT UrI HTTP/1.0\r\nContent-Type: "
- "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n",
- "192.168.2.1", 90))
- .Times(AtLeast(2))
- .WillOnce(Return(""))
- .WillRepeatedly(Return("\r\n\r\ntestreply"));
-
- EXPECT_THROW(handler.PUTString("UrI", "text/html", "body", "192.168.2.1", 90), HueException);
- EXPECT_EQ("testreply", handler.PUTString("UrI", "text/html", "body", "192.168.2.1", 90));
-}
-
-TEST(BaseHttpHandler, DELETEString)
-{
- using namespace ::testing;
- MockBaseHttpHandler handler;
-
- EXPECT_CALL(handler,
- send("DELETE UrI HTTP/1.0\r\nContent-Type: "
- "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n",
- "192.168.2.1", 90))
- .Times(AtLeast(2))
- .WillOnce(Return(""))
- .WillRepeatedly(Return("\r\n\r\ntestreply"));
-
- EXPECT_THROW(handler.DELETEString("UrI", "text/html", "body", "192.168.2.1", 90), HueException);
- EXPECT_EQ("testreply", handler.DELETEString("UrI", "text/html", "body", "192.168.2.1", 90));
-}
-
-TEST(BaseHttpHandler, GETJson)
-{
- using namespace ::testing;
- MockBaseHttpHandler handler;
-
- nlohmann::json testval;
- testval["test"] = 100;
- std::string expected_call = "GET UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: ";
- expected_call.append(std::to_string(testval.dump().size()));
- expected_call.append("\r\n\r\n");
- expected_call.append(testval.dump());
- expected_call.append("\r\n\r\n");
-
- EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90))
- .Times(AtLeast(2))
- .WillOnce(Return(""))
- .WillOnce(Return("\r\n\r\n"))
- .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}"));
- nlohmann::json expected;
- expected["test"] = "whatever";
-
- EXPECT_THROW(handler.GETJson("UrI", testval, "192.168.2.1", 90), HueException);
- EXPECT_THROW(handler.GETJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error);
- EXPECT_EQ(expected, handler.GETJson("UrI", testval, "192.168.2.1", 90));
-}
-
-TEST(BaseHttpHandler, POSTJson)
-{
- using namespace ::testing;
- MockBaseHttpHandler handler;
-
- nlohmann::json testval;
- testval["test"] = 100;
- std::string expected_call = "POST UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: ";
- expected_call.append(std::to_string(testval.dump().size()));
- expected_call.append("\r\n\r\n");
- expected_call.append(testval.dump());
- expected_call.append("\r\n\r\n");
-
- EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90))
- .Times(AtLeast(2))
- .WillOnce(Return(""))
- .WillOnce(Return("\r\n\r\n"))
- .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}"));
- nlohmann::json expected;
- expected["test"] = "whatever";
-
- EXPECT_THROW(handler.POSTJson("UrI", testval, "192.168.2.1", 90), HueException);
- EXPECT_THROW(handler.POSTJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error);
- EXPECT_EQ(expected, handler.POSTJson("UrI", testval, "192.168.2.1", 90));
-}
-
-TEST(BaseHttpHandler, PUTJson)
-{
- using namespace ::testing;
- MockBaseHttpHandler handler;
-
- nlohmann::json testval;
- testval["test"] = 100;
- std::string expected_call = "PUT UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: ";
- expected_call.append(std::to_string(testval.dump().size()));
- expected_call.append("\r\n\r\n");
- expected_call.append(testval.dump());
- expected_call.append("\r\n\r\n");
-
- EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90))
- .Times(AtLeast(2))
- .WillOnce(Return(""))
- .WillOnce(Return("\r\n\r\n"))
- .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}"));
- nlohmann::json expected;
- expected["test"] = "whatever";
-
- EXPECT_THROW(handler.PUTJson("UrI", testval, "192.168.2.1", 90), HueException);
- EXPECT_THROW(handler.PUTJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error);
- EXPECT_EQ(expected, handler.PUTJson("UrI", testval, "192.168.2.1", 90));
-}
-
-TEST(BaseHttpHandler, DELETEJson)
-{
- using namespace ::testing;
- MockBaseHttpHandler handler;
-
- nlohmann::json testval;
- testval["test"] = 100;
- std::string expected_call = "DELETE UrI HTTP/1.0\r\nContent-Type: "
- "application/json\r\nContent-Length: ";
- expected_call.append(std::to_string(testval.dump().size()));
- expected_call.append("\r\n\r\n");
- expected_call.append(testval.dump());
- expected_call.append("\r\n\r\n");
-
- EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90))
- .Times(AtLeast(2))
- .WillOnce(Return(""))
- .WillOnce(Return("\r\n\r\n"))
- .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}"));
- nlohmann::json expected;
- expected["test"] = "whatever";
-
- EXPECT_THROW(handler.DELETEJson("UrI", testval, "192.168.2.1", 90), HueException);
- EXPECT_THROW(handler.DELETEJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error);
- EXPECT_EQ(expected, handler.DELETEJson("UrI", testval, "192.168.2.1", 90));
-}
+/**
+ \file test_BaseHttpHandler.cpp
+ Copyright Notice\n
+ Copyright (C) 2017 Jan Rogall - developer\n
+ Copyright (C) 2017 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+**/
+
+#include
+#include
+
+#include
+#include
+
+#include "testhelper.h"
+
+#include "../include/json/json.hpp"
+#include "mocks/mock_BaseHttpHandler.h"
+#include "../include/HueException.h"
+
+TEST(BaseHttpHandler, sendGetHTTPBody)
+{
+ using namespace ::testing;
+ MockBaseHttpHandler handler;
+
+ EXPECT_CALL(handler, send("testmsg", "192.168.2.1", 90))
+ .Times(AtLeast(2))
+ .WillOnce(Return(""))
+ .WillRepeatedly(Return("\r\n\r\ntestreply"));
+
+ EXPECT_THROW(handler.sendGetHTTPBody("testmsg", "192.168.2.1", 90), HueException);
+ EXPECT_EQ("testreply", handler.sendGetHTTPBody("testmsg", "192.168.2.1", 90));
+}
+
+TEST(BaseHttpHandler, sendHTTPRequest)
+{
+ using namespace ::testing;
+ MockBaseHttpHandler handler;
+
+ EXPECT_CALL(handler,
+ send("GET UrI HTTP/1.0\r\nContent-Type: "
+ "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n",
+ "192.168.2.1", 90))
+ .Times(AtLeast(2))
+ .WillOnce(Return(""))
+ .WillRepeatedly(Return("\r\n\r\ntestreply"));
+
+ EXPECT_THROW(handler.sendHTTPRequest("GET", "UrI", "text/html", "body", "192.168.2.1", 90), HueException);
+ EXPECT_EQ("testreply", handler.sendHTTPRequest("GET", "UrI", "text/html", "body", "192.168.2.1", 90));
+}
+
+TEST(BaseHttpHandler, GETString)
+{
+ using namespace ::testing;
+ MockBaseHttpHandler handler;
+
+ EXPECT_CALL(handler,
+ send("GET UrI HTTP/1.0\r\nContent-Type: "
+ "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n",
+ "192.168.2.1", 90))
+ .Times(AtLeast(2))
+ .WillOnce(Return(""))
+ .WillRepeatedly(Return("\r\n\r\ntestreply"));
+
+ EXPECT_THROW(handler.GETString("UrI", "text/html", "body", "192.168.2.1", 90), HueException);
+ EXPECT_EQ("testreply", handler.GETString("UrI", "text/html", "body", "192.168.2.1", 90));
+}
+
+TEST(BaseHttpHandler, POSTString)
+{
+ using namespace ::testing;
+ MockBaseHttpHandler handler;
+
+ EXPECT_CALL(handler,
+ send("POST UrI HTTP/1.0\r\nContent-Type: "
+ "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n",
+ "192.168.2.1", 90))
+ .Times(AtLeast(2))
+ .WillOnce(Return(""))
+ .WillRepeatedly(Return("\r\n\r\ntestreply"));
+
+ EXPECT_THROW(handler.POSTString("UrI", "text/html", "body", "192.168.2.1", 90), HueException);
+ EXPECT_EQ("testreply", handler.POSTString("UrI", "text/html", "body", "192.168.2.1", 90));
+}
+
+TEST(BaseHttpHandler, PUTString)
+{
+ using namespace ::testing;
+ MockBaseHttpHandler handler;
+
+ EXPECT_CALL(handler,
+ send("PUT UrI HTTP/1.0\r\nContent-Type: "
+ "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n",
+ "192.168.2.1", 90))
+ .Times(AtLeast(2))
+ .WillOnce(Return(""))
+ .WillRepeatedly(Return("\r\n\r\ntestreply"));
+
+ EXPECT_THROW(handler.PUTString("UrI", "text/html", "body", "192.168.2.1", 90), HueException);
+ EXPECT_EQ("testreply", handler.PUTString("UrI", "text/html", "body", "192.168.2.1", 90));
+}
+
+TEST(BaseHttpHandler, DELETEString)
+{
+ using namespace ::testing;
+ MockBaseHttpHandler handler;
+
+ EXPECT_CALL(handler,
+ send("DELETE UrI HTTP/1.0\r\nContent-Type: "
+ "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n",
+ "192.168.2.1", 90))
+ .Times(AtLeast(2))
+ .WillOnce(Return(""))
+ .WillRepeatedly(Return("\r\n\r\ntestreply"));
+
+ EXPECT_THROW(handler.DELETEString("UrI", "text/html", "body", "192.168.2.1", 90), HueException);
+ EXPECT_EQ("testreply", handler.DELETEString("UrI", "text/html", "body", "192.168.2.1", 90));
+}
+
+TEST(BaseHttpHandler, GETJson)
+{
+ using namespace ::testing;
+ MockBaseHttpHandler handler;
+
+ nlohmann::json testval;
+ testval["test"] = 100;
+ std::string expected_call = "GET UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: ";
+ expected_call.append(std::to_string(testval.dump().size()));
+ expected_call.append("\r\n\r\n");
+ expected_call.append(testval.dump());
+ expected_call.append("\r\n\r\n");
+
+ EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90))
+ .Times(AtLeast(2))
+ .WillOnce(Return(""))
+ .WillOnce(Return("\r\n\r\n"))
+ .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}"));
+ nlohmann::json expected;
+ expected["test"] = "whatever";
+
+ EXPECT_THROW(handler.GETJson("UrI", testval, "192.168.2.1", 90), HueException);
+ EXPECT_THROW(handler.GETJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error);
+ EXPECT_EQ(expected, handler.GETJson("UrI", testval, "192.168.2.1", 90));
+}
+
+TEST(BaseHttpHandler, POSTJson)
+{
+ using namespace ::testing;
+ MockBaseHttpHandler handler;
+
+ nlohmann::json testval;
+ testval["test"] = 100;
+ std::string expected_call = "POST UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: ";
+ expected_call.append(std::to_string(testval.dump().size()));
+ expected_call.append("\r\n\r\n");
+ expected_call.append(testval.dump());
+ expected_call.append("\r\n\r\n");
+
+ EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90))
+ .Times(AtLeast(2))
+ .WillOnce(Return(""))
+ .WillOnce(Return("\r\n\r\n"))
+ .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}"));
+ nlohmann::json expected;
+ expected["test"] = "whatever";
+
+ EXPECT_THROW(handler.POSTJson("UrI", testval, "192.168.2.1", 90), HueException);
+ EXPECT_THROW(handler.POSTJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error);
+ EXPECT_EQ(expected, handler.POSTJson("UrI", testval, "192.168.2.1", 90));
+}
+
+TEST(BaseHttpHandler, PUTJson)
+{
+ using namespace ::testing;
+ MockBaseHttpHandler handler;
+
+ nlohmann::json testval;
+ testval["test"] = 100;
+ std::string expected_call = "PUT UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: ";
+ expected_call.append(std::to_string(testval.dump().size()));
+ expected_call.append("\r\n\r\n");
+ expected_call.append(testval.dump());
+ expected_call.append("\r\n\r\n");
+
+ EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90))
+ .Times(AtLeast(2))
+ .WillOnce(Return(""))
+ .WillOnce(Return("\r\n\r\n"))
+ .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}"));
+ nlohmann::json expected;
+ expected["test"] = "whatever";
+
+ EXPECT_THROW(handler.PUTJson("UrI", testval, "192.168.2.1", 90), HueException);
+ EXPECT_THROW(handler.PUTJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error);
+ EXPECT_EQ(expected, handler.PUTJson("UrI", testval, "192.168.2.1", 90));
+}
+
+TEST(BaseHttpHandler, DELETEJson)
+{
+ using namespace ::testing;
+ MockBaseHttpHandler handler;
+
+ nlohmann::json testval;
+ testval["test"] = 100;
+ std::string expected_call = "DELETE UrI HTTP/1.0\r\nContent-Type: "
+ "application/json\r\nContent-Length: ";
+ expected_call.append(std::to_string(testval.dump().size()));
+ expected_call.append("\r\n\r\n");
+ expected_call.append(testval.dump());
+ expected_call.append("\r\n\r\n");
+
+ EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90))
+ .Times(AtLeast(2))
+ .WillOnce(Return(""))
+ .WillOnce(Return("\r\n\r\n"))
+ .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}"));
+ nlohmann::json expected;
+ expected["test"] = "whatever";
+
+ EXPECT_THROW(handler.DELETEJson("UrI", testval, "192.168.2.1", 90), HueException);
+ EXPECT_THROW(handler.DELETEJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error);
+ EXPECT_EQ(expected, handler.DELETEJson("UrI", testval, "192.168.2.1", 90));
+}
diff --git a/hueplusplus/test/test_ExtendedColorHueStrategy.cpp b/src/test/test_ExtendedColorHueStrategy.cpp
old mode 100755
new mode 100644
index 3c1c115..ac65ac9
--- a/hueplusplus/test/test_ExtendedColorHueStrategy.cpp
+++ b/src/test/test_ExtendedColorHueStrategy.cpp
@@ -1,248 +1,248 @@
-/**
- \file test_ExtendedColorHueStrategy.cpp
- Copyright Notice\n
- Copyright (C) 2017 Jan Rogall - developer\n
- Copyright (C) 2017 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#include
-#include
-
-#include
-#include
-
-#include "testhelper.h"
-
-#include "../include/ExtendedColorHueStrategy.h"
-#include "../include/json/json.hpp"
-#include "mocks/mock_HttpHandler.h"
-#include "mocks/mock_HueLight.h"
-
-TEST(ExtendedColorHueStrategy, alertHueSaturation)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["colormode"] = "invalid";
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(30000, 128, test_light));
-
- EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "hs";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["sat"] = 100;
- test_light.getState()["state"]["hue"] = 200;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "xy";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["xy"][0] = 0.1;
- test_light.getState()["state"]["xy"][1] = 0.1;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "ct";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["ct"] = 200;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
-}
-
-TEST(ExtendedColorHueStrategy, alertXY)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["colormode"] = "invalid";
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "hs";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["xy"][0] = 0.1;
- test_light.getState()["state"]["xy"][1] = 0.1;
- test_light.getState()["state"]["sat"] = 100;
- test_light.getState()["state"]["hue"] = 200;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "xy";
- test_light.getState()["state"]["on"] = true;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "ct";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["ct"] = 200;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-}
-
-TEST(ExtendedColorHueStrategy, alertRGB)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["colormode"] = "invalid";
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, setColorRGB(_, _, _, 1))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "hs";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["sat"] = 100;
- test_light.getState()["state"]["hue"] = 200;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, setColorRGB(_, _, _, 1))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "xy";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["xy"][0] = 0.1;
- test_light.getState()["state"]["xy"][1] = 0.1;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, setColorRGB(_, _, _, 1))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "ct";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["ct"] = 200;
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
-}
+/**
+ \file test_ExtendedColorHueStrategy.cpp
+ Copyright Notice\n
+ Copyright (C) 2017 Jan Rogall - developer\n
+ Copyright (C) 2017 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+**/
+
+#include
+#include
+
+#include
+#include
+
+#include "testhelper.h"
+
+#include "../include/ExtendedColorHueStrategy.h"
+#include "../include/json/json.hpp"
+#include "mocks/mock_HttpHandler.h"
+#include "mocks/mock_HueLight.h"
+
+TEST(ExtendedColorHueStrategy, alertHueSaturation)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+
+ test_light.getState()["state"]["colormode"] = "invalid";
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(30000, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "hs";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["sat"] = 100;
+ test_light.getState()["state"]["hue"] = 200;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "xy";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["xy"][0] = 0.1;
+ test_light.getState()["state"]["xy"][1] = 0.1;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "ct";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["ct"] = 200;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light));
+}
+
+TEST(ExtendedColorHueStrategy, alertXY)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+
+ test_light.getState()["state"]["colormode"] = "invalid";
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "hs";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["xy"][0] = 0.1;
+ test_light.getState()["state"]["xy"][1] = 0.1;
+ test_light.getState()["state"]["sat"] = 100;
+ test_light.getState()["state"]["hue"] = 200;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "xy";
+ test_light.getState()["state"]["on"] = true;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "ct";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["ct"] = 200;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+}
+
+TEST(ExtendedColorHueStrategy, alertRGB)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+
+ test_light.getState()["state"]["colormode"] = "invalid";
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorRGB(_, _, _, 1))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "hs";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["sat"] = 100;
+ test_light.getState()["state"]["hue"] = 200;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorRGB(_, _, _, 1))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "xy";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["xy"][0] = 0.1;
+ test_light.getState()["state"]["xy"][1] = 0.1;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorRGB(_, _, _, 1))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "ct";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["ct"] = 200;
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light));
+}
diff --git a/hueplusplus/test/test_ExtendedColorTemperatureStrategy.cpp b/src/test/test_ExtendedColorTemperatureStrategy.cpp
old mode 100755
new mode 100644
index a7e9c18..8aae609
--- a/hueplusplus/test/test_ExtendedColorTemperatureStrategy.cpp
+++ b/src/test/test_ExtendedColorTemperatureStrategy.cpp
@@ -1,148 +1,148 @@
-/**
- \file test_ExtendedColorTemperatureStrategy.cpp
- Copyright Notice\n
- Copyright (C) 2017 Jan Rogall - developer\n
- Copyright (C) 2017 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#include
-#include
-
-#include
-#include
-
-#include "testhelper.h"
-
-#include "../include/ExtendedColorTemperatureStrategy.h"
-#include "../include/json/json.hpp"
-#include "mocks/mock_HttpHandler.h"
-#include "mocks/mock_HueLight.h"
-
-TEST(ExtendedColorTemperatureStrategy, setColorTemperature)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
- nlohmann::json prep_ret;
- prep_ret = nlohmann::json::array();
- prep_ret[0] = nlohmann::json::object();
- prep_ret[0]["success"] = nlohmann::json::object();
- prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
- prep_ret[1] = nlohmann::json::object();
- prep_ret[1]["success"] = nlohmann::json::object();
- prep_ret[1]["success"]["/lights/1/state/on"] = true;
- prep_ret[2] = nlohmann::json::object();
- prep_ret[2]["success"] = nlohmann::json::object();
- prep_ret[2]["success"]["/lights/1/state/ct"] = 155;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
-
- test_light.getState()["state"]["colormode"] = "ct";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["ct"] = 200;
- EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(200, 4, test_light));
-
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(155, 6, test_light));
-
- prep_ret[2]["success"]["/lights/1/state/ct"] = 153;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
- EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(0, 6, test_light));
-
- prep_ret[2]["success"]["/lights/1/state/ct"] = 500;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
- EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(600, 6, test_light));
-}
-
-TEST(ExtendedColorTemperatureStrategy, alertTemperature)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["colormode"] = "invalid";
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, setColorTemperature(_, _))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "hs";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["ct"] = 200;
- test_light.getState()["state"]["sat"] = 100;
- test_light.getState()["state"]["hue"] = 200;
- EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, setColorTemperature(_, _))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "xy";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["xy"][0] = 0.1;
- test_light.getState()["state"]["xy"][1] = 0.1;
- EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, setColorTemperature(_, _))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "ct";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["ct"] = 200;
- EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
-}
+/**
+ \file test_ExtendedColorTemperatureStrategy.cpp
+ Copyright Notice\n
+ Copyright (C) 2017 Jan Rogall - developer\n
+ Copyright (C) 2017 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+**/
+
+#include
+#include
+
+#include
+#include
+
+#include "testhelper.h"
+
+#include "../include/ExtendedColorTemperatureStrategy.h"
+#include "../include/json/json.hpp"
+#include "mocks/mock_HttpHandler.h"
+#include "mocks/mock_HueLight.h"
+
+TEST(ExtendedColorTemperatureStrategy, setColorTemperature)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+ nlohmann::json prep_ret;
+ prep_ret = nlohmann::json::array();
+ prep_ret[0] = nlohmann::json::object();
+ prep_ret[0]["success"] = nlohmann::json::object();
+ prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
+ prep_ret[1] = nlohmann::json::object();
+ prep_ret[1]["success"] = nlohmann::json::object();
+ prep_ret[1]["success"]["/lights/1/state/on"] = true;
+ prep_ret[2] = nlohmann::json::object();
+ prep_ret[2]["success"] = nlohmann::json::object();
+ prep_ret[2]["success"]["/lights/1/state/ct"] = 155;
+ EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
+
+ test_light.getState()["state"]["colormode"] = "ct";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["ct"] = 200;
+ EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(200, 4, test_light));
+
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(155, 6, test_light));
+
+ prep_ret[2]["success"]["/lights/1/state/ct"] = 153;
+ EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
+ EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(0, 6, test_light));
+
+ prep_ret[2]["success"]["/lights/1/state/ct"] = 500;
+ EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
+ EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(600, 6, test_light));
+}
+
+TEST(ExtendedColorTemperatureStrategy, alertTemperature)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+
+ test_light.getState()["state"]["colormode"] = "invalid";
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ EXPECT_CALL(test_light, setColorTemperature(_, _))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "hs";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["ct"] = 200;
+ test_light.getState()["state"]["sat"] = 100;
+ test_light.getState()["state"]["hue"] = 200;
+ EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ EXPECT_CALL(test_light, setColorTemperature(_, _))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "xy";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["xy"][0] = 0.1;
+ test_light.getState()["state"]["xy"][1] = 0.1;
+ EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ EXPECT_CALL(test_light, setColorTemperature(_, _))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "ct";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["ct"] = 200;
+ EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light));
+}
diff --git a/hueplusplus/test/test_Hue.cpp b/src/test/test_Hue.cpp
index 80b22d2..9f8e0d1 100644
--- a/hueplusplus/test/test_Hue.cpp
+++ b/src/test/test_Hue.cpp
@@ -1,523 +1,523 @@
-/**
- \file test_Hue.cpp
- Copyright Notice\n
- Copyright (C) 2017 Jan Rogall - developer\n
- Copyright (C) 2017 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-#include "testhelper.h"
-
-#include "../include/Hue.h"
-#include "../include/json/json.hpp"
-#include "mocks/mock_HttpHandler.h"
-
-class HueFinderTest : public ::testing::Test
-{
-protected:
- std::shared_ptr handler;
-
-protected:
- HueFinderTest() : handler(std::make_shared())
- {
- using namespace ::testing;
-
- EXPECT_CALL(*handler,
- sendMulticast("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: "
- "\"ssdp:discover\"\r\nMX: 5\r\nST: ssdp:all\r\n\r\n",
- "239.255.255.250", 1900, 5))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(getMulticastReply()));
-
- EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", "192.168.2.1", getBridgePort()))
- .Times(0);
-
- EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(getBridgeXml()));
- }
- ~HueFinderTest(){};
-};
-
-TEST_F(HueFinderTest, FindBridges)
-{
- HueFinder finder(handler);
- std::vector bridges = finder.FindBridges();
-
- HueFinder::HueIdentification bridge_to_comp;
- bridge_to_comp.ip = getBridgeIp();
- bridge_to_comp.port = getBridgePort();
- bridge_to_comp.mac = getBridgeMac();
-
- EXPECT_EQ(bridges.size(), 1) << "HueFinder found more than one Bridge";
- EXPECT_EQ(bridges[0].ip, bridge_to_comp.ip) << "HueIdentification ip does not match";
- EXPECT_EQ(bridges[0].port, bridge_to_comp.port) << "HueIdentification port does not match";
- EXPECT_EQ(bridges[0].mac, bridge_to_comp.mac) << "HueIdentification mac does not match";
-
- // Test invalid description
- EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(::testing::Return("invalid stuff"));
- bridges = finder.FindBridges();
- EXPECT_TRUE(bridges.empty());
-}
-
-TEST_F(HueFinderTest, GetBridge)
-{
- using namespace ::testing;
- nlohmann::json request{{"devicetype", "HuePlusPlus#User"}};
-
- nlohmann::json errorResponse
- = {{{"error", {{"type", 101}, {"address", ""}, {"description", "link button not pressed"}}}}};
-
- EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(errorResponse));
-
- HueFinder finder(handler);
- std::vector bridges = finder.FindBridges();
-
- ASSERT_THROW(finder.GetBridge(bridges[0]), HueException);
-
- nlohmann::json successResponse = {{{"success", {{"username", getBridgeUsername()}}}}};
-
- EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(Return(successResponse));
-
- finder = HueFinder(handler);
- bridges = finder.FindBridges();
-
- Hue test_bridge = finder.GetBridge(bridges[0]);
-
- EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching";
- EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching";
- EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching";
-
- // Verify that username is correctly set in api requests
- nlohmann::json hue_bridge_state{{"lights", {}}};
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(Return(hue_bridge_state));
-
- test_bridge.getAllLights();
-
- Mock::VerifyAndClearExpectations(handler.get());
-}
-
-TEST_F(HueFinderTest, AddUsername)
-{
- HueFinder finder(handler);
- std::vector bridges = finder.FindBridges();
-
- finder.AddUsername(bridges[0].mac, getBridgeUsername());
- Hue test_bridge = finder.GetBridge(bridges[0]);
-
- EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching";
- EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching";
- EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching";
-}
-
-TEST_F(HueFinderTest, GetAllUsernames)
-{
- HueFinder finder(handler);
- std::vector bridges = finder.FindBridges();
-
- finder.AddUsername(bridges[0].mac, getBridgeUsername());
-
- std::map users = finder.GetAllUsernames();
- EXPECT_EQ(users[getBridgeMac()], getBridgeUsername()) << "Username of MAC:" << getBridgeMac() << "not matching";
-}
-
-TEST(Hue, Constructor)
-{
- std::shared_ptr handler = std::make_shared();
- Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
-
- EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching";
- EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching";
- EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching";
-}
-
-TEST(Hue, requestUsername)
-{
- using namespace ::testing;
- std::shared_ptr handler = std::make_shared();
- nlohmann::json request{{"devicetype", "HuePlusPlus#User"}};
-
- {
- nlohmann::json errorResponse
- = {{{"error", {{"type", 101}, {"address", ""}, {"description", "link button not pressed"}}}}};
-
- EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(errorResponse));
-
- Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler);
-
- std::string username = test_bridge.requestUsername();
- EXPECT_EQ(username, "") << "Returned username not matching";
- EXPECT_EQ(test_bridge.getUsername(), "") << "Bridge username not matching";
- }
-
- {
- // Other error code causes exception
- int otherError = 1;
- nlohmann::json exceptionResponse
- = {{{"error", {{"type", otherError}, {"address", ""}, {"description", "some error"}}}}};
- Hue testBridge(getBridgeIp(), getBridgePort(), "", handler);
-
- EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
- .WillOnce(Return(exceptionResponse));
-
- try
- {
- testBridge.requestUsername();
- FAIL() << "requestUsername did not throw";
- }
- catch (const HueAPIResponseException& e)
- {
- EXPECT_EQ(e.GetErrorNumber(), otherError);
- }
- catch (const std::exception& e)
- {
- FAIL() << "wrong exception: " << e.what();
- }
- }
-
- {
- nlohmann::json successResponse = {{{"success", {{"username", getBridgeUsername()}}}}};
- EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillRepeatedly(Return(successResponse));
-
- Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler);
-
- std::string username = test_bridge.requestUsername();
-
- EXPECT_EQ(username, test_bridge.getUsername()) << "Returned username not matching";
- EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching";
- EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching";
-
- // Verify that username is correctly set in api requests
- nlohmann::json hue_bridge_state{{"lights", {}}};
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(Return(hue_bridge_state));
-
- test_bridge.getAllLights();
- }
-}
-
-TEST(Hue, setIP)
-{
- std::shared_ptr handler = std::make_shared();
- Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler);
- EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching after initialization";
- test_bridge.setIP("192.168.2.112");
- EXPECT_EQ(test_bridge.getBridgeIP(), "192.168.2.112") << "Bridge IP not matching after setting it";
-}
-
-TEST(Hue, setPort)
-{
- std::shared_ptr handler = std::make_shared();
- Hue test_bridge = Hue(getBridgeIp(), getBridgePort(), "", handler);
- EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching after initialization";
- test_bridge.setPort(81);
- EXPECT_EQ(test_bridge.getBridgePort(), 81) << "Bridge Port not matching after setting it";
-}
-
-TEST(Hue, getLight)
-{
- using namespace ::testing;
- std::shared_ptr handler = std::make_shared();
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1);
-
- Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
-
- // Test exception
- ASSERT_THROW(test_bridge.getLight(1), HueException);
-
- nlohmann::json hue_bridge_state{{"lights",
- {{"1",
- {{"state",
- {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
- {"reachable", true}}},
- {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
- {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
- {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}}};
-
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(Return(hue_bridge_state));
-
- EXPECT_CALL(*handler,
- GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
-
- // Test when correct data is sent
- HueLight test_light_1 = test_bridge.getLight(1);
- EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
- EXPECT_EQ(test_light_1.getColorType(), ColorType::TEMPERATURE);
-
- // Test again to check whether light is returned directly -> interesting for
- // code coverage test
- test_light_1 = test_bridge.getLight(1);
- EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
- EXPECT_EQ(test_light_1.getColorType(), ColorType::TEMPERATURE);
-
- // more coverage stuff
- hue_bridge_state["lights"]["1"]["modelid"] = "LCT001";
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(Return(hue_bridge_state));
-
- EXPECT_CALL(*handler,
- GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
- test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
-
- // Test when correct data is sent
- test_light_1 = test_bridge.getLight(1);
- EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
- EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_B);
-
- hue_bridge_state["lights"]["1"]["modelid"] = "LCT010";
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(Return(hue_bridge_state));
-
- EXPECT_CALL(*handler,
- GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
- test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
-
- // Test when correct data is sent
- test_light_1 = test_bridge.getLight(1);
- EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
- EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_C);
-
- hue_bridge_state["lights"]["1"]["modelid"] = "LST001";
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(Return(hue_bridge_state));
-
- EXPECT_CALL(*handler,
- GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
- test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
-
- // Test when correct data is sent
- test_light_1 = test_bridge.getLight(1);
- EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
- EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_A);
-
- hue_bridge_state["lights"]["1"]["modelid"] = "LWB004";
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(Return(hue_bridge_state));
-
- EXPECT_CALL(*handler,
- GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
- test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
-
- // Test when correct data is sent
- test_light_1 = test_bridge.getLight(1);
- EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
- EXPECT_EQ(test_light_1.getColorType(), ColorType::NONE);
-
- hue_bridge_state["lights"]["1"]["modelid"] = "ABC000";
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(Return(hue_bridge_state));
- test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
- ASSERT_THROW(test_bridge.getLight(1), HueException);
-}
-
-TEST(Hue, removeLight)
-{
- using namespace ::testing;
- std::shared_ptr handler = std::make_shared();
- nlohmann::json hue_bridge_state{ {"lights",
- {{"1",
- {{"state",
- {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
- {"reachable", true}}},
- {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
- {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
- {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} };
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillOnce(Return(hue_bridge_state));
-
- Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
-
- EXPECT_CALL(*handler,
- GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(1)
- .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
-
- nlohmann::json return_answer;
- return_answer = nlohmann::json::array();
- return_answer[0] = nlohmann::json::object();
- return_answer[0]["success"] = "/lights/1 deleted";
- EXPECT_CALL(*handler,
- DELETEJson(
- "/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(2)
- .WillOnce(Return(return_answer))
- .WillOnce(Return(nlohmann::json()));
-
- // Test when correct data is sent
- HueLight test_light_1 = test_bridge.getLight(1);
-
- EXPECT_EQ(test_bridge.removeLight(1), true);
-
- EXPECT_EQ(test_bridge.removeLight(1), false);
-}
-
-TEST(Hue, getAllLights)
-{
- using namespace ::testing;
- std::shared_ptr handler = std::make_shared();
- nlohmann::json hue_bridge_state{ {"lights",
- {{"1",
- {{"state",
- {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
- {"reachable", true}}},
- {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
- {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
- {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} };
-
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(2)
- .WillRepeatedly(Return(hue_bridge_state));
-
- EXPECT_CALL(*handler,
- GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(2)
- .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
-
- Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
-
- std::vector> test_lights = test_bridge.getAllLights();
- ASSERT_EQ(1, test_lights.size());
- EXPECT_EQ(test_lights[0].get().getName(), "Hue ambiance lamp 1");
- EXPECT_EQ(test_lights[0].get().getColorType(), ColorType::TEMPERATURE);
-}
-
-TEST(Hue, lightExists)
-{
- using namespace ::testing;
- std::shared_ptr handler = std::make_shared();
- nlohmann::json hue_bridge_state{ {"lights",
- {{"1",
- {{"state",
- {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
- {"reachable", true}}},
- {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
- {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
- {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} };
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(AtLeast(2))
- .WillRepeatedly(Return(hue_bridge_state));
- EXPECT_CALL(*handler,
- GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
-
- Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
-
- EXPECT_EQ(true, test_bridge.lightExists(1));
- EXPECT_EQ(false, test_bridge.lightExists(2));
-
- const Hue const_test_bridge1 = test_bridge;
- EXPECT_EQ(true, const_test_bridge1.lightExists(1));
- EXPECT_EQ(false, const_test_bridge1.lightExists(2));
-
- test_bridge.getLight(1);
- const Hue const_test_bridge2 = test_bridge;
- EXPECT_EQ(true, test_bridge.lightExists(1));
- EXPECT_EQ(true, const_test_bridge2.lightExists(1));
-}
-
-TEST(Hue, getPictureOfLight)
-{
- using namespace ::testing;
- std::shared_ptr handler = std::make_shared();
- nlohmann::json hue_bridge_state{ {"lights",
- {{"1",
- {{"state",
- {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
- {"reachable", true}}},
- {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
- {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
- {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} };
-
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(hue_bridge_state));
- EXPECT_CALL(*handler,
- GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
-
- Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
-
- test_bridge.getLight(1);
-
- EXPECT_EQ("", test_bridge.getPictureOfLight(2));
-
- EXPECT_EQ("e27_waca", test_bridge.getPictureOfLight(1));
-}
-
-TEST(Hue, refreshState)
-{
- std::shared_ptr handler = std::make_shared();
- Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); // NULL as username leads to segfault
-
- std::vector> test_lights = test_bridge.getAllLights();
- EXPECT_EQ(test_lights.size(), 0);
-}
+/**
+ \file test_Hue.cpp
+ Copyright Notice\n
+ Copyright (C) 2017 Jan Rogall - developer\n
+ Copyright (C) 2017 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+**/
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include "testhelper.h"
+
+#include "../include/Hue.h"
+#include "../include/json/json.hpp"
+#include "mocks/mock_HttpHandler.h"
+
+class HueFinderTest : public ::testing::Test
+{
+protected:
+ std::shared_ptr handler;
+
+protected:
+ HueFinderTest() : handler(std::make_shared())
+ {
+ using namespace ::testing;
+
+ EXPECT_CALL(*handler,
+ sendMulticast("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: "
+ "\"ssdp:discover\"\r\nMX: 5\r\nST: ssdp:all\r\n\r\n",
+ "239.255.255.250", 1900, 5))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(getMulticastReply()));
+
+ EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", "192.168.2.1", getBridgePort()))
+ .Times(0);
+
+ EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(getBridgeXml()));
+ }
+ ~HueFinderTest(){};
+};
+
+TEST_F(HueFinderTest, FindBridges)
+{
+ HueFinder finder(handler);
+ std::vector bridges = finder.FindBridges();
+
+ HueFinder::HueIdentification bridge_to_comp;
+ bridge_to_comp.ip = getBridgeIp();
+ bridge_to_comp.port = getBridgePort();
+ bridge_to_comp.mac = getBridgeMac();
+
+ EXPECT_EQ(bridges.size(), 1) << "HueFinder found more than one Bridge";
+ EXPECT_EQ(bridges[0].ip, bridge_to_comp.ip) << "HueIdentification ip does not match";
+ EXPECT_EQ(bridges[0].port, bridge_to_comp.port) << "HueIdentification port does not match";
+ EXPECT_EQ(bridges[0].mac, bridge_to_comp.mac) << "HueIdentification mac does not match";
+
+ // Test invalid description
+ EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(::testing::Return("invalid stuff"));
+ bridges = finder.FindBridges();
+ EXPECT_TRUE(bridges.empty());
+}
+
+TEST_F(HueFinderTest, GetBridge)
+{
+ using namespace ::testing;
+ nlohmann::json request{{"devicetype", "HuePlusPlus#User"}};
+
+ nlohmann::json errorResponse
+ = {{{"error", {{"type", 101}, {"address", ""}, {"description", "link button not pressed"}}}}};
+
+ EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(errorResponse));
+
+ HueFinder finder(handler);
+ std::vector bridges = finder.FindBridges();
+
+ ASSERT_THROW(finder.GetBridge(bridges[0]), HueException);
+
+ nlohmann::json successResponse = {{{"success", {{"username", getBridgeUsername()}}}}};
+
+ EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(Return(successResponse));
+
+ finder = HueFinder(handler);
+ bridges = finder.FindBridges();
+
+ Hue test_bridge = finder.GetBridge(bridges[0]);
+
+ EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching";
+ EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching";
+ EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching";
+
+ // Verify that username is correctly set in api requests
+ nlohmann::json hue_bridge_state{{"lights", {}}};
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(Return(hue_bridge_state));
+
+ test_bridge.getAllLights();
+
+ Mock::VerifyAndClearExpectations(handler.get());
+}
+
+TEST_F(HueFinderTest, AddUsername)
+{
+ HueFinder finder(handler);
+ std::vector bridges = finder.FindBridges();
+
+ finder.AddUsername(bridges[0].mac, getBridgeUsername());
+ Hue test_bridge = finder.GetBridge(bridges[0]);
+
+ EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching";
+ EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching";
+ EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching";
+}
+
+TEST_F(HueFinderTest, GetAllUsernames)
+{
+ HueFinder finder(handler);
+ std::vector bridges = finder.FindBridges();
+
+ finder.AddUsername(bridges[0].mac, getBridgeUsername());
+
+ std::map users = finder.GetAllUsernames();
+ EXPECT_EQ(users[getBridgeMac()], getBridgeUsername()) << "Username of MAC:" << getBridgeMac() << "not matching";
+}
+
+TEST(Hue, Constructor)
+{
+ std::shared_ptr handler = std::make_shared();
+ Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+
+ EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching";
+ EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching";
+ EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching";
+}
+
+TEST(Hue, requestUsername)
+{
+ using namespace ::testing;
+ std::shared_ptr handler = std::make_shared();
+ nlohmann::json request{{"devicetype", "HuePlusPlus#User"}};
+
+ {
+ nlohmann::json errorResponse
+ = {{{"error", {{"type", 101}, {"address", ""}, {"description", "link button not pressed"}}}}};
+
+ EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(errorResponse));
+
+ Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler);
+
+ std::string username = test_bridge.requestUsername();
+ EXPECT_EQ(username, "") << "Returned username not matching";
+ EXPECT_EQ(test_bridge.getUsername(), "") << "Bridge username not matching";
+ }
+
+ {
+ // Other error code causes exception
+ int otherError = 1;
+ nlohmann::json exceptionResponse
+ = {{{"error", {{"type", otherError}, {"address", ""}, {"description", "some error"}}}}};
+ Hue testBridge(getBridgeIp(), getBridgePort(), "", handler);
+
+ EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
+ .WillOnce(Return(exceptionResponse));
+
+ try
+ {
+ testBridge.requestUsername();
+ FAIL() << "requestUsername did not throw";
+ }
+ catch (const HueAPIResponseException& e)
+ {
+ EXPECT_EQ(e.GetErrorNumber(), otherError);
+ }
+ catch (const std::exception& e)
+ {
+ FAIL() << "wrong exception: " << e.what();
+ }
+ }
+
+ {
+ nlohmann::json successResponse = {{{"success", {{"username", getBridgeUsername()}}}}};
+ EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillRepeatedly(Return(successResponse));
+
+ Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler);
+
+ std::string username = test_bridge.requestUsername();
+
+ EXPECT_EQ(username, test_bridge.getUsername()) << "Returned username not matching";
+ EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching";
+ EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching";
+
+ // Verify that username is correctly set in api requests
+ nlohmann::json hue_bridge_state{{"lights", {}}};
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(Return(hue_bridge_state));
+
+ test_bridge.getAllLights();
+ }
+}
+
+TEST(Hue, setIP)
+{
+ std::shared_ptr handler = std::make_shared();
+ Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler);
+ EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching after initialization";
+ test_bridge.setIP("192.168.2.112");
+ EXPECT_EQ(test_bridge.getBridgeIP(), "192.168.2.112") << "Bridge IP not matching after setting it";
+}
+
+TEST(Hue, setPort)
+{
+ std::shared_ptr handler = std::make_shared();
+ Hue test_bridge = Hue(getBridgeIp(), getBridgePort(), "", handler);
+ EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching after initialization";
+ test_bridge.setPort(81);
+ EXPECT_EQ(test_bridge.getBridgePort(), 81) << "Bridge Port not matching after setting it";
+}
+
+TEST(Hue, getLight)
+{
+ using namespace ::testing;
+ std::shared_ptr handler = std::make_shared();
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1);
+
+ Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+
+ // Test exception
+ ASSERT_THROW(test_bridge.getLight(1), HueException);
+
+ nlohmann::json hue_bridge_state{{"lights",
+ {{"1",
+ {{"state",
+ {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
+ {"reachable", true}}},
+ {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
+ {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
+ {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}}};
+
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(Return(hue_bridge_state));
+
+ EXPECT_CALL(*handler,
+ GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
+
+ // Test when correct data is sent
+ HueLight test_light_1 = test_bridge.getLight(1);
+ EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
+ EXPECT_EQ(test_light_1.getColorType(), ColorType::TEMPERATURE);
+
+ // Test again to check whether light is returned directly -> interesting for
+ // code coverage test
+ test_light_1 = test_bridge.getLight(1);
+ EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
+ EXPECT_EQ(test_light_1.getColorType(), ColorType::TEMPERATURE);
+
+ // more coverage stuff
+ hue_bridge_state["lights"]["1"]["modelid"] = "LCT001";
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(Return(hue_bridge_state));
+
+ EXPECT_CALL(*handler,
+ GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
+ test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+
+ // Test when correct data is sent
+ test_light_1 = test_bridge.getLight(1);
+ EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
+ EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_B);
+
+ hue_bridge_state["lights"]["1"]["modelid"] = "LCT010";
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(Return(hue_bridge_state));
+
+ EXPECT_CALL(*handler,
+ GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
+ test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+
+ // Test when correct data is sent
+ test_light_1 = test_bridge.getLight(1);
+ EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
+ EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_C);
+
+ hue_bridge_state["lights"]["1"]["modelid"] = "LST001";
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(Return(hue_bridge_state));
+
+ EXPECT_CALL(*handler,
+ GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
+ test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+
+ // Test when correct data is sent
+ test_light_1 = test_bridge.getLight(1);
+ EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
+ EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_A);
+
+ hue_bridge_state["lights"]["1"]["modelid"] = "LWB004";
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(Return(hue_bridge_state));
+
+ EXPECT_CALL(*handler,
+ GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
+ test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+
+ // Test when correct data is sent
+ test_light_1 = test_bridge.getLight(1);
+ EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1");
+ EXPECT_EQ(test_light_1.getColorType(), ColorType::NONE);
+
+ hue_bridge_state["lights"]["1"]["modelid"] = "ABC000";
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(Return(hue_bridge_state));
+ test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+ ASSERT_THROW(test_bridge.getLight(1), HueException);
+}
+
+TEST(Hue, removeLight)
+{
+ using namespace ::testing;
+ std::shared_ptr handler = std::make_shared();
+ nlohmann::json hue_bridge_state{ {"lights",
+ {{"1",
+ {{"state",
+ {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
+ {"reachable", true}}},
+ {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
+ {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
+ {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} };
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillOnce(Return(hue_bridge_state));
+
+ Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+
+ EXPECT_CALL(*handler,
+ GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(1)
+ .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
+
+ nlohmann::json return_answer;
+ return_answer = nlohmann::json::array();
+ return_answer[0] = nlohmann::json::object();
+ return_answer[0]["success"] = "/lights/1 deleted";
+ EXPECT_CALL(*handler,
+ DELETEJson(
+ "/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(2)
+ .WillOnce(Return(return_answer))
+ .WillOnce(Return(nlohmann::json()));
+
+ // Test when correct data is sent
+ HueLight test_light_1 = test_bridge.getLight(1);
+
+ EXPECT_EQ(test_bridge.removeLight(1), true);
+
+ EXPECT_EQ(test_bridge.removeLight(1), false);
+}
+
+TEST(Hue, getAllLights)
+{
+ using namespace ::testing;
+ std::shared_ptr handler = std::make_shared();
+ nlohmann::json hue_bridge_state{ {"lights",
+ {{"1",
+ {{"state",
+ {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
+ {"reachable", true}}},
+ {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
+ {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
+ {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} };
+
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(2)
+ .WillRepeatedly(Return(hue_bridge_state));
+
+ EXPECT_CALL(*handler,
+ GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(2)
+ .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
+
+ Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+
+ std::vector> test_lights = test_bridge.getAllLights();
+ ASSERT_EQ(1, test_lights.size());
+ EXPECT_EQ(test_lights[0].get().getName(), "Hue ambiance lamp 1");
+ EXPECT_EQ(test_lights[0].get().getColorType(), ColorType::TEMPERATURE);
+}
+
+TEST(Hue, lightExists)
+{
+ using namespace ::testing;
+ std::shared_ptr handler = std::make_shared();
+ nlohmann::json hue_bridge_state{ {"lights",
+ {{"1",
+ {{"state",
+ {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
+ {"reachable", true}}},
+ {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
+ {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
+ {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} };
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(2))
+ .WillRepeatedly(Return(hue_bridge_state));
+ EXPECT_CALL(*handler,
+ GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
+
+ Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+
+ EXPECT_EQ(true, test_bridge.lightExists(1));
+ EXPECT_EQ(false, test_bridge.lightExists(2));
+
+ const Hue const_test_bridge1 = test_bridge;
+ EXPECT_EQ(true, const_test_bridge1.lightExists(1));
+ EXPECT_EQ(false, const_test_bridge1.lightExists(2));
+
+ test_bridge.getLight(1);
+ const Hue const_test_bridge2 = test_bridge;
+ EXPECT_EQ(true, test_bridge.lightExists(1));
+ EXPECT_EQ(true, const_test_bridge2.lightExists(1));
+}
+
+TEST(Hue, getPictureOfLight)
+{
+ using namespace ::testing;
+ std::shared_ptr handler = std::make_shared();
+ nlohmann::json hue_bridge_state{ {"lights",
+ {{"1",
+ {{"state",
+ {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
+ {"reachable", true}}},
+ {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
+ {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
+ {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} };
+
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(hue_bridge_state));
+ EXPECT_CALL(*handler,
+ GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort()))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(hue_bridge_state["lights"]["1"]));
+
+ Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler);
+
+ test_bridge.getLight(1);
+
+ EXPECT_EQ("", test_bridge.getPictureOfLight(2));
+
+ EXPECT_EQ("e27_waca", test_bridge.getPictureOfLight(1));
+}
+
+TEST(Hue, refreshState)
+{
+ std::shared_ptr handler = std::make_shared();
+ Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); // NULL as username leads to segfault
+
+ std::vector> test_lights = test_bridge.getAllLights();
+ EXPECT_EQ(test_lights.size(), 0);
+}
diff --git a/hueplusplus/test/test_HueCommandAPI.cpp b/src/test/test_HueCommandAPI.cpp
index f3be0e8..f3be0e8 100644
--- a/hueplusplus/test/test_HueCommandAPI.cpp
+++ b/src/test/test_HueCommandAPI.cpp
diff --git a/hueplusplus/test/test_HueLight.cpp b/src/test/test_HueLight.cpp
index 891f69e..891f69e 100644
--- a/hueplusplus/test/test_HueLight.cpp
+++ b/src/test/test_HueLight.cpp
diff --git a/hueplusplus/test/test_Main.cpp b/src/test/test_Main.cpp
old mode 100755
new mode 100644
index e6fb21c..a51d328
--- a/hueplusplus/test/test_Main.cpp
+++ b/src/test/test_Main.cpp
@@ -1,29 +1,29 @@
-/**
- \file test_Main.cpp
- Copyright Notice\n
- Copyright (C) 2017 Jan Rogall - developer\n
- Copyright (C) 2017 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#include
-
-int main(int argc, char** argv)
-{
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
+/**
+ \file test_Main.cpp
+ Copyright Notice\n
+ Copyright (C) 2017 Jan Rogall - developer\n
+ Copyright (C) 2017 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+**/
+
+#include
+
+int main(int argc, char** argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/hueplusplus/test/test_SimpleBrightnessStrategy.cpp b/src/test/test_SimpleBrightnessStrategy.cpp
old mode 100755
new mode 100644
index f0f1b60..ce52624
--- a/hueplusplus/test/test_SimpleBrightnessStrategy.cpp
+++ b/src/test/test_SimpleBrightnessStrategy.cpp
@@ -1,93 +1,93 @@
-/**
- \file test_SimpleBrightnessStrategy.cpp
- Copyright Notice\n
- Copyright (C) 2017 Jan Rogall - developer\n
- Copyright (C) 2017 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#include
-#include
-#include
-
-#include
-#include
-
-#include "testhelper.h"
-
-#include "../include/SimpleBrightnessStrategy.h"
-#include "../include/json/json.hpp"
-#include "mocks/mock_HttpHandler.h"
-#include "mocks/mock_HueLight.h"
-
-TEST(SimpleBrightnessStrategy, setBrightness)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- nlohmann::json prep_ret;
- prep_ret = nlohmann::json::array();
- prep_ret[0] = nlohmann::json::object();
- prep_ret[0]["success"] = nlohmann::json::object();
- prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
- prep_ret[1] = nlohmann::json::object();
- prep_ret[1]["success"] = nlohmann::json::object();
- prep_ret[1]["success"]["/lights/1/state/on"] = true;
- prep_ret[2] = nlohmann::json::object();
- prep_ret[2]["success"] = nlohmann::json::object();
- prep_ret[2]["success"]["/lights/1/state/bri"] = 50;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
-
- test_light.getState()["state"]["on"] = true;
- EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light));
-
- test_light.getState()["state"]["bri"] = 0;
- EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(50, 6, test_light));
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["bri"] = 50;
- EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(50, 6, test_light));
-
- prep_ret[2]["success"]["/lights/1/state/bri"] = 254;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(255, 6, test_light));
-}
-
-TEST(SimpleBrightnessStrategy, getBrightness)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["bri"] = 200;
- EXPECT_EQ(200, SimpleBrightnessStrategy().getBrightness(test_light));
- test_light.getState()["state"]["bri"] = 0;
- EXPECT_EQ(0, SimpleBrightnessStrategy().getBrightness(static_cast(test_light)));
-}
+/**
+ \file test_SimpleBrightnessStrategy.cpp
+ Copyright Notice\n
+ Copyright (C) 2017 Jan Rogall - developer\n
+ Copyright (C) 2017 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+**/
+
+#include
+#include
+#include
+
+#include
+#include
+
+#include "testhelper.h"
+
+#include "../include/SimpleBrightnessStrategy.h"
+#include "../include/json/json.hpp"
+#include "mocks/mock_HttpHandler.h"
+#include "mocks/mock_HueLight.h"
+
+TEST(SimpleBrightnessStrategy, setBrightness)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ nlohmann::json prep_ret;
+ prep_ret = nlohmann::json::array();
+ prep_ret[0] = nlohmann::json::object();
+ prep_ret[0]["success"] = nlohmann::json::object();
+ prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
+ prep_ret[1] = nlohmann::json::object();
+ prep_ret[1]["success"] = nlohmann::json::object();
+ prep_ret[1]["success"]["/lights/1/state/on"] = true;
+ prep_ret[2] = nlohmann::json::object();
+ prep_ret[2]["success"] = nlohmann::json::object();
+ prep_ret[2]["success"]["/lights/1/state/bri"] = 50;
+ EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
+
+ test_light.getState()["state"]["on"] = true;
+ EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light));
+
+ test_light.getState()["state"]["bri"] = 0;
+ EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(50, 6, test_light));
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["bri"] = 50;
+ EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(50, 6, test_light));
+
+ prep_ret[2]["success"]["/lights/1/state/bri"] = 254;
+ EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(255, 6, test_light));
+}
+
+TEST(SimpleBrightnessStrategy, getBrightness)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+
+ test_light.getState()["state"]["bri"] = 200;
+ EXPECT_EQ(200, SimpleBrightnessStrategy().getBrightness(test_light));
+ test_light.getState()["state"]["bri"] = 0;
+ EXPECT_EQ(0, SimpleBrightnessStrategy().getBrightness(static_cast(test_light)));
+}
diff --git a/hueplusplus/test/test_SimpleColorHueStrategy.cpp b/src/test/test_SimpleColorHueStrategy.cpp
old mode 100755
new mode 100644
index a9afafd..5bdd3a9
--- a/hueplusplus/test/test_SimpleColorHueStrategy.cpp
+++ b/src/test/test_SimpleColorHueStrategy.cpp
@@ -1,418 +1,418 @@
-/**
- \file test_SimpleColorHuewStrategy.cpp
- Copyright Notice\n
- Copyright (C) 2017 Jan Rogall - developer\n
- Copyright (C) 2017 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#include
-#include
-
-#include
-#include
-
-#include "testhelper.h"
-
-#include "../include/SimpleColorHueStrategy.h"
-#include "../include/json/json.hpp"
-#include "mocks/mock_HttpHandler.h"
-#include "mocks/mock_HueLight.h"
-
-TEST(SimpleColorHueStrategy, setColorHue)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
- nlohmann::json prep_ret;
- prep_ret = nlohmann::json::array();
- prep_ret[0] = nlohmann::json::object();
- prep_ret[0]["success"] = nlohmann::json::object();
- prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
- prep_ret[1] = nlohmann::json::object();
- prep_ret[1]["success"] = nlohmann::json::object();
- prep_ret[1]["success"]["/lights/1/state/on"] = true;
- prep_ret[2] = nlohmann::json::object();
- prep_ret[2]["success"] = nlohmann::json::object();
- prep_ret[2]["success"]["/lights/1/state/hue"] = 30500;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
-
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["hue"] = 200;
- test_light.getState()["state"]["colormode"] = "hs";
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorHue(200, 4, test_light));
-
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorHue(30500, 6, test_light));
-}
-
-TEST(SimpleColorHueStrategy, setColorSaturation)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
- nlohmann::json prep_ret;
- prep_ret = nlohmann::json::array();
- prep_ret[0] = nlohmann::json::object();
- prep_ret[0]["success"] = nlohmann::json::object();
- prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
- prep_ret[1] = nlohmann::json::object();
- prep_ret[1]["success"] = nlohmann::json::object();
- prep_ret[1]["success"]["/lights/1/state/on"] = true;
- prep_ret[2] = nlohmann::json::object();
- prep_ret[2]["success"] = nlohmann::json::object();
- prep_ret[2]["success"]["/lights/1/state/sat"] = 254;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
-
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["sat"] = 100;
- test_light.getState()["state"]["colormode"] = "hs";
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorSaturation(100, 4, test_light));
-
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorSaturation(255, 6, test_light));
-}
-
-TEST(SimpleColorHueStrategy, setColorHueSaturation)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
- nlohmann::json prep_ret;
- prep_ret = nlohmann::json::array();
- prep_ret[0] = nlohmann::json::object();
- prep_ret[0]["success"] = nlohmann::json::object();
- prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
- prep_ret[1] = nlohmann::json::object();
- prep_ret[1]["success"] = nlohmann::json::object();
- prep_ret[1]["success"]["/lights/1/state/on"] = true;
- prep_ret[2] = nlohmann::json::object();
- prep_ret[2]["success"] = nlohmann::json::object();
- prep_ret[2]["success"]["/lights/1/state/hue"] = 30500;
- prep_ret[3] = nlohmann::json::object();
- prep_ret[3]["success"] = nlohmann::json::object();
- prep_ret[3]["success"]["/lights/1/state/sat"] = 254;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
-
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["sat"] = 100;
- test_light.getState()["state"]["hue"] = 200;
- test_light.getState()["state"]["colormode"] = "hs";
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorHueSaturation(200, 100, 4, test_light));
-
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorHueSaturation(30500, 255, 6, test_light));
-}
-
-TEST(SimpleColorHueStrategy, setColorXY)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
- nlohmann::json prep_ret;
- prep_ret = nlohmann::json::array();
- prep_ret[0] = nlohmann::json::object();
- prep_ret[0]["success"] = nlohmann::json::object();
- prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
- prep_ret[1] = nlohmann::json::object();
- prep_ret[1]["success"] = nlohmann::json::object();
- prep_ret[1]["success"]["/lights/1/state/on"] = true;
- prep_ret[2] = nlohmann::json::object();
- prep_ret[2]["success"] = nlohmann::json::object();
- prep_ret[2]["success"]["/lights/1/state/xy"][0] = 0.2355;
- prep_ret[2]["success"]["/lights/1/state/xy"][1] = 0.1234;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
-
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["xy"][0] = 0.1f;
- test_light.getState()["state"]["xy"][1] = 0.1f;
- test_light.getState()["state"]["colormode"] = "xy";
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorXY(0.1f, 0.1f, 4, test_light));
-
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorXY(0.2355f, 0.1234f, 6, test_light));
-}
-
-TEST(SimpleColorHueStrategy, setColorRGB)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, setColorXY(_, _, 4)).Times(2).WillRepeatedly(Return(true));
-
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(128, 128, 128, 4, test_light));
-
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(255, 255, 255, 4, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(4)).Times(1).WillOnce(Return(true));
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(0, 0, 0, 4, test_light));
-}
-
-TEST(SimpleColorHueStrategy, setColorLoop)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
- nlohmann::json prep_ret;
- prep_ret = nlohmann::json::array();
- prep_ret[0] = nlohmann::json::object();
- prep_ret[0]["success"] = nlohmann::json::object();
- prep_ret[0]["success"]["/lights/1/state/on"] = true;
- prep_ret[1] = nlohmann::json::object();
- prep_ret[1]["success"] = nlohmann::json::object();
- prep_ret[1]["success"]["/lights/1/state/effect"] = "colorloop";
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
-
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["effect"] = "colorloop";
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorLoop(true, test_light));
-
- test_light.getState()["state"]["on"] = false;
- test_light.getState()["state"]["effect"] = "none";
- EXPECT_EQ(true, SimpleColorHueStrategy().setColorLoop(true, test_light));
-}
-
-TEST(SimpleColorHueStrategy, alertHueSaturation)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["colormode"] = "invalid";
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(30000, 128, test_light));
-
- EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "hs";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["sat"] = 100;
- test_light.getState()["state"]["hue"] = 200;
- EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "xy";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["xy"][0] = 0.1;
- test_light.getState()["state"]["xy"][1] = 0.1;
- EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
-}
-
-TEST(SimpleColorHueStrategy, alertXY)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["colormode"] = "invalid";
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "hs";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["xy"][0] = 0.1;
- test_light.getState()["state"]["xy"][1] = 0.1;
- test_light.getState()["state"]["sat"] = 100;
- test_light.getState()["state"]["hue"] = 200;
- EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "xy";
- test_light.getState()["state"]["on"] = true;
- EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
-}
-
-TEST(SimpleColorHueStrategy, alertRGB)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["colormode"] = "invalid";
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, setColorRGB(_, _, _, 1))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "hs";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["sat"] = 100;
- test_light.getState()["state"]["hue"] = 200;
- EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, setColorRGB(_, _, _, 1))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "xy";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["xy"][0] = 0.1;
- test_light.getState()["state"]["xy"][1] = 0.1;
- EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
- EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
-}
-
-TEST(SimpleColorHueStrategy, getColorHueSaturation)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["hue"] = 5000;
- test_light.getState()["state"]["sat"] = 128;
- EXPECT_EQ(std::make_pair(static_cast(5000), static_cast(128)),
- SimpleColorHueStrategy().getColorHueSaturation(test_light));
- test_light.getState()["state"]["hue"] = 50000;
- test_light.getState()["state"]["sat"] = 158;
- EXPECT_EQ(std::make_pair(static_cast(50000), static_cast(158)),
- SimpleColorHueStrategy().getColorHueSaturation(static_cast(test_light)));
-}
-
-TEST(SimpleColorHueStrategy, getColorXY)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["xy"][0] = 0.1234;
- test_light.getState()["state"]["xy"][1] = 0.1234;
- EXPECT_EQ(std::make_pair(static_cast(0.1234), static_cast(0.1234)),
- SimpleColorHueStrategy().getColorXY(test_light));
- test_light.getState()["state"]["xy"][0] = 0.12;
- test_light.getState()["state"]["xy"][1] = 0.6458;
- EXPECT_EQ(std::make_pair(static_cast(0.12), static_cast(0.6458)),
- SimpleColorHueStrategy().getColorXY(static_cast(test_light)));
-}
+/**
+ \file test_SimpleColorHuewStrategy.cpp
+ Copyright Notice\n
+ Copyright (C) 2017 Jan Rogall - developer\n
+ Copyright (C) 2017 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+**/
+
+#include
+#include
+
+#include
+#include
+
+#include "testhelper.h"
+
+#include "../include/SimpleColorHueStrategy.h"
+#include "../include/json/json.hpp"
+#include "mocks/mock_HttpHandler.h"
+#include "mocks/mock_HueLight.h"
+
+TEST(SimpleColorHueStrategy, setColorHue)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+ nlohmann::json prep_ret;
+ prep_ret = nlohmann::json::array();
+ prep_ret[0] = nlohmann::json::object();
+ prep_ret[0]["success"] = nlohmann::json::object();
+ prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
+ prep_ret[1] = nlohmann::json::object();
+ prep_ret[1]["success"] = nlohmann::json::object();
+ prep_ret[1]["success"]["/lights/1/state/on"] = true;
+ prep_ret[2] = nlohmann::json::object();
+ prep_ret[2]["success"] = nlohmann::json::object();
+ prep_ret[2]["success"]["/lights/1/state/hue"] = 30500;
+ EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
+
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["hue"] = 200;
+ test_light.getState()["state"]["colormode"] = "hs";
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorHue(200, 4, test_light));
+
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorHue(30500, 6, test_light));
+}
+
+TEST(SimpleColorHueStrategy, setColorSaturation)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+ nlohmann::json prep_ret;
+ prep_ret = nlohmann::json::array();
+ prep_ret[0] = nlohmann::json::object();
+ prep_ret[0]["success"] = nlohmann::json::object();
+ prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
+ prep_ret[1] = nlohmann::json::object();
+ prep_ret[1]["success"] = nlohmann::json::object();
+ prep_ret[1]["success"]["/lights/1/state/on"] = true;
+ prep_ret[2] = nlohmann::json::object();
+ prep_ret[2]["success"] = nlohmann::json::object();
+ prep_ret[2]["success"]["/lights/1/state/sat"] = 254;
+ EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
+
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["sat"] = 100;
+ test_light.getState()["state"]["colormode"] = "hs";
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorSaturation(100, 4, test_light));
+
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorSaturation(255, 6, test_light));
+}
+
+TEST(SimpleColorHueStrategy, setColorHueSaturation)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+ nlohmann::json prep_ret;
+ prep_ret = nlohmann::json::array();
+ prep_ret[0] = nlohmann::json::object();
+ prep_ret[0]["success"] = nlohmann::json::object();
+ prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
+ prep_ret[1] = nlohmann::json::object();
+ prep_ret[1]["success"] = nlohmann::json::object();
+ prep_ret[1]["success"]["/lights/1/state/on"] = true;
+ prep_ret[2] = nlohmann::json::object();
+ prep_ret[2]["success"] = nlohmann::json::object();
+ prep_ret[2]["success"]["/lights/1/state/hue"] = 30500;
+ prep_ret[3] = nlohmann::json::object();
+ prep_ret[3]["success"] = nlohmann::json::object();
+ prep_ret[3]["success"]["/lights/1/state/sat"] = 254;
+ EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
+
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["sat"] = 100;
+ test_light.getState()["state"]["hue"] = 200;
+ test_light.getState()["state"]["colormode"] = "hs";
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorHueSaturation(200, 100, 4, test_light));
+
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorHueSaturation(30500, 255, 6, test_light));
+}
+
+TEST(SimpleColorHueStrategy, setColorXY)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+ nlohmann::json prep_ret;
+ prep_ret = nlohmann::json::array();
+ prep_ret[0] = nlohmann::json::object();
+ prep_ret[0]["success"] = nlohmann::json::object();
+ prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
+ prep_ret[1] = nlohmann::json::object();
+ prep_ret[1]["success"] = nlohmann::json::object();
+ prep_ret[1]["success"]["/lights/1/state/on"] = true;
+ prep_ret[2] = nlohmann::json::object();
+ prep_ret[2]["success"] = nlohmann::json::object();
+ prep_ret[2]["success"]["/lights/1/state/xy"][0] = 0.2355;
+ prep_ret[2]["success"]["/lights/1/state/xy"][1] = 0.1234;
+ EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
+
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["xy"][0] = 0.1f;
+ test_light.getState()["state"]["xy"][1] = 0.1f;
+ test_light.getState()["state"]["colormode"] = "xy";
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorXY(0.1f, 0.1f, 4, test_light));
+
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorXY(0.2355f, 0.1234f, 6, test_light));
+}
+
+TEST(SimpleColorHueStrategy, setColorRGB)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, setColorXY(_, _, 4)).Times(2).WillRepeatedly(Return(true));
+
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(128, 128, 128, 4, test_light));
+
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(255, 255, 255, 4, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(4)).Times(1).WillOnce(Return(true));
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(0, 0, 0, 4, test_light));
+}
+
+TEST(SimpleColorHueStrategy, setColorLoop)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+ nlohmann::json prep_ret;
+ prep_ret = nlohmann::json::array();
+ prep_ret[0] = nlohmann::json::object();
+ prep_ret[0]["success"] = nlohmann::json::object();
+ prep_ret[0]["success"]["/lights/1/state/on"] = true;
+ prep_ret[1] = nlohmann::json::object();
+ prep_ret[1]["success"] = nlohmann::json::object();
+ prep_ret[1]["success"]["/lights/1/state/effect"] = "colorloop";
+ EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
+
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["effect"] = "colorloop";
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorLoop(true, test_light));
+
+ test_light.getState()["state"]["on"] = false;
+ test_light.getState()["state"]["effect"] = "none";
+ EXPECT_EQ(true, SimpleColorHueStrategy().setColorLoop(true, test_light));
+}
+
+TEST(SimpleColorHueStrategy, alertHueSaturation)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+
+ test_light.getState()["state"]["colormode"] = "invalid";
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(30000, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "hs";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["sat"] = 100;
+ test_light.getState()["state"]["hue"] = 200;
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "xy";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["xy"][0] = 0.1;
+ test_light.getState()["state"]["xy"][1] = 0.1;
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light));
+}
+
+TEST(SimpleColorHueStrategy, alertXY)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+
+ test_light.getState()["state"]["colormode"] = "invalid";
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "hs";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["xy"][0] = 0.1;
+ test_light.getState()["state"]["xy"][1] = 0.1;
+ test_light.getState()["state"]["sat"] = 100;
+ test_light.getState()["state"]["hue"] = 200;
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "xy";
+ test_light.getState()["state"]["on"] = true;
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light));
+}
+
+TEST(SimpleColorHueStrategy, alertRGB)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+
+ test_light.getState()["state"]["colormode"] = "invalid";
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorRGB(_, _, _, 1))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "hs";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["sat"] = 100;
+ test_light.getState()["state"]["hue"] = 200;
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorRGB(_, _, _, 1))
+ .Times(AtLeast(2))
+ .WillOnce(Return(false))
+ .WillRepeatedly(Return(true));
+ test_light.getState()["state"]["colormode"] = "xy";
+ test_light.getState()["state"]["on"] = true;
+ test_light.getState()["state"]["xy"][0] = 0.1;
+ test_light.getState()["state"]["xy"][1] = 0.1;
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
+ EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true));
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
+
+ EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ test_light.getState()["state"]["on"] = false;
+ EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light));
+}
+
+TEST(SimpleColorHueStrategy, getColorHueSaturation)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+
+ test_light.getState()["state"]["hue"] = 5000;
+ test_light.getState()["state"]["sat"] = 128;
+ EXPECT_EQ(std::make_pair(static_cast(5000), static_cast(128)),
+ SimpleColorHueStrategy().getColorHueSaturation(test_light));
+ test_light.getState()["state"]["hue"] = 50000;
+ test_light.getState()["state"]["sat"] = 158;
+ EXPECT_EQ(std::make_pair(static_cast(50000), static_cast(158)),
+ SimpleColorHueStrategy().getColorHueSaturation(static_cast(test_light)));
+}
+
+TEST(SimpleColorHueStrategy, getColorXY)
+{
+ using namespace ::testing;
+ std::shared_ptr handler(std::make_shared());
+ EXPECT_CALL(
+ *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
+ .Times(AtLeast(1))
+ .WillRepeatedly(Return(nlohmann::json::object()));
+ MockHueLight test_light(handler);
+ EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
+
+ test_light.getState()["state"]["xy"][0] = 0.1234;
+ test_light.getState()["state"]["xy"][1] = 0.1234;
+ EXPECT_EQ(std::make_pair(static_cast(0.1234), static_cast(0.1234)),
+ SimpleColorHueStrategy().getColorXY(test_light));
+ test_light.getState()["state"]["xy"][0] = 0.12;
+ test_light.getState()["state"]["xy"][1] = 0.6458;
+ EXPECT_EQ(std::make_pair(static_cast(0.12), static_cast(0.6458)),
+ SimpleColorHueStrategy().getColorXY(static_cast(test_light)));
+}
diff --git a/hueplusplus/test/test_SimpleColorTemperatureStrategy.cpp b/src/test/test_SimpleColorTemperatureStrategy.cpp
old mode 100755
new mode 100644
index d6cde22..1525046
--- a/hueplusplus/test/test_SimpleColorTemperatureStrategy.cpp
+++ b/src/test/test_SimpleColorTemperatureStrategy.cpp
@@ -1,125 +1,125 @@
-/**
- \file test_SimpleColorTemperatureStrategy.cpp
- Copyright Notice\n
- Copyright (C) 2017 Jan Rogall - developer\n
- Copyright (C) 2017 Moritz Wirger - developer\n
-
- This file is part of hueplusplus.
-
- hueplusplus is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- hueplusplus is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with hueplusplus. If not, see .
-**/
-
-#include
-#include
-#include
-
-#include
-#include
-
-#include "testhelper.h"
-
-#include "../include/SimpleColorTemperatureStrategy.h"
-#include "../include/json/json.hpp"
-#include "mocks/mock_HttpHandler.h"
-#include "mocks/mock_HueLight.h"
-
-TEST(SimpleColorTemperatureStrategy, setColorTemperature)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
- nlohmann::json prep_ret;
- prep_ret = nlohmann::json::array();
- prep_ret[0] = nlohmann::json::object();
- prep_ret[0]["success"] = nlohmann::json::object();
- prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6;
- prep_ret[1] = nlohmann::json::object();
- prep_ret[1]["success"] = nlohmann::json::object();
- prep_ret[1]["success"]["/lights/1/state/on"] = true;
- prep_ret[2] = nlohmann::json::object();
- prep_ret[2]["success"] = nlohmann::json::object();
- prep_ret[2]["success"]["/lights/1/state/ct"] = 155;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
-
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["ct"] = 200;
- EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(200, 4, test_light));
-
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(155, 6, test_light));
-
- prep_ret[2]["success"]["/lights/1/state/ct"] = 153;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
- EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(0, 6, test_light));
-
- prep_ret[2]["success"]["/lights/1/state/ct"] = 500;
- EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret));
- EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(600, 6, test_light));
-}
-
-TEST(SimpleColorTemperatureStrategy, alertTemperature)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["colormode"] = "invalid";
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(false, SimpleColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, setColorTemperature(_, _))
- .Times(AtLeast(2))
- .WillOnce(Return(false))
- .WillRepeatedly(Return(true));
- test_light.getState()["state"]["colormode"] = "ct";
- test_light.getState()["state"]["on"] = true;
- test_light.getState()["state"]["ct"] = 200;
- EXPECT_EQ(false, SimpleColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true));
- EXPECT_EQ(false, SimpleColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_EQ(true, SimpleColorTemperatureStrategy().alertTemperature(400, test_light));
-
- EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true));
- test_light.getState()["state"]["on"] = false;
- EXPECT_EQ(true, SimpleColorTemperatureStrategy().alertTemperature(400, test_light));
-}
-
-TEST(SimpleColorTemperatureStrategy, getColorTemperature)
-{
- using namespace ::testing;
- std::shared_ptr handler(std::make_shared());
- EXPECT_CALL(
- *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80))
- .Times(AtLeast(1))
- .WillRepeatedly(Return(nlohmann::json::object()));
- MockHueLight test_light(handler);
- EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return());
-
- test_light.getState()["state"]["ct"] = 200;
- EXPECT_EQ(200, SimpleColorTemperatureStrategy().getColorTemperature(test_light));
- test_light.getState()["state"]["ct"] = 500;
- EXPECT_EQ(500, SimpleColorTemperatureStrategy().getColorTemperature(static_cast(test_light)));
-}
+/**
+ \file test_SimpleColorTemperatureStrategy.cpp
+ Copyright Notice\n
+ Copyright (C) 2017 Jan Rogall - developer\n
+ Copyright (C) 2017 Moritz Wirger - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see