Commit 0f45635072fa0c87d46d593f8ad965d73a1e34f4
Committed by
Moritz Wirger
1 parent
749fa821
Rename directory structure (not building).
Showing
59 changed files
with
2580 additions
and
2582 deletions
CMakeLists.txt
| 1 | -cmake_minimum_required(VERSION 2.8.3) | ||
| 2 | -project(hueplusplus) | 1 | +cmake_minimum_required(VERSION 3.2) |
| 2 | + | ||
| 3 | +if(${CMAKE_VERSION} VERSION_LESS 3.11) | ||
| 4 | + cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) | ||
| 5 | +else() | ||
| 6 | + cmake_policy(VERSION 3.11) | ||
| 7 | +endif() | ||
| 8 | + | ||
| 9 | +# Add cmake dir to module path, so Find*.cmake can be found | ||
| 10 | +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) | ||
| 11 | + | ||
| 12 | +project(hueplusplus LANGUAGES CXX) | ||
| 3 | 13 | ||
| 4 | # options to set | 14 | # options to set |
| 5 | option(hueplusplus_TESTS "Build tests" OFF) | 15 | option(hueplusplus_TESTS "Build tests" OFF) |
cmake_uninstall.cmake.in renamed to cmake/cmake_uninstall.cmake.in
100755 → 100644
hueplusplus/hueplusplus-config.cmake.in renamed to cmake/hueplusplus-config.cmake.in
100755 → 100644
extern
0 → 100644
hueplusplus/include/BaseHttpHandler.h renamed to include/hueplusplus/BaseHttpHandler.h
| 1 | -/** | ||
| 2 | - \file BaseHttpHandler.h | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2020 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2020 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#ifndef _BASE_HTTPHANDLER_H | ||
| 24 | -#define _BASE_HTTPHANDLER_H | ||
| 25 | - | ||
| 26 | -#include <iostream> | ||
| 27 | -#include <memory> | ||
| 28 | -#include <string> | ||
| 29 | -#include <vector> | ||
| 30 | - | ||
| 31 | -#include "IHttpHandler.h" | ||
| 32 | - | ||
| 33 | -#include "json/json.hpp" | ||
| 34 | - | ||
| 35 | -//! Base class for classes that handle http requests and multicast requests | ||
| 36 | -class BaseHttpHandler : public IHttpHandler | ||
| 37 | -{ | ||
| 38 | -public: | ||
| 39 | - //! \brief Virtual dtor | ||
| 40 | - virtual ~BaseHttpHandler() = default; | ||
| 41 | - | ||
| 42 | - //! \brief Send a message to a specified host and return the body of the response. | ||
| 43 | - //! | ||
| 44 | - //! \param msg The message that should sent to the specified address | ||
| 45 | - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 46 | - //! \param port Optional port the request is sent to, default is 80 | ||
| 47 | - //! \return The body of the response of the host as a string | ||
| 48 | - //! \throws std::system_error when system or socket operations fail | ||
| 49 | - //! \throws HueException when response contained no body | ||
| 50 | - std::string sendGetHTTPBody(const std::string& msg, const std::string& adr, int port = 80) const override; | ||
| 51 | - | ||
| 52 | - //! \brief Send a HTTP request with the given method to the specified host and return the body of the response. | ||
| 53 | - //! | ||
| 54 | - //! \param method HTTP method type e.g. GET, HEAD, POST, PUT, DELETE, ... | ||
| 55 | - //! \param uri Uniform Resource Identifier in the request | ||
| 56 | - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ... | ||
| 57 | - //! \param body Request body, may be empty | ||
| 58 | - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 59 | - //! \param port Optional port the request is sent to, default is 80 | ||
| 60 | - //! \return Body of the response of the host | ||
| 61 | - //! \throws std::system_error when system or socket operations fail | ||
| 62 | - //! \throws HueException when response contained no body | ||
| 63 | - std::string sendHTTPRequest(const std::string& method, const std::string& uri, const std::string& contentType, | ||
| 64 | - const std::string& body, const std::string& adr, int port = 80) const override; | ||
| 65 | - | ||
| 66 | - //! \brief Send a HTTP GET request to the specified host and return the body of the response. | ||
| 67 | - //! | ||
| 68 | - //! \param uri Uniform Resource Identifier in the request | ||
| 69 | - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ... | ||
| 70 | - //! \param body Request body, may be empty | ||
| 71 | - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 72 | - //! \param port Optional port the request is sent to, default is 80 | ||
| 73 | - //! that specifies the port to which the request is sent to. Default is 80 | ||
| 74 | - //! \return Body of the response of the host | ||
| 75 | - //! \throws std::system_error when system or socket operations fail | ||
| 76 | - //! \throws HueException when response contained no body | ||
| 77 | - std::string GETString(const std::string& uri, const std::string& contentType, const std::string& body, | ||
| 78 | - const std::string& adr, int port = 80) const override; | ||
| 79 | - | ||
| 80 | - //! \brief Send a HTTP POST request to the specified host and return the body of the response. | ||
| 81 | - //! | ||
| 82 | - //! \param uri Uniform Resource Identifier in the request | ||
| 83 | - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ... | ||
| 84 | - //! \param body Request body, may be empty | ||
| 85 | - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 86 | - //! \param port Optional port the request is sent to, default is 80 | ||
| 87 | - //! that specifies the port to which the request is sent to. Default is 80 | ||
| 88 | - //! \return Body of the response of the host | ||
| 89 | - //! \throws std::system_error when system or socket operations fail | ||
| 90 | - //! \throws HueException when response contained no body | ||
| 91 | - std::string POSTString(const std::string& uri, const std::string& contentType, const std::string& body, | ||
| 92 | - const std::string& adr, int port = 80) const override; | ||
| 93 | - | ||
| 94 | - //! \brief Send a HTTP PUT request to the specified host and return the body of the response. | ||
| 95 | - //! | ||
| 96 | - //! \param uri Uniform Resource Identifier in the request | ||
| 97 | - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ... | ||
| 98 | - //! \param body Request body, may be empty | ||
| 99 | - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 100 | - //! \param port Optional port the request is sent to, default is 80 | ||
| 101 | - //! that specifies the port to which the request is sent to. Default is 80 | ||
| 102 | - //! \return Body of the response of the host | ||
| 103 | - //! \throws std::system_error when system or socket operations fail | ||
| 104 | - //! \throws HueException when response contained no body | ||
| 105 | - std::string PUTString(const std::string& uri, const std::string& contentType, const std::string& body, | ||
| 106 | - const std::string& adr, int port = 80) const override; | ||
| 107 | - | ||
| 108 | - //! \brief Send a HTTP DELETE request to the specified host and return the body of the response. | ||
| 109 | - //! | ||
| 110 | - //! \param uri Uniform Resource Identifier in the request | ||
| 111 | - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ... | ||
| 112 | - //! \param body Request body, may be empty | ||
| 113 | - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 114 | - //! \param port Optional port the request is sent to, default is 80 | ||
| 115 | - //! that specifies the port to which the request is sent to. Default is 80 | ||
| 116 | - //! \return Body of the response of the host | ||
| 117 | - //! \throws std::system_error when system or socket operations fail | ||
| 118 | - //! \throws HueException when response contained no body | ||
| 119 | - std::string DELETEString(const std::string& uri, const std::string& contentType, const std::string& body, | ||
| 120 | - const std::string& adr, int port = 80) const override; | ||
| 121 | - | ||
| 122 | - //! \brief Send a HTTP GET request to the specified host and return the body of the response parsed as JSON. | ||
| 123 | - //! | ||
| 124 | - //! \param uri Uniform Resource Identifier in the request | ||
| 125 | - //! \param body Request body, may be empty | ||
| 126 | - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 127 | - //! \param port Optional port the request is sent to, default is 80 | ||
| 128 | - //! \return Parsed body of the response of the host | ||
| 129 | - //! \throws std::system_error when system or socket operations fail | ||
| 130 | - //! \throws HueException when response contained no body | ||
| 131 | - //! \throws nlohmann::json::parse_error when the body could not be parsed | ||
| 132 | - nlohmann::json GETJson( | ||
| 133 | - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override; | ||
| 134 | - | ||
| 135 | - //! \brief Send a HTTP POST request to the specified host and return the body of the response parsed as JSON. | ||
| 136 | - //! | ||
| 137 | - //! \param uri Uniform Resource Identifier in the request | ||
| 138 | - //! \param body Request body, may be empty | ||
| 139 | - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 140 | - //! \param port Optional port the request is sent to, default is 80 | ||
| 141 | - //! \return Parsed body of the response of the host | ||
| 142 | - //! \throws std::system_error when system or socket operations fail | ||
| 143 | - //! \throws HueException when response contained no body | ||
| 144 | - //! \throws nlohmann::json::parse_error when the body could not be parsed | ||
| 145 | - nlohmann::json POSTJson( | ||
| 146 | - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override; | ||
| 147 | - | ||
| 148 | - //! \brief Send a HTTP PUT request to the specified host and return the body of the response parsed as JSON. | ||
| 149 | - //! | ||
| 150 | - //! \param uri Uniform Resource Identifier in the request | ||
| 151 | - //! \param body Request body, may be empty | ||
| 152 | - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 153 | - //! \param port Optional port the request is sent to, default is 80 | ||
| 154 | - //! \return Parsed body of the response of the host | ||
| 155 | - //! \throws std::system_error when system or socket operations fail | ||
| 156 | - //! \throws HueException when response contained no body | ||
| 157 | - //! \throws nlohmann::json::parse_error when the body could not be parsed | ||
| 158 | - nlohmann::json PUTJson( | ||
| 159 | - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override; | ||
| 160 | - | ||
| 161 | - //! \brief Send a HTTP DELETE request to the specified host and return the body of the response parsed as JSON. | ||
| 162 | - //! | ||
| 163 | - //! \param uri Uniform Resource Identifier in the request | ||
| 164 | - //! \param body Request body, may be empty | ||
| 165 | - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 166 | - //! \param port Optional port the request is sent to, default is 80 | ||
| 167 | - //! \return Parsed body of the response of the host | ||
| 168 | - //! \throws std::system_error when system or socket operations fail | ||
| 169 | - //! \throws HueException when response contained no body | ||
| 170 | - //! \throws nlohmann::json::parse_error when the body could not be parsed | ||
| 171 | - nlohmann::json DELETEJson( | ||
| 172 | - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override; | ||
| 173 | -}; | ||
| 174 | - | ||
| 175 | -#endif | 1 | +/** |
| 2 | + \file BaseHttpHandler.h | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2020 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2020 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#ifndef _BASE_HTTPHANDLER_H | ||
| 24 | +#define _BASE_HTTPHANDLER_H | ||
| 25 | + | ||
| 26 | +#include <iostream> | ||
| 27 | +#include <memory> | ||
| 28 | +#include <string> | ||
| 29 | +#include <vector> | ||
| 30 | + | ||
| 31 | +#include "IHttpHandler.h" | ||
| 32 | + | ||
| 33 | +#include "json/json.hpp" | ||
| 34 | + | ||
| 35 | +//! Base class for classes that handle http requests and multicast requests | ||
| 36 | +class BaseHttpHandler : public IHttpHandler | ||
| 37 | +{ | ||
| 38 | +public: | ||
| 39 | + //! \brief Virtual dtor | ||
| 40 | + virtual ~BaseHttpHandler() = default; | ||
| 41 | + | ||
| 42 | + //! \brief Send a message to a specified host and return the body of the response. | ||
| 43 | + //! | ||
| 44 | + //! \param msg The message that should sent to the specified address | ||
| 45 | + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 46 | + //! \param port Optional port the request is sent to, default is 80 | ||
| 47 | + //! \return The body of the response of the host as a string | ||
| 48 | + //! \throws std::system_error when system or socket operations fail | ||
| 49 | + //! \throws HueException when response contained no body | ||
| 50 | + std::string sendGetHTTPBody(const std::string& msg, const std::string& adr, int port = 80) const override; | ||
| 51 | + | ||
| 52 | + //! \brief Send a HTTP request with the given method to the specified host and return the body of the response. | ||
| 53 | + //! | ||
| 54 | + //! \param method HTTP method type e.g. GET, HEAD, POST, PUT, DELETE, ... | ||
| 55 | + //! \param uri Uniform Resource Identifier in the request | ||
| 56 | + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ... | ||
| 57 | + //! \param body Request body, may be empty | ||
| 58 | + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 59 | + //! \param port Optional port the request is sent to, default is 80 | ||
| 60 | + //! \return Body of the response of the host | ||
| 61 | + //! \throws std::system_error when system or socket operations fail | ||
| 62 | + //! \throws HueException when response contained no body | ||
| 63 | + std::string sendHTTPRequest(const std::string& method, const std::string& uri, const std::string& contentType, | ||
| 64 | + const std::string& body, const std::string& adr, int port = 80) const override; | ||
| 65 | + | ||
| 66 | + //! \brief Send a HTTP GET request to the specified host and return the body of the response. | ||
| 67 | + //! | ||
| 68 | + //! \param uri Uniform Resource Identifier in the request | ||
| 69 | + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ... | ||
| 70 | + //! \param body Request body, may be empty | ||
| 71 | + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 72 | + //! \param port Optional port the request is sent to, default is 80 | ||
| 73 | + //! that specifies the port to which the request is sent to. Default is 80 | ||
| 74 | + //! \return Body of the response of the host | ||
| 75 | + //! \throws std::system_error when system or socket operations fail | ||
| 76 | + //! \throws HueException when response contained no body | ||
| 77 | + std::string GETString(const std::string& uri, const std::string& contentType, const std::string& body, | ||
| 78 | + const std::string& adr, int port = 80) const override; | ||
| 79 | + | ||
| 80 | + //! \brief Send a HTTP POST request to the specified host and return the body of the response. | ||
| 81 | + //! | ||
| 82 | + //! \param uri Uniform Resource Identifier in the request | ||
| 83 | + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ... | ||
| 84 | + //! \param body Request body, may be empty | ||
| 85 | + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 86 | + //! \param port Optional port the request is sent to, default is 80 | ||
| 87 | + //! that specifies the port to which the request is sent to. Default is 80 | ||
| 88 | + //! \return Body of the response of the host | ||
| 89 | + //! \throws std::system_error when system or socket operations fail | ||
| 90 | + //! \throws HueException when response contained no body | ||
| 91 | + std::string POSTString(const std::string& uri, const std::string& contentType, const std::string& body, | ||
| 92 | + const std::string& adr, int port = 80) const override; | ||
| 93 | + | ||
| 94 | + //! \brief Send a HTTP PUT request to the specified host and return the body of the response. | ||
| 95 | + //! | ||
| 96 | + //! \param uri Uniform Resource Identifier in the request | ||
| 97 | + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ... | ||
| 98 | + //! \param body Request body, may be empty | ||
| 99 | + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 100 | + //! \param port Optional port the request is sent to, default is 80 | ||
| 101 | + //! that specifies the port to which the request is sent to. Default is 80 | ||
| 102 | + //! \return Body of the response of the host | ||
| 103 | + //! \throws std::system_error when system or socket operations fail | ||
| 104 | + //! \throws HueException when response contained no body | ||
| 105 | + std::string PUTString(const std::string& uri, const std::string& contentType, const std::string& body, | ||
| 106 | + const std::string& adr, int port = 80) const override; | ||
| 107 | + | ||
| 108 | + //! \brief Send a HTTP DELETE request to the specified host and return the body of the response. | ||
| 109 | + //! | ||
| 110 | + //! \param uri Uniform Resource Identifier in the request | ||
| 111 | + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ... | ||
| 112 | + //! \param body Request body, may be empty | ||
| 113 | + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 114 | + //! \param port Optional port the request is sent to, default is 80 | ||
| 115 | + //! that specifies the port to which the request is sent to. Default is 80 | ||
| 116 | + //! \return Body of the response of the host | ||
| 117 | + //! \throws std::system_error when system or socket operations fail | ||
| 118 | + //! \throws HueException when response contained no body | ||
| 119 | + std::string DELETEString(const std::string& uri, const std::string& contentType, const std::string& body, | ||
| 120 | + const std::string& adr, int port = 80) const override; | ||
| 121 | + | ||
| 122 | + //! \brief Send a HTTP GET request to the specified host and return the body of the response parsed as JSON. | ||
| 123 | + //! | ||
| 124 | + //! \param uri Uniform Resource Identifier in the request | ||
| 125 | + //! \param body Request body, may be empty | ||
| 126 | + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 127 | + //! \param port Optional port the request is sent to, default is 80 | ||
| 128 | + //! \return Parsed body of the response of the host | ||
| 129 | + //! \throws std::system_error when system or socket operations fail | ||
| 130 | + //! \throws HueException when response contained no body | ||
| 131 | + //! \throws nlohmann::json::parse_error when the body could not be parsed | ||
| 132 | + nlohmann::json GETJson( | ||
| 133 | + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override; | ||
| 134 | + | ||
| 135 | + //! \brief Send a HTTP POST request to the specified host and return the body of the response parsed as JSON. | ||
| 136 | + //! | ||
| 137 | + //! \param uri Uniform Resource Identifier in the request | ||
| 138 | + //! \param body Request body, may be empty | ||
| 139 | + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 140 | + //! \param port Optional port the request is sent to, default is 80 | ||
| 141 | + //! \return Parsed body of the response of the host | ||
| 142 | + //! \throws std::system_error when system or socket operations fail | ||
| 143 | + //! \throws HueException when response contained no body | ||
| 144 | + //! \throws nlohmann::json::parse_error when the body could not be parsed | ||
| 145 | + nlohmann::json POSTJson( | ||
| 146 | + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override; | ||
| 147 | + | ||
| 148 | + //! \brief Send a HTTP PUT request to the specified host and return the body of the response parsed as JSON. | ||
| 149 | + //! | ||
| 150 | + //! \param uri Uniform Resource Identifier in the request | ||
| 151 | + //! \param body Request body, may be empty | ||
| 152 | + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 153 | + //! \param port Optional port the request is sent to, default is 80 | ||
| 154 | + //! \return Parsed body of the response of the host | ||
| 155 | + //! \throws std::system_error when system or socket operations fail | ||
| 156 | + //! \throws HueException when response contained no body | ||
| 157 | + //! \throws nlohmann::json::parse_error when the body could not be parsed | ||
| 158 | + nlohmann::json PUTJson( | ||
| 159 | + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override; | ||
| 160 | + | ||
| 161 | + //! \brief Send a HTTP DELETE request to the specified host and return the body of the response parsed as JSON. | ||
| 162 | + //! | ||
| 163 | + //! \param uri Uniform Resource Identifier in the request | ||
| 164 | + //! \param body Request body, may be empty | ||
| 165 | + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1" | ||
| 166 | + //! \param port Optional port the request is sent to, default is 80 | ||
| 167 | + //! \return Parsed body of the response of the host | ||
| 168 | + //! \throws std::system_error when system or socket operations fail | ||
| 169 | + //! \throws HueException when response contained no body | ||
| 170 | + //! \throws nlohmann::json::parse_error when the body could not be parsed | ||
| 171 | + nlohmann::json DELETEJson( | ||
| 172 | + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override; | ||
| 173 | +}; | ||
| 174 | + | ||
| 175 | +#endif |
hueplusplus/include/BrightnessStrategy.h renamed to include/hueplusplus/BrightnessStrategy.h
100755 → 100644
hueplusplus/include/ColorHueStrategy.h renamed to include/hueplusplus/ColorHueStrategy.h
100755 → 100644
hueplusplus/include/ColorTemperatureStrategy.h renamed to include/hueplusplus/ColorTemperatureStrategy.h
100755 → 100644
hueplusplus/include/ExtendedColorHueStrategy.h renamed to include/hueplusplus/ExtendedColorHueStrategy.h
100755 → 100644
hueplusplus/include/ExtendedColorTemperatureStrategy.h renamed to include/hueplusplus/ExtendedColorTemperatureStrategy.h
100755 → 100644
hueplusplus/include/Hue.h renamed to include/hueplusplus/Hue.h
hueplusplus/include/HueCommandAPI.h renamed to include/hueplusplus/HueCommandAPI.h
hueplusplus/include/HueConfig.h renamed to include/hueplusplus/HueConfig.h
100755 → 100644
hueplusplus/include/HueException.h renamed to include/hueplusplus/HueException.h
hueplusplus/include/HueExceptionMacro.h renamed to include/hueplusplus/HueExceptionMacro.h
hueplusplus/include/HueLight.h renamed to include/hueplusplus/HueLight.h
hueplusplus/include/IHttpHandler.h renamed to include/hueplusplus/IHttpHandler.h
100755 → 100644
hueplusplus/include/LinHttpHandler.h renamed to include/hueplusplus/LinHttpHandler.h
100755 → 100644
hueplusplus/include/SimpleBrightnessStrategy.h renamed to include/hueplusplus/SimpleBrightnessStrategy.h
100755 → 100644
hueplusplus/include/SimpleColorHueStrategy.h renamed to include/hueplusplus/SimpleColorHueStrategy.h
100755 → 100644
hueplusplus/include/SimpleColorTemperatureStrategy.h renamed to include/hueplusplus/SimpleColorTemperatureStrategy.h
100755 → 100644
hueplusplus/include/UPnP.h renamed to include/hueplusplus/UPnP.h
100755 → 100644
hueplusplus/include/Units.h renamed to include/hueplusplus/Units.h
hueplusplus/include/Utils.h renamed to include/hueplusplus/Utils.h
hueplusplus/include/WinHttpHandler.h renamed to include/hueplusplus/WinHttpHandler.h
hueplusplus/include/json/json.hpp renamed to include/json/json.hpp
hueplusplus/BaseHttpHandler.cpp renamed to src/BaseHttpHandler.cpp
hueplusplus/CMakeLists.txt renamed to src/CMakeLists.txt
100755 → 100644
| @@ -36,21 +36,11 @@ if(ESP_PLATFORM) | @@ -36,21 +36,11 @@ if(ESP_PLATFORM) | ||
| 36 | ) | 36 | ) |
| 37 | endif() | 37 | endif() |
| 38 | 38 | ||
| 39 | - | ||
| 40 | -# Set global includes BEFORE adding any targets for legacy CMake versions | ||
| 41 | -if(CMAKE_VERSION VERSION_LESS 2.8.12) | ||
| 42 | - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") | ||
| 43 | - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/json") | ||
| 44 | -endif() | ||
| 45 | - | ||
| 46 | - | ||
| 47 | # hueplusplus shared library | 39 | # hueplusplus shared library |
| 48 | add_library(hueplusplusshared SHARED ${hueplusplus_SOURCES}) | 40 | add_library(hueplusplusshared SHARED ${hueplusplus_SOURCES}) |
| 49 | set_property(TARGET hueplusplusshared PROPERTY CXX_STANDARD 14) | 41 | set_property(TARGET hueplusplusshared PROPERTY CXX_STANDARD 14) |
| 50 | set_property(TARGET hueplusplusshared PROPERTY CXX_EXTENSIONS OFF) | 42 | set_property(TARGET hueplusplusshared PROPERTY CXX_EXTENSIONS OFF) |
| 51 | -if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) | ||
| 52 | - target_include_directories(hueplusplusshared PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") | ||
| 53 | -endif() | 43 | +target_include_directories(hueplusplusshared PUBLIC $<BUILD_INTERFACE:"${CMAKE_CURRENT_SOURCE_DIR}/include"> $<INSTALL_INTERFACE:include/hueplusplus>) |
| 54 | install(TARGETS hueplusplusshared DESTINATION lib) | 44 | install(TARGETS hueplusplusshared DESTINATION lib) |
| 55 | 45 | ||
| 56 | # hueplusplus static library | 46 | # hueplusplus static library |
| @@ -58,9 +48,7 @@ add_library(hueplusplusstatic STATIC ${hueplusplus_SOURCES}) | @@ -58,9 +48,7 @@ add_library(hueplusplusstatic STATIC ${hueplusplus_SOURCES}) | ||
| 58 | set_property(TARGET hueplusplusstatic PROPERTY CXX_STANDARD 14) | 48 | set_property(TARGET hueplusplusstatic PROPERTY CXX_STANDARD 14) |
| 59 | set_property(TARGET hueplusplusstatic PROPERTY CXX_EXTENSIONS OFF) | 49 | set_property(TARGET hueplusplusstatic PROPERTY CXX_EXTENSIONS OFF) |
| 60 | install(TARGETS hueplusplusstatic DESTINATION lib) | 50 | install(TARGETS hueplusplusstatic DESTINATION lib) |
| 61 | -if (NOT CMAKE_VERSION VERSION_LESS 2.8.12) | ||
| 62 | - target_include_directories(hueplusplusstatic PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") | ||
| 63 | -endif() | 51 | +target_include_directories(hueplusplusstatic PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") |
| 64 | install(FILES ${hueplusplus_HEADERS} DESTINATION include/hueplusplus) | 52 | install(FILES ${hueplusplus_HEADERS} DESTINATION include/hueplusplus) |
| 65 | 53 | ||
| 66 | # Export the package for use from the build-tree | 54 | # Export the package for use from the build-tree |
hueplusplus/ExtendedColorHueStrategy.cpp renamed to src/ExtendedColorHueStrategy.cpp
100755 → 100644
hueplusplus/ExtendedColorTemperatureStrategy.cpp renamed to src/ExtendedColorTemperatureStrategy.cpp
hueplusplus/Hue.cpp renamed to src/Hue.cpp
hueplusplus/HueCommandAPI.cpp renamed to src/HueCommandAPI.cpp
hueplusplus/HueException.cpp renamed to src/HueException.cpp
hueplusplus/HueLight.cpp renamed to src/HueLight.cpp
hueplusplus/LinHttpHandler.cpp renamed to src/LinHttpHandler.cpp
100755 → 100644
hueplusplus/SimpleBrightnessStrategy.cpp renamed to src/SimpleBrightnessStrategy.cpp
hueplusplus/SimpleColorHueStrategy.cpp renamed to src/SimpleColorHueStrategy.cpp
hueplusplus/SimpleColorTemperatureStrategy.cpp renamed to src/SimpleColorTemperatureStrategy.cpp
hueplusplus/UPnP.cpp renamed to src/UPnP.cpp
100755 → 100644
hueplusplus/Utils.cpp renamed to src/Utils.cpp
hueplusplus/WinHttpHandler.cpp renamed to src/WinHttpHandler.cpp
100755 → 100644
hueplusplus/test/CMakeLists.txt renamed to src/test/CMakeLists.txt
100755 → 100644
| 1 | -# Set cmake cxx standard to 14 | ||
| 2 | -set(CMAKE_CXX_STANDARD 14) | ||
| 3 | - | ||
| 4 | -# Download and unpack googletest at configure time | ||
| 5 | -configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) | ||
| 6 | -execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} . | ||
| 7 | - RESULT_VARIABLE result | ||
| 8 | - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" | ||
| 9 | -) | ||
| 10 | -if(result) | ||
| 11 | - message(FATAL_ERROR "CMake step for googletest failed: ${result}") | ||
| 12 | -endif() | ||
| 13 | -execute_process(COMMAND "${CMAKE_COMMAND}" --build . | ||
| 14 | - RESULT_VARIABLE result | ||
| 15 | - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" | ||
| 16 | -) | ||
| 17 | -if(result) | ||
| 18 | - message(FATAL_ERROR "Build step for googletest failed: ${result}") | ||
| 19 | -endif() | ||
| 20 | - | ||
| 21 | -# Prevent overriding the parent project's compiler/linker | ||
| 22 | -# settings on Windows | ||
| 23 | -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
| 24 | - | ||
| 25 | -# Add googletest directly to our build. This defines | ||
| 26 | -# the gtest and gtest_main targets. | ||
| 27 | -add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src EXCLUDE_FROM_ALL | ||
| 28 | - ${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL | ||
| 29 | -) | ||
| 30 | - | ||
| 31 | -# The gtest/gtest_main targets carry header search path | ||
| 32 | -# dependencies automatically when using CMake 2.8.11 or | ||
| 33 | -# later. Otherwise we have to add them here ourselves. | ||
| 34 | -if (CMAKE_VERSION VERSION_LESS 2.8.11) | ||
| 35 | - include_directories("${gtest_SOURCE_DIR}/include" EXCLUDE_FROM_ALL) | ||
| 36 | -endif() | ||
| 37 | - | ||
| 38 | -# define all test sources | ||
| 39 | -set(TEST_SOURCES | ||
| 40 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_BaseHttpHandler.cpp | ||
| 41 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_ExtendedColorHueStrategy.cpp | ||
| 42 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_ExtendedColorTemperatureStrategy.cpp | ||
| 43 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_Hue.cpp | ||
| 44 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_HueLight.cpp | ||
| 45 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_HueCommandAPI.cpp | ||
| 46 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_Main.cpp | ||
| 47 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleBrightnessStrategy.cpp | ||
| 48 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleColorHueStrategy.cpp | ||
| 49 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleColorTemperatureStrategy.cpp | ||
| 50 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_UPnP.cpp | ||
| 51 | -) | ||
| 52 | - | ||
| 53 | -# test executable | ||
| 54 | -add_executable(test_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES}) | ||
| 55 | -target_link_libraries(test_HuePlusPlus gtest gmock) | ||
| 56 | -target_include_directories(test_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS}) | ||
| 57 | -target_include_directories(test_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR}) | ||
| 58 | -set_property(TARGET test_HuePlusPlus PROPERTY CXX_STANDARD 14) | ||
| 59 | -set_property(TARGET test_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF) | ||
| 60 | -set_property(TARGET gmock PROPERTY CXX_STANDARD 14) | ||
| 61 | -set_property(TARGET gtest PROPERTY CXX_STANDARD 14) | ||
| 62 | -# add custom target to make it simple to run the tests | ||
| 63 | -add_custom_target("unittest" | ||
| 64 | - # Run the executable | ||
| 65 | - COMMAND test_HuePlusPlus | ||
| 66 | - # Depends on test_HuePlusPlus | ||
| 67 | - DEPENDS test_HuePlusPlus | ||
| 68 | -) | ||
| 69 | - | ||
| 70 | -# Check for coverage test prerequisites | ||
| 71 | -find_program( GCOV_PATH gcov ) | ||
| 72 | -find_program( LCOV_PATH lcov ) | ||
| 73 | - | ||
| 74 | -if(LCOV_PATH AND GCOV_PATH) | ||
| 75 | - # GCov | ||
| 76 | - include(CodeCoverage.cmake) | ||
| 77 | - add_executable(testcov_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES}) | ||
| 78 | - target_link_libraries(testcov_HuePlusPlus gtest gmock) | ||
| 79 | - # prevent Main.cpp from defining main() | ||
| 80 | - target_compile_definitions(testcov_HuePlusPlus PUBLIC MAIN_CPP_NO_MAIN_FUNCTION) | ||
| 81 | - target_include_directories(testcov_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS}) | ||
| 82 | - target_include_directories(testcov_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR}) | ||
| 83 | - set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_STANDARD 14) | ||
| 84 | - set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF) | ||
| 85 | - # this will be already done by APPEND_COVERAGE_COMPILER_FLAGS() | ||
| 86 | - #set_target_properties( | ||
| 87 | - # testcov_HuePlusPlus PROPERTIES | ||
| 88 | - # COMPILE_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage" | ||
| 89 | - #) | ||
| 90 | - # Normally this would be -lgcov, but on mac only -Lgcov works | ||
| 91 | - #set_target_properties( | ||
| 92 | - # testcov_HuePlusPlus PROPERTIES | ||
| 93 | - # LINK_FLAGS "-O0 -g -Lgcov -fprofile-arcs -ftest-coverage" | ||
| 94 | - #) | ||
| 95 | - # exclude some special files we do not want to profile | ||
| 96 | - set(COVERAGE_EXCLUDES | ||
| 97 | - '/usr/*' # unix | ||
| 98 | - '*/hueplusplus/build/*' | ||
| 99 | - '*/json*' | ||
| 100 | - '*/test/*' | ||
| 101 | - '*/v1/*' # iOS | ||
| 102 | - ) | ||
| 103 | - APPEND_COVERAGE_COMPILER_FLAGS() | ||
| 104 | - SETUP_TARGET_FOR_COVERAGE( | ||
| 105 | - NAME "coveragetest" | ||
| 106 | - EXECUTABLE testcov_HuePlusPlus | ||
| 107 | - DEPENDENCIES testcov_HuePlusPlus | ||
| 108 | - ) | ||
| 109 | -endif() | 1 | +# Set cmake cxx standard to 14 |
| 2 | +set(CMAKE_CXX_STANDARD 14) | ||
| 3 | + | ||
| 4 | +# Download and unpack googletest at configure time | ||
| 5 | +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) | ||
| 6 | +execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} . | ||
| 7 | + RESULT_VARIABLE result | ||
| 8 | + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" | ||
| 9 | +) | ||
| 10 | +if(result) | ||
| 11 | + message(FATAL_ERROR "CMake step for googletest failed: ${result}") | ||
| 12 | +endif() | ||
| 13 | +execute_process(COMMAND "${CMAKE_COMMAND}" --build . | ||
| 14 | + RESULT_VARIABLE result | ||
| 15 | + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" | ||
| 16 | +) | ||
| 17 | +if(result) | ||
| 18 | + message(FATAL_ERROR "Build step for googletest failed: ${result}") | ||
| 19 | +endif() | ||
| 20 | + | ||
| 21 | +# Prevent overriding the parent project's compiler/linker | ||
| 22 | +# settings on Windows | ||
| 23 | +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
| 24 | + | ||
| 25 | +# Add googletest directly to our build. This defines | ||
| 26 | +# the gtest and gtest_main targets. | ||
| 27 | +add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src EXCLUDE_FROM_ALL | ||
| 28 | + ${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL | ||
| 29 | +) | ||
| 30 | + | ||
| 31 | +# The gtest/gtest_main targets carry header search path | ||
| 32 | +# dependencies automatically when using CMake 2.8.11 or | ||
| 33 | +# later. Otherwise we have to add them here ourselves. | ||
| 34 | +if (CMAKE_VERSION VERSION_LESS 2.8.11) | ||
| 35 | + include_directories("${gtest_SOURCE_DIR}/include" EXCLUDE_FROM_ALL) | ||
| 36 | +endif() | ||
| 37 | + | ||
| 38 | +# define all test sources | ||
| 39 | +set(TEST_SOURCES | ||
| 40 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_BaseHttpHandler.cpp | ||
| 41 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_ExtendedColorHueStrategy.cpp | ||
| 42 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_ExtendedColorTemperatureStrategy.cpp | ||
| 43 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_Hue.cpp | ||
| 44 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_HueLight.cpp | ||
| 45 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_HueCommandAPI.cpp | ||
| 46 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_Main.cpp | ||
| 47 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleBrightnessStrategy.cpp | ||
| 48 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleColorHueStrategy.cpp | ||
| 49 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleColorTemperatureStrategy.cpp | ||
| 50 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_UPnP.cpp | ||
| 51 | +) | ||
| 52 | + | ||
| 53 | +# test executable | ||
| 54 | +add_executable(test_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES}) | ||
| 55 | +target_link_libraries(test_HuePlusPlus gtest gmock) | ||
| 56 | +target_include_directories(test_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS}) | ||
| 57 | +target_include_directories(test_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR}) | ||
| 58 | +set_property(TARGET test_HuePlusPlus PROPERTY CXX_STANDARD 14) | ||
| 59 | +set_property(TARGET test_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF) | ||
| 60 | +set_property(TARGET gmock PROPERTY CXX_STANDARD 14) | ||
| 61 | +set_property(TARGET gtest PROPERTY CXX_STANDARD 14) | ||
| 62 | +# add custom target to make it simple to run the tests | ||
| 63 | +add_custom_target("unittest" | ||
| 64 | + # Run the executable | ||
| 65 | + COMMAND test_HuePlusPlus | ||
| 66 | + # Depends on test_HuePlusPlus | ||
| 67 | + DEPENDS test_HuePlusPlus | ||
| 68 | +) | ||
| 69 | + | ||
| 70 | +# Check for coverage test prerequisites | ||
| 71 | +find_program( GCOV_PATH gcov ) | ||
| 72 | +find_program( LCOV_PATH lcov ) | ||
| 73 | + | ||
| 74 | +if(LCOV_PATH AND GCOV_PATH) | ||
| 75 | + # GCov | ||
| 76 | + include(CodeCoverage.cmake) | ||
| 77 | + add_executable(testcov_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES}) | ||
| 78 | + target_link_libraries(testcov_HuePlusPlus gtest gmock) | ||
| 79 | + # prevent Main.cpp from defining main() | ||
| 80 | + target_compile_definitions(testcov_HuePlusPlus PUBLIC MAIN_CPP_NO_MAIN_FUNCTION) | ||
| 81 | + target_include_directories(testcov_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS}) | ||
| 82 | + target_include_directories(testcov_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR}) | ||
| 83 | + set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_STANDARD 14) | ||
| 84 | + set_property(TARGET testcov_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF) | ||
| 85 | + # this will be already done by APPEND_COVERAGE_COMPILER_FLAGS() | ||
| 86 | + #set_target_properties( | ||
| 87 | + # testcov_HuePlusPlus PROPERTIES | ||
| 88 | + # COMPILE_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage" | ||
| 89 | + #) | ||
| 90 | + # Normally this would be -lgcov, but on mac only -Lgcov works | ||
| 91 | + #set_target_properties( | ||
| 92 | + # testcov_HuePlusPlus PROPERTIES | ||
| 93 | + # LINK_FLAGS "-O0 -g -Lgcov -fprofile-arcs -ftest-coverage" | ||
| 94 | + #) | ||
| 95 | + # exclude some special files we do not want to profile | ||
| 96 | + set(COVERAGE_EXCLUDES | ||
| 97 | + '/usr/*' # unix | ||
| 98 | + '*/hueplusplus/build/*' | ||
| 99 | + '*/json*' | ||
| 100 | + '*/test/*' | ||
| 101 | + '*/v1/*' # iOS | ||
| 102 | + ) | ||
| 103 | + APPEND_COVERAGE_COMPILER_FLAGS() | ||
| 104 | + SETUP_TARGET_FOR_COVERAGE( | ||
| 105 | + NAME "coveragetest" | ||
| 106 | + EXECUTABLE testcov_HuePlusPlus | ||
| 107 | + DEPENDENCIES testcov_HuePlusPlus | ||
| 108 | + ) | ||
| 109 | +endif() |
hueplusplus/test/CMakeLists.txt.in renamed to src/test/CMakeLists.txt.in
100755 → 100644
| 1 | -cmake_minimum_required(VERSION 2.8.2) | ||
| 2 | - | ||
| 3 | -project(googletest-download NONE) | ||
| 4 | - | ||
| 5 | -include(ExternalProject) | ||
| 6 | -ExternalProject_Add(googletest | ||
| 7 | - GIT_REPOSITORY https://github.com/google/googletest.git | ||
| 8 | - GIT_TAG master | ||
| 9 | - SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" | ||
| 10 | - BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" | ||
| 11 | - CONFIGURE_COMMAND "" | ||
| 12 | - BUILD_COMMAND "" | ||
| 13 | - INSTALL_COMMAND "" | ||
| 14 | - TEST_COMMAND "" | ||
| 15 | -) | 1 | +cmake_minimum_required(VERSION 2.8.2) |
| 2 | + | ||
| 3 | +project(googletest-download NONE) | ||
| 4 | + | ||
| 5 | +include(ExternalProject) | ||
| 6 | +ExternalProject_Add(googletest | ||
| 7 | + GIT_REPOSITORY https://github.com/google/googletest.git | ||
| 8 | + GIT_TAG master | ||
| 9 | + SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" | ||
| 10 | + BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" | ||
| 11 | + CONFIGURE_COMMAND "" | ||
| 12 | + BUILD_COMMAND "" | ||
| 13 | + INSTALL_COMMAND "" | ||
| 14 | + TEST_COMMAND "" | ||
| 15 | +) |
hueplusplus/test/CodeCoverage.cmake renamed to src/test/CodeCoverage.cmake
100755 → 100644
| 1 | -# Copyright (c) 2012 - 2017, Lars Bilke | ||
| 2 | -# All rights reserved. | ||
| 3 | -# | ||
| 4 | -# Redistribution and use in source and binary forms, with or without modification, | ||
| 5 | -# are permitted provided that the following conditions are met: | ||
| 6 | -# | ||
| 7 | -# 1. Redistributions of source code must retain the above copyright notice, this | ||
| 8 | -# list of conditions and the following disclaimer. | ||
| 9 | -# | ||
| 10 | -# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| 11 | -# this list of conditions and the following disclaimer in the documentation | ||
| 12 | -# and/or other materials provided with the distribution. | ||
| 13 | -# | ||
| 14 | -# 3. Neither the name of the copyright holder nor the names of its contributors | ||
| 15 | -# may be used to endorse or promote products derived from this software without | ||
| 16 | -# specific prior written permission. | ||
| 17 | -# | ||
| 18 | -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| 19 | -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| 20 | -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| 21 | -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
| 22 | -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| 23 | -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 24 | -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
| 25 | -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 26 | -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 27 | -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | -# | ||
| 29 | -# CHANGES: | ||
| 30 | -# | ||
| 31 | -# 2012-01-31, Lars Bilke | ||
| 32 | -# - Enable Code Coverage | ||
| 33 | -# | ||
| 34 | -# 2013-09-17, Joakim Söderberg | ||
| 35 | -# - Added support for Clang. | ||
| 36 | -# - Some additional usage instructions. | ||
| 37 | -# | ||
| 38 | -# 2016-02-03, Lars Bilke | ||
| 39 | -# - Refactored functions to use named parameters | ||
| 40 | -# | ||
| 41 | -# 2017-06-02, Lars Bilke | ||
| 42 | -# - Merged with modified version from github.com/ufz/ogs | ||
| 43 | -# | ||
| 44 | -# | ||
| 45 | -# USAGE: | ||
| 46 | -# | ||
| 47 | -# 1. Copy this file into your cmake modules path. | ||
| 48 | -# | ||
| 49 | -# 2. Add the following line to your CMakeLists.txt: | ||
| 50 | -# include(CodeCoverage) | ||
| 51 | -# | ||
| 52 | -# 3. Append necessary compiler flags: | ||
| 53 | -# APPEND_COVERAGE_COMPILER_FLAGS() | ||
| 54 | -# | ||
| 55 | -# 4. If you need to exclude additional directories from the report, specify them | ||
| 56 | -# using the COVERAGE_EXCLUDES variable before calling SETUP_TARGET_FOR_COVERAGE. | ||
| 57 | -# Example: | ||
| 58 | -# set(COVERAGE_EXCLUDES 'dir1/*' 'dir2/*') | ||
| 59 | -# | ||
| 60 | -# 5. Use the functions described below to create a custom make target which | ||
| 61 | -# runs your test executable and produces a code coverage report. | ||
| 62 | -# | ||
| 63 | -# 6. Build a Debug build: | ||
| 64 | -# cmake -DCMAKE_BUILD_TYPE=Debug .. | ||
| 65 | -# make | ||
| 66 | -# make my_coverage_target | ||
| 67 | -# | ||
| 68 | - | ||
| 69 | -include(CMakeParseArguments) | ||
| 70 | - | ||
| 71 | -# Check prereqs | ||
| 72 | -find_program( GCOV_PATH gcov ) | ||
| 73 | -find_program( LCOV_PATH lcov ) | ||
| 74 | -find_program( GENHTML_PATH genhtml ) | ||
| 75 | -find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test) | ||
| 76 | -find_program( SIMPLE_PYTHON_EXECUTABLE python ) | ||
| 77 | - | ||
| 78 | -if(NOT GCOV_PATH) | ||
| 79 | - message(FATAL_ERROR "gcov not found! Aborting...") | ||
| 80 | -endif() # NOT GCOV_PATH | ||
| 81 | - | ||
| 82 | -if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") | ||
| 83 | - if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3) | ||
| 84 | - message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") | ||
| 85 | - endif() | ||
| 86 | -elseif(NOT CMAKE_COMPILER_IS_GNUCXX) | ||
| 87 | - message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") | ||
| 88 | -endif() | ||
| 89 | - | ||
| 90 | -set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage" | ||
| 91 | - CACHE INTERNAL "") | ||
| 92 | - | ||
| 93 | -set(CMAKE_CXX_FLAGS_COVERAGE | ||
| 94 | - ${COVERAGE_COMPILER_FLAGS} | ||
| 95 | - CACHE STRING "Flags used by the C++ compiler during coverage builds." | ||
| 96 | - FORCE ) | ||
| 97 | -set(CMAKE_C_FLAGS_COVERAGE | ||
| 98 | - ${COVERAGE_COMPILER_FLAGS} | ||
| 99 | - CACHE STRING "Flags used by the C compiler during coverage builds." | ||
| 100 | - FORCE ) | ||
| 101 | -set(CMAKE_EXE_LINKER_FLAGS_COVERAGE | ||
| 102 | - "" | ||
| 103 | - CACHE STRING "Flags used for linking binaries during coverage builds." | ||
| 104 | - FORCE ) | ||
| 105 | -set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE | ||
| 106 | - "" | ||
| 107 | - CACHE STRING "Flags used by the shared libraries linker during coverage builds." | ||
| 108 | - FORCE ) | ||
| 109 | -mark_as_advanced( | ||
| 110 | - CMAKE_CXX_FLAGS_COVERAGE | ||
| 111 | - CMAKE_C_FLAGS_COVERAGE | ||
| 112 | - CMAKE_EXE_LINKER_FLAGS_COVERAGE | ||
| 113 | - CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) | ||
| 114 | - | ||
| 115 | -if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
| 116 | - message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") | ||
| 117 | -endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" | ||
| 118 | - | ||
| 119 | -if(CMAKE_C_COMPILER_ID STREQUAL "GNU") | ||
| 120 | - link_libraries(gcov) | ||
| 121 | -else() | ||
| 122 | - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") | ||
| 123 | -endif() | ||
| 124 | - | ||
| 125 | -# Defines a target for running and collection code coverage information | ||
| 126 | -# Builds dependencies, runs the given executable and outputs reports. | ||
| 127 | -# NOTE! The executable should always have a ZERO as exit code otherwise | ||
| 128 | -# the coverage generation will not complete. | ||
| 129 | -# | ||
| 130 | -# SETUP_TARGET_FOR_COVERAGE( | ||
| 131 | -# NAME testrunner_coverage # New target name | ||
| 132 | -# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR | ||
| 133 | -# DEPENDENCIES testrunner # Dependencies to build first | ||
| 134 | -# ) | ||
| 135 | -function(SETUP_TARGET_FOR_COVERAGE) | ||
| 136 | - | ||
| 137 | - set(options NONE) | ||
| 138 | - set(oneValueArgs NAME) | ||
| 139 | - set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) | ||
| 140 | - cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
| 141 | - | ||
| 142 | - if(NOT LCOV_PATH) | ||
| 143 | - message(FATAL_ERROR "lcov not found! Aborting...") | ||
| 144 | - endif() # NOT LCOV_PATH | ||
| 145 | - | ||
| 146 | - if(NOT GENHTML_PATH) | ||
| 147 | - message(FATAL_ERROR "genhtml not found! Aborting...") | ||
| 148 | - endif() # NOT GENHTML_PATH | ||
| 149 | - | ||
| 150 | - # Setup target | ||
| 151 | - add_custom_target(${Coverage_NAME} | ||
| 152 | - | ||
| 153 | - # Cleanup lcov | ||
| 154 | - COMMAND ${LCOV_PATH} --directory . --zerocounters | ||
| 155 | - | ||
| 156 | - # Run tests | ||
| 157 | - COMMAND ${Coverage_EXECUTABLE} | ||
| 158 | - | ||
| 159 | - # Capturing lcov counters and generating report | ||
| 160 | - COMMAND ${LCOV_PATH} --directory . --capture --output-file ${Coverage_NAME}.info | ||
| 161 | - COMMAND ${LCOV_PATH} --remove ${Coverage_NAME}.info ${COVERAGE_EXCLUDES} --output-file ${Coverage_NAME}.info.cleaned | ||
| 162 | - COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${Coverage_NAME}.info.cleaned | ||
| 163 | - COMMAND ${CMAKE_COMMAND} -E remove ${Coverage_NAME}.info ${Coverage_NAME}.info.cleaned | ||
| 164 | - | ||
| 165 | - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} | ||
| 166 | - DEPENDS ${Coverage_DEPENDENCIES} | ||
| 167 | - COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." | ||
| 168 | - ) | ||
| 169 | - | ||
| 170 | - # Show info where to find the report | ||
| 171 | - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD | ||
| 172 | - COMMAND ; | ||
| 173 | - COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report." | ||
| 174 | - ) | ||
| 175 | - | ||
| 176 | -endfunction() # SETUP_TARGET_FOR_COVERAGE | ||
| 177 | - | ||
| 178 | -# Defines a target for running and collection code coverage information | ||
| 179 | -# Builds dependencies, runs the given executable and outputs reports. | ||
| 180 | -# NOTE! The executable should always have a ZERO as exit code otherwise | ||
| 181 | -# the coverage generation will not complete. | ||
| 182 | -# | ||
| 183 | -# SETUP_TARGET_FOR_COVERAGE_COBERTURA( | ||
| 184 | -# NAME ctest_coverage # New target name | ||
| 185 | -# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR | ||
| 186 | -# DEPENDENCIES executable_target # Dependencies to build first | ||
| 187 | -# ) | ||
| 188 | -function(SETUP_TARGET_FOR_COVERAGE_COBERTURA) | ||
| 189 | - | ||
| 190 | - set(options NONE) | ||
| 191 | - set(oneValueArgs NAME) | ||
| 192 | - set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) | ||
| 193 | - cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
| 194 | - | ||
| 195 | - if(NOT SIMPLE_PYTHON_EXECUTABLE) | ||
| 196 | - message(FATAL_ERROR "python not found! Aborting...") | ||
| 197 | - endif() # NOT SIMPLE_PYTHON_EXECUTABLE | ||
| 198 | - | ||
| 199 | - if(NOT GCOVR_PATH) | ||
| 200 | - message(FATAL_ERROR "gcovr not found! Aborting...") | ||
| 201 | - endif() # NOT GCOVR_PATH | ||
| 202 | - | ||
| 203 | - # Combine excludes to several -e arguments | ||
| 204 | - set(COBERTURA_EXCLUDES "") | ||
| 205 | - foreach(EXCLUDE ${COVERAGE_EXCLUDES}) | ||
| 206 | - set(COBERTURA_EXCLUDES "-e ${EXCLUDE} ${COBERTURA_EXCLUDES}") | ||
| 207 | - endforeach() | ||
| 208 | - | ||
| 209 | - add_custom_target(${Coverage_NAME} | ||
| 210 | - | ||
| 211 | - # Run tests | ||
| 212 | - ${Coverage_EXECUTABLE} | ||
| 213 | - | ||
| 214 | - # Running gcovr | ||
| 215 | - COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} ${COBERTURA_EXCLUDES} | ||
| 216 | - -o ${Coverage_NAME}.xml | ||
| 217 | - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} | ||
| 218 | - DEPENDS ${Coverage_DEPENDENCIES} | ||
| 219 | - COMMENT "Running gcovr to produce Cobertura code coverage report." | ||
| 220 | - ) | ||
| 221 | - | ||
| 222 | - # Show info where to find the report | ||
| 223 | - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD | ||
| 224 | - COMMAND ; | ||
| 225 | - COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml." | ||
| 226 | - ) | ||
| 227 | - | ||
| 228 | -endfunction() # SETUP_TARGET_FOR_COVERAGE_COBERTURA | ||
| 229 | - | ||
| 230 | -function(APPEND_COVERAGE_COMPILER_FLAGS) | ||
| 231 | - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) | ||
| 232 | - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) | ||
| 233 | - message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}") | ||
| 234 | -endfunction() # APPEND_COVERAGE_COMPILER_FLAGS | 1 | +# Copyright (c) 2012 - 2017, Lars Bilke |
| 2 | +# All rights reserved. | ||
| 3 | +# | ||
| 4 | +# Redistribution and use in source and binary forms, with or without modification, | ||
| 5 | +# are permitted provided that the following conditions are met: | ||
| 6 | +# | ||
| 7 | +# 1. Redistributions of source code must retain the above copyright notice, this | ||
| 8 | +# list of conditions and the following disclaimer. | ||
| 9 | +# | ||
| 10 | +# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| 11 | +# this list of conditions and the following disclaimer in the documentation | ||
| 12 | +# and/or other materials provided with the distribution. | ||
| 13 | +# | ||
| 14 | +# 3. Neither the name of the copyright holder nor the names of its contributors | ||
| 15 | +# may be used to endorse or promote products derived from this software without | ||
| 16 | +# specific prior written permission. | ||
| 17 | +# | ||
| 18 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| 19 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| 20 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| 21 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
| 22 | +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| 23 | +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 24 | +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
| 25 | +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 26 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 27 | +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | +# | ||
| 29 | +# CHANGES: | ||
| 30 | +# | ||
| 31 | +# 2012-01-31, Lars Bilke | ||
| 32 | +# - Enable Code Coverage | ||
| 33 | +# | ||
| 34 | +# 2013-09-17, Joakim Söderberg | ||
| 35 | +# - Added support for Clang. | ||
| 36 | +# - Some additional usage instructions. | ||
| 37 | +# | ||
| 38 | +# 2016-02-03, Lars Bilke | ||
| 39 | +# - Refactored functions to use named parameters | ||
| 40 | +# | ||
| 41 | +# 2017-06-02, Lars Bilke | ||
| 42 | +# - Merged with modified version from github.com/ufz/ogs | ||
| 43 | +# | ||
| 44 | +# | ||
| 45 | +# USAGE: | ||
| 46 | +# | ||
| 47 | +# 1. Copy this file into your cmake modules path. | ||
| 48 | +# | ||
| 49 | +# 2. Add the following line to your CMakeLists.txt: | ||
| 50 | +# include(CodeCoverage) | ||
| 51 | +# | ||
| 52 | +# 3. Append necessary compiler flags: | ||
| 53 | +# APPEND_COVERAGE_COMPILER_FLAGS() | ||
| 54 | +# | ||
| 55 | +# 4. If you need to exclude additional directories from the report, specify them | ||
| 56 | +# using the COVERAGE_EXCLUDES variable before calling SETUP_TARGET_FOR_COVERAGE. | ||
| 57 | +# Example: | ||
| 58 | +# set(COVERAGE_EXCLUDES 'dir1/*' 'dir2/*') | ||
| 59 | +# | ||
| 60 | +# 5. Use the functions described below to create a custom make target which | ||
| 61 | +# runs your test executable and produces a code coverage report. | ||
| 62 | +# | ||
| 63 | +# 6. Build a Debug build: | ||
| 64 | +# cmake -DCMAKE_BUILD_TYPE=Debug .. | ||
| 65 | +# make | ||
| 66 | +# make my_coverage_target | ||
| 67 | +# | ||
| 68 | + | ||
| 69 | +include(CMakeParseArguments) | ||
| 70 | + | ||
| 71 | +# Check prereqs | ||
| 72 | +find_program( GCOV_PATH gcov ) | ||
| 73 | +find_program( LCOV_PATH lcov ) | ||
| 74 | +find_program( GENHTML_PATH genhtml ) | ||
| 75 | +find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test) | ||
| 76 | +find_program( SIMPLE_PYTHON_EXECUTABLE python ) | ||
| 77 | + | ||
| 78 | +if(NOT GCOV_PATH) | ||
| 79 | + message(FATAL_ERROR "gcov not found! Aborting...") | ||
| 80 | +endif() # NOT GCOV_PATH | ||
| 81 | + | ||
| 82 | +if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") | ||
| 83 | + if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3) | ||
| 84 | + message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") | ||
| 85 | + endif() | ||
| 86 | +elseif(NOT CMAKE_COMPILER_IS_GNUCXX) | ||
| 87 | + message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") | ||
| 88 | +endif() | ||
| 89 | + | ||
| 90 | +set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage" | ||
| 91 | + CACHE INTERNAL "") | ||
| 92 | + | ||
| 93 | +set(CMAKE_CXX_FLAGS_COVERAGE | ||
| 94 | + ${COVERAGE_COMPILER_FLAGS} | ||
| 95 | + CACHE STRING "Flags used by the C++ compiler during coverage builds." | ||
| 96 | + FORCE ) | ||
| 97 | +set(CMAKE_C_FLAGS_COVERAGE | ||
| 98 | + ${COVERAGE_COMPILER_FLAGS} | ||
| 99 | + CACHE STRING "Flags used by the C compiler during coverage builds." | ||
| 100 | + FORCE ) | ||
| 101 | +set(CMAKE_EXE_LINKER_FLAGS_COVERAGE | ||
| 102 | + "" | ||
| 103 | + CACHE STRING "Flags used for linking binaries during coverage builds." | ||
| 104 | + FORCE ) | ||
| 105 | +set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE | ||
| 106 | + "" | ||
| 107 | + CACHE STRING "Flags used by the shared libraries linker during coverage builds." | ||
| 108 | + FORCE ) | ||
| 109 | +mark_as_advanced( | ||
| 110 | + CMAKE_CXX_FLAGS_COVERAGE | ||
| 111 | + CMAKE_C_FLAGS_COVERAGE | ||
| 112 | + CMAKE_EXE_LINKER_FLAGS_COVERAGE | ||
| 113 | + CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) | ||
| 114 | + | ||
| 115 | +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
| 116 | + message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") | ||
| 117 | +endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" | ||
| 118 | + | ||
| 119 | +if(CMAKE_C_COMPILER_ID STREQUAL "GNU") | ||
| 120 | + link_libraries(gcov) | ||
| 121 | +else() | ||
| 122 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") | ||
| 123 | +endif() | ||
| 124 | + | ||
| 125 | +# Defines a target for running and collection code coverage information | ||
| 126 | +# Builds dependencies, runs the given executable and outputs reports. | ||
| 127 | +# NOTE! The executable should always have a ZERO as exit code otherwise | ||
| 128 | +# the coverage generation will not complete. | ||
| 129 | +# | ||
| 130 | +# SETUP_TARGET_FOR_COVERAGE( | ||
| 131 | +# NAME testrunner_coverage # New target name | ||
| 132 | +# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR | ||
| 133 | +# DEPENDENCIES testrunner # Dependencies to build first | ||
| 134 | +# ) | ||
| 135 | +function(SETUP_TARGET_FOR_COVERAGE) | ||
| 136 | + | ||
| 137 | + set(options NONE) | ||
| 138 | + set(oneValueArgs NAME) | ||
| 139 | + set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) | ||
| 140 | + cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
| 141 | + | ||
| 142 | + if(NOT LCOV_PATH) | ||
| 143 | + message(FATAL_ERROR "lcov not found! Aborting...") | ||
| 144 | + endif() # NOT LCOV_PATH | ||
| 145 | + | ||
| 146 | + if(NOT GENHTML_PATH) | ||
| 147 | + message(FATAL_ERROR "genhtml not found! Aborting...") | ||
| 148 | + endif() # NOT GENHTML_PATH | ||
| 149 | + | ||
| 150 | + # Setup target | ||
| 151 | + add_custom_target(${Coverage_NAME} | ||
| 152 | + | ||
| 153 | + # Cleanup lcov | ||
| 154 | + COMMAND ${LCOV_PATH} --directory . --zerocounters | ||
| 155 | + | ||
| 156 | + # Run tests | ||
| 157 | + COMMAND ${Coverage_EXECUTABLE} | ||
| 158 | + | ||
| 159 | + # Capturing lcov counters and generating report | ||
| 160 | + COMMAND ${LCOV_PATH} --directory . --capture --output-file ${Coverage_NAME}.info | ||
| 161 | + COMMAND ${LCOV_PATH} --remove ${Coverage_NAME}.info ${COVERAGE_EXCLUDES} --output-file ${Coverage_NAME}.info.cleaned | ||
| 162 | + COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${Coverage_NAME}.info.cleaned | ||
| 163 | + COMMAND ${CMAKE_COMMAND} -E remove ${Coverage_NAME}.info ${Coverage_NAME}.info.cleaned | ||
| 164 | + | ||
| 165 | + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} | ||
| 166 | + DEPENDS ${Coverage_DEPENDENCIES} | ||
| 167 | + COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." | ||
| 168 | + ) | ||
| 169 | + | ||
| 170 | + # Show info where to find the report | ||
| 171 | + add_custom_command(TARGET ${Coverage_NAME} POST_BUILD | ||
| 172 | + COMMAND ; | ||
| 173 | + COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report." | ||
| 174 | + ) | ||
| 175 | + | ||
| 176 | +endfunction() # SETUP_TARGET_FOR_COVERAGE | ||
| 177 | + | ||
| 178 | +# Defines a target for running and collection code coverage information | ||
| 179 | +# Builds dependencies, runs the given executable and outputs reports. | ||
| 180 | +# NOTE! The executable should always have a ZERO as exit code otherwise | ||
| 181 | +# the coverage generation will not complete. | ||
| 182 | +# | ||
| 183 | +# SETUP_TARGET_FOR_COVERAGE_COBERTURA( | ||
| 184 | +# NAME ctest_coverage # New target name | ||
| 185 | +# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR | ||
| 186 | +# DEPENDENCIES executable_target # Dependencies to build first | ||
| 187 | +# ) | ||
| 188 | +function(SETUP_TARGET_FOR_COVERAGE_COBERTURA) | ||
| 189 | + | ||
| 190 | + set(options NONE) | ||
| 191 | + set(oneValueArgs NAME) | ||
| 192 | + set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) | ||
| 193 | + cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
| 194 | + | ||
| 195 | + if(NOT SIMPLE_PYTHON_EXECUTABLE) | ||
| 196 | + message(FATAL_ERROR "python not found! Aborting...") | ||
| 197 | + endif() # NOT SIMPLE_PYTHON_EXECUTABLE | ||
| 198 | + | ||
| 199 | + if(NOT GCOVR_PATH) | ||
| 200 | + message(FATAL_ERROR "gcovr not found! Aborting...") | ||
| 201 | + endif() # NOT GCOVR_PATH | ||
| 202 | + | ||
| 203 | + # Combine excludes to several -e arguments | ||
| 204 | + set(COBERTURA_EXCLUDES "") | ||
| 205 | + foreach(EXCLUDE ${COVERAGE_EXCLUDES}) | ||
| 206 | + set(COBERTURA_EXCLUDES "-e ${EXCLUDE} ${COBERTURA_EXCLUDES}") | ||
| 207 | + endforeach() | ||
| 208 | + | ||
| 209 | + add_custom_target(${Coverage_NAME} | ||
| 210 | + | ||
| 211 | + # Run tests | ||
| 212 | + ${Coverage_EXECUTABLE} | ||
| 213 | + | ||
| 214 | + # Running gcovr | ||
| 215 | + COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} ${COBERTURA_EXCLUDES} | ||
| 216 | + -o ${Coverage_NAME}.xml | ||
| 217 | + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} | ||
| 218 | + DEPENDS ${Coverage_DEPENDENCIES} | ||
| 219 | + COMMENT "Running gcovr to produce Cobertura code coverage report." | ||
| 220 | + ) | ||
| 221 | + | ||
| 222 | + # Show info where to find the report | ||
| 223 | + add_custom_command(TARGET ${Coverage_NAME} POST_BUILD | ||
| 224 | + COMMAND ; | ||
| 225 | + COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml." | ||
| 226 | + ) | ||
| 227 | + | ||
| 228 | +endfunction() # SETUP_TARGET_FOR_COVERAGE_COBERTURA | ||
| 229 | + | ||
| 230 | +function(APPEND_COVERAGE_COMPILER_FLAGS) | ||
| 231 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) | ||
| 232 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) | ||
| 233 | + message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}") | ||
| 234 | +endfunction() # APPEND_COVERAGE_COMPILER_FLAGS |
hueplusplus/test/mocks/mock_BaseHttpHandler.h renamed to src/test/mocks/mock_BaseHttpHandler.h
100755 → 100644
hueplusplus/test/mocks/mock_HttpHandler.h renamed to src/test/mocks/mock_HttpHandler.h
100755 → 100644
| 1 | -/** | ||
| 2 | - \file mock_HttpHandler.h | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#ifndef _MOCK_HTTPHANDLER_H | ||
| 24 | -#define _MOCK_HTTPHANDLER_H | ||
| 25 | - | ||
| 26 | -#include <string> | ||
| 27 | -#include <vector> | ||
| 28 | - | ||
| 29 | -#include <gmock/gmock.h> | ||
| 30 | - | ||
| 31 | -#include "../hueplusplus/include/IHttpHandler.h" | ||
| 32 | -#include "../hueplusplus/include/json/json.hpp" | ||
| 33 | - | ||
| 34 | -//! Mock Class | ||
| 35 | -class MockHttpHandler : public IHttpHandler | ||
| 36 | -{ | ||
| 37 | -public: | ||
| 38 | - MOCK_CONST_METHOD3(send, std::string(const std::string& msg, const std::string& adr, int port)); | ||
| 39 | - | ||
| 40 | - MOCK_CONST_METHOD3(sendGetHTTPBody, std::string(const std::string& msg, const std::string& adr, int port)); | ||
| 41 | - | ||
| 42 | - MOCK_CONST_METHOD4( | ||
| 43 | - sendMulticast, std::vector<std::string>(const std::string& msg, const std::string& adr, int port, int timeout)); | ||
| 44 | - | ||
| 45 | - MOCK_CONST_METHOD6(sendHTTPRequest, | ||
| 46 | - std::string(const std::string& method, const std::string& uri, const std::string& content_type, | ||
| 47 | - const std::string& body, const std::string& adr, int port)); | ||
| 48 | - | ||
| 49 | - MOCK_CONST_METHOD5(GETString, | ||
| 50 | - std::string(const std::string& uri, const std::string& content_type, const std::string& body, | ||
| 51 | - const std::string& adr, int port)); | ||
| 52 | - | ||
| 53 | - MOCK_CONST_METHOD5(POSTString, | ||
| 54 | - std::string(const std::string& uri, const std::string& content_type, const std::string& body, | ||
| 55 | - const std::string& adr, int port)); | ||
| 56 | - | ||
| 57 | - MOCK_CONST_METHOD5(PUTString, | ||
| 58 | - std::string(const std::string& uri, const std::string& content_type, const std::string& body, | ||
| 59 | - const std::string& adr, int port)); | ||
| 60 | - | ||
| 61 | - MOCK_CONST_METHOD5(DELETEString, | ||
| 62 | - std::string(const std::string& uri, const std::string& content_type, const std::string& body, | ||
| 63 | - const std::string& adr, int port)); | ||
| 64 | - | ||
| 65 | - MOCK_CONST_METHOD4( | ||
| 66 | - GETJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port)); | ||
| 67 | - | ||
| 68 | - MOCK_CONST_METHOD4( | ||
| 69 | - POSTJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port)); | ||
| 70 | - | ||
| 71 | - MOCK_CONST_METHOD4( | ||
| 72 | - PUTJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port)); | ||
| 73 | - | ||
| 74 | - MOCK_CONST_METHOD4(DELETEJson, | ||
| 75 | - nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port)); | ||
| 76 | -}; | ||
| 77 | - | ||
| 78 | -#endif | 1 | +/** |
| 2 | + \file mock_HttpHandler.h | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#ifndef _MOCK_HTTPHANDLER_H | ||
| 24 | +#define _MOCK_HTTPHANDLER_H | ||
| 25 | + | ||
| 26 | +#include <string> | ||
| 27 | +#include <vector> | ||
| 28 | + | ||
| 29 | +#include <gmock/gmock.h> | ||
| 30 | + | ||
| 31 | +#include "../hueplusplus/include/IHttpHandler.h" | ||
| 32 | +#include "../hueplusplus/include/json/json.hpp" | ||
| 33 | + | ||
| 34 | +//! Mock Class | ||
| 35 | +class MockHttpHandler : public IHttpHandler | ||
| 36 | +{ | ||
| 37 | +public: | ||
| 38 | + MOCK_CONST_METHOD3(send, std::string(const std::string& msg, const std::string& adr, int port)); | ||
| 39 | + | ||
| 40 | + MOCK_CONST_METHOD3(sendGetHTTPBody, std::string(const std::string& msg, const std::string& adr, int port)); | ||
| 41 | + | ||
| 42 | + MOCK_CONST_METHOD4( | ||
| 43 | + sendMulticast, std::vector<std::string>(const std::string& msg, const std::string& adr, int port, int timeout)); | ||
| 44 | + | ||
| 45 | + MOCK_CONST_METHOD6(sendHTTPRequest, | ||
| 46 | + std::string(const std::string& method, const std::string& uri, const std::string& content_type, | ||
| 47 | + const std::string& body, const std::string& adr, int port)); | ||
| 48 | + | ||
| 49 | + MOCK_CONST_METHOD5(GETString, | ||
| 50 | + std::string(const std::string& uri, const std::string& content_type, const std::string& body, | ||
| 51 | + const std::string& adr, int port)); | ||
| 52 | + | ||
| 53 | + MOCK_CONST_METHOD5(POSTString, | ||
| 54 | + std::string(const std::string& uri, const std::string& content_type, const std::string& body, | ||
| 55 | + const std::string& adr, int port)); | ||
| 56 | + | ||
| 57 | + MOCK_CONST_METHOD5(PUTString, | ||
| 58 | + std::string(const std::string& uri, const std::string& content_type, const std::string& body, | ||
| 59 | + const std::string& adr, int port)); | ||
| 60 | + | ||
| 61 | + MOCK_CONST_METHOD5(DELETEString, | ||
| 62 | + std::string(const std::string& uri, const std::string& content_type, const std::string& body, | ||
| 63 | + const std::string& adr, int port)); | ||
| 64 | + | ||
| 65 | + MOCK_CONST_METHOD4( | ||
| 66 | + GETJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port)); | ||
| 67 | + | ||
| 68 | + MOCK_CONST_METHOD4( | ||
| 69 | + POSTJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port)); | ||
| 70 | + | ||
| 71 | + MOCK_CONST_METHOD4( | ||
| 72 | + PUTJson, nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port)); | ||
| 73 | + | ||
| 74 | + MOCK_CONST_METHOD4(DELETEJson, | ||
| 75 | + nlohmann::json(const std::string& uri, const nlohmann::json& body, const std::string& adr, int port)); | ||
| 76 | +}; | ||
| 77 | + | ||
| 78 | +#endif |
hueplusplus/test/mocks/mock_HueLight.h renamed to src/test/mocks/mock_HueLight.h
| 1 | -/** | ||
| 2 | - \file mock_HueLight.h | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#ifndef _MOCK_HUE_LIGHT_H | ||
| 24 | -#define _MOCK_HUE_LIGHT_H | ||
| 25 | - | ||
| 26 | -#include <string> | ||
| 27 | -#include <vector> | ||
| 28 | - | ||
| 29 | -#include <gmock/gmock.h> | ||
| 30 | - | ||
| 31 | -#include "../hueplusplus/include/HueLight.h" | ||
| 32 | -#include "../hueplusplus/include/json/json.hpp" | ||
| 33 | -#include "../testhelper.h" | ||
| 34 | - | ||
| 35 | -//! Mock Class | ||
| 36 | -class MockHueLight : public HueLight | ||
| 37 | -{ | ||
| 38 | -public: | ||
| 39 | - MockHueLight(std::shared_ptr<const IHttpHandler> handler) | ||
| 40 | - : HueLight(1, HueCommandAPI(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler)) {}; | ||
| 41 | - | ||
| 42 | - nlohmann::json& getState() { return state; }; | ||
| 43 | - | ||
| 44 | - MOCK_METHOD1(On, bool(uint8_t transition)); | ||
| 45 | - | ||
| 46 | - MOCK_METHOD1(Off, bool(uint8_t transition)); | ||
| 47 | - | ||
| 48 | - MOCK_METHOD0(isOn, bool()); | ||
| 49 | - | ||
| 50 | - MOCK_CONST_METHOD0(isOn, bool()); | ||
| 51 | - | ||
| 52 | - MOCK_CONST_METHOD0(getId, int()); | ||
| 53 | - | ||
| 54 | - MOCK_CONST_METHOD0(getType, std::string()); | ||
| 55 | - | ||
| 56 | - MOCK_METHOD0(getName, std::string()); | ||
| 57 | - | ||
| 58 | - MOCK_CONST_METHOD0(getName, std::string()); | ||
| 59 | - | ||
| 60 | - MOCK_CONST_METHOD0(getModelId, std::string()); | ||
| 61 | - | ||
| 62 | - MOCK_CONST_METHOD0(getUId, std::string()); | ||
| 63 | - | ||
| 64 | - MOCK_CONST_METHOD0(getManufacturername, std::string()); | ||
| 65 | - | ||
| 66 | - MOCK_CONST_METHOD0(getLuminaireUId, std::string()); | ||
| 67 | - | ||
| 68 | - MOCK_METHOD0(getSwVersion, std::string()); | ||
| 69 | - | ||
| 70 | - MOCK_CONST_METHOD0(getSwVersion, std::string()); | ||
| 71 | - | ||
| 72 | - MOCK_METHOD1(setName, bool(std::string& name)); | ||
| 73 | - | ||
| 74 | - MOCK_CONST_METHOD0(getColorType, ColorType()); | ||
| 75 | - | ||
| 76 | - MOCK_CONST_METHOD0(hasBrightnessControl, bool()); | ||
| 77 | - | ||
| 78 | - MOCK_CONST_METHOD0(hasTemperatureControl, bool()); | ||
| 79 | - | ||
| 80 | - MOCK_CONST_METHOD0(hasColorControl, bool()); | ||
| 81 | - | ||
| 82 | - MOCK_METHOD2(setBrightness, bool(unsigned int bri, uint8_t transition)); | ||
| 83 | - | ||
| 84 | - MOCK_CONST_METHOD0(getBrightness, unsigned int()); | ||
| 85 | - | ||
| 86 | - MOCK_METHOD0(getBrightness, unsigned int()); | ||
| 87 | - | ||
| 88 | - MOCK_METHOD2(setColorTemperature, bool(unsigned int mired, uint8_t transition)); | ||
| 89 | - | ||
| 90 | - MOCK_CONST_METHOD0(getColorTemperature, unsigned int()); | ||
| 91 | - | ||
| 92 | - MOCK_METHOD0(getColorTemperature, unsigned int()); | ||
| 93 | - | ||
| 94 | - MOCK_METHOD2(setColorHue, bool(uint16_t hue, uint8_t transition)); | ||
| 95 | - | ||
| 96 | - MOCK_METHOD2(setColorSaturation, bool(uint8_t sat, uint8_t transition)); | ||
| 97 | - | ||
| 98 | - MOCK_METHOD3(setColorHueSaturation, bool(uint16_t hue, uint8_t sat, uint8_t transition)); | ||
| 99 | - | ||
| 100 | - MOCK_CONST_METHOD0(getColorHueSaturation, std::pair<uint16_t, uint8_t>()); | ||
| 101 | - | ||
| 102 | - MOCK_METHOD0(getColorHueSaturation, std::pair<uint16_t, uint8_t>()); | ||
| 103 | - | ||
| 104 | - MOCK_METHOD3(setColorXY, bool(float x, float y, uint8_t transition)); | ||
| 105 | - | ||
| 106 | - MOCK_CONST_METHOD0(getColorXY, std::pair<float, float>()); | ||
| 107 | - | ||
| 108 | - MOCK_METHOD0(getColorXY, std::pair<float, float>()); | ||
| 109 | - | ||
| 110 | - MOCK_METHOD4(setColorRGB, bool(uint8_t r, uint8_t g, uint8_t b, uint8_t transition)); | ||
| 111 | - | ||
| 112 | - MOCK_METHOD0(alert, bool()); | ||
| 113 | - | ||
| 114 | - MOCK_METHOD1(alertTemperature, bool(unsigned int mired)); | ||
| 115 | - | ||
| 116 | - MOCK_METHOD2(alertHueSaturation, bool(uint16_t hue, uint8_t sat)); | ||
| 117 | - | ||
| 118 | - MOCK_METHOD2(alertXY, bool(float x, float y)); | ||
| 119 | - | ||
| 120 | - MOCK_METHOD3(alertRGB, bool(uint8_t r, uint8_t g, uint8_t b)); | ||
| 121 | - | ||
| 122 | - MOCK_METHOD1(setColorLoop, bool(bool on)); | ||
| 123 | - | ||
| 124 | - MOCK_METHOD1(OnNoRefresh, bool(uint8_t transition)); | ||
| 125 | - | ||
| 126 | - MOCK_METHOD1(OffNoRefresh, bool(uint8_t transition)); | ||
| 127 | - | ||
| 128 | - MOCK_METHOD3( | ||
| 129 | - SendPutRequest, nlohmann::json(const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo)); | ||
| 130 | - | ||
| 131 | - MOCK_METHOD0(refreshState, void()); | ||
| 132 | -}; | ||
| 133 | - | ||
| 134 | -#endif | 1 | +/** |
| 2 | + \file mock_HueLight.h | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#ifndef _MOCK_HUE_LIGHT_H | ||
| 24 | +#define _MOCK_HUE_LIGHT_H | ||
| 25 | + | ||
| 26 | +#include <string> | ||
| 27 | +#include <vector> | ||
| 28 | + | ||
| 29 | +#include <gmock/gmock.h> | ||
| 30 | + | ||
| 31 | +#include "../hueplusplus/include/HueLight.h" | ||
| 32 | +#include "../hueplusplus/include/json/json.hpp" | ||
| 33 | +#include "../testhelper.h" | ||
| 34 | + | ||
| 35 | +//! Mock Class | ||
| 36 | +class MockHueLight : public HueLight | ||
| 37 | +{ | ||
| 38 | +public: | ||
| 39 | + MockHueLight(std::shared_ptr<const IHttpHandler> handler) | ||
| 40 | + : HueLight(1, HueCommandAPI(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler)) {}; | ||
| 41 | + | ||
| 42 | + nlohmann::json& getState() { return state; }; | ||
| 43 | + | ||
| 44 | + MOCK_METHOD1(On, bool(uint8_t transition)); | ||
| 45 | + | ||
| 46 | + MOCK_METHOD1(Off, bool(uint8_t transition)); | ||
| 47 | + | ||
| 48 | + MOCK_METHOD0(isOn, bool()); | ||
| 49 | + | ||
| 50 | + MOCK_CONST_METHOD0(isOn, bool()); | ||
| 51 | + | ||
| 52 | + MOCK_CONST_METHOD0(getId, int()); | ||
| 53 | + | ||
| 54 | + MOCK_CONST_METHOD0(getType, std::string()); | ||
| 55 | + | ||
| 56 | + MOCK_METHOD0(getName, std::string()); | ||
| 57 | + | ||
| 58 | + MOCK_CONST_METHOD0(getName, std::string()); | ||
| 59 | + | ||
| 60 | + MOCK_CONST_METHOD0(getModelId, std::string()); | ||
| 61 | + | ||
| 62 | + MOCK_CONST_METHOD0(getUId, std::string()); | ||
| 63 | + | ||
| 64 | + MOCK_CONST_METHOD0(getManufacturername, std::string()); | ||
| 65 | + | ||
| 66 | + MOCK_CONST_METHOD0(getLuminaireUId, std::string()); | ||
| 67 | + | ||
| 68 | + MOCK_METHOD0(getSwVersion, std::string()); | ||
| 69 | + | ||
| 70 | + MOCK_CONST_METHOD0(getSwVersion, std::string()); | ||
| 71 | + | ||
| 72 | + MOCK_METHOD1(setName, bool(std::string& name)); | ||
| 73 | + | ||
| 74 | + MOCK_CONST_METHOD0(getColorType, ColorType()); | ||
| 75 | + | ||
| 76 | + MOCK_CONST_METHOD0(hasBrightnessControl, bool()); | ||
| 77 | + | ||
| 78 | + MOCK_CONST_METHOD0(hasTemperatureControl, bool()); | ||
| 79 | + | ||
| 80 | + MOCK_CONST_METHOD0(hasColorControl, bool()); | ||
| 81 | + | ||
| 82 | + MOCK_METHOD2(setBrightness, bool(unsigned int bri, uint8_t transition)); | ||
| 83 | + | ||
| 84 | + MOCK_CONST_METHOD0(getBrightness, unsigned int()); | ||
| 85 | + | ||
| 86 | + MOCK_METHOD0(getBrightness, unsigned int()); | ||
| 87 | + | ||
| 88 | + MOCK_METHOD2(setColorTemperature, bool(unsigned int mired, uint8_t transition)); | ||
| 89 | + | ||
| 90 | + MOCK_CONST_METHOD0(getColorTemperature, unsigned int()); | ||
| 91 | + | ||
| 92 | + MOCK_METHOD0(getColorTemperature, unsigned int()); | ||
| 93 | + | ||
| 94 | + MOCK_METHOD2(setColorHue, bool(uint16_t hue, uint8_t transition)); | ||
| 95 | + | ||
| 96 | + MOCK_METHOD2(setColorSaturation, bool(uint8_t sat, uint8_t transition)); | ||
| 97 | + | ||
| 98 | + MOCK_METHOD3(setColorHueSaturation, bool(uint16_t hue, uint8_t sat, uint8_t transition)); | ||
| 99 | + | ||
| 100 | + MOCK_CONST_METHOD0(getColorHueSaturation, std::pair<uint16_t, uint8_t>()); | ||
| 101 | + | ||
| 102 | + MOCK_METHOD0(getColorHueSaturation, std::pair<uint16_t, uint8_t>()); | ||
| 103 | + | ||
| 104 | + MOCK_METHOD3(setColorXY, bool(float x, float y, uint8_t transition)); | ||
| 105 | + | ||
| 106 | + MOCK_CONST_METHOD0(getColorXY, std::pair<float, float>()); | ||
| 107 | + | ||
| 108 | + MOCK_METHOD0(getColorXY, std::pair<float, float>()); | ||
| 109 | + | ||
| 110 | + MOCK_METHOD4(setColorRGB, bool(uint8_t r, uint8_t g, uint8_t b, uint8_t transition)); | ||
| 111 | + | ||
| 112 | + MOCK_METHOD0(alert, bool()); | ||
| 113 | + | ||
| 114 | + MOCK_METHOD1(alertTemperature, bool(unsigned int mired)); | ||
| 115 | + | ||
| 116 | + MOCK_METHOD2(alertHueSaturation, bool(uint16_t hue, uint8_t sat)); | ||
| 117 | + | ||
| 118 | + MOCK_METHOD2(alertXY, bool(float x, float y)); | ||
| 119 | + | ||
| 120 | + MOCK_METHOD3(alertRGB, bool(uint8_t r, uint8_t g, uint8_t b)); | ||
| 121 | + | ||
| 122 | + MOCK_METHOD1(setColorLoop, bool(bool on)); | ||
| 123 | + | ||
| 124 | + MOCK_METHOD1(OnNoRefresh, bool(uint8_t transition)); | ||
| 125 | + | ||
| 126 | + MOCK_METHOD1(OffNoRefresh, bool(uint8_t transition)); | ||
| 127 | + | ||
| 128 | + MOCK_METHOD3( | ||
| 129 | + SendPutRequest, nlohmann::json(const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo)); | ||
| 130 | + | ||
| 131 | + MOCK_METHOD0(refreshState, void()); | ||
| 132 | +}; | ||
| 133 | + | ||
| 134 | +#endif |
hueplusplus/test/test_BaseHttpHandler.cpp renamed to src/test/test_BaseHttpHandler.cpp
100755 → 100644
| 1 | -/** | ||
| 2 | - \file test_BaseHttpHandler.cpp | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#include <memory> | ||
| 24 | -#include <string> | ||
| 25 | - | ||
| 26 | -#include <gmock/gmock.h> | ||
| 27 | -#include <gtest/gtest.h> | ||
| 28 | - | ||
| 29 | -#include "testhelper.h" | ||
| 30 | - | ||
| 31 | -#include "../include/json/json.hpp" | ||
| 32 | -#include "mocks/mock_BaseHttpHandler.h" | ||
| 33 | -#include "../include/HueException.h" | ||
| 34 | - | ||
| 35 | -TEST(BaseHttpHandler, sendGetHTTPBody) | ||
| 36 | -{ | ||
| 37 | - using namespace ::testing; | ||
| 38 | - MockBaseHttpHandler handler; | ||
| 39 | - | ||
| 40 | - EXPECT_CALL(handler, send("testmsg", "192.168.2.1", 90)) | ||
| 41 | - .Times(AtLeast(2)) | ||
| 42 | - .WillOnce(Return("")) | ||
| 43 | - .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 44 | - | ||
| 45 | - EXPECT_THROW(handler.sendGetHTTPBody("testmsg", "192.168.2.1", 90), HueException); | ||
| 46 | - EXPECT_EQ("testreply", handler.sendGetHTTPBody("testmsg", "192.168.2.1", 90)); | ||
| 47 | -} | ||
| 48 | - | ||
| 49 | -TEST(BaseHttpHandler, sendHTTPRequest) | ||
| 50 | -{ | ||
| 51 | - using namespace ::testing; | ||
| 52 | - MockBaseHttpHandler handler; | ||
| 53 | - | ||
| 54 | - EXPECT_CALL(handler, | ||
| 55 | - send("GET UrI HTTP/1.0\r\nContent-Type: " | ||
| 56 | - "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n", | ||
| 57 | - "192.168.2.1", 90)) | ||
| 58 | - .Times(AtLeast(2)) | ||
| 59 | - .WillOnce(Return("")) | ||
| 60 | - .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 61 | - | ||
| 62 | - EXPECT_THROW(handler.sendHTTPRequest("GET", "UrI", "text/html", "body", "192.168.2.1", 90), HueException); | ||
| 63 | - EXPECT_EQ("testreply", handler.sendHTTPRequest("GET", "UrI", "text/html", "body", "192.168.2.1", 90)); | ||
| 64 | -} | ||
| 65 | - | ||
| 66 | -TEST(BaseHttpHandler, GETString) | ||
| 67 | -{ | ||
| 68 | - using namespace ::testing; | ||
| 69 | - MockBaseHttpHandler handler; | ||
| 70 | - | ||
| 71 | - EXPECT_CALL(handler, | ||
| 72 | - send("GET UrI HTTP/1.0\r\nContent-Type: " | ||
| 73 | - "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n", | ||
| 74 | - "192.168.2.1", 90)) | ||
| 75 | - .Times(AtLeast(2)) | ||
| 76 | - .WillOnce(Return("")) | ||
| 77 | - .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 78 | - | ||
| 79 | - EXPECT_THROW(handler.GETString("UrI", "text/html", "body", "192.168.2.1", 90), HueException); | ||
| 80 | - EXPECT_EQ("testreply", handler.GETString("UrI", "text/html", "body", "192.168.2.1", 90)); | ||
| 81 | -} | ||
| 82 | - | ||
| 83 | -TEST(BaseHttpHandler, POSTString) | ||
| 84 | -{ | ||
| 85 | - using namespace ::testing; | ||
| 86 | - MockBaseHttpHandler handler; | ||
| 87 | - | ||
| 88 | - EXPECT_CALL(handler, | ||
| 89 | - send("POST UrI HTTP/1.0\r\nContent-Type: " | ||
| 90 | - "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n", | ||
| 91 | - "192.168.2.1", 90)) | ||
| 92 | - .Times(AtLeast(2)) | ||
| 93 | - .WillOnce(Return("")) | ||
| 94 | - .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 95 | - | ||
| 96 | - EXPECT_THROW(handler.POSTString("UrI", "text/html", "body", "192.168.2.1", 90), HueException); | ||
| 97 | - EXPECT_EQ("testreply", handler.POSTString("UrI", "text/html", "body", "192.168.2.1", 90)); | ||
| 98 | -} | ||
| 99 | - | ||
| 100 | -TEST(BaseHttpHandler, PUTString) | ||
| 101 | -{ | ||
| 102 | - using namespace ::testing; | ||
| 103 | - MockBaseHttpHandler handler; | ||
| 104 | - | ||
| 105 | - EXPECT_CALL(handler, | ||
| 106 | - send("PUT UrI HTTP/1.0\r\nContent-Type: " | ||
| 107 | - "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n", | ||
| 108 | - "192.168.2.1", 90)) | ||
| 109 | - .Times(AtLeast(2)) | ||
| 110 | - .WillOnce(Return("")) | ||
| 111 | - .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 112 | - | ||
| 113 | - EXPECT_THROW(handler.PUTString("UrI", "text/html", "body", "192.168.2.1", 90), HueException); | ||
| 114 | - EXPECT_EQ("testreply", handler.PUTString("UrI", "text/html", "body", "192.168.2.1", 90)); | ||
| 115 | -} | ||
| 116 | - | ||
| 117 | -TEST(BaseHttpHandler, DELETEString) | ||
| 118 | -{ | ||
| 119 | - using namespace ::testing; | ||
| 120 | - MockBaseHttpHandler handler; | ||
| 121 | - | ||
| 122 | - EXPECT_CALL(handler, | ||
| 123 | - send("DELETE UrI HTTP/1.0\r\nContent-Type: " | ||
| 124 | - "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n", | ||
| 125 | - "192.168.2.1", 90)) | ||
| 126 | - .Times(AtLeast(2)) | ||
| 127 | - .WillOnce(Return("")) | ||
| 128 | - .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 129 | - | ||
| 130 | - EXPECT_THROW(handler.DELETEString("UrI", "text/html", "body", "192.168.2.1", 90), HueException); | ||
| 131 | - EXPECT_EQ("testreply", handler.DELETEString("UrI", "text/html", "body", "192.168.2.1", 90)); | ||
| 132 | -} | ||
| 133 | - | ||
| 134 | -TEST(BaseHttpHandler, GETJson) | ||
| 135 | -{ | ||
| 136 | - using namespace ::testing; | ||
| 137 | - MockBaseHttpHandler handler; | ||
| 138 | - | ||
| 139 | - nlohmann::json testval; | ||
| 140 | - testval["test"] = 100; | ||
| 141 | - std::string expected_call = "GET UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: "; | ||
| 142 | - expected_call.append(std::to_string(testval.dump().size())); | ||
| 143 | - expected_call.append("\r\n\r\n"); | ||
| 144 | - expected_call.append(testval.dump()); | ||
| 145 | - expected_call.append("\r\n\r\n"); | ||
| 146 | - | ||
| 147 | - EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90)) | ||
| 148 | - .Times(AtLeast(2)) | ||
| 149 | - .WillOnce(Return("")) | ||
| 150 | - .WillOnce(Return("\r\n\r\n")) | ||
| 151 | - .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}")); | ||
| 152 | - nlohmann::json expected; | ||
| 153 | - expected["test"] = "whatever"; | ||
| 154 | - | ||
| 155 | - EXPECT_THROW(handler.GETJson("UrI", testval, "192.168.2.1", 90), HueException); | ||
| 156 | - EXPECT_THROW(handler.GETJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error); | ||
| 157 | - EXPECT_EQ(expected, handler.GETJson("UrI", testval, "192.168.2.1", 90)); | ||
| 158 | -} | ||
| 159 | - | ||
| 160 | -TEST(BaseHttpHandler, POSTJson) | ||
| 161 | -{ | ||
| 162 | - using namespace ::testing; | ||
| 163 | - MockBaseHttpHandler handler; | ||
| 164 | - | ||
| 165 | - nlohmann::json testval; | ||
| 166 | - testval["test"] = 100; | ||
| 167 | - std::string expected_call = "POST UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: "; | ||
| 168 | - expected_call.append(std::to_string(testval.dump().size())); | ||
| 169 | - expected_call.append("\r\n\r\n"); | ||
| 170 | - expected_call.append(testval.dump()); | ||
| 171 | - expected_call.append("\r\n\r\n"); | ||
| 172 | - | ||
| 173 | - EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90)) | ||
| 174 | - .Times(AtLeast(2)) | ||
| 175 | - .WillOnce(Return("")) | ||
| 176 | - .WillOnce(Return("\r\n\r\n")) | ||
| 177 | - .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}")); | ||
| 178 | - nlohmann::json expected; | ||
| 179 | - expected["test"] = "whatever"; | ||
| 180 | - | ||
| 181 | - EXPECT_THROW(handler.POSTJson("UrI", testval, "192.168.2.1", 90), HueException); | ||
| 182 | - EXPECT_THROW(handler.POSTJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error); | ||
| 183 | - EXPECT_EQ(expected, handler.POSTJson("UrI", testval, "192.168.2.1", 90)); | ||
| 184 | -} | ||
| 185 | - | ||
| 186 | -TEST(BaseHttpHandler, PUTJson) | ||
| 187 | -{ | ||
| 188 | - using namespace ::testing; | ||
| 189 | - MockBaseHttpHandler handler; | ||
| 190 | - | ||
| 191 | - nlohmann::json testval; | ||
| 192 | - testval["test"] = 100; | ||
| 193 | - std::string expected_call = "PUT UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: "; | ||
| 194 | - expected_call.append(std::to_string(testval.dump().size())); | ||
| 195 | - expected_call.append("\r\n\r\n"); | ||
| 196 | - expected_call.append(testval.dump()); | ||
| 197 | - expected_call.append("\r\n\r\n"); | ||
| 198 | - | ||
| 199 | - EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90)) | ||
| 200 | - .Times(AtLeast(2)) | ||
| 201 | - .WillOnce(Return("")) | ||
| 202 | - .WillOnce(Return("\r\n\r\n")) | ||
| 203 | - .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}")); | ||
| 204 | - nlohmann::json expected; | ||
| 205 | - expected["test"] = "whatever"; | ||
| 206 | - | ||
| 207 | - EXPECT_THROW(handler.PUTJson("UrI", testval, "192.168.2.1", 90), HueException); | ||
| 208 | - EXPECT_THROW(handler.PUTJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error); | ||
| 209 | - EXPECT_EQ(expected, handler.PUTJson("UrI", testval, "192.168.2.1", 90)); | ||
| 210 | -} | ||
| 211 | - | ||
| 212 | -TEST(BaseHttpHandler, DELETEJson) | ||
| 213 | -{ | ||
| 214 | - using namespace ::testing; | ||
| 215 | - MockBaseHttpHandler handler; | ||
| 216 | - | ||
| 217 | - nlohmann::json testval; | ||
| 218 | - testval["test"] = 100; | ||
| 219 | - std::string expected_call = "DELETE UrI HTTP/1.0\r\nContent-Type: " | ||
| 220 | - "application/json\r\nContent-Length: "; | ||
| 221 | - expected_call.append(std::to_string(testval.dump().size())); | ||
| 222 | - expected_call.append("\r\n\r\n"); | ||
| 223 | - expected_call.append(testval.dump()); | ||
| 224 | - expected_call.append("\r\n\r\n"); | ||
| 225 | - | ||
| 226 | - EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90)) | ||
| 227 | - .Times(AtLeast(2)) | ||
| 228 | - .WillOnce(Return("")) | ||
| 229 | - .WillOnce(Return("\r\n\r\n")) | ||
| 230 | - .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}")); | ||
| 231 | - nlohmann::json expected; | ||
| 232 | - expected["test"] = "whatever"; | ||
| 233 | - | ||
| 234 | - EXPECT_THROW(handler.DELETEJson("UrI", testval, "192.168.2.1", 90), HueException); | ||
| 235 | - EXPECT_THROW(handler.DELETEJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error); | ||
| 236 | - EXPECT_EQ(expected, handler.DELETEJson("UrI", testval, "192.168.2.1", 90)); | ||
| 237 | -} | 1 | +/** |
| 2 | + \file test_BaseHttpHandler.cpp | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#include <memory> | ||
| 24 | +#include <string> | ||
| 25 | + | ||
| 26 | +#include <gmock/gmock.h> | ||
| 27 | +#include <gtest/gtest.h> | ||
| 28 | + | ||
| 29 | +#include "testhelper.h" | ||
| 30 | + | ||
| 31 | +#include "../include/json/json.hpp" | ||
| 32 | +#include "mocks/mock_BaseHttpHandler.h" | ||
| 33 | +#include "../include/HueException.h" | ||
| 34 | + | ||
| 35 | +TEST(BaseHttpHandler, sendGetHTTPBody) | ||
| 36 | +{ | ||
| 37 | + using namespace ::testing; | ||
| 38 | + MockBaseHttpHandler handler; | ||
| 39 | + | ||
| 40 | + EXPECT_CALL(handler, send("testmsg", "192.168.2.1", 90)) | ||
| 41 | + .Times(AtLeast(2)) | ||
| 42 | + .WillOnce(Return("")) | ||
| 43 | + .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 44 | + | ||
| 45 | + EXPECT_THROW(handler.sendGetHTTPBody("testmsg", "192.168.2.1", 90), HueException); | ||
| 46 | + EXPECT_EQ("testreply", handler.sendGetHTTPBody("testmsg", "192.168.2.1", 90)); | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +TEST(BaseHttpHandler, sendHTTPRequest) | ||
| 50 | +{ | ||
| 51 | + using namespace ::testing; | ||
| 52 | + MockBaseHttpHandler handler; | ||
| 53 | + | ||
| 54 | + EXPECT_CALL(handler, | ||
| 55 | + send("GET UrI HTTP/1.0\r\nContent-Type: " | ||
| 56 | + "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n", | ||
| 57 | + "192.168.2.1", 90)) | ||
| 58 | + .Times(AtLeast(2)) | ||
| 59 | + .WillOnce(Return("")) | ||
| 60 | + .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 61 | + | ||
| 62 | + EXPECT_THROW(handler.sendHTTPRequest("GET", "UrI", "text/html", "body", "192.168.2.1", 90), HueException); | ||
| 63 | + EXPECT_EQ("testreply", handler.sendHTTPRequest("GET", "UrI", "text/html", "body", "192.168.2.1", 90)); | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +TEST(BaseHttpHandler, GETString) | ||
| 67 | +{ | ||
| 68 | + using namespace ::testing; | ||
| 69 | + MockBaseHttpHandler handler; | ||
| 70 | + | ||
| 71 | + EXPECT_CALL(handler, | ||
| 72 | + send("GET UrI HTTP/1.0\r\nContent-Type: " | ||
| 73 | + "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n", | ||
| 74 | + "192.168.2.1", 90)) | ||
| 75 | + .Times(AtLeast(2)) | ||
| 76 | + .WillOnce(Return("")) | ||
| 77 | + .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 78 | + | ||
| 79 | + EXPECT_THROW(handler.GETString("UrI", "text/html", "body", "192.168.2.1", 90), HueException); | ||
| 80 | + EXPECT_EQ("testreply", handler.GETString("UrI", "text/html", "body", "192.168.2.1", 90)); | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +TEST(BaseHttpHandler, POSTString) | ||
| 84 | +{ | ||
| 85 | + using namespace ::testing; | ||
| 86 | + MockBaseHttpHandler handler; | ||
| 87 | + | ||
| 88 | + EXPECT_CALL(handler, | ||
| 89 | + send("POST UrI HTTP/1.0\r\nContent-Type: " | ||
| 90 | + "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n", | ||
| 91 | + "192.168.2.1", 90)) | ||
| 92 | + .Times(AtLeast(2)) | ||
| 93 | + .WillOnce(Return("")) | ||
| 94 | + .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 95 | + | ||
| 96 | + EXPECT_THROW(handler.POSTString("UrI", "text/html", "body", "192.168.2.1", 90), HueException); | ||
| 97 | + EXPECT_EQ("testreply", handler.POSTString("UrI", "text/html", "body", "192.168.2.1", 90)); | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +TEST(BaseHttpHandler, PUTString) | ||
| 101 | +{ | ||
| 102 | + using namespace ::testing; | ||
| 103 | + MockBaseHttpHandler handler; | ||
| 104 | + | ||
| 105 | + EXPECT_CALL(handler, | ||
| 106 | + send("PUT UrI HTTP/1.0\r\nContent-Type: " | ||
| 107 | + "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n", | ||
| 108 | + "192.168.2.1", 90)) | ||
| 109 | + .Times(AtLeast(2)) | ||
| 110 | + .WillOnce(Return("")) | ||
| 111 | + .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 112 | + | ||
| 113 | + EXPECT_THROW(handler.PUTString("UrI", "text/html", "body", "192.168.2.1", 90), HueException); | ||
| 114 | + EXPECT_EQ("testreply", handler.PUTString("UrI", "text/html", "body", "192.168.2.1", 90)); | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +TEST(BaseHttpHandler, DELETEString) | ||
| 118 | +{ | ||
| 119 | + using namespace ::testing; | ||
| 120 | + MockBaseHttpHandler handler; | ||
| 121 | + | ||
| 122 | + EXPECT_CALL(handler, | ||
| 123 | + send("DELETE UrI HTTP/1.0\r\nContent-Type: " | ||
| 124 | + "text/html\r\nContent-Length: 4\r\n\r\nbody\r\n\r\n", | ||
| 125 | + "192.168.2.1", 90)) | ||
| 126 | + .Times(AtLeast(2)) | ||
| 127 | + .WillOnce(Return("")) | ||
| 128 | + .WillRepeatedly(Return("\r\n\r\ntestreply")); | ||
| 129 | + | ||
| 130 | + EXPECT_THROW(handler.DELETEString("UrI", "text/html", "body", "192.168.2.1", 90), HueException); | ||
| 131 | + EXPECT_EQ("testreply", handler.DELETEString("UrI", "text/html", "body", "192.168.2.1", 90)); | ||
| 132 | +} | ||
| 133 | + | ||
| 134 | +TEST(BaseHttpHandler, GETJson) | ||
| 135 | +{ | ||
| 136 | + using namespace ::testing; | ||
| 137 | + MockBaseHttpHandler handler; | ||
| 138 | + | ||
| 139 | + nlohmann::json testval; | ||
| 140 | + testval["test"] = 100; | ||
| 141 | + std::string expected_call = "GET UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: "; | ||
| 142 | + expected_call.append(std::to_string(testval.dump().size())); | ||
| 143 | + expected_call.append("\r\n\r\n"); | ||
| 144 | + expected_call.append(testval.dump()); | ||
| 145 | + expected_call.append("\r\n\r\n"); | ||
| 146 | + | ||
| 147 | + EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90)) | ||
| 148 | + .Times(AtLeast(2)) | ||
| 149 | + .WillOnce(Return("")) | ||
| 150 | + .WillOnce(Return("\r\n\r\n")) | ||
| 151 | + .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}")); | ||
| 152 | + nlohmann::json expected; | ||
| 153 | + expected["test"] = "whatever"; | ||
| 154 | + | ||
| 155 | + EXPECT_THROW(handler.GETJson("UrI", testval, "192.168.2.1", 90), HueException); | ||
| 156 | + EXPECT_THROW(handler.GETJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error); | ||
| 157 | + EXPECT_EQ(expected, handler.GETJson("UrI", testval, "192.168.2.1", 90)); | ||
| 158 | +} | ||
| 159 | + | ||
| 160 | +TEST(BaseHttpHandler, POSTJson) | ||
| 161 | +{ | ||
| 162 | + using namespace ::testing; | ||
| 163 | + MockBaseHttpHandler handler; | ||
| 164 | + | ||
| 165 | + nlohmann::json testval; | ||
| 166 | + testval["test"] = 100; | ||
| 167 | + std::string expected_call = "POST UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: "; | ||
| 168 | + expected_call.append(std::to_string(testval.dump().size())); | ||
| 169 | + expected_call.append("\r\n\r\n"); | ||
| 170 | + expected_call.append(testval.dump()); | ||
| 171 | + expected_call.append("\r\n\r\n"); | ||
| 172 | + | ||
| 173 | + EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90)) | ||
| 174 | + .Times(AtLeast(2)) | ||
| 175 | + .WillOnce(Return("")) | ||
| 176 | + .WillOnce(Return("\r\n\r\n")) | ||
| 177 | + .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}")); | ||
| 178 | + nlohmann::json expected; | ||
| 179 | + expected["test"] = "whatever"; | ||
| 180 | + | ||
| 181 | + EXPECT_THROW(handler.POSTJson("UrI", testval, "192.168.2.1", 90), HueException); | ||
| 182 | + EXPECT_THROW(handler.POSTJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error); | ||
| 183 | + EXPECT_EQ(expected, handler.POSTJson("UrI", testval, "192.168.2.1", 90)); | ||
| 184 | +} | ||
| 185 | + | ||
| 186 | +TEST(BaseHttpHandler, PUTJson) | ||
| 187 | +{ | ||
| 188 | + using namespace ::testing; | ||
| 189 | + MockBaseHttpHandler handler; | ||
| 190 | + | ||
| 191 | + nlohmann::json testval; | ||
| 192 | + testval["test"] = 100; | ||
| 193 | + std::string expected_call = "PUT UrI HTTP/1.0\r\nContent-Type: application/json\r\nContent-Length: "; | ||
| 194 | + expected_call.append(std::to_string(testval.dump().size())); | ||
| 195 | + expected_call.append("\r\n\r\n"); | ||
| 196 | + expected_call.append(testval.dump()); | ||
| 197 | + expected_call.append("\r\n\r\n"); | ||
| 198 | + | ||
| 199 | + EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90)) | ||
| 200 | + .Times(AtLeast(2)) | ||
| 201 | + .WillOnce(Return("")) | ||
| 202 | + .WillOnce(Return("\r\n\r\n")) | ||
| 203 | + .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}")); | ||
| 204 | + nlohmann::json expected; | ||
| 205 | + expected["test"] = "whatever"; | ||
| 206 | + | ||
| 207 | + EXPECT_THROW(handler.PUTJson("UrI", testval, "192.168.2.1", 90), HueException); | ||
| 208 | + EXPECT_THROW(handler.PUTJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error); | ||
| 209 | + EXPECT_EQ(expected, handler.PUTJson("UrI", testval, "192.168.2.1", 90)); | ||
| 210 | +} | ||
| 211 | + | ||
| 212 | +TEST(BaseHttpHandler, DELETEJson) | ||
| 213 | +{ | ||
| 214 | + using namespace ::testing; | ||
| 215 | + MockBaseHttpHandler handler; | ||
| 216 | + | ||
| 217 | + nlohmann::json testval; | ||
| 218 | + testval["test"] = 100; | ||
| 219 | + std::string expected_call = "DELETE UrI HTTP/1.0\r\nContent-Type: " | ||
| 220 | + "application/json\r\nContent-Length: "; | ||
| 221 | + expected_call.append(std::to_string(testval.dump().size())); | ||
| 222 | + expected_call.append("\r\n\r\n"); | ||
| 223 | + expected_call.append(testval.dump()); | ||
| 224 | + expected_call.append("\r\n\r\n"); | ||
| 225 | + | ||
| 226 | + EXPECT_CALL(handler, send(expected_call, "192.168.2.1", 90)) | ||
| 227 | + .Times(AtLeast(2)) | ||
| 228 | + .WillOnce(Return("")) | ||
| 229 | + .WillOnce(Return("\r\n\r\n")) | ||
| 230 | + .WillRepeatedly(Return("\r\n\r\n{\"test\" : \"whatever\"}")); | ||
| 231 | + nlohmann::json expected; | ||
| 232 | + expected["test"] = "whatever"; | ||
| 233 | + | ||
| 234 | + EXPECT_THROW(handler.DELETEJson("UrI", testval, "192.168.2.1", 90), HueException); | ||
| 235 | + EXPECT_THROW(handler.DELETEJson("UrI", testval, "192.168.2.1", 90), nlohmann::json::parse_error); | ||
| 236 | + EXPECT_EQ(expected, handler.DELETEJson("UrI", testval, "192.168.2.1", 90)); | ||
| 237 | +} |
hueplusplus/test/test_ExtendedColorHueStrategy.cpp renamed to src/test/test_ExtendedColorHueStrategy.cpp
100755 → 100644
| 1 | -/** | ||
| 2 | - \file test_ExtendedColorHueStrategy.cpp | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#include <memory> | ||
| 24 | -#include <string> | ||
| 25 | - | ||
| 26 | -#include <gmock/gmock.h> | ||
| 27 | -#include <gtest/gtest.h> | ||
| 28 | - | ||
| 29 | -#include "testhelper.h" | ||
| 30 | - | ||
| 31 | -#include "../include/ExtendedColorHueStrategy.h" | ||
| 32 | -#include "../include/json/json.hpp" | ||
| 33 | -#include "mocks/mock_HttpHandler.h" | ||
| 34 | -#include "mocks/mock_HueLight.h" | ||
| 35 | - | ||
| 36 | -TEST(ExtendedColorHueStrategy, alertHueSaturation) | ||
| 37 | -{ | ||
| 38 | - using namespace ::testing; | ||
| 39 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 40 | - EXPECT_CALL( | ||
| 41 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 42 | - .Times(AtLeast(1)) | ||
| 43 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 44 | - MockHueLight test_light(handler); | ||
| 45 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 46 | - | ||
| 47 | - test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 48 | - test_light.getState()["state"]["on"] = false; | ||
| 49 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(30000, 128, test_light)); | ||
| 50 | - | ||
| 51 | - EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)) | ||
| 52 | - .Times(AtLeast(2)) | ||
| 53 | - .WillOnce(Return(false)) | ||
| 54 | - .WillRepeatedly(Return(true)); | ||
| 55 | - test_light.getState()["state"]["colormode"] = "hs"; | ||
| 56 | - test_light.getState()["state"]["on"] = true; | ||
| 57 | - test_light.getState()["state"]["sat"] = 100; | ||
| 58 | - test_light.getState()["state"]["hue"] = 200; | ||
| 59 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 60 | - | ||
| 61 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 62 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 63 | - | ||
| 64 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 65 | - | ||
| 66 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 67 | - test_light.getState()["state"]["on"] = false; | ||
| 68 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 69 | - | ||
| 70 | - EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)) | ||
| 71 | - .Times(AtLeast(2)) | ||
| 72 | - .WillOnce(Return(false)) | ||
| 73 | - .WillRepeatedly(Return(true)); | ||
| 74 | - test_light.getState()["state"]["colormode"] = "xy"; | ||
| 75 | - test_light.getState()["state"]["on"] = true; | ||
| 76 | - test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 77 | - test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 78 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 79 | - | ||
| 80 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 81 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 82 | - | ||
| 83 | - EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 84 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 85 | - | ||
| 86 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 87 | - test_light.getState()["state"]["on"] = false; | ||
| 88 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 89 | - | ||
| 90 | - EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)) | ||
| 91 | - .Times(AtLeast(2)) | ||
| 92 | - .WillOnce(Return(false)) | ||
| 93 | - .WillRepeatedly(Return(true)); | ||
| 94 | - test_light.getState()["state"]["colormode"] = "ct"; | ||
| 95 | - test_light.getState()["state"]["on"] = true; | ||
| 96 | - test_light.getState()["state"]["ct"] = 200; | ||
| 97 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 98 | - | ||
| 99 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 100 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 101 | - | ||
| 102 | - EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 103 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 104 | - | ||
| 105 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 106 | - test_light.getState()["state"]["on"] = false; | ||
| 107 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 108 | -} | ||
| 109 | - | ||
| 110 | -TEST(ExtendedColorHueStrategy, alertXY) | ||
| 111 | -{ | ||
| 112 | - using namespace ::testing; | ||
| 113 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 114 | - EXPECT_CALL( | ||
| 115 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 116 | - .Times(AtLeast(1)) | ||
| 117 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 118 | - MockHueLight test_light(handler); | ||
| 119 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 120 | - | ||
| 121 | - test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 122 | - test_light.getState()["state"]["on"] = false; | ||
| 123 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 124 | - | ||
| 125 | - EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 126 | - test_light.getState()["state"]["colormode"] = "hs"; | ||
| 127 | - test_light.getState()["state"]["on"] = true; | ||
| 128 | - test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 129 | - test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 130 | - test_light.getState()["state"]["sat"] = 100; | ||
| 131 | - test_light.getState()["state"]["hue"] = 200; | ||
| 132 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 133 | - | ||
| 134 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 135 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 136 | - | ||
| 137 | - EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 138 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 139 | - | ||
| 140 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 141 | - test_light.getState()["state"]["on"] = false; | ||
| 142 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 143 | - | ||
| 144 | - EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 145 | - test_light.getState()["state"]["colormode"] = "xy"; | ||
| 146 | - test_light.getState()["state"]["on"] = true; | ||
| 147 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 148 | - | ||
| 149 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 150 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 151 | - | ||
| 152 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 153 | - | ||
| 154 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 155 | - test_light.getState()["state"]["on"] = false; | ||
| 156 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 157 | - | ||
| 158 | - EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 159 | - test_light.getState()["state"]["colormode"] = "ct"; | ||
| 160 | - test_light.getState()["state"]["on"] = true; | ||
| 161 | - test_light.getState()["state"]["ct"] = 200; | ||
| 162 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 163 | - | ||
| 164 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 165 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 166 | - | ||
| 167 | - EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 168 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 169 | - | ||
| 170 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 171 | - test_light.getState()["state"]["on"] = false; | ||
| 172 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 173 | -} | ||
| 174 | - | ||
| 175 | -TEST(ExtendedColorHueStrategy, alertRGB) | ||
| 176 | -{ | ||
| 177 | - using namespace ::testing; | ||
| 178 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 179 | - EXPECT_CALL( | ||
| 180 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 181 | - .Times(AtLeast(1)) | ||
| 182 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 183 | - MockHueLight test_light(handler); | ||
| 184 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 185 | - | ||
| 186 | - test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 187 | - test_light.getState()["state"]["on"] = false; | ||
| 188 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 189 | - | ||
| 190 | - EXPECT_CALL(test_light, setColorRGB(_, _, _, 1)) | ||
| 191 | - .Times(AtLeast(2)) | ||
| 192 | - .WillOnce(Return(false)) | ||
| 193 | - .WillRepeatedly(Return(true)); | ||
| 194 | - test_light.getState()["state"]["colormode"] = "hs"; | ||
| 195 | - test_light.getState()["state"]["on"] = true; | ||
| 196 | - test_light.getState()["state"]["sat"] = 100; | ||
| 197 | - test_light.getState()["state"]["hue"] = 200; | ||
| 198 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 199 | - | ||
| 200 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 201 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 202 | - | ||
| 203 | - EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 204 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 205 | - | ||
| 206 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 207 | - test_light.getState()["state"]["on"] = false; | ||
| 208 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 209 | - | ||
| 210 | - EXPECT_CALL(test_light, setColorRGB(_, _, _, 1)) | ||
| 211 | - .Times(AtLeast(2)) | ||
| 212 | - .WillOnce(Return(false)) | ||
| 213 | - .WillRepeatedly(Return(true)); | ||
| 214 | - test_light.getState()["state"]["colormode"] = "xy"; | ||
| 215 | - test_light.getState()["state"]["on"] = true; | ||
| 216 | - test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 217 | - test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 218 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 219 | - | ||
| 220 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 221 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 222 | - | ||
| 223 | - EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 224 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 225 | - | ||
| 226 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 227 | - test_light.getState()["state"]["on"] = false; | ||
| 228 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 229 | - | ||
| 230 | - EXPECT_CALL(test_light, setColorRGB(_, _, _, 1)) | ||
| 231 | - .Times(AtLeast(2)) | ||
| 232 | - .WillOnce(Return(false)) | ||
| 233 | - .WillRepeatedly(Return(true)); | ||
| 234 | - test_light.getState()["state"]["colormode"] = "ct"; | ||
| 235 | - test_light.getState()["state"]["on"] = true; | ||
| 236 | - test_light.getState()["state"]["ct"] = 200; | ||
| 237 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 238 | - | ||
| 239 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 240 | - EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 241 | - | ||
| 242 | - EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 243 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 244 | - | ||
| 245 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 246 | - test_light.getState()["state"]["on"] = false; | ||
| 247 | - EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 248 | -} | 1 | +/** |
| 2 | + \file test_ExtendedColorHueStrategy.cpp | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#include <memory> | ||
| 24 | +#include <string> | ||
| 25 | + | ||
| 26 | +#include <gmock/gmock.h> | ||
| 27 | +#include <gtest/gtest.h> | ||
| 28 | + | ||
| 29 | +#include "testhelper.h" | ||
| 30 | + | ||
| 31 | +#include "../include/ExtendedColorHueStrategy.h" | ||
| 32 | +#include "../include/json/json.hpp" | ||
| 33 | +#include "mocks/mock_HttpHandler.h" | ||
| 34 | +#include "mocks/mock_HueLight.h" | ||
| 35 | + | ||
| 36 | +TEST(ExtendedColorHueStrategy, alertHueSaturation) | ||
| 37 | +{ | ||
| 38 | + using namespace ::testing; | ||
| 39 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 40 | + EXPECT_CALL( | ||
| 41 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 42 | + .Times(AtLeast(1)) | ||
| 43 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 44 | + MockHueLight test_light(handler); | ||
| 45 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 46 | + | ||
| 47 | + test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 48 | + test_light.getState()["state"]["on"] = false; | ||
| 49 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(30000, 128, test_light)); | ||
| 50 | + | ||
| 51 | + EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)) | ||
| 52 | + .Times(AtLeast(2)) | ||
| 53 | + .WillOnce(Return(false)) | ||
| 54 | + .WillRepeatedly(Return(true)); | ||
| 55 | + test_light.getState()["state"]["colormode"] = "hs"; | ||
| 56 | + test_light.getState()["state"]["on"] = true; | ||
| 57 | + test_light.getState()["state"]["sat"] = 100; | ||
| 58 | + test_light.getState()["state"]["hue"] = 200; | ||
| 59 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 60 | + | ||
| 61 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 62 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 63 | + | ||
| 64 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 65 | + | ||
| 66 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 67 | + test_light.getState()["state"]["on"] = false; | ||
| 68 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 69 | + | ||
| 70 | + EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)) | ||
| 71 | + .Times(AtLeast(2)) | ||
| 72 | + .WillOnce(Return(false)) | ||
| 73 | + .WillRepeatedly(Return(true)); | ||
| 74 | + test_light.getState()["state"]["colormode"] = "xy"; | ||
| 75 | + test_light.getState()["state"]["on"] = true; | ||
| 76 | + test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 77 | + test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 78 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 79 | + | ||
| 80 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 81 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 82 | + | ||
| 83 | + EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 84 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 85 | + | ||
| 86 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 87 | + test_light.getState()["state"]["on"] = false; | ||
| 88 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 89 | + | ||
| 90 | + EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)) | ||
| 91 | + .Times(AtLeast(2)) | ||
| 92 | + .WillOnce(Return(false)) | ||
| 93 | + .WillRepeatedly(Return(true)); | ||
| 94 | + test_light.getState()["state"]["colormode"] = "ct"; | ||
| 95 | + test_light.getState()["state"]["on"] = true; | ||
| 96 | + test_light.getState()["state"]["ct"] = 200; | ||
| 97 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 98 | + | ||
| 99 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 100 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 101 | + | ||
| 102 | + EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 103 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 104 | + | ||
| 105 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 106 | + test_light.getState()["state"]["on"] = false; | ||
| 107 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +TEST(ExtendedColorHueStrategy, alertXY) | ||
| 111 | +{ | ||
| 112 | + using namespace ::testing; | ||
| 113 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 114 | + EXPECT_CALL( | ||
| 115 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 116 | + .Times(AtLeast(1)) | ||
| 117 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 118 | + MockHueLight test_light(handler); | ||
| 119 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 120 | + | ||
| 121 | + test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 122 | + test_light.getState()["state"]["on"] = false; | ||
| 123 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 124 | + | ||
| 125 | + EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 126 | + test_light.getState()["state"]["colormode"] = "hs"; | ||
| 127 | + test_light.getState()["state"]["on"] = true; | ||
| 128 | + test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 129 | + test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 130 | + test_light.getState()["state"]["sat"] = 100; | ||
| 131 | + test_light.getState()["state"]["hue"] = 200; | ||
| 132 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 133 | + | ||
| 134 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 135 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 136 | + | ||
| 137 | + EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 138 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 139 | + | ||
| 140 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 141 | + test_light.getState()["state"]["on"] = false; | ||
| 142 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 143 | + | ||
| 144 | + EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 145 | + test_light.getState()["state"]["colormode"] = "xy"; | ||
| 146 | + test_light.getState()["state"]["on"] = true; | ||
| 147 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 148 | + | ||
| 149 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 150 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 151 | + | ||
| 152 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 153 | + | ||
| 154 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 155 | + test_light.getState()["state"]["on"] = false; | ||
| 156 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 157 | + | ||
| 158 | + EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 159 | + test_light.getState()["state"]["colormode"] = "ct"; | ||
| 160 | + test_light.getState()["state"]["on"] = true; | ||
| 161 | + test_light.getState()["state"]["ct"] = 200; | ||
| 162 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 163 | + | ||
| 164 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 165 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 166 | + | ||
| 167 | + EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 168 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 169 | + | ||
| 170 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 171 | + test_light.getState()["state"]["on"] = false; | ||
| 172 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 173 | +} | ||
| 174 | + | ||
| 175 | +TEST(ExtendedColorHueStrategy, alertRGB) | ||
| 176 | +{ | ||
| 177 | + using namespace ::testing; | ||
| 178 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 179 | + EXPECT_CALL( | ||
| 180 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 181 | + .Times(AtLeast(1)) | ||
| 182 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 183 | + MockHueLight test_light(handler); | ||
| 184 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 185 | + | ||
| 186 | + test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 187 | + test_light.getState()["state"]["on"] = false; | ||
| 188 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 189 | + | ||
| 190 | + EXPECT_CALL(test_light, setColorRGB(_, _, _, 1)) | ||
| 191 | + .Times(AtLeast(2)) | ||
| 192 | + .WillOnce(Return(false)) | ||
| 193 | + .WillRepeatedly(Return(true)); | ||
| 194 | + test_light.getState()["state"]["colormode"] = "hs"; | ||
| 195 | + test_light.getState()["state"]["on"] = true; | ||
| 196 | + test_light.getState()["state"]["sat"] = 100; | ||
| 197 | + test_light.getState()["state"]["hue"] = 200; | ||
| 198 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 199 | + | ||
| 200 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 201 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 202 | + | ||
| 203 | + EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 204 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 205 | + | ||
| 206 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 207 | + test_light.getState()["state"]["on"] = false; | ||
| 208 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 209 | + | ||
| 210 | + EXPECT_CALL(test_light, setColorRGB(_, _, _, 1)) | ||
| 211 | + .Times(AtLeast(2)) | ||
| 212 | + .WillOnce(Return(false)) | ||
| 213 | + .WillRepeatedly(Return(true)); | ||
| 214 | + test_light.getState()["state"]["colormode"] = "xy"; | ||
| 215 | + test_light.getState()["state"]["on"] = true; | ||
| 216 | + test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 217 | + test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 218 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 219 | + | ||
| 220 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 221 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 222 | + | ||
| 223 | + EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 224 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 225 | + | ||
| 226 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 227 | + test_light.getState()["state"]["on"] = false; | ||
| 228 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 229 | + | ||
| 230 | + EXPECT_CALL(test_light, setColorRGB(_, _, _, 1)) | ||
| 231 | + .Times(AtLeast(2)) | ||
| 232 | + .WillOnce(Return(false)) | ||
| 233 | + .WillRepeatedly(Return(true)); | ||
| 234 | + test_light.getState()["state"]["colormode"] = "ct"; | ||
| 235 | + test_light.getState()["state"]["on"] = true; | ||
| 236 | + test_light.getState()["state"]["ct"] = 200; | ||
| 237 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 238 | + | ||
| 239 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 240 | + EXPECT_EQ(false, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 241 | + | ||
| 242 | + EXPECT_CALL(test_light, setColorTemperature(_, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 243 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 244 | + | ||
| 245 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 246 | + test_light.getState()["state"]["on"] = false; | ||
| 247 | + EXPECT_EQ(true, ExtendedColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 248 | +} |
hueplusplus/test/test_ExtendedColorTemperatureStrategy.cpp renamed to src/test/test_ExtendedColorTemperatureStrategy.cpp
100755 → 100644
| 1 | -/** | ||
| 2 | - \file test_ExtendedColorTemperatureStrategy.cpp | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#include <memory> | ||
| 24 | -#include <string> | ||
| 25 | - | ||
| 26 | -#include <gmock/gmock.h> | ||
| 27 | -#include <gtest/gtest.h> | ||
| 28 | - | ||
| 29 | -#include "testhelper.h" | ||
| 30 | - | ||
| 31 | -#include "../include/ExtendedColorTemperatureStrategy.h" | ||
| 32 | -#include "../include/json/json.hpp" | ||
| 33 | -#include "mocks/mock_HttpHandler.h" | ||
| 34 | -#include "mocks/mock_HueLight.h" | ||
| 35 | - | ||
| 36 | -TEST(ExtendedColorTemperatureStrategy, setColorTemperature) | ||
| 37 | -{ | ||
| 38 | - using namespace ::testing; | ||
| 39 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 40 | - EXPECT_CALL( | ||
| 41 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 42 | - .Times(AtLeast(1)) | ||
| 43 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 44 | - MockHueLight test_light(handler); | ||
| 45 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 46 | - nlohmann::json prep_ret; | ||
| 47 | - prep_ret = nlohmann::json::array(); | ||
| 48 | - prep_ret[0] = nlohmann::json::object(); | ||
| 49 | - prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 50 | - prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 51 | - prep_ret[1] = nlohmann::json::object(); | ||
| 52 | - prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 53 | - prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 54 | - prep_ret[2] = nlohmann::json::object(); | ||
| 55 | - prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 56 | - prep_ret[2]["success"]["/lights/1/state/ct"] = 155; | ||
| 57 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 58 | - | ||
| 59 | - test_light.getState()["state"]["colormode"] = "ct"; | ||
| 60 | - test_light.getState()["state"]["on"] = true; | ||
| 61 | - test_light.getState()["state"]["ct"] = 200; | ||
| 62 | - EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(200, 4, test_light)); | ||
| 63 | - | ||
| 64 | - test_light.getState()["state"]["on"] = false; | ||
| 65 | - EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(155, 6, test_light)); | ||
| 66 | - | ||
| 67 | - prep_ret[2]["success"]["/lights/1/state/ct"] = 153; | ||
| 68 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 69 | - EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(0, 6, test_light)); | ||
| 70 | - | ||
| 71 | - prep_ret[2]["success"]["/lights/1/state/ct"] = 500; | ||
| 72 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 73 | - EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(600, 6, test_light)); | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | -TEST(ExtendedColorTemperatureStrategy, alertTemperature) | ||
| 77 | -{ | ||
| 78 | - using namespace ::testing; | ||
| 79 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 80 | - EXPECT_CALL( | ||
| 81 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 82 | - .Times(AtLeast(1)) | ||
| 83 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 84 | - MockHueLight test_light(handler); | ||
| 85 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 86 | - | ||
| 87 | - test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 88 | - test_light.getState()["state"]["on"] = false; | ||
| 89 | - EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 90 | - | ||
| 91 | - EXPECT_CALL(test_light, setColorTemperature(_, _)) | ||
| 92 | - .Times(AtLeast(2)) | ||
| 93 | - .WillOnce(Return(false)) | ||
| 94 | - .WillRepeatedly(Return(true)); | ||
| 95 | - test_light.getState()["state"]["colormode"] = "hs"; | ||
| 96 | - test_light.getState()["state"]["on"] = true; | ||
| 97 | - test_light.getState()["state"]["ct"] = 200; | ||
| 98 | - test_light.getState()["state"]["sat"] = 100; | ||
| 99 | - test_light.getState()["state"]["hue"] = 200; | ||
| 100 | - EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 101 | - | ||
| 102 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 103 | - EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 104 | - | ||
| 105 | - EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 106 | - EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 107 | - | ||
| 108 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 109 | - test_light.getState()["state"]["on"] = false; | ||
| 110 | - EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 111 | - | ||
| 112 | - EXPECT_CALL(test_light, setColorTemperature(_, _)) | ||
| 113 | - .Times(AtLeast(2)) | ||
| 114 | - .WillOnce(Return(false)) | ||
| 115 | - .WillRepeatedly(Return(true)); | ||
| 116 | - test_light.getState()["state"]["colormode"] = "xy"; | ||
| 117 | - test_light.getState()["state"]["on"] = true; | ||
| 118 | - test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 119 | - test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 120 | - EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 121 | - | ||
| 122 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 123 | - EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 124 | - | ||
| 125 | - EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 126 | - EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 127 | - | ||
| 128 | - test_light.getState()["state"]["on"] = false; | ||
| 129 | - EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 130 | - | ||
| 131 | - EXPECT_CALL(test_light, setColorTemperature(_, _)) | ||
| 132 | - .Times(AtLeast(2)) | ||
| 133 | - .WillOnce(Return(false)) | ||
| 134 | - .WillRepeatedly(Return(true)); | ||
| 135 | - test_light.getState()["state"]["colormode"] = "ct"; | ||
| 136 | - test_light.getState()["state"]["on"] = true; | ||
| 137 | - test_light.getState()["state"]["on"] = true; | ||
| 138 | - test_light.getState()["state"]["ct"] = 200; | ||
| 139 | - EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 140 | - | ||
| 141 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 142 | - EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 143 | - | ||
| 144 | - EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 145 | - | ||
| 146 | - test_light.getState()["state"]["on"] = false; | ||
| 147 | - EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 148 | -} | 1 | +/** |
| 2 | + \file test_ExtendedColorTemperatureStrategy.cpp | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#include <memory> | ||
| 24 | +#include <string> | ||
| 25 | + | ||
| 26 | +#include <gmock/gmock.h> | ||
| 27 | +#include <gtest/gtest.h> | ||
| 28 | + | ||
| 29 | +#include "testhelper.h" | ||
| 30 | + | ||
| 31 | +#include "../include/ExtendedColorTemperatureStrategy.h" | ||
| 32 | +#include "../include/json/json.hpp" | ||
| 33 | +#include "mocks/mock_HttpHandler.h" | ||
| 34 | +#include "mocks/mock_HueLight.h" | ||
| 35 | + | ||
| 36 | +TEST(ExtendedColorTemperatureStrategy, setColorTemperature) | ||
| 37 | +{ | ||
| 38 | + using namespace ::testing; | ||
| 39 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 40 | + EXPECT_CALL( | ||
| 41 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 42 | + .Times(AtLeast(1)) | ||
| 43 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 44 | + MockHueLight test_light(handler); | ||
| 45 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 46 | + nlohmann::json prep_ret; | ||
| 47 | + prep_ret = nlohmann::json::array(); | ||
| 48 | + prep_ret[0] = nlohmann::json::object(); | ||
| 49 | + prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 50 | + prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 51 | + prep_ret[1] = nlohmann::json::object(); | ||
| 52 | + prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 53 | + prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 54 | + prep_ret[2] = nlohmann::json::object(); | ||
| 55 | + prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 56 | + prep_ret[2]["success"]["/lights/1/state/ct"] = 155; | ||
| 57 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 58 | + | ||
| 59 | + test_light.getState()["state"]["colormode"] = "ct"; | ||
| 60 | + test_light.getState()["state"]["on"] = true; | ||
| 61 | + test_light.getState()["state"]["ct"] = 200; | ||
| 62 | + EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(200, 4, test_light)); | ||
| 63 | + | ||
| 64 | + test_light.getState()["state"]["on"] = false; | ||
| 65 | + EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(155, 6, test_light)); | ||
| 66 | + | ||
| 67 | + prep_ret[2]["success"]["/lights/1/state/ct"] = 153; | ||
| 68 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 69 | + EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(0, 6, test_light)); | ||
| 70 | + | ||
| 71 | + prep_ret[2]["success"]["/lights/1/state/ct"] = 500; | ||
| 72 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 73 | + EXPECT_EQ(true, ExtendedColorTemperatureStrategy().setColorTemperature(600, 6, test_light)); | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +TEST(ExtendedColorTemperatureStrategy, alertTemperature) | ||
| 77 | +{ | ||
| 78 | + using namespace ::testing; | ||
| 79 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 80 | + EXPECT_CALL( | ||
| 81 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 82 | + .Times(AtLeast(1)) | ||
| 83 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 84 | + MockHueLight test_light(handler); | ||
| 85 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 86 | + | ||
| 87 | + test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 88 | + test_light.getState()["state"]["on"] = false; | ||
| 89 | + EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 90 | + | ||
| 91 | + EXPECT_CALL(test_light, setColorTemperature(_, _)) | ||
| 92 | + .Times(AtLeast(2)) | ||
| 93 | + .WillOnce(Return(false)) | ||
| 94 | + .WillRepeatedly(Return(true)); | ||
| 95 | + test_light.getState()["state"]["colormode"] = "hs"; | ||
| 96 | + test_light.getState()["state"]["on"] = true; | ||
| 97 | + test_light.getState()["state"]["ct"] = 200; | ||
| 98 | + test_light.getState()["state"]["sat"] = 100; | ||
| 99 | + test_light.getState()["state"]["hue"] = 200; | ||
| 100 | + EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 101 | + | ||
| 102 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 103 | + EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 104 | + | ||
| 105 | + EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 106 | + EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 107 | + | ||
| 108 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 109 | + test_light.getState()["state"]["on"] = false; | ||
| 110 | + EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 111 | + | ||
| 112 | + EXPECT_CALL(test_light, setColorTemperature(_, _)) | ||
| 113 | + .Times(AtLeast(2)) | ||
| 114 | + .WillOnce(Return(false)) | ||
| 115 | + .WillRepeatedly(Return(true)); | ||
| 116 | + test_light.getState()["state"]["colormode"] = "xy"; | ||
| 117 | + test_light.getState()["state"]["on"] = true; | ||
| 118 | + test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 119 | + test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 120 | + EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 121 | + | ||
| 122 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 123 | + EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 124 | + | ||
| 125 | + EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 126 | + EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 127 | + | ||
| 128 | + test_light.getState()["state"]["on"] = false; | ||
| 129 | + EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 130 | + | ||
| 131 | + EXPECT_CALL(test_light, setColorTemperature(_, _)) | ||
| 132 | + .Times(AtLeast(2)) | ||
| 133 | + .WillOnce(Return(false)) | ||
| 134 | + .WillRepeatedly(Return(true)); | ||
| 135 | + test_light.getState()["state"]["colormode"] = "ct"; | ||
| 136 | + test_light.getState()["state"]["on"] = true; | ||
| 137 | + test_light.getState()["state"]["on"] = true; | ||
| 138 | + test_light.getState()["state"]["ct"] = 200; | ||
| 139 | + EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 140 | + | ||
| 141 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 142 | + EXPECT_EQ(false, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 143 | + | ||
| 144 | + EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 145 | + | ||
| 146 | + test_light.getState()["state"]["on"] = false; | ||
| 147 | + EXPECT_EQ(true, ExtendedColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 148 | +} |
hueplusplus/test/test_Hue.cpp renamed to src/test/test_Hue.cpp
| 1 | -/** | ||
| 2 | - \file test_Hue.cpp | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#include <atomic> | ||
| 24 | -#include <iostream> | ||
| 25 | -#include <memory> | ||
| 26 | -#include <string> | ||
| 27 | - | ||
| 28 | -#include <gmock/gmock.h> | ||
| 29 | -#include <gtest/gtest.h> | ||
| 30 | - | ||
| 31 | -#include "testhelper.h" | ||
| 32 | - | ||
| 33 | -#include "../include/Hue.h" | ||
| 34 | -#include "../include/json/json.hpp" | ||
| 35 | -#include "mocks/mock_HttpHandler.h" | ||
| 36 | - | ||
| 37 | -class HueFinderTest : public ::testing::Test | ||
| 38 | -{ | ||
| 39 | -protected: | ||
| 40 | - std::shared_ptr<MockHttpHandler> handler; | ||
| 41 | - | ||
| 42 | -protected: | ||
| 43 | - HueFinderTest() : handler(std::make_shared<MockHttpHandler>()) | ||
| 44 | - { | ||
| 45 | - using namespace ::testing; | ||
| 46 | - | ||
| 47 | - EXPECT_CALL(*handler, | ||
| 48 | - sendMulticast("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: " | ||
| 49 | - "\"ssdp:discover\"\r\nMX: 5\r\nST: ssdp:all\r\n\r\n", | ||
| 50 | - "239.255.255.250", 1900, 5)) | ||
| 51 | - .Times(AtLeast(1)) | ||
| 52 | - .WillRepeatedly(Return(getMulticastReply())); | ||
| 53 | - | ||
| 54 | - EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", "192.168.2.1", getBridgePort())) | ||
| 55 | - .Times(0); | ||
| 56 | - | ||
| 57 | - EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), getBridgePort())) | ||
| 58 | - .Times(AtLeast(1)) | ||
| 59 | - .WillRepeatedly(Return(getBridgeXml())); | ||
| 60 | - } | ||
| 61 | - ~HueFinderTest(){}; | ||
| 62 | -}; | ||
| 63 | - | ||
| 64 | -TEST_F(HueFinderTest, FindBridges) | ||
| 65 | -{ | ||
| 66 | - HueFinder finder(handler); | ||
| 67 | - std::vector<HueFinder::HueIdentification> bridges = finder.FindBridges(); | ||
| 68 | - | ||
| 69 | - HueFinder::HueIdentification bridge_to_comp; | ||
| 70 | - bridge_to_comp.ip = getBridgeIp(); | ||
| 71 | - bridge_to_comp.port = getBridgePort(); | ||
| 72 | - bridge_to_comp.mac = getBridgeMac(); | ||
| 73 | - | ||
| 74 | - EXPECT_EQ(bridges.size(), 1) << "HueFinder found more than one Bridge"; | ||
| 75 | - EXPECT_EQ(bridges[0].ip, bridge_to_comp.ip) << "HueIdentification ip does not match"; | ||
| 76 | - EXPECT_EQ(bridges[0].port, bridge_to_comp.port) << "HueIdentification port does not match"; | ||
| 77 | - EXPECT_EQ(bridges[0].mac, bridge_to_comp.mac) << "HueIdentification mac does not match"; | ||
| 78 | - | ||
| 79 | - // Test invalid description | ||
| 80 | - EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), getBridgePort())) | ||
| 81 | - .Times(1) | ||
| 82 | - .WillOnce(::testing::Return("invalid stuff")); | ||
| 83 | - bridges = finder.FindBridges(); | ||
| 84 | - EXPECT_TRUE(bridges.empty()); | ||
| 85 | -} | ||
| 86 | - | ||
| 87 | -TEST_F(HueFinderTest, GetBridge) | ||
| 88 | -{ | ||
| 89 | - using namespace ::testing; | ||
| 90 | - nlohmann::json request{{"devicetype", "HuePlusPlus#User"}}; | ||
| 91 | - | ||
| 92 | - nlohmann::json errorResponse | ||
| 93 | - = {{{"error", {{"type", 101}, {"address", ""}, {"description", "link button not pressed"}}}}}; | ||
| 94 | - | ||
| 95 | - EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort())) | ||
| 96 | - .Times(AtLeast(1)) | ||
| 97 | - .WillRepeatedly(Return(errorResponse)); | ||
| 98 | - | ||
| 99 | - HueFinder finder(handler); | ||
| 100 | - std::vector<HueFinder::HueIdentification> bridges = finder.FindBridges(); | ||
| 101 | - | ||
| 102 | - ASSERT_THROW(finder.GetBridge(bridges[0]), HueException); | ||
| 103 | - | ||
| 104 | - nlohmann::json successResponse = {{{"success", {{"username", getBridgeUsername()}}}}}; | ||
| 105 | - | ||
| 106 | - EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort())) | ||
| 107 | - .Times(1) | ||
| 108 | - .WillOnce(Return(successResponse)); | ||
| 109 | - | ||
| 110 | - finder = HueFinder(handler); | ||
| 111 | - bridges = finder.FindBridges(); | ||
| 112 | - | ||
| 113 | - Hue test_bridge = finder.GetBridge(bridges[0]); | ||
| 114 | - | ||
| 115 | - EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; | ||
| 116 | - EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching"; | ||
| 117 | - EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching"; | ||
| 118 | - | ||
| 119 | - // Verify that username is correctly set in api requests | ||
| 120 | - nlohmann::json hue_bridge_state{{"lights", {}}}; | ||
| 121 | - EXPECT_CALL( | ||
| 122 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 123 | - .Times(1) | ||
| 124 | - .WillOnce(Return(hue_bridge_state)); | ||
| 125 | - | ||
| 126 | - test_bridge.getAllLights(); | ||
| 127 | - | ||
| 128 | - Mock::VerifyAndClearExpectations(handler.get()); | ||
| 129 | -} | ||
| 130 | - | ||
| 131 | -TEST_F(HueFinderTest, AddUsername) | ||
| 132 | -{ | ||
| 133 | - HueFinder finder(handler); | ||
| 134 | - std::vector<HueFinder::HueIdentification> bridges = finder.FindBridges(); | ||
| 135 | - | ||
| 136 | - finder.AddUsername(bridges[0].mac, getBridgeUsername()); | ||
| 137 | - Hue test_bridge = finder.GetBridge(bridges[0]); | ||
| 138 | - | ||
| 139 | - EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; | ||
| 140 | - EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching"; | ||
| 141 | - EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching"; | ||
| 142 | -} | ||
| 143 | - | ||
| 144 | -TEST_F(HueFinderTest, GetAllUsernames) | ||
| 145 | -{ | ||
| 146 | - HueFinder finder(handler); | ||
| 147 | - std::vector<HueFinder::HueIdentification> bridges = finder.FindBridges(); | ||
| 148 | - | ||
| 149 | - finder.AddUsername(bridges[0].mac, getBridgeUsername()); | ||
| 150 | - | ||
| 151 | - std::map<std::string, std::string> users = finder.GetAllUsernames(); | ||
| 152 | - EXPECT_EQ(users[getBridgeMac()], getBridgeUsername()) << "Username of MAC:" << getBridgeMac() << "not matching"; | ||
| 153 | -} | ||
| 154 | - | ||
| 155 | -TEST(Hue, Constructor) | ||
| 156 | -{ | ||
| 157 | - std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 158 | - Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 159 | - | ||
| 160 | - EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; | ||
| 161 | - EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching"; | ||
| 162 | - EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching"; | ||
| 163 | -} | ||
| 164 | - | ||
| 165 | -TEST(Hue, requestUsername) | ||
| 166 | -{ | ||
| 167 | - using namespace ::testing; | ||
| 168 | - std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 169 | - nlohmann::json request{{"devicetype", "HuePlusPlus#User"}}; | ||
| 170 | - | ||
| 171 | - { | ||
| 172 | - nlohmann::json errorResponse | ||
| 173 | - = {{{"error", {{"type", 101}, {"address", ""}, {"description", "link button not pressed"}}}}}; | ||
| 174 | - | ||
| 175 | - EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort())) | ||
| 176 | - .Times(AtLeast(1)) | ||
| 177 | - .WillRepeatedly(Return(errorResponse)); | ||
| 178 | - | ||
| 179 | - Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); | ||
| 180 | - | ||
| 181 | - std::string username = test_bridge.requestUsername(); | ||
| 182 | - EXPECT_EQ(username, "") << "Returned username not matching"; | ||
| 183 | - EXPECT_EQ(test_bridge.getUsername(), "") << "Bridge username not matching"; | ||
| 184 | - } | ||
| 185 | - | ||
| 186 | - { | ||
| 187 | - // Other error code causes exception | ||
| 188 | - int otherError = 1; | ||
| 189 | - nlohmann::json exceptionResponse | ||
| 190 | - = {{{"error", {{"type", otherError}, {"address", ""}, {"description", "some error"}}}}}; | ||
| 191 | - Hue testBridge(getBridgeIp(), getBridgePort(), "", handler); | ||
| 192 | - | ||
| 193 | - EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort())) | ||
| 194 | - .WillOnce(Return(exceptionResponse)); | ||
| 195 | - | ||
| 196 | - try | ||
| 197 | - { | ||
| 198 | - testBridge.requestUsername(); | ||
| 199 | - FAIL() << "requestUsername did not throw"; | ||
| 200 | - } | ||
| 201 | - catch (const HueAPIResponseException& e) | ||
| 202 | - { | ||
| 203 | - EXPECT_EQ(e.GetErrorNumber(), otherError); | ||
| 204 | - } | ||
| 205 | - catch (const std::exception& e) | ||
| 206 | - { | ||
| 207 | - FAIL() << "wrong exception: " << e.what(); | ||
| 208 | - } | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | - { | ||
| 212 | - nlohmann::json successResponse = {{{"success", {{"username", getBridgeUsername()}}}}}; | ||
| 213 | - EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort())) | ||
| 214 | - .Times(1) | ||
| 215 | - .WillRepeatedly(Return(successResponse)); | ||
| 216 | - | ||
| 217 | - Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); | ||
| 218 | - | ||
| 219 | - std::string username = test_bridge.requestUsername(); | ||
| 220 | - | ||
| 221 | - EXPECT_EQ(username, test_bridge.getUsername()) << "Returned username not matching"; | ||
| 222 | - EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; | ||
| 223 | - EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching"; | ||
| 224 | - | ||
| 225 | - // Verify that username is correctly set in api requests | ||
| 226 | - nlohmann::json hue_bridge_state{{"lights", {}}}; | ||
| 227 | - EXPECT_CALL( | ||
| 228 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 229 | - .Times(1) | ||
| 230 | - .WillOnce(Return(hue_bridge_state)); | ||
| 231 | - | ||
| 232 | - test_bridge.getAllLights(); | ||
| 233 | - } | ||
| 234 | -} | ||
| 235 | - | ||
| 236 | -TEST(Hue, setIP) | ||
| 237 | -{ | ||
| 238 | - std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 239 | - Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); | ||
| 240 | - EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching after initialization"; | ||
| 241 | - test_bridge.setIP("192.168.2.112"); | ||
| 242 | - EXPECT_EQ(test_bridge.getBridgeIP(), "192.168.2.112") << "Bridge IP not matching after setting it"; | ||
| 243 | -} | ||
| 244 | - | ||
| 245 | -TEST(Hue, setPort) | ||
| 246 | -{ | ||
| 247 | - std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 248 | - Hue test_bridge = Hue(getBridgeIp(), getBridgePort(), "", handler); | ||
| 249 | - EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching after initialization"; | ||
| 250 | - test_bridge.setPort(81); | ||
| 251 | - EXPECT_EQ(test_bridge.getBridgePort(), 81) << "Bridge Port not matching after setting it"; | ||
| 252 | -} | ||
| 253 | - | ||
| 254 | -TEST(Hue, getLight) | ||
| 255 | -{ | ||
| 256 | - using namespace ::testing; | ||
| 257 | - std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 258 | - EXPECT_CALL( | ||
| 259 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 260 | - .Times(1); | ||
| 261 | - | ||
| 262 | - Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 263 | - | ||
| 264 | - // Test exception | ||
| 265 | - ASSERT_THROW(test_bridge.getLight(1), HueException); | ||
| 266 | - | ||
| 267 | - nlohmann::json hue_bridge_state{{"lights", | ||
| 268 | - {{"1", | ||
| 269 | - {{"state", | ||
| 270 | - {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, | ||
| 271 | - {"reachable", true}}}, | ||
| 272 | - {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, | ||
| 273 | - {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, | ||
| 274 | - {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}}}; | ||
| 275 | - | ||
| 276 | - EXPECT_CALL( | ||
| 277 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 278 | - .Times(1) | ||
| 279 | - .WillOnce(Return(hue_bridge_state)); | ||
| 280 | - | ||
| 281 | - EXPECT_CALL(*handler, | ||
| 282 | - GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 283 | - .Times(AtLeast(1)) | ||
| 284 | - .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 285 | - | ||
| 286 | - // Test when correct data is sent | ||
| 287 | - HueLight test_light_1 = test_bridge.getLight(1); | ||
| 288 | - EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 289 | - EXPECT_EQ(test_light_1.getColorType(), ColorType::TEMPERATURE); | ||
| 290 | - | ||
| 291 | - // Test again to check whether light is returned directly -> interesting for | ||
| 292 | - // code coverage test | ||
| 293 | - test_light_1 = test_bridge.getLight(1); | ||
| 294 | - EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 295 | - EXPECT_EQ(test_light_1.getColorType(), ColorType::TEMPERATURE); | ||
| 296 | - | ||
| 297 | - // more coverage stuff | ||
| 298 | - hue_bridge_state["lights"]["1"]["modelid"] = "LCT001"; | ||
| 299 | - EXPECT_CALL( | ||
| 300 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 301 | - .Times(1) | ||
| 302 | - .WillOnce(Return(hue_bridge_state)); | ||
| 303 | - | ||
| 304 | - EXPECT_CALL(*handler, | ||
| 305 | - GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 306 | - .Times(AtLeast(1)) | ||
| 307 | - .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 308 | - test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 309 | - | ||
| 310 | - // Test when correct data is sent | ||
| 311 | - test_light_1 = test_bridge.getLight(1); | ||
| 312 | - EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 313 | - EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_B); | ||
| 314 | - | ||
| 315 | - hue_bridge_state["lights"]["1"]["modelid"] = "LCT010"; | ||
| 316 | - EXPECT_CALL( | ||
| 317 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 318 | - .Times(1) | ||
| 319 | - .WillOnce(Return(hue_bridge_state)); | ||
| 320 | - | ||
| 321 | - EXPECT_CALL(*handler, | ||
| 322 | - GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 323 | - .Times(AtLeast(1)) | ||
| 324 | - .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 325 | - test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 326 | - | ||
| 327 | - // Test when correct data is sent | ||
| 328 | - test_light_1 = test_bridge.getLight(1); | ||
| 329 | - EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 330 | - EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_C); | ||
| 331 | - | ||
| 332 | - hue_bridge_state["lights"]["1"]["modelid"] = "LST001"; | ||
| 333 | - EXPECT_CALL( | ||
| 334 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 335 | - .Times(1) | ||
| 336 | - .WillOnce(Return(hue_bridge_state)); | ||
| 337 | - | ||
| 338 | - EXPECT_CALL(*handler, | ||
| 339 | - GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 340 | - .Times(AtLeast(1)) | ||
| 341 | - .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 342 | - test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 343 | - | ||
| 344 | - // Test when correct data is sent | ||
| 345 | - test_light_1 = test_bridge.getLight(1); | ||
| 346 | - EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 347 | - EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_A); | ||
| 348 | - | ||
| 349 | - hue_bridge_state["lights"]["1"]["modelid"] = "LWB004"; | ||
| 350 | - EXPECT_CALL( | ||
| 351 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 352 | - .Times(1) | ||
| 353 | - .WillOnce(Return(hue_bridge_state)); | ||
| 354 | - | ||
| 355 | - EXPECT_CALL(*handler, | ||
| 356 | - GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 357 | - .Times(AtLeast(1)) | ||
| 358 | - .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 359 | - test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 360 | - | ||
| 361 | - // Test when correct data is sent | ||
| 362 | - test_light_1 = test_bridge.getLight(1); | ||
| 363 | - EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 364 | - EXPECT_EQ(test_light_1.getColorType(), ColorType::NONE); | ||
| 365 | - | ||
| 366 | - hue_bridge_state["lights"]["1"]["modelid"] = "ABC000"; | ||
| 367 | - EXPECT_CALL( | ||
| 368 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 369 | - .Times(1) | ||
| 370 | - .WillOnce(Return(hue_bridge_state)); | ||
| 371 | - test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 372 | - ASSERT_THROW(test_bridge.getLight(1), HueException); | ||
| 373 | -} | ||
| 374 | - | ||
| 375 | -TEST(Hue, removeLight) | ||
| 376 | -{ | ||
| 377 | - using namespace ::testing; | ||
| 378 | - std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 379 | - nlohmann::json hue_bridge_state{ {"lights", | ||
| 380 | - {{"1", | ||
| 381 | - {{"state", | ||
| 382 | - {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, | ||
| 383 | - {"reachable", true}}}, | ||
| 384 | - {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, | ||
| 385 | - {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, | ||
| 386 | - {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; | ||
| 387 | - EXPECT_CALL( | ||
| 388 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 389 | - .Times(1) | ||
| 390 | - .WillOnce(Return(hue_bridge_state)); | ||
| 391 | - | ||
| 392 | - Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 393 | - | ||
| 394 | - EXPECT_CALL(*handler, | ||
| 395 | - GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 396 | - .Times(1) | ||
| 397 | - .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 398 | - | ||
| 399 | - nlohmann::json return_answer; | ||
| 400 | - return_answer = nlohmann::json::array(); | ||
| 401 | - return_answer[0] = nlohmann::json::object(); | ||
| 402 | - return_answer[0]["success"] = "/lights/1 deleted"; | ||
| 403 | - EXPECT_CALL(*handler, | ||
| 404 | - DELETEJson( | ||
| 405 | - "/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 406 | - .Times(2) | ||
| 407 | - .WillOnce(Return(return_answer)) | ||
| 408 | - .WillOnce(Return(nlohmann::json())); | ||
| 409 | - | ||
| 410 | - // Test when correct data is sent | ||
| 411 | - HueLight test_light_1 = test_bridge.getLight(1); | ||
| 412 | - | ||
| 413 | - EXPECT_EQ(test_bridge.removeLight(1), true); | ||
| 414 | - | ||
| 415 | - EXPECT_EQ(test_bridge.removeLight(1), false); | ||
| 416 | -} | ||
| 417 | - | ||
| 418 | -TEST(Hue, getAllLights) | ||
| 419 | -{ | ||
| 420 | - using namespace ::testing; | ||
| 421 | - std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 422 | - nlohmann::json hue_bridge_state{ {"lights", | ||
| 423 | - {{"1", | ||
| 424 | - {{"state", | ||
| 425 | - {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, | ||
| 426 | - {"reachable", true}}}, | ||
| 427 | - {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, | ||
| 428 | - {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, | ||
| 429 | - {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; | ||
| 430 | - | ||
| 431 | - EXPECT_CALL( | ||
| 432 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 433 | - .Times(2) | ||
| 434 | - .WillRepeatedly(Return(hue_bridge_state)); | ||
| 435 | - | ||
| 436 | - EXPECT_CALL(*handler, | ||
| 437 | - GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 438 | - .Times(2) | ||
| 439 | - .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 440 | - | ||
| 441 | - Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 442 | - | ||
| 443 | - std::vector<std::reference_wrapper<HueLight>> test_lights = test_bridge.getAllLights(); | ||
| 444 | - ASSERT_EQ(1, test_lights.size()); | ||
| 445 | - EXPECT_EQ(test_lights[0].get().getName(), "Hue ambiance lamp 1"); | ||
| 446 | - EXPECT_EQ(test_lights[0].get().getColorType(), ColorType::TEMPERATURE); | ||
| 447 | -} | ||
| 448 | - | ||
| 449 | -TEST(Hue, lightExists) | ||
| 450 | -{ | ||
| 451 | - using namespace ::testing; | ||
| 452 | - std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 453 | - nlohmann::json hue_bridge_state{ {"lights", | ||
| 454 | - {{"1", | ||
| 455 | - {{"state", | ||
| 456 | - {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, | ||
| 457 | - {"reachable", true}}}, | ||
| 458 | - {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, | ||
| 459 | - {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, | ||
| 460 | - {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; | ||
| 461 | - EXPECT_CALL( | ||
| 462 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 463 | - .Times(AtLeast(2)) | ||
| 464 | - .WillRepeatedly(Return(hue_bridge_state)); | ||
| 465 | - EXPECT_CALL(*handler, | ||
| 466 | - GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 467 | - .Times(AtLeast(1)) | ||
| 468 | - .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 469 | - | ||
| 470 | - Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 471 | - | ||
| 472 | - EXPECT_EQ(true, test_bridge.lightExists(1)); | ||
| 473 | - EXPECT_EQ(false, test_bridge.lightExists(2)); | ||
| 474 | - | ||
| 475 | - const Hue const_test_bridge1 = test_bridge; | ||
| 476 | - EXPECT_EQ(true, const_test_bridge1.lightExists(1)); | ||
| 477 | - EXPECT_EQ(false, const_test_bridge1.lightExists(2)); | ||
| 478 | - | ||
| 479 | - test_bridge.getLight(1); | ||
| 480 | - const Hue const_test_bridge2 = test_bridge; | ||
| 481 | - EXPECT_EQ(true, test_bridge.lightExists(1)); | ||
| 482 | - EXPECT_EQ(true, const_test_bridge2.lightExists(1)); | ||
| 483 | -} | ||
| 484 | - | ||
| 485 | -TEST(Hue, getPictureOfLight) | ||
| 486 | -{ | ||
| 487 | - using namespace ::testing; | ||
| 488 | - std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 489 | - nlohmann::json hue_bridge_state{ {"lights", | ||
| 490 | - {{"1", | ||
| 491 | - {{"state", | ||
| 492 | - {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, | ||
| 493 | - {"reachable", true}}}, | ||
| 494 | - {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, | ||
| 495 | - {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, | ||
| 496 | - {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; | ||
| 497 | - | ||
| 498 | - EXPECT_CALL( | ||
| 499 | - *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 500 | - .Times(AtLeast(1)) | ||
| 501 | - .WillRepeatedly(Return(hue_bridge_state)); | ||
| 502 | - EXPECT_CALL(*handler, | ||
| 503 | - GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 504 | - .Times(AtLeast(1)) | ||
| 505 | - .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 506 | - | ||
| 507 | - Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 508 | - | ||
| 509 | - test_bridge.getLight(1); | ||
| 510 | - | ||
| 511 | - EXPECT_EQ("", test_bridge.getPictureOfLight(2)); | ||
| 512 | - | ||
| 513 | - EXPECT_EQ("e27_waca", test_bridge.getPictureOfLight(1)); | ||
| 514 | -} | ||
| 515 | - | ||
| 516 | -TEST(Hue, refreshState) | ||
| 517 | -{ | ||
| 518 | - std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 519 | - Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); // NULL as username leads to segfault | ||
| 520 | - | ||
| 521 | - std::vector<std::reference_wrapper<HueLight>> test_lights = test_bridge.getAllLights(); | ||
| 522 | - EXPECT_EQ(test_lights.size(), 0); | ||
| 523 | -} | 1 | +/** |
| 2 | + \file test_Hue.cpp | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#include <atomic> | ||
| 24 | +#include <iostream> | ||
| 25 | +#include <memory> | ||
| 26 | +#include <string> | ||
| 27 | + | ||
| 28 | +#include <gmock/gmock.h> | ||
| 29 | +#include <gtest/gtest.h> | ||
| 30 | + | ||
| 31 | +#include "testhelper.h" | ||
| 32 | + | ||
| 33 | +#include "../include/Hue.h" | ||
| 34 | +#include "../include/json/json.hpp" | ||
| 35 | +#include "mocks/mock_HttpHandler.h" | ||
| 36 | + | ||
| 37 | +class HueFinderTest : public ::testing::Test | ||
| 38 | +{ | ||
| 39 | +protected: | ||
| 40 | + std::shared_ptr<MockHttpHandler> handler; | ||
| 41 | + | ||
| 42 | +protected: | ||
| 43 | + HueFinderTest() : handler(std::make_shared<MockHttpHandler>()) | ||
| 44 | + { | ||
| 45 | + using namespace ::testing; | ||
| 46 | + | ||
| 47 | + EXPECT_CALL(*handler, | ||
| 48 | + sendMulticast("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: " | ||
| 49 | + "\"ssdp:discover\"\r\nMX: 5\r\nST: ssdp:all\r\n\r\n", | ||
| 50 | + "239.255.255.250", 1900, 5)) | ||
| 51 | + .Times(AtLeast(1)) | ||
| 52 | + .WillRepeatedly(Return(getMulticastReply())); | ||
| 53 | + | ||
| 54 | + EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", "192.168.2.1", getBridgePort())) | ||
| 55 | + .Times(0); | ||
| 56 | + | ||
| 57 | + EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), getBridgePort())) | ||
| 58 | + .Times(AtLeast(1)) | ||
| 59 | + .WillRepeatedly(Return(getBridgeXml())); | ||
| 60 | + } | ||
| 61 | + ~HueFinderTest(){}; | ||
| 62 | +}; | ||
| 63 | + | ||
| 64 | +TEST_F(HueFinderTest, FindBridges) | ||
| 65 | +{ | ||
| 66 | + HueFinder finder(handler); | ||
| 67 | + std::vector<HueFinder::HueIdentification> bridges = finder.FindBridges(); | ||
| 68 | + | ||
| 69 | + HueFinder::HueIdentification bridge_to_comp; | ||
| 70 | + bridge_to_comp.ip = getBridgeIp(); | ||
| 71 | + bridge_to_comp.port = getBridgePort(); | ||
| 72 | + bridge_to_comp.mac = getBridgeMac(); | ||
| 73 | + | ||
| 74 | + EXPECT_EQ(bridges.size(), 1) << "HueFinder found more than one Bridge"; | ||
| 75 | + EXPECT_EQ(bridges[0].ip, bridge_to_comp.ip) << "HueIdentification ip does not match"; | ||
| 76 | + EXPECT_EQ(bridges[0].port, bridge_to_comp.port) << "HueIdentification port does not match"; | ||
| 77 | + EXPECT_EQ(bridges[0].mac, bridge_to_comp.mac) << "HueIdentification mac does not match"; | ||
| 78 | + | ||
| 79 | + // Test invalid description | ||
| 80 | + EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), getBridgePort())) | ||
| 81 | + .Times(1) | ||
| 82 | + .WillOnce(::testing::Return("invalid stuff")); | ||
| 83 | + bridges = finder.FindBridges(); | ||
| 84 | + EXPECT_TRUE(bridges.empty()); | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +TEST_F(HueFinderTest, GetBridge) | ||
| 88 | +{ | ||
| 89 | + using namespace ::testing; | ||
| 90 | + nlohmann::json request{{"devicetype", "HuePlusPlus#User"}}; | ||
| 91 | + | ||
| 92 | + nlohmann::json errorResponse | ||
| 93 | + = {{{"error", {{"type", 101}, {"address", ""}, {"description", "link button not pressed"}}}}}; | ||
| 94 | + | ||
| 95 | + EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort())) | ||
| 96 | + .Times(AtLeast(1)) | ||
| 97 | + .WillRepeatedly(Return(errorResponse)); | ||
| 98 | + | ||
| 99 | + HueFinder finder(handler); | ||
| 100 | + std::vector<HueFinder::HueIdentification> bridges = finder.FindBridges(); | ||
| 101 | + | ||
| 102 | + ASSERT_THROW(finder.GetBridge(bridges[0]), HueException); | ||
| 103 | + | ||
| 104 | + nlohmann::json successResponse = {{{"success", {{"username", getBridgeUsername()}}}}}; | ||
| 105 | + | ||
| 106 | + EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort())) | ||
| 107 | + .Times(1) | ||
| 108 | + .WillOnce(Return(successResponse)); | ||
| 109 | + | ||
| 110 | + finder = HueFinder(handler); | ||
| 111 | + bridges = finder.FindBridges(); | ||
| 112 | + | ||
| 113 | + Hue test_bridge = finder.GetBridge(bridges[0]); | ||
| 114 | + | ||
| 115 | + EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; | ||
| 116 | + EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching"; | ||
| 117 | + EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching"; | ||
| 118 | + | ||
| 119 | + // Verify that username is correctly set in api requests | ||
| 120 | + nlohmann::json hue_bridge_state{{"lights", {}}}; | ||
| 121 | + EXPECT_CALL( | ||
| 122 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 123 | + .Times(1) | ||
| 124 | + .WillOnce(Return(hue_bridge_state)); | ||
| 125 | + | ||
| 126 | + test_bridge.getAllLights(); | ||
| 127 | + | ||
| 128 | + Mock::VerifyAndClearExpectations(handler.get()); | ||
| 129 | +} | ||
| 130 | + | ||
| 131 | +TEST_F(HueFinderTest, AddUsername) | ||
| 132 | +{ | ||
| 133 | + HueFinder finder(handler); | ||
| 134 | + std::vector<HueFinder::HueIdentification> bridges = finder.FindBridges(); | ||
| 135 | + | ||
| 136 | + finder.AddUsername(bridges[0].mac, getBridgeUsername()); | ||
| 137 | + Hue test_bridge = finder.GetBridge(bridges[0]); | ||
| 138 | + | ||
| 139 | + EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; | ||
| 140 | + EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching"; | ||
| 141 | + EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching"; | ||
| 142 | +} | ||
| 143 | + | ||
| 144 | +TEST_F(HueFinderTest, GetAllUsernames) | ||
| 145 | +{ | ||
| 146 | + HueFinder finder(handler); | ||
| 147 | + std::vector<HueFinder::HueIdentification> bridges = finder.FindBridges(); | ||
| 148 | + | ||
| 149 | + finder.AddUsername(bridges[0].mac, getBridgeUsername()); | ||
| 150 | + | ||
| 151 | + std::map<std::string, std::string> users = finder.GetAllUsernames(); | ||
| 152 | + EXPECT_EQ(users[getBridgeMac()], getBridgeUsername()) << "Username of MAC:" << getBridgeMac() << "not matching"; | ||
| 153 | +} | ||
| 154 | + | ||
| 155 | +TEST(Hue, Constructor) | ||
| 156 | +{ | ||
| 157 | + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 158 | + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 159 | + | ||
| 160 | + EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; | ||
| 161 | + EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching"; | ||
| 162 | + EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching"; | ||
| 163 | +} | ||
| 164 | + | ||
| 165 | +TEST(Hue, requestUsername) | ||
| 166 | +{ | ||
| 167 | + using namespace ::testing; | ||
| 168 | + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 169 | + nlohmann::json request{{"devicetype", "HuePlusPlus#User"}}; | ||
| 170 | + | ||
| 171 | + { | ||
| 172 | + nlohmann::json errorResponse | ||
| 173 | + = {{{"error", {{"type", 101}, {"address", ""}, {"description", "link button not pressed"}}}}}; | ||
| 174 | + | ||
| 175 | + EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort())) | ||
| 176 | + .Times(AtLeast(1)) | ||
| 177 | + .WillRepeatedly(Return(errorResponse)); | ||
| 178 | + | ||
| 179 | + Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); | ||
| 180 | + | ||
| 181 | + std::string username = test_bridge.requestUsername(); | ||
| 182 | + EXPECT_EQ(username, "") << "Returned username not matching"; | ||
| 183 | + EXPECT_EQ(test_bridge.getUsername(), "") << "Bridge username not matching"; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + { | ||
| 187 | + // Other error code causes exception | ||
| 188 | + int otherError = 1; | ||
| 189 | + nlohmann::json exceptionResponse | ||
| 190 | + = {{{"error", {{"type", otherError}, {"address", ""}, {"description", "some error"}}}}}; | ||
| 191 | + Hue testBridge(getBridgeIp(), getBridgePort(), "", handler); | ||
| 192 | + | ||
| 193 | + EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort())) | ||
| 194 | + .WillOnce(Return(exceptionResponse)); | ||
| 195 | + | ||
| 196 | + try | ||
| 197 | + { | ||
| 198 | + testBridge.requestUsername(); | ||
| 199 | + FAIL() << "requestUsername did not throw"; | ||
| 200 | + } | ||
| 201 | + catch (const HueAPIResponseException& e) | ||
| 202 | + { | ||
| 203 | + EXPECT_EQ(e.GetErrorNumber(), otherError); | ||
| 204 | + } | ||
| 205 | + catch (const std::exception& e) | ||
| 206 | + { | ||
| 207 | + FAIL() << "wrong exception: " << e.what(); | ||
| 208 | + } | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + { | ||
| 212 | + nlohmann::json successResponse = {{{"success", {{"username", getBridgeUsername()}}}}}; | ||
| 213 | + EXPECT_CALL(*handler, POSTJson("/api", request, getBridgeIp(), getBridgePort())) | ||
| 214 | + .Times(1) | ||
| 215 | + .WillRepeatedly(Return(successResponse)); | ||
| 216 | + | ||
| 217 | + Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); | ||
| 218 | + | ||
| 219 | + std::string username = test_bridge.requestUsername(); | ||
| 220 | + | ||
| 221 | + EXPECT_EQ(username, test_bridge.getUsername()) << "Returned username not matching"; | ||
| 222 | + EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; | ||
| 223 | + EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching"; | ||
| 224 | + | ||
| 225 | + // Verify that username is correctly set in api requests | ||
| 226 | + nlohmann::json hue_bridge_state{{"lights", {}}}; | ||
| 227 | + EXPECT_CALL( | ||
| 228 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 229 | + .Times(1) | ||
| 230 | + .WillOnce(Return(hue_bridge_state)); | ||
| 231 | + | ||
| 232 | + test_bridge.getAllLights(); | ||
| 233 | + } | ||
| 234 | +} | ||
| 235 | + | ||
| 236 | +TEST(Hue, setIP) | ||
| 237 | +{ | ||
| 238 | + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 239 | + Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); | ||
| 240 | + EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching after initialization"; | ||
| 241 | + test_bridge.setIP("192.168.2.112"); | ||
| 242 | + EXPECT_EQ(test_bridge.getBridgeIP(), "192.168.2.112") << "Bridge IP not matching after setting it"; | ||
| 243 | +} | ||
| 244 | + | ||
| 245 | +TEST(Hue, setPort) | ||
| 246 | +{ | ||
| 247 | + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 248 | + Hue test_bridge = Hue(getBridgeIp(), getBridgePort(), "", handler); | ||
| 249 | + EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching after initialization"; | ||
| 250 | + test_bridge.setPort(81); | ||
| 251 | + EXPECT_EQ(test_bridge.getBridgePort(), 81) << "Bridge Port not matching after setting it"; | ||
| 252 | +} | ||
| 253 | + | ||
| 254 | +TEST(Hue, getLight) | ||
| 255 | +{ | ||
| 256 | + using namespace ::testing; | ||
| 257 | + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 258 | + EXPECT_CALL( | ||
| 259 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 260 | + .Times(1); | ||
| 261 | + | ||
| 262 | + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 263 | + | ||
| 264 | + // Test exception | ||
| 265 | + ASSERT_THROW(test_bridge.getLight(1), HueException); | ||
| 266 | + | ||
| 267 | + nlohmann::json hue_bridge_state{{"lights", | ||
| 268 | + {{"1", | ||
| 269 | + {{"state", | ||
| 270 | + {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, | ||
| 271 | + {"reachable", true}}}, | ||
| 272 | + {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, | ||
| 273 | + {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, | ||
| 274 | + {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}}}; | ||
| 275 | + | ||
| 276 | + EXPECT_CALL( | ||
| 277 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 278 | + .Times(1) | ||
| 279 | + .WillOnce(Return(hue_bridge_state)); | ||
| 280 | + | ||
| 281 | + EXPECT_CALL(*handler, | ||
| 282 | + GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 283 | + .Times(AtLeast(1)) | ||
| 284 | + .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 285 | + | ||
| 286 | + // Test when correct data is sent | ||
| 287 | + HueLight test_light_1 = test_bridge.getLight(1); | ||
| 288 | + EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 289 | + EXPECT_EQ(test_light_1.getColorType(), ColorType::TEMPERATURE); | ||
| 290 | + | ||
| 291 | + // Test again to check whether light is returned directly -> interesting for | ||
| 292 | + // code coverage test | ||
| 293 | + test_light_1 = test_bridge.getLight(1); | ||
| 294 | + EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 295 | + EXPECT_EQ(test_light_1.getColorType(), ColorType::TEMPERATURE); | ||
| 296 | + | ||
| 297 | + // more coverage stuff | ||
| 298 | + hue_bridge_state["lights"]["1"]["modelid"] = "LCT001"; | ||
| 299 | + EXPECT_CALL( | ||
| 300 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 301 | + .Times(1) | ||
| 302 | + .WillOnce(Return(hue_bridge_state)); | ||
| 303 | + | ||
| 304 | + EXPECT_CALL(*handler, | ||
| 305 | + GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 306 | + .Times(AtLeast(1)) | ||
| 307 | + .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 308 | + test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 309 | + | ||
| 310 | + // Test when correct data is sent | ||
| 311 | + test_light_1 = test_bridge.getLight(1); | ||
| 312 | + EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 313 | + EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_B); | ||
| 314 | + | ||
| 315 | + hue_bridge_state["lights"]["1"]["modelid"] = "LCT010"; | ||
| 316 | + EXPECT_CALL( | ||
| 317 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 318 | + .Times(1) | ||
| 319 | + .WillOnce(Return(hue_bridge_state)); | ||
| 320 | + | ||
| 321 | + EXPECT_CALL(*handler, | ||
| 322 | + GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 323 | + .Times(AtLeast(1)) | ||
| 324 | + .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 325 | + test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 326 | + | ||
| 327 | + // Test when correct data is sent | ||
| 328 | + test_light_1 = test_bridge.getLight(1); | ||
| 329 | + EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 330 | + EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_C); | ||
| 331 | + | ||
| 332 | + hue_bridge_state["lights"]["1"]["modelid"] = "LST001"; | ||
| 333 | + EXPECT_CALL( | ||
| 334 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 335 | + .Times(1) | ||
| 336 | + .WillOnce(Return(hue_bridge_state)); | ||
| 337 | + | ||
| 338 | + EXPECT_CALL(*handler, | ||
| 339 | + GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 340 | + .Times(AtLeast(1)) | ||
| 341 | + .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 342 | + test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 343 | + | ||
| 344 | + // Test when correct data is sent | ||
| 345 | + test_light_1 = test_bridge.getLight(1); | ||
| 346 | + EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 347 | + EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_A); | ||
| 348 | + | ||
| 349 | + hue_bridge_state["lights"]["1"]["modelid"] = "LWB004"; | ||
| 350 | + EXPECT_CALL( | ||
| 351 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 352 | + .Times(1) | ||
| 353 | + .WillOnce(Return(hue_bridge_state)); | ||
| 354 | + | ||
| 355 | + EXPECT_CALL(*handler, | ||
| 356 | + GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 357 | + .Times(AtLeast(1)) | ||
| 358 | + .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 359 | + test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 360 | + | ||
| 361 | + // Test when correct data is sent | ||
| 362 | + test_light_1 = test_bridge.getLight(1); | ||
| 363 | + EXPECT_EQ(test_light_1.getName(), "Hue ambiance lamp 1"); | ||
| 364 | + EXPECT_EQ(test_light_1.getColorType(), ColorType::NONE); | ||
| 365 | + | ||
| 366 | + hue_bridge_state["lights"]["1"]["modelid"] = "ABC000"; | ||
| 367 | + EXPECT_CALL( | ||
| 368 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 369 | + .Times(1) | ||
| 370 | + .WillOnce(Return(hue_bridge_state)); | ||
| 371 | + test_bridge = Hue(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 372 | + ASSERT_THROW(test_bridge.getLight(1), HueException); | ||
| 373 | +} | ||
| 374 | + | ||
| 375 | +TEST(Hue, removeLight) | ||
| 376 | +{ | ||
| 377 | + using namespace ::testing; | ||
| 378 | + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 379 | + nlohmann::json hue_bridge_state{ {"lights", | ||
| 380 | + {{"1", | ||
| 381 | + {{"state", | ||
| 382 | + {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, | ||
| 383 | + {"reachable", true}}}, | ||
| 384 | + {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, | ||
| 385 | + {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, | ||
| 386 | + {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; | ||
| 387 | + EXPECT_CALL( | ||
| 388 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 389 | + .Times(1) | ||
| 390 | + .WillOnce(Return(hue_bridge_state)); | ||
| 391 | + | ||
| 392 | + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 393 | + | ||
| 394 | + EXPECT_CALL(*handler, | ||
| 395 | + GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 396 | + .Times(1) | ||
| 397 | + .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 398 | + | ||
| 399 | + nlohmann::json return_answer; | ||
| 400 | + return_answer = nlohmann::json::array(); | ||
| 401 | + return_answer[0] = nlohmann::json::object(); | ||
| 402 | + return_answer[0]["success"] = "/lights/1 deleted"; | ||
| 403 | + EXPECT_CALL(*handler, | ||
| 404 | + DELETEJson( | ||
| 405 | + "/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 406 | + .Times(2) | ||
| 407 | + .WillOnce(Return(return_answer)) | ||
| 408 | + .WillOnce(Return(nlohmann::json())); | ||
| 409 | + | ||
| 410 | + // Test when correct data is sent | ||
| 411 | + HueLight test_light_1 = test_bridge.getLight(1); | ||
| 412 | + | ||
| 413 | + EXPECT_EQ(test_bridge.removeLight(1), true); | ||
| 414 | + | ||
| 415 | + EXPECT_EQ(test_bridge.removeLight(1), false); | ||
| 416 | +} | ||
| 417 | + | ||
| 418 | +TEST(Hue, getAllLights) | ||
| 419 | +{ | ||
| 420 | + using namespace ::testing; | ||
| 421 | + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 422 | + nlohmann::json hue_bridge_state{ {"lights", | ||
| 423 | + {{"1", | ||
| 424 | + {{"state", | ||
| 425 | + {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, | ||
| 426 | + {"reachable", true}}}, | ||
| 427 | + {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, | ||
| 428 | + {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, | ||
| 429 | + {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; | ||
| 430 | + | ||
| 431 | + EXPECT_CALL( | ||
| 432 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 433 | + .Times(2) | ||
| 434 | + .WillRepeatedly(Return(hue_bridge_state)); | ||
| 435 | + | ||
| 436 | + EXPECT_CALL(*handler, | ||
| 437 | + GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 438 | + .Times(2) | ||
| 439 | + .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 440 | + | ||
| 441 | + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 442 | + | ||
| 443 | + std::vector<std::reference_wrapper<HueLight>> test_lights = test_bridge.getAllLights(); | ||
| 444 | + ASSERT_EQ(1, test_lights.size()); | ||
| 445 | + EXPECT_EQ(test_lights[0].get().getName(), "Hue ambiance lamp 1"); | ||
| 446 | + EXPECT_EQ(test_lights[0].get().getColorType(), ColorType::TEMPERATURE); | ||
| 447 | +} | ||
| 448 | + | ||
| 449 | +TEST(Hue, lightExists) | ||
| 450 | +{ | ||
| 451 | + using namespace ::testing; | ||
| 452 | + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 453 | + nlohmann::json hue_bridge_state{ {"lights", | ||
| 454 | + {{"1", | ||
| 455 | + {{"state", | ||
| 456 | + {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, | ||
| 457 | + {"reachable", true}}}, | ||
| 458 | + {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, | ||
| 459 | + {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, | ||
| 460 | + {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; | ||
| 461 | + EXPECT_CALL( | ||
| 462 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 463 | + .Times(AtLeast(2)) | ||
| 464 | + .WillRepeatedly(Return(hue_bridge_state)); | ||
| 465 | + EXPECT_CALL(*handler, | ||
| 466 | + GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 467 | + .Times(AtLeast(1)) | ||
| 468 | + .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 469 | + | ||
| 470 | + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 471 | + | ||
| 472 | + EXPECT_EQ(true, test_bridge.lightExists(1)); | ||
| 473 | + EXPECT_EQ(false, test_bridge.lightExists(2)); | ||
| 474 | + | ||
| 475 | + const Hue const_test_bridge1 = test_bridge; | ||
| 476 | + EXPECT_EQ(true, const_test_bridge1.lightExists(1)); | ||
| 477 | + EXPECT_EQ(false, const_test_bridge1.lightExists(2)); | ||
| 478 | + | ||
| 479 | + test_bridge.getLight(1); | ||
| 480 | + const Hue const_test_bridge2 = test_bridge; | ||
| 481 | + EXPECT_EQ(true, test_bridge.lightExists(1)); | ||
| 482 | + EXPECT_EQ(true, const_test_bridge2.lightExists(1)); | ||
| 483 | +} | ||
| 484 | + | ||
| 485 | +TEST(Hue, getPictureOfLight) | ||
| 486 | +{ | ||
| 487 | + using namespace ::testing; | ||
| 488 | + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 489 | + nlohmann::json hue_bridge_state{ {"lights", | ||
| 490 | + {{"1", | ||
| 491 | + {{"state", | ||
| 492 | + {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, | ||
| 493 | + {"reachable", true}}}, | ||
| 494 | + {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, | ||
| 495 | + {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, | ||
| 496 | + {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; | ||
| 497 | + | ||
| 498 | + EXPECT_CALL( | ||
| 499 | + *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 500 | + .Times(AtLeast(1)) | ||
| 501 | + .WillRepeatedly(Return(hue_bridge_state)); | ||
| 502 | + EXPECT_CALL(*handler, | ||
| 503 | + GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), getBridgePort())) | ||
| 504 | + .Times(AtLeast(1)) | ||
| 505 | + .WillRepeatedly(Return(hue_bridge_state["lights"]["1"])); | ||
| 506 | + | ||
| 507 | + Hue test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler); | ||
| 508 | + | ||
| 509 | + test_bridge.getLight(1); | ||
| 510 | + | ||
| 511 | + EXPECT_EQ("", test_bridge.getPictureOfLight(2)); | ||
| 512 | + | ||
| 513 | + EXPECT_EQ("e27_waca", test_bridge.getPictureOfLight(1)); | ||
| 514 | +} | ||
| 515 | + | ||
| 516 | +TEST(Hue, refreshState) | ||
| 517 | +{ | ||
| 518 | + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); | ||
| 519 | + Hue test_bridge(getBridgeIp(), getBridgePort(), "", handler); // NULL as username leads to segfault | ||
| 520 | + | ||
| 521 | + std::vector<std::reference_wrapper<HueLight>> test_lights = test_bridge.getAllLights(); | ||
| 522 | + EXPECT_EQ(test_lights.size(), 0); | ||
| 523 | +} |
hueplusplus/test/test_HueCommandAPI.cpp renamed to src/test/test_HueCommandAPI.cpp
hueplusplus/test/test_HueLight.cpp renamed to src/test/test_HueLight.cpp
hueplusplus/test/test_Main.cpp renamed to src/test/test_Main.cpp
100755 → 100644
| 1 | -/** | ||
| 2 | - \file test_Main.cpp | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#include <gtest/gtest.h> | ||
| 24 | - | ||
| 25 | -int main(int argc, char** argv) | ||
| 26 | -{ | ||
| 27 | - ::testing::InitGoogleTest(&argc, argv); | ||
| 28 | - return RUN_ALL_TESTS(); | ||
| 29 | -} | 1 | +/** |
| 2 | + \file test_Main.cpp | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#include <gtest/gtest.h> | ||
| 24 | + | ||
| 25 | +int main(int argc, char** argv) | ||
| 26 | +{ | ||
| 27 | + ::testing::InitGoogleTest(&argc, argv); | ||
| 28 | + return RUN_ALL_TESTS(); | ||
| 29 | +} |
hueplusplus/test/test_SimpleBrightnessStrategy.cpp renamed to src/test/test_SimpleBrightnessStrategy.cpp
100755 → 100644
| 1 | -/** | ||
| 2 | - \file test_SimpleBrightnessStrategy.cpp | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#include <iostream> | ||
| 24 | -#include <memory> | ||
| 25 | -#include <string> | ||
| 26 | - | ||
| 27 | -#include <gmock/gmock.h> | ||
| 28 | -#include <gtest/gtest.h> | ||
| 29 | - | ||
| 30 | -#include "testhelper.h" | ||
| 31 | - | ||
| 32 | -#include "../include/SimpleBrightnessStrategy.h" | ||
| 33 | -#include "../include/json/json.hpp" | ||
| 34 | -#include "mocks/mock_HttpHandler.h" | ||
| 35 | -#include "mocks/mock_HueLight.h" | ||
| 36 | - | ||
| 37 | -TEST(SimpleBrightnessStrategy, setBrightness) | ||
| 38 | -{ | ||
| 39 | - using namespace ::testing; | ||
| 40 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 41 | - EXPECT_CALL( | ||
| 42 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 43 | - .Times(AtLeast(1)) | ||
| 44 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 45 | - MockHueLight test_light(handler); | ||
| 46 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 47 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 48 | - nlohmann::json prep_ret; | ||
| 49 | - prep_ret = nlohmann::json::array(); | ||
| 50 | - prep_ret[0] = nlohmann::json::object(); | ||
| 51 | - prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 52 | - prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 53 | - prep_ret[1] = nlohmann::json::object(); | ||
| 54 | - prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 55 | - prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 56 | - prep_ret[2] = nlohmann::json::object(); | ||
| 57 | - prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 58 | - prep_ret[2]["success"]["/lights/1/state/bri"] = 50; | ||
| 59 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 60 | - | ||
| 61 | - test_light.getState()["state"]["on"] = true; | ||
| 62 | - EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light)); | ||
| 63 | - test_light.getState()["state"]["on"] = false; | ||
| 64 | - EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light)); | ||
| 65 | - | ||
| 66 | - test_light.getState()["state"]["bri"] = 0; | ||
| 67 | - EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(50, 6, test_light)); | ||
| 68 | - test_light.getState()["state"]["on"] = true; | ||
| 69 | - test_light.getState()["state"]["bri"] = 50; | ||
| 70 | - EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(50, 6, test_light)); | ||
| 71 | - | ||
| 72 | - prep_ret[2]["success"]["/lights/1/state/bri"] = 254; | ||
| 73 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 74 | - test_light.getState()["state"]["on"] = false; | ||
| 75 | - EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(255, 6, test_light)); | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | -TEST(SimpleBrightnessStrategy, getBrightness) | ||
| 79 | -{ | ||
| 80 | - using namespace ::testing; | ||
| 81 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 82 | - EXPECT_CALL( | ||
| 83 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 84 | - .Times(AtLeast(1)) | ||
| 85 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 86 | - MockHueLight test_light(handler); | ||
| 87 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 88 | - | ||
| 89 | - test_light.getState()["state"]["bri"] = 200; | ||
| 90 | - EXPECT_EQ(200, SimpleBrightnessStrategy().getBrightness(test_light)); | ||
| 91 | - test_light.getState()["state"]["bri"] = 0; | ||
| 92 | - EXPECT_EQ(0, SimpleBrightnessStrategy().getBrightness(static_cast<const HueLight>(test_light))); | ||
| 93 | -} | 1 | +/** |
| 2 | + \file test_SimpleBrightnessStrategy.cpp | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#include <iostream> | ||
| 24 | +#include <memory> | ||
| 25 | +#include <string> | ||
| 26 | + | ||
| 27 | +#include <gmock/gmock.h> | ||
| 28 | +#include <gtest/gtest.h> | ||
| 29 | + | ||
| 30 | +#include "testhelper.h" | ||
| 31 | + | ||
| 32 | +#include "../include/SimpleBrightnessStrategy.h" | ||
| 33 | +#include "../include/json/json.hpp" | ||
| 34 | +#include "mocks/mock_HttpHandler.h" | ||
| 35 | +#include "mocks/mock_HueLight.h" | ||
| 36 | + | ||
| 37 | +TEST(SimpleBrightnessStrategy, setBrightness) | ||
| 38 | +{ | ||
| 39 | + using namespace ::testing; | ||
| 40 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 41 | + EXPECT_CALL( | ||
| 42 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 43 | + .Times(AtLeast(1)) | ||
| 44 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 45 | + MockHueLight test_light(handler); | ||
| 46 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 47 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 48 | + nlohmann::json prep_ret; | ||
| 49 | + prep_ret = nlohmann::json::array(); | ||
| 50 | + prep_ret[0] = nlohmann::json::object(); | ||
| 51 | + prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 52 | + prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 53 | + prep_ret[1] = nlohmann::json::object(); | ||
| 54 | + prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 55 | + prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 56 | + prep_ret[2] = nlohmann::json::object(); | ||
| 57 | + prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 58 | + prep_ret[2]["success"]["/lights/1/state/bri"] = 50; | ||
| 59 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 60 | + | ||
| 61 | + test_light.getState()["state"]["on"] = true; | ||
| 62 | + EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light)); | ||
| 63 | + test_light.getState()["state"]["on"] = false; | ||
| 64 | + EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(0, 4, test_light)); | ||
| 65 | + | ||
| 66 | + test_light.getState()["state"]["bri"] = 0; | ||
| 67 | + EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(50, 6, test_light)); | ||
| 68 | + test_light.getState()["state"]["on"] = true; | ||
| 69 | + test_light.getState()["state"]["bri"] = 50; | ||
| 70 | + EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(50, 6, test_light)); | ||
| 71 | + | ||
| 72 | + prep_ret[2]["success"]["/lights/1/state/bri"] = 254; | ||
| 73 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 74 | + test_light.getState()["state"]["on"] = false; | ||
| 75 | + EXPECT_EQ(true, SimpleBrightnessStrategy().setBrightness(255, 6, test_light)); | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +TEST(SimpleBrightnessStrategy, getBrightness) | ||
| 79 | +{ | ||
| 80 | + using namespace ::testing; | ||
| 81 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 82 | + EXPECT_CALL( | ||
| 83 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 84 | + .Times(AtLeast(1)) | ||
| 85 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 86 | + MockHueLight test_light(handler); | ||
| 87 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 88 | + | ||
| 89 | + test_light.getState()["state"]["bri"] = 200; | ||
| 90 | + EXPECT_EQ(200, SimpleBrightnessStrategy().getBrightness(test_light)); | ||
| 91 | + test_light.getState()["state"]["bri"] = 0; | ||
| 92 | + EXPECT_EQ(0, SimpleBrightnessStrategy().getBrightness(static_cast<const HueLight>(test_light))); | ||
| 93 | +} |
hueplusplus/test/test_SimpleColorHueStrategy.cpp renamed to src/test/test_SimpleColorHueStrategy.cpp
100755 → 100644
| 1 | -/** | ||
| 2 | - \file test_SimpleColorHuewStrategy.cpp | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#include <memory> | ||
| 24 | -#include <string> | ||
| 25 | - | ||
| 26 | -#include <gmock/gmock.h> | ||
| 27 | -#include <gtest/gtest.h> | ||
| 28 | - | ||
| 29 | -#include "testhelper.h" | ||
| 30 | - | ||
| 31 | -#include "../include/SimpleColorHueStrategy.h" | ||
| 32 | -#include "../include/json/json.hpp" | ||
| 33 | -#include "mocks/mock_HttpHandler.h" | ||
| 34 | -#include "mocks/mock_HueLight.h" | ||
| 35 | - | ||
| 36 | -TEST(SimpleColorHueStrategy, setColorHue) | ||
| 37 | -{ | ||
| 38 | - using namespace ::testing; | ||
| 39 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 40 | - EXPECT_CALL( | ||
| 41 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 42 | - .Times(AtLeast(1)) | ||
| 43 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 44 | - MockHueLight test_light(handler); | ||
| 45 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 46 | - nlohmann::json prep_ret; | ||
| 47 | - prep_ret = nlohmann::json::array(); | ||
| 48 | - prep_ret[0] = nlohmann::json::object(); | ||
| 49 | - prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 50 | - prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 51 | - prep_ret[1] = nlohmann::json::object(); | ||
| 52 | - prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 53 | - prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 54 | - prep_ret[2] = nlohmann::json::object(); | ||
| 55 | - prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 56 | - prep_ret[2]["success"]["/lights/1/state/hue"] = 30500; | ||
| 57 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 58 | - | ||
| 59 | - test_light.getState()["state"]["on"] = true; | ||
| 60 | - test_light.getState()["state"]["hue"] = 200; | ||
| 61 | - test_light.getState()["state"]["colormode"] = "hs"; | ||
| 62 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorHue(200, 4, test_light)); | ||
| 63 | - | ||
| 64 | - test_light.getState()["state"]["on"] = false; | ||
| 65 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorHue(30500, 6, test_light)); | ||
| 66 | -} | ||
| 67 | - | ||
| 68 | -TEST(SimpleColorHueStrategy, setColorSaturation) | ||
| 69 | -{ | ||
| 70 | - using namespace ::testing; | ||
| 71 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 72 | - EXPECT_CALL( | ||
| 73 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 74 | - .Times(AtLeast(1)) | ||
| 75 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 76 | - MockHueLight test_light(handler); | ||
| 77 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 78 | - nlohmann::json prep_ret; | ||
| 79 | - prep_ret = nlohmann::json::array(); | ||
| 80 | - prep_ret[0] = nlohmann::json::object(); | ||
| 81 | - prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 82 | - prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 83 | - prep_ret[1] = nlohmann::json::object(); | ||
| 84 | - prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 85 | - prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 86 | - prep_ret[2] = nlohmann::json::object(); | ||
| 87 | - prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 88 | - prep_ret[2]["success"]["/lights/1/state/sat"] = 254; | ||
| 89 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 90 | - | ||
| 91 | - test_light.getState()["state"]["on"] = true; | ||
| 92 | - test_light.getState()["state"]["sat"] = 100; | ||
| 93 | - test_light.getState()["state"]["colormode"] = "hs"; | ||
| 94 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorSaturation(100, 4, test_light)); | ||
| 95 | - | ||
| 96 | - test_light.getState()["state"]["on"] = false; | ||
| 97 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorSaturation(255, 6, test_light)); | ||
| 98 | -} | ||
| 99 | - | ||
| 100 | -TEST(SimpleColorHueStrategy, setColorHueSaturation) | ||
| 101 | -{ | ||
| 102 | - using namespace ::testing; | ||
| 103 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 104 | - EXPECT_CALL( | ||
| 105 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 106 | - .Times(AtLeast(1)) | ||
| 107 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 108 | - MockHueLight test_light(handler); | ||
| 109 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 110 | - nlohmann::json prep_ret; | ||
| 111 | - prep_ret = nlohmann::json::array(); | ||
| 112 | - prep_ret[0] = nlohmann::json::object(); | ||
| 113 | - prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 114 | - prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 115 | - prep_ret[1] = nlohmann::json::object(); | ||
| 116 | - prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 117 | - prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 118 | - prep_ret[2] = nlohmann::json::object(); | ||
| 119 | - prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 120 | - prep_ret[2]["success"]["/lights/1/state/hue"] = 30500; | ||
| 121 | - prep_ret[3] = nlohmann::json::object(); | ||
| 122 | - prep_ret[3]["success"] = nlohmann::json::object(); | ||
| 123 | - prep_ret[3]["success"]["/lights/1/state/sat"] = 254; | ||
| 124 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 125 | - | ||
| 126 | - test_light.getState()["state"]["on"] = true; | ||
| 127 | - test_light.getState()["state"]["sat"] = 100; | ||
| 128 | - test_light.getState()["state"]["hue"] = 200; | ||
| 129 | - test_light.getState()["state"]["colormode"] = "hs"; | ||
| 130 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorHueSaturation(200, 100, 4, test_light)); | ||
| 131 | - | ||
| 132 | - test_light.getState()["state"]["on"] = false; | ||
| 133 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorHueSaturation(30500, 255, 6, test_light)); | ||
| 134 | -} | ||
| 135 | - | ||
| 136 | -TEST(SimpleColorHueStrategy, setColorXY) | ||
| 137 | -{ | ||
| 138 | - using namespace ::testing; | ||
| 139 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 140 | - EXPECT_CALL( | ||
| 141 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 142 | - .Times(AtLeast(1)) | ||
| 143 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 144 | - MockHueLight test_light(handler); | ||
| 145 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 146 | - nlohmann::json prep_ret; | ||
| 147 | - prep_ret = nlohmann::json::array(); | ||
| 148 | - prep_ret[0] = nlohmann::json::object(); | ||
| 149 | - prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 150 | - prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 151 | - prep_ret[1] = nlohmann::json::object(); | ||
| 152 | - prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 153 | - prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 154 | - prep_ret[2] = nlohmann::json::object(); | ||
| 155 | - prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 156 | - prep_ret[2]["success"]["/lights/1/state/xy"][0] = 0.2355; | ||
| 157 | - prep_ret[2]["success"]["/lights/1/state/xy"][1] = 0.1234; | ||
| 158 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 159 | - | ||
| 160 | - test_light.getState()["state"]["on"] = true; | ||
| 161 | - test_light.getState()["state"]["xy"][0] = 0.1f; | ||
| 162 | - test_light.getState()["state"]["xy"][1] = 0.1f; | ||
| 163 | - test_light.getState()["state"]["colormode"] = "xy"; | ||
| 164 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorXY(0.1f, 0.1f, 4, test_light)); | ||
| 165 | - | ||
| 166 | - test_light.getState()["state"]["on"] = false; | ||
| 167 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorXY(0.2355f, 0.1234f, 6, test_light)); | ||
| 168 | -} | ||
| 169 | - | ||
| 170 | -TEST(SimpleColorHueStrategy, setColorRGB) | ||
| 171 | -{ | ||
| 172 | - using namespace ::testing; | ||
| 173 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 174 | - EXPECT_CALL( | ||
| 175 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 176 | - .Times(AtLeast(1)) | ||
| 177 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 178 | - MockHueLight test_light(handler); | ||
| 179 | - EXPECT_CALL(test_light, setColorXY(_, _, 4)).Times(2).WillRepeatedly(Return(true)); | ||
| 180 | - | ||
| 181 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(128, 128, 128, 4, test_light)); | ||
| 182 | - | ||
| 183 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(255, 255, 255, 4, test_light)); | ||
| 184 | - | ||
| 185 | - EXPECT_CALL(test_light, OffNoRefresh(4)).Times(1).WillOnce(Return(true)); | ||
| 186 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(0, 0, 0, 4, test_light)); | ||
| 187 | -} | ||
| 188 | - | ||
| 189 | -TEST(SimpleColorHueStrategy, setColorLoop) | ||
| 190 | -{ | ||
| 191 | - using namespace ::testing; | ||
| 192 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 193 | - EXPECT_CALL( | ||
| 194 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 195 | - .Times(AtLeast(1)) | ||
| 196 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 197 | - MockHueLight test_light(handler); | ||
| 198 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 199 | - nlohmann::json prep_ret; | ||
| 200 | - prep_ret = nlohmann::json::array(); | ||
| 201 | - prep_ret[0] = nlohmann::json::object(); | ||
| 202 | - prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 203 | - prep_ret[0]["success"]["/lights/1/state/on"] = true; | ||
| 204 | - prep_ret[1] = nlohmann::json::object(); | ||
| 205 | - prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 206 | - prep_ret[1]["success"]["/lights/1/state/effect"] = "colorloop"; | ||
| 207 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 208 | - | ||
| 209 | - test_light.getState()["state"]["on"] = true; | ||
| 210 | - test_light.getState()["state"]["effect"] = "colorloop"; | ||
| 211 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorLoop(true, test_light)); | ||
| 212 | - | ||
| 213 | - test_light.getState()["state"]["on"] = false; | ||
| 214 | - test_light.getState()["state"]["effect"] = "none"; | ||
| 215 | - EXPECT_EQ(true, SimpleColorHueStrategy().setColorLoop(true, test_light)); | ||
| 216 | -} | ||
| 217 | - | ||
| 218 | -TEST(SimpleColorHueStrategy, alertHueSaturation) | ||
| 219 | -{ | ||
| 220 | - using namespace ::testing; | ||
| 221 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 222 | - EXPECT_CALL( | ||
| 223 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 224 | - .Times(AtLeast(1)) | ||
| 225 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 226 | - MockHueLight test_light(handler); | ||
| 227 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 228 | - | ||
| 229 | - test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 230 | - test_light.getState()["state"]["on"] = false; | ||
| 231 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(30000, 128, test_light)); | ||
| 232 | - | ||
| 233 | - EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)) | ||
| 234 | - .Times(AtLeast(2)) | ||
| 235 | - .WillOnce(Return(false)) | ||
| 236 | - .WillRepeatedly(Return(true)); | ||
| 237 | - test_light.getState()["state"]["colormode"] = "hs"; | ||
| 238 | - test_light.getState()["state"]["on"] = true; | ||
| 239 | - test_light.getState()["state"]["sat"] = 100; | ||
| 240 | - test_light.getState()["state"]["hue"] = 200; | ||
| 241 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 242 | - | ||
| 243 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 244 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 245 | - | ||
| 246 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 247 | - | ||
| 248 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 249 | - test_light.getState()["state"]["on"] = false; | ||
| 250 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 251 | - | ||
| 252 | - EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)) | ||
| 253 | - .Times(AtLeast(2)) | ||
| 254 | - .WillOnce(Return(false)) | ||
| 255 | - .WillRepeatedly(Return(true)); | ||
| 256 | - test_light.getState()["state"]["colormode"] = "xy"; | ||
| 257 | - test_light.getState()["state"]["on"] = true; | ||
| 258 | - test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 259 | - test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 260 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 261 | - | ||
| 262 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 263 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 264 | - | ||
| 265 | - EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 266 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 267 | - | ||
| 268 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 269 | - test_light.getState()["state"]["on"] = false; | ||
| 270 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 271 | -} | ||
| 272 | - | ||
| 273 | -TEST(SimpleColorHueStrategy, alertXY) | ||
| 274 | -{ | ||
| 275 | - using namespace ::testing; | ||
| 276 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 277 | - EXPECT_CALL( | ||
| 278 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 279 | - .Times(AtLeast(1)) | ||
| 280 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 281 | - MockHueLight test_light(handler); | ||
| 282 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 283 | - | ||
| 284 | - test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 285 | - test_light.getState()["state"]["on"] = false; | ||
| 286 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 287 | - | ||
| 288 | - EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 289 | - test_light.getState()["state"]["colormode"] = "hs"; | ||
| 290 | - test_light.getState()["state"]["on"] = true; | ||
| 291 | - test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 292 | - test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 293 | - test_light.getState()["state"]["sat"] = 100; | ||
| 294 | - test_light.getState()["state"]["hue"] = 200; | ||
| 295 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 296 | - | ||
| 297 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 298 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 299 | - | ||
| 300 | - EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 301 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 302 | - | ||
| 303 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 304 | - test_light.getState()["state"]["on"] = false; | ||
| 305 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 306 | - | ||
| 307 | - EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 308 | - test_light.getState()["state"]["colormode"] = "xy"; | ||
| 309 | - test_light.getState()["state"]["on"] = true; | ||
| 310 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 311 | - | ||
| 312 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 313 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 314 | - | ||
| 315 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 316 | - | ||
| 317 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 318 | - test_light.getState()["state"]["on"] = false; | ||
| 319 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 320 | -} | ||
| 321 | - | ||
| 322 | -TEST(SimpleColorHueStrategy, alertRGB) | ||
| 323 | -{ | ||
| 324 | - using namespace ::testing; | ||
| 325 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 326 | - EXPECT_CALL( | ||
| 327 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 328 | - .Times(AtLeast(1)) | ||
| 329 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 330 | - MockHueLight test_light(handler); | ||
| 331 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 332 | - | ||
| 333 | - test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 334 | - test_light.getState()["state"]["on"] = false; | ||
| 335 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 336 | - | ||
| 337 | - EXPECT_CALL(test_light, setColorRGB(_, _, _, 1)) | ||
| 338 | - .Times(AtLeast(2)) | ||
| 339 | - .WillOnce(Return(false)) | ||
| 340 | - .WillRepeatedly(Return(true)); | ||
| 341 | - test_light.getState()["state"]["colormode"] = "hs"; | ||
| 342 | - test_light.getState()["state"]["on"] = true; | ||
| 343 | - test_light.getState()["state"]["sat"] = 100; | ||
| 344 | - test_light.getState()["state"]["hue"] = 200; | ||
| 345 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 346 | - | ||
| 347 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 348 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 349 | - | ||
| 350 | - EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 351 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 352 | - | ||
| 353 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 354 | - test_light.getState()["state"]["on"] = false; | ||
| 355 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 356 | - | ||
| 357 | - EXPECT_CALL(test_light, setColorRGB(_, _, _, 1)) | ||
| 358 | - .Times(AtLeast(2)) | ||
| 359 | - .WillOnce(Return(false)) | ||
| 360 | - .WillRepeatedly(Return(true)); | ||
| 361 | - test_light.getState()["state"]["colormode"] = "xy"; | ||
| 362 | - test_light.getState()["state"]["on"] = true; | ||
| 363 | - test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 364 | - test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 365 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 366 | - | ||
| 367 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 368 | - EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 369 | - | ||
| 370 | - EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 371 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 372 | - | ||
| 373 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 374 | - test_light.getState()["state"]["on"] = false; | ||
| 375 | - EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 376 | -} | ||
| 377 | - | ||
| 378 | -TEST(SimpleColorHueStrategy, getColorHueSaturation) | ||
| 379 | -{ | ||
| 380 | - using namespace ::testing; | ||
| 381 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 382 | - EXPECT_CALL( | ||
| 383 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 384 | - .Times(AtLeast(1)) | ||
| 385 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 386 | - MockHueLight test_light(handler); | ||
| 387 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 388 | - | ||
| 389 | - test_light.getState()["state"]["hue"] = 5000; | ||
| 390 | - test_light.getState()["state"]["sat"] = 128; | ||
| 391 | - EXPECT_EQ(std::make_pair(static_cast<uint16_t>(5000), static_cast<uint8_t>(128)), | ||
| 392 | - SimpleColorHueStrategy().getColorHueSaturation(test_light)); | ||
| 393 | - test_light.getState()["state"]["hue"] = 50000; | ||
| 394 | - test_light.getState()["state"]["sat"] = 158; | ||
| 395 | - EXPECT_EQ(std::make_pair(static_cast<uint16_t>(50000), static_cast<uint8_t>(158)), | ||
| 396 | - SimpleColorHueStrategy().getColorHueSaturation(static_cast<const HueLight>(test_light))); | ||
| 397 | -} | ||
| 398 | - | ||
| 399 | -TEST(SimpleColorHueStrategy, getColorXY) | ||
| 400 | -{ | ||
| 401 | - using namespace ::testing; | ||
| 402 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 403 | - EXPECT_CALL( | ||
| 404 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 405 | - .Times(AtLeast(1)) | ||
| 406 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 407 | - MockHueLight test_light(handler); | ||
| 408 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 409 | - | ||
| 410 | - test_light.getState()["state"]["xy"][0] = 0.1234; | ||
| 411 | - test_light.getState()["state"]["xy"][1] = 0.1234; | ||
| 412 | - EXPECT_EQ(std::make_pair(static_cast<float>(0.1234), static_cast<float>(0.1234)), | ||
| 413 | - SimpleColorHueStrategy().getColorXY(test_light)); | ||
| 414 | - test_light.getState()["state"]["xy"][0] = 0.12; | ||
| 415 | - test_light.getState()["state"]["xy"][1] = 0.6458; | ||
| 416 | - EXPECT_EQ(std::make_pair(static_cast<float>(0.12), static_cast<float>(0.6458)), | ||
| 417 | - SimpleColorHueStrategy().getColorXY(static_cast<const HueLight>(test_light))); | ||
| 418 | -} | 1 | +/** |
| 2 | + \file test_SimpleColorHuewStrategy.cpp | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#include <memory> | ||
| 24 | +#include <string> | ||
| 25 | + | ||
| 26 | +#include <gmock/gmock.h> | ||
| 27 | +#include <gtest/gtest.h> | ||
| 28 | + | ||
| 29 | +#include "testhelper.h" | ||
| 30 | + | ||
| 31 | +#include "../include/SimpleColorHueStrategy.h" | ||
| 32 | +#include "../include/json/json.hpp" | ||
| 33 | +#include "mocks/mock_HttpHandler.h" | ||
| 34 | +#include "mocks/mock_HueLight.h" | ||
| 35 | + | ||
| 36 | +TEST(SimpleColorHueStrategy, setColorHue) | ||
| 37 | +{ | ||
| 38 | + using namespace ::testing; | ||
| 39 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 40 | + EXPECT_CALL( | ||
| 41 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 42 | + .Times(AtLeast(1)) | ||
| 43 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 44 | + MockHueLight test_light(handler); | ||
| 45 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 46 | + nlohmann::json prep_ret; | ||
| 47 | + prep_ret = nlohmann::json::array(); | ||
| 48 | + prep_ret[0] = nlohmann::json::object(); | ||
| 49 | + prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 50 | + prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 51 | + prep_ret[1] = nlohmann::json::object(); | ||
| 52 | + prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 53 | + prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 54 | + prep_ret[2] = nlohmann::json::object(); | ||
| 55 | + prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 56 | + prep_ret[2]["success"]["/lights/1/state/hue"] = 30500; | ||
| 57 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 58 | + | ||
| 59 | + test_light.getState()["state"]["on"] = true; | ||
| 60 | + test_light.getState()["state"]["hue"] = 200; | ||
| 61 | + test_light.getState()["state"]["colormode"] = "hs"; | ||
| 62 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorHue(200, 4, test_light)); | ||
| 63 | + | ||
| 64 | + test_light.getState()["state"]["on"] = false; | ||
| 65 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorHue(30500, 6, test_light)); | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +TEST(SimpleColorHueStrategy, setColorSaturation) | ||
| 69 | +{ | ||
| 70 | + using namespace ::testing; | ||
| 71 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 72 | + EXPECT_CALL( | ||
| 73 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 74 | + .Times(AtLeast(1)) | ||
| 75 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 76 | + MockHueLight test_light(handler); | ||
| 77 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 78 | + nlohmann::json prep_ret; | ||
| 79 | + prep_ret = nlohmann::json::array(); | ||
| 80 | + prep_ret[0] = nlohmann::json::object(); | ||
| 81 | + prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 82 | + prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 83 | + prep_ret[1] = nlohmann::json::object(); | ||
| 84 | + prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 85 | + prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 86 | + prep_ret[2] = nlohmann::json::object(); | ||
| 87 | + prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 88 | + prep_ret[2]["success"]["/lights/1/state/sat"] = 254; | ||
| 89 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 90 | + | ||
| 91 | + test_light.getState()["state"]["on"] = true; | ||
| 92 | + test_light.getState()["state"]["sat"] = 100; | ||
| 93 | + test_light.getState()["state"]["colormode"] = "hs"; | ||
| 94 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorSaturation(100, 4, test_light)); | ||
| 95 | + | ||
| 96 | + test_light.getState()["state"]["on"] = false; | ||
| 97 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorSaturation(255, 6, test_light)); | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +TEST(SimpleColorHueStrategy, setColorHueSaturation) | ||
| 101 | +{ | ||
| 102 | + using namespace ::testing; | ||
| 103 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 104 | + EXPECT_CALL( | ||
| 105 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 106 | + .Times(AtLeast(1)) | ||
| 107 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 108 | + MockHueLight test_light(handler); | ||
| 109 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 110 | + nlohmann::json prep_ret; | ||
| 111 | + prep_ret = nlohmann::json::array(); | ||
| 112 | + prep_ret[0] = nlohmann::json::object(); | ||
| 113 | + prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 114 | + prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 115 | + prep_ret[1] = nlohmann::json::object(); | ||
| 116 | + prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 117 | + prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 118 | + prep_ret[2] = nlohmann::json::object(); | ||
| 119 | + prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 120 | + prep_ret[2]["success"]["/lights/1/state/hue"] = 30500; | ||
| 121 | + prep_ret[3] = nlohmann::json::object(); | ||
| 122 | + prep_ret[3]["success"] = nlohmann::json::object(); | ||
| 123 | + prep_ret[3]["success"]["/lights/1/state/sat"] = 254; | ||
| 124 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 125 | + | ||
| 126 | + test_light.getState()["state"]["on"] = true; | ||
| 127 | + test_light.getState()["state"]["sat"] = 100; | ||
| 128 | + test_light.getState()["state"]["hue"] = 200; | ||
| 129 | + test_light.getState()["state"]["colormode"] = "hs"; | ||
| 130 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorHueSaturation(200, 100, 4, test_light)); | ||
| 131 | + | ||
| 132 | + test_light.getState()["state"]["on"] = false; | ||
| 133 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorHueSaturation(30500, 255, 6, test_light)); | ||
| 134 | +} | ||
| 135 | + | ||
| 136 | +TEST(SimpleColorHueStrategy, setColorXY) | ||
| 137 | +{ | ||
| 138 | + using namespace ::testing; | ||
| 139 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 140 | + EXPECT_CALL( | ||
| 141 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 142 | + .Times(AtLeast(1)) | ||
| 143 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 144 | + MockHueLight test_light(handler); | ||
| 145 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 146 | + nlohmann::json prep_ret; | ||
| 147 | + prep_ret = nlohmann::json::array(); | ||
| 148 | + prep_ret[0] = nlohmann::json::object(); | ||
| 149 | + prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 150 | + prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 151 | + prep_ret[1] = nlohmann::json::object(); | ||
| 152 | + prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 153 | + prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 154 | + prep_ret[2] = nlohmann::json::object(); | ||
| 155 | + prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 156 | + prep_ret[2]["success"]["/lights/1/state/xy"][0] = 0.2355; | ||
| 157 | + prep_ret[2]["success"]["/lights/1/state/xy"][1] = 0.1234; | ||
| 158 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 159 | + | ||
| 160 | + test_light.getState()["state"]["on"] = true; | ||
| 161 | + test_light.getState()["state"]["xy"][0] = 0.1f; | ||
| 162 | + test_light.getState()["state"]["xy"][1] = 0.1f; | ||
| 163 | + test_light.getState()["state"]["colormode"] = "xy"; | ||
| 164 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorXY(0.1f, 0.1f, 4, test_light)); | ||
| 165 | + | ||
| 166 | + test_light.getState()["state"]["on"] = false; | ||
| 167 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorXY(0.2355f, 0.1234f, 6, test_light)); | ||
| 168 | +} | ||
| 169 | + | ||
| 170 | +TEST(SimpleColorHueStrategy, setColorRGB) | ||
| 171 | +{ | ||
| 172 | + using namespace ::testing; | ||
| 173 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 174 | + EXPECT_CALL( | ||
| 175 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 176 | + .Times(AtLeast(1)) | ||
| 177 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 178 | + MockHueLight test_light(handler); | ||
| 179 | + EXPECT_CALL(test_light, setColorXY(_, _, 4)).Times(2).WillRepeatedly(Return(true)); | ||
| 180 | + | ||
| 181 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(128, 128, 128, 4, test_light)); | ||
| 182 | + | ||
| 183 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(255, 255, 255, 4, test_light)); | ||
| 184 | + | ||
| 185 | + EXPECT_CALL(test_light, OffNoRefresh(4)).Times(1).WillOnce(Return(true)); | ||
| 186 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorRGB(0, 0, 0, 4, test_light)); | ||
| 187 | +} | ||
| 188 | + | ||
| 189 | +TEST(SimpleColorHueStrategy, setColorLoop) | ||
| 190 | +{ | ||
| 191 | + using namespace ::testing; | ||
| 192 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 193 | + EXPECT_CALL( | ||
| 194 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 195 | + .Times(AtLeast(1)) | ||
| 196 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 197 | + MockHueLight test_light(handler); | ||
| 198 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 199 | + nlohmann::json prep_ret; | ||
| 200 | + prep_ret = nlohmann::json::array(); | ||
| 201 | + prep_ret[0] = nlohmann::json::object(); | ||
| 202 | + prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 203 | + prep_ret[0]["success"]["/lights/1/state/on"] = true; | ||
| 204 | + prep_ret[1] = nlohmann::json::object(); | ||
| 205 | + prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 206 | + prep_ret[1]["success"]["/lights/1/state/effect"] = "colorloop"; | ||
| 207 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 208 | + | ||
| 209 | + test_light.getState()["state"]["on"] = true; | ||
| 210 | + test_light.getState()["state"]["effect"] = "colorloop"; | ||
| 211 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorLoop(true, test_light)); | ||
| 212 | + | ||
| 213 | + test_light.getState()["state"]["on"] = false; | ||
| 214 | + test_light.getState()["state"]["effect"] = "none"; | ||
| 215 | + EXPECT_EQ(true, SimpleColorHueStrategy().setColorLoop(true, test_light)); | ||
| 216 | +} | ||
| 217 | + | ||
| 218 | +TEST(SimpleColorHueStrategy, alertHueSaturation) | ||
| 219 | +{ | ||
| 220 | + using namespace ::testing; | ||
| 221 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 222 | + EXPECT_CALL( | ||
| 223 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 224 | + .Times(AtLeast(1)) | ||
| 225 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 226 | + MockHueLight test_light(handler); | ||
| 227 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 228 | + | ||
| 229 | + test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 230 | + test_light.getState()["state"]["on"] = false; | ||
| 231 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(30000, 128, test_light)); | ||
| 232 | + | ||
| 233 | + EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)) | ||
| 234 | + .Times(AtLeast(2)) | ||
| 235 | + .WillOnce(Return(false)) | ||
| 236 | + .WillRepeatedly(Return(true)); | ||
| 237 | + test_light.getState()["state"]["colormode"] = "hs"; | ||
| 238 | + test_light.getState()["state"]["on"] = true; | ||
| 239 | + test_light.getState()["state"]["sat"] = 100; | ||
| 240 | + test_light.getState()["state"]["hue"] = 200; | ||
| 241 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 242 | + | ||
| 243 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 244 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 245 | + | ||
| 246 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 247 | + | ||
| 248 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 249 | + test_light.getState()["state"]["on"] = false; | ||
| 250 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 251 | + | ||
| 252 | + EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)) | ||
| 253 | + .Times(AtLeast(2)) | ||
| 254 | + .WillOnce(Return(false)) | ||
| 255 | + .WillRepeatedly(Return(true)); | ||
| 256 | + test_light.getState()["state"]["colormode"] = "xy"; | ||
| 257 | + test_light.getState()["state"]["on"] = true; | ||
| 258 | + test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 259 | + test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 260 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 261 | + | ||
| 262 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 263 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 264 | + | ||
| 265 | + EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 266 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 267 | + | ||
| 268 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 269 | + test_light.getState()["state"]["on"] = false; | ||
| 270 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertHueSaturation(200, 100, test_light)); | ||
| 271 | +} | ||
| 272 | + | ||
| 273 | +TEST(SimpleColorHueStrategy, alertXY) | ||
| 274 | +{ | ||
| 275 | + using namespace ::testing; | ||
| 276 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 277 | + EXPECT_CALL( | ||
| 278 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 279 | + .Times(AtLeast(1)) | ||
| 280 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 281 | + MockHueLight test_light(handler); | ||
| 282 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 283 | + | ||
| 284 | + test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 285 | + test_light.getState()["state"]["on"] = false; | ||
| 286 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 287 | + | ||
| 288 | + EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 289 | + test_light.getState()["state"]["colormode"] = "hs"; | ||
| 290 | + test_light.getState()["state"]["on"] = true; | ||
| 291 | + test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 292 | + test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 293 | + test_light.getState()["state"]["sat"] = 100; | ||
| 294 | + test_light.getState()["state"]["hue"] = 200; | ||
| 295 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 296 | + | ||
| 297 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 298 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 299 | + | ||
| 300 | + EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 301 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 302 | + | ||
| 303 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 304 | + test_light.getState()["state"]["on"] = false; | ||
| 305 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 306 | + | ||
| 307 | + EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 308 | + test_light.getState()["state"]["colormode"] = "xy"; | ||
| 309 | + test_light.getState()["state"]["on"] = true; | ||
| 310 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 311 | + | ||
| 312 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 313 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 314 | + | ||
| 315 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 316 | + | ||
| 317 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 318 | + test_light.getState()["state"]["on"] = false; | ||
| 319 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertXY(0.1f, 0.1f, test_light)); | ||
| 320 | +} | ||
| 321 | + | ||
| 322 | +TEST(SimpleColorHueStrategy, alertRGB) | ||
| 323 | +{ | ||
| 324 | + using namespace ::testing; | ||
| 325 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 326 | + EXPECT_CALL( | ||
| 327 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 328 | + .Times(AtLeast(1)) | ||
| 329 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 330 | + MockHueLight test_light(handler); | ||
| 331 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 332 | + | ||
| 333 | + test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 334 | + test_light.getState()["state"]["on"] = false; | ||
| 335 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 336 | + | ||
| 337 | + EXPECT_CALL(test_light, setColorRGB(_, _, _, 1)) | ||
| 338 | + .Times(AtLeast(2)) | ||
| 339 | + .WillOnce(Return(false)) | ||
| 340 | + .WillRepeatedly(Return(true)); | ||
| 341 | + test_light.getState()["state"]["colormode"] = "hs"; | ||
| 342 | + test_light.getState()["state"]["on"] = true; | ||
| 343 | + test_light.getState()["state"]["sat"] = 100; | ||
| 344 | + test_light.getState()["state"]["hue"] = 200; | ||
| 345 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 346 | + | ||
| 347 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 348 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 349 | + | ||
| 350 | + EXPECT_CALL(test_light, setColorHueSaturation(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 351 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 352 | + | ||
| 353 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 354 | + test_light.getState()["state"]["on"] = false; | ||
| 355 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 356 | + | ||
| 357 | + EXPECT_CALL(test_light, setColorRGB(_, _, _, 1)) | ||
| 358 | + .Times(AtLeast(2)) | ||
| 359 | + .WillOnce(Return(false)) | ||
| 360 | + .WillRepeatedly(Return(true)); | ||
| 361 | + test_light.getState()["state"]["colormode"] = "xy"; | ||
| 362 | + test_light.getState()["state"]["on"] = true; | ||
| 363 | + test_light.getState()["state"]["xy"][0] = 0.1; | ||
| 364 | + test_light.getState()["state"]["xy"][1] = 0.1; | ||
| 365 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 366 | + | ||
| 367 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 368 | + EXPECT_EQ(false, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 369 | + | ||
| 370 | + EXPECT_CALL(test_light, setColorXY(_, _, 1)).Times(AtLeast(2)).WillRepeatedly(Return(true)); | ||
| 371 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 372 | + | ||
| 373 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 374 | + test_light.getState()["state"]["on"] = false; | ||
| 375 | + EXPECT_EQ(true, SimpleColorHueStrategy().alertRGB(128, 128, 128, test_light)); | ||
| 376 | +} | ||
| 377 | + | ||
| 378 | +TEST(SimpleColorHueStrategy, getColorHueSaturation) | ||
| 379 | +{ | ||
| 380 | + using namespace ::testing; | ||
| 381 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 382 | + EXPECT_CALL( | ||
| 383 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 384 | + .Times(AtLeast(1)) | ||
| 385 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 386 | + MockHueLight test_light(handler); | ||
| 387 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 388 | + | ||
| 389 | + test_light.getState()["state"]["hue"] = 5000; | ||
| 390 | + test_light.getState()["state"]["sat"] = 128; | ||
| 391 | + EXPECT_EQ(std::make_pair(static_cast<uint16_t>(5000), static_cast<uint8_t>(128)), | ||
| 392 | + SimpleColorHueStrategy().getColorHueSaturation(test_light)); | ||
| 393 | + test_light.getState()["state"]["hue"] = 50000; | ||
| 394 | + test_light.getState()["state"]["sat"] = 158; | ||
| 395 | + EXPECT_EQ(std::make_pair(static_cast<uint16_t>(50000), static_cast<uint8_t>(158)), | ||
| 396 | + SimpleColorHueStrategy().getColorHueSaturation(static_cast<const HueLight>(test_light))); | ||
| 397 | +} | ||
| 398 | + | ||
| 399 | +TEST(SimpleColorHueStrategy, getColorXY) | ||
| 400 | +{ | ||
| 401 | + using namespace ::testing; | ||
| 402 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 403 | + EXPECT_CALL( | ||
| 404 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 405 | + .Times(AtLeast(1)) | ||
| 406 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 407 | + MockHueLight test_light(handler); | ||
| 408 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 409 | + | ||
| 410 | + test_light.getState()["state"]["xy"][0] = 0.1234; | ||
| 411 | + test_light.getState()["state"]["xy"][1] = 0.1234; | ||
| 412 | + EXPECT_EQ(std::make_pair(static_cast<float>(0.1234), static_cast<float>(0.1234)), | ||
| 413 | + SimpleColorHueStrategy().getColorXY(test_light)); | ||
| 414 | + test_light.getState()["state"]["xy"][0] = 0.12; | ||
| 415 | + test_light.getState()["state"]["xy"][1] = 0.6458; | ||
| 416 | + EXPECT_EQ(std::make_pair(static_cast<float>(0.12), static_cast<float>(0.6458)), | ||
| 417 | + SimpleColorHueStrategy().getColorXY(static_cast<const HueLight>(test_light))); | ||
| 418 | +} |
hueplusplus/test/test_SimpleColorTemperatureStrategy.cpp renamed to src/test/test_SimpleColorTemperatureStrategy.cpp
100755 → 100644
| 1 | -/** | ||
| 2 | - \file test_SimpleColorTemperatureStrategy.cpp | ||
| 3 | - Copyright Notice\n | ||
| 4 | - Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | - Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | - | ||
| 7 | - This file is part of hueplusplus. | ||
| 8 | - | ||
| 9 | - hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | - it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | - the Free Software Foundation, either version 3 of the License, or | ||
| 12 | - (at your option) any later version. | ||
| 13 | - | ||
| 14 | - hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - GNU Lesser General Public License for more details. | ||
| 18 | - | ||
| 19 | - You should have received a copy of the GNU Lesser General Public License | ||
| 20 | - along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | -**/ | ||
| 22 | - | ||
| 23 | -#include <iostream> | ||
| 24 | -#include <memory> | ||
| 25 | -#include <string> | ||
| 26 | - | ||
| 27 | -#include <gmock/gmock.h> | ||
| 28 | -#include <gtest/gtest.h> | ||
| 29 | - | ||
| 30 | -#include "testhelper.h" | ||
| 31 | - | ||
| 32 | -#include "../include/SimpleColorTemperatureStrategy.h" | ||
| 33 | -#include "../include/json/json.hpp" | ||
| 34 | -#include "mocks/mock_HttpHandler.h" | ||
| 35 | -#include "mocks/mock_HueLight.h" | ||
| 36 | - | ||
| 37 | -TEST(SimpleColorTemperatureStrategy, setColorTemperature) | ||
| 38 | -{ | ||
| 39 | - using namespace ::testing; | ||
| 40 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 41 | - EXPECT_CALL( | ||
| 42 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 43 | - .Times(AtLeast(1)) | ||
| 44 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 45 | - MockHueLight test_light(handler); | ||
| 46 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 47 | - nlohmann::json prep_ret; | ||
| 48 | - prep_ret = nlohmann::json::array(); | ||
| 49 | - prep_ret[0] = nlohmann::json::object(); | ||
| 50 | - prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 51 | - prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 52 | - prep_ret[1] = nlohmann::json::object(); | ||
| 53 | - prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 54 | - prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 55 | - prep_ret[2] = nlohmann::json::object(); | ||
| 56 | - prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 57 | - prep_ret[2]["success"]["/lights/1/state/ct"] = 155; | ||
| 58 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 59 | - | ||
| 60 | - test_light.getState()["state"]["on"] = true; | ||
| 61 | - test_light.getState()["state"]["ct"] = 200; | ||
| 62 | - EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(200, 4, test_light)); | ||
| 63 | - | ||
| 64 | - test_light.getState()["state"]["on"] = false; | ||
| 65 | - EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(155, 6, test_light)); | ||
| 66 | - | ||
| 67 | - prep_ret[2]["success"]["/lights/1/state/ct"] = 153; | ||
| 68 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 69 | - EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(0, 6, test_light)); | ||
| 70 | - | ||
| 71 | - prep_ret[2]["success"]["/lights/1/state/ct"] = 500; | ||
| 72 | - EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 73 | - EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(600, 6, test_light)); | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | -TEST(SimpleColorTemperatureStrategy, alertTemperature) | ||
| 77 | -{ | ||
| 78 | - using namespace ::testing; | ||
| 79 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 80 | - EXPECT_CALL( | ||
| 81 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 82 | - .Times(AtLeast(1)) | ||
| 83 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 84 | - MockHueLight test_light(handler); | ||
| 85 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 86 | - | ||
| 87 | - test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 88 | - test_light.getState()["state"]["on"] = false; | ||
| 89 | - EXPECT_EQ(false, SimpleColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 90 | - | ||
| 91 | - EXPECT_CALL(test_light, setColorTemperature(_, _)) | ||
| 92 | - .Times(AtLeast(2)) | ||
| 93 | - .WillOnce(Return(false)) | ||
| 94 | - .WillRepeatedly(Return(true)); | ||
| 95 | - test_light.getState()["state"]["colormode"] = "ct"; | ||
| 96 | - test_light.getState()["state"]["on"] = true; | ||
| 97 | - test_light.getState()["state"]["ct"] = 200; | ||
| 98 | - EXPECT_EQ(false, SimpleColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 99 | - | ||
| 100 | - EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 101 | - EXPECT_EQ(false, SimpleColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 102 | - | ||
| 103 | - EXPECT_EQ(true, SimpleColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 104 | - | ||
| 105 | - EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 106 | - test_light.getState()["state"]["on"] = false; | ||
| 107 | - EXPECT_EQ(true, SimpleColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 108 | -} | ||
| 109 | - | ||
| 110 | -TEST(SimpleColorTemperatureStrategy, getColorTemperature) | ||
| 111 | -{ | ||
| 112 | - using namespace ::testing; | ||
| 113 | - std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 114 | - EXPECT_CALL( | ||
| 115 | - *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 116 | - .Times(AtLeast(1)) | ||
| 117 | - .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 118 | - MockHueLight test_light(handler); | ||
| 119 | - EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 120 | - | ||
| 121 | - test_light.getState()["state"]["ct"] = 200; | ||
| 122 | - EXPECT_EQ(200, SimpleColorTemperatureStrategy().getColorTemperature(test_light)); | ||
| 123 | - test_light.getState()["state"]["ct"] = 500; | ||
| 124 | - EXPECT_EQ(500, SimpleColorTemperatureStrategy().getColorTemperature(static_cast<const HueLight>(test_light))); | ||
| 125 | -} | 1 | +/** |
| 2 | + \file test_SimpleColorTemperatureStrategy.cpp | ||
| 3 | + Copyright Notice\n | ||
| 4 | + Copyright (C) 2017 Jan Rogall - developer\n | ||
| 5 | + Copyright (C) 2017 Moritz Wirger - developer\n | ||
| 6 | + | ||
| 7 | + This file is part of hueplusplus. | ||
| 8 | + | ||
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU Lesser General Public License as published by | ||
| 11 | + the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + (at your option) any later version. | ||
| 13 | + | ||
| 14 | + hueplusplus is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU Lesser General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU Lesser General Public License | ||
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | +**/ | ||
| 22 | + | ||
| 23 | +#include <iostream> | ||
| 24 | +#include <memory> | ||
| 25 | +#include <string> | ||
| 26 | + | ||
| 27 | +#include <gmock/gmock.h> | ||
| 28 | +#include <gtest/gtest.h> | ||
| 29 | + | ||
| 30 | +#include "testhelper.h" | ||
| 31 | + | ||
| 32 | +#include "../include/SimpleColorTemperatureStrategy.h" | ||
| 33 | +#include "../include/json/json.hpp" | ||
| 34 | +#include "mocks/mock_HttpHandler.h" | ||
| 35 | +#include "mocks/mock_HueLight.h" | ||
| 36 | + | ||
| 37 | +TEST(SimpleColorTemperatureStrategy, setColorTemperature) | ||
| 38 | +{ | ||
| 39 | + using namespace ::testing; | ||
| 40 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 41 | + EXPECT_CALL( | ||
| 42 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 43 | + .Times(AtLeast(1)) | ||
| 44 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 45 | + MockHueLight test_light(handler); | ||
| 46 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 47 | + nlohmann::json prep_ret; | ||
| 48 | + prep_ret = nlohmann::json::array(); | ||
| 49 | + prep_ret[0] = nlohmann::json::object(); | ||
| 50 | + prep_ret[0]["success"] = nlohmann::json::object(); | ||
| 51 | + prep_ret[0]["success"]["/lights/1/state/transitiontime"] = 6; | ||
| 52 | + prep_ret[1] = nlohmann::json::object(); | ||
| 53 | + prep_ret[1]["success"] = nlohmann::json::object(); | ||
| 54 | + prep_ret[1]["success"]["/lights/1/state/on"] = true; | ||
| 55 | + prep_ret[2] = nlohmann::json::object(); | ||
| 56 | + prep_ret[2]["success"] = nlohmann::json::object(); | ||
| 57 | + prep_ret[2]["success"]["/lights/1/state/ct"] = 155; | ||
| 58 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 59 | + | ||
| 60 | + test_light.getState()["state"]["on"] = true; | ||
| 61 | + test_light.getState()["state"]["ct"] = 200; | ||
| 62 | + EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(200, 4, test_light)); | ||
| 63 | + | ||
| 64 | + test_light.getState()["state"]["on"] = false; | ||
| 65 | + EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(155, 6, test_light)); | ||
| 66 | + | ||
| 67 | + prep_ret[2]["success"]["/lights/1/state/ct"] = 153; | ||
| 68 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 69 | + EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(0, 6, test_light)); | ||
| 70 | + | ||
| 71 | + prep_ret[2]["success"]["/lights/1/state/ct"] = 500; | ||
| 72 | + EXPECT_CALL(test_light, SendPutRequest(_, "/state", _)).Times(1).WillOnce(Return(prep_ret)); | ||
| 73 | + EXPECT_EQ(true, SimpleColorTemperatureStrategy().setColorTemperature(600, 6, test_light)); | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +TEST(SimpleColorTemperatureStrategy, alertTemperature) | ||
| 77 | +{ | ||
| 78 | + using namespace ::testing; | ||
| 79 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 80 | + EXPECT_CALL( | ||
| 81 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 82 | + .Times(AtLeast(1)) | ||
| 83 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 84 | + MockHueLight test_light(handler); | ||
| 85 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 86 | + | ||
| 87 | + test_light.getState()["state"]["colormode"] = "invalid"; | ||
| 88 | + test_light.getState()["state"]["on"] = false; | ||
| 89 | + EXPECT_EQ(false, SimpleColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 90 | + | ||
| 91 | + EXPECT_CALL(test_light, setColorTemperature(_, _)) | ||
| 92 | + .Times(AtLeast(2)) | ||
| 93 | + .WillOnce(Return(false)) | ||
| 94 | + .WillRepeatedly(Return(true)); | ||
| 95 | + test_light.getState()["state"]["colormode"] = "ct"; | ||
| 96 | + test_light.getState()["state"]["on"] = true; | ||
| 97 | + test_light.getState()["state"]["ct"] = 200; | ||
| 98 | + EXPECT_EQ(false, SimpleColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 99 | + | ||
| 100 | + EXPECT_CALL(test_light, alert()).Times(AtLeast(2)).WillOnce(Return(false)).WillRepeatedly(Return(true)); | ||
| 101 | + EXPECT_EQ(false, SimpleColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 102 | + | ||
| 103 | + EXPECT_EQ(true, SimpleColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 104 | + | ||
| 105 | + EXPECT_CALL(test_light, OffNoRefresh(_)).Times(AtLeast(1)).WillRepeatedly(Return(true)); | ||
| 106 | + test_light.getState()["state"]["on"] = false; | ||
| 107 | + EXPECT_EQ(true, SimpleColorTemperatureStrategy().alertTemperature(400, test_light)); | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +TEST(SimpleColorTemperatureStrategy, getColorTemperature) | ||
| 111 | +{ | ||
| 112 | + using namespace ::testing; | ||
| 113 | + std::shared_ptr<MockHttpHandler> handler(std::make_shared<MockHttpHandler>()); | ||
| 114 | + EXPECT_CALL( | ||
| 115 | + *handler, GETJson("/api/" + getBridgeUsername() + "/lights/1", nlohmann::json::object(), getBridgeIp(), 80)) | ||
| 116 | + .Times(AtLeast(1)) | ||
| 117 | + .WillRepeatedly(Return(nlohmann::json::object())); | ||
| 118 | + MockHueLight test_light(handler); | ||
| 119 | + EXPECT_CALL(test_light, refreshState()).Times(AtLeast(1)).WillRepeatedly(Return()); | ||
| 120 | + | ||
| 121 | + test_light.getState()["state"]["ct"] = 200; | ||
| 122 | + EXPECT_EQ(200, SimpleColorTemperatureStrategy().getColorTemperature(test_light)); | ||
| 123 | + test_light.getState()["state"]["ct"] = 500; | ||
| 124 | + EXPECT_EQ(500, SimpleColorTemperatureStrategy().getColorTemperature(static_cast<const HueLight>(test_light))); | ||
| 125 | +} |
hueplusplus/test/test_UPnP.cpp renamed to src/test/test_UPnP.cpp
100755 → 100644
hueplusplus/test/testhelper.h renamed to src/test/testhelper.h