mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-06-10 03:02:20 +00:00
Add some colour tests.
This commit is contained in:
parent
a39015b7bd
commit
de3bd0c2eb
|
@ -26,9 +26,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifndef _COLOURS_H
|
||||
#define _COLOURS_H
|
||||
#pragma once
|
||||
|
||||
#include <config.h>
|
||||
#include <cassert>
|
||||
#include <climits>
|
||||
#include <memory>
|
||||
|
@ -96,5 +96,3 @@ extern Colour error_colour;
|
|||
Colour parse_color(const std::string &colour);
|
||||
// XXX: when everyone uses C++ strings, remove this C version
|
||||
Colour parse_color(const char *);
|
||||
|
||||
#endif /* _COLOURS_H */
|
||||
|
|
|
@ -18,6 +18,7 @@ set(test_srcs ${test_srcs} test-core.cc)
|
|||
set(test_srcs ${test_srcs} test-diskio.cc)
|
||||
set(test_srcs ${test_srcs} test-fs.cc)
|
||||
set(test_srcs ${test_srcs} test-gradient.cc)
|
||||
set(test_srcs ${test_srcs} test-colours.cc)
|
||||
|
||||
add_executable(test-conky test-common.cc ${test_srcs})
|
||||
target_link_libraries(test-conky conky_core)
|
||||
|
|
93
tests/test-colours.cc
Normal file
93
tests/test-colours.cc
Normal file
|
@ -0,0 +1,93 @@
|
|||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <colours.h>
|
||||
#include <config.h>
|
||||
|
||||
TEST_CASE("parse_color correctly parses colours", "[colours][parse_color]") {
|
||||
SECTION("parsing hex red") {
|
||||
auto colour = parse_color("#ff0000");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 255);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("parsing hex green") {
|
||||
auto colour = parse_color("#00ff00");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 255);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("parsing hex blue") {
|
||||
auto colour = parse_color("#0000ff");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 255);
|
||||
}
|
||||
|
||||
SECTION("parsing hex red") {
|
||||
auto colour = parse_color("#ff0000");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 255);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("parsing hex green") {
|
||||
auto colour = parse_color("#00ff00");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 255);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("parsing hex blue") {
|
||||
auto colour = parse_color("#0000ff");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 255);
|
||||
}
|
||||
|
||||
SECTION("argb values produce the expected result") {
|
||||
auto colour = Colour::from_argb32(0x11223344);
|
||||
REQUIRE(colour.alpha == 0x11);
|
||||
REQUIRE(colour.red == 0x22);
|
||||
REQUIRE(colour.green == 0x33);
|
||||
REQUIRE(colour.blue == 0x44);
|
||||
}
|
||||
|
||||
SECTION("it parses the colour red") {
|
||||
auto colour = parse_color("red");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 255);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("it parses the colour green") {
|
||||
auto colour = parse_color("green");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 255);
|
||||
REQUIRE(colour.blue == 0);
|
||||
}
|
||||
|
||||
SECTION("it parses the colour blue") {
|
||||
auto colour = parse_color("blue");
|
||||
REQUIRE(colour.alpha == 255);
|
||||
REQUIRE(colour.red == 0);
|
||||
REQUIRE(colour.green == 0);
|
||||
REQUIRE(colour.blue == 255);
|
||||
}
|
||||
|
||||
SECTION("two identical colours should be equal") {
|
||||
auto c = GENERATE(take(100, random((uint32_t)0, (uint32_t)0xffffffff)));
|
||||
auto colour1 = Colour::from_argb32(c);
|
||||
auto colour2 = Colour::from_argb32(c);
|
||||
REQUIRE(colour1 == colour2);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user