From 938526755cd1f109c98cd3b37f19510aacf3aa73 Mon Sep 17 00:00:00 2001 From: Caio Freitas de Oliveira Date: Wed, 5 Oct 2022 00:54:00 -0300 Subject: [PATCH] restore tests --- src/conky.cc | 1 + tests/CMakeLists.txt | 2 ++ tests/test-hsv.cc | 72 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 tests/test-hsv.cc diff --git a/src/conky.cc b/src/conky.cc index 558d8369..c4603ce7 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -133,6 +133,7 @@ #ifdef BUILD_HCL_GRADIENT #include "hcl_gradient.h" #endif /* BUILD_HCL_GRADIENT */ + #ifdef BUILD_HSV_GRADIENT #include "hsv_gradient.h" #endif /* BUILD_HSV_GRADIENT */ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index de7f1e1f..0d825a64 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,8 @@ set(test_srcs ${test_srcs} test-diskio.cc) set(test_srcs ${test_srcs} test-fs.cc) if(BUILD_HCL_GRADIENT) set(test_srcs ${test_srcs} test-hcl.cc) +elseif(BUILD_HSV_GRADIENT) + set(test_srcs ${test_srcs} test-hsv.cc) endif(BUILD_HCL_GRADIENT) add_executable(test-conky test-common.cc ${test_srcs}) diff --git a/tests/test-hsv.cc b/tests/test-hsv.cc new file mode 100644 index 00000000..b46052a9 --- /dev/null +++ b/tests/test-hsv.cc @@ -0,0 +1,72 @@ +/* + * + * Conky, a system monitor, based on torsmo + * + * Any original torsmo code is licensed under the BSD license + * + * All code written since the fork of torsmo is licensed under the GPL + * + * Please see COPYING for details + * + * Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al. + * (see AUTHORS) + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "catch2/catch.hpp" + +#include +#include +#include + +int testColor(long *rgb, int scale) { + long hsv[3]; + long rgb1[3]; + long rgb2[3]; + long rgb3[3]; + + rgb1[0] = to_decimal_scale(rgb[0], scale); + rgb1[1] = to_decimal_scale(rgb[1], scale); + rgb1[2] = to_decimal_scale(rgb[2], scale); + + scaled_rgb_to_scaled_hsv(rgb1, hsv); + scaled_hsv_to_scaled_rgb(hsv, rgb2); + + rgb3[0] = from_decimal_scale(rgb2[0], scale); + rgb3[1] = from_decimal_scale(rgb2[1], scale); + rgb3[2] = from_decimal_scale(rgb2[2], scale); + + return (rgb[0] != rgb3[0] || rgb[1] != rgb3[1] || rgb[2] != rgb3[2]); +} + +TEST_CASE("hsv gradient tests") { + SECTION("rgb -> hsv -> rgb should returns original value") { + int failedCount = 0; + long rgb1[3]; + + for (int i = 0; i < 256 && failedCount < 10; i++) { + for (int j = 0; j < 256 && failedCount < 10; j++) { + for (int k = 0; k < 256 && failedCount < 10; k++) { + rgb1[0] = i; + rgb1[1] = j; + rgb1[2] = k; + failedCount += testColor(rgb1, 255); + } + } + } + REQUIRE(failedCount == 0); + } +}