gradient: initialize alpha when converting from rgb (#1491)

this fixes tests that ended up comparing zero alpha to an unitialized alpha value

also improve reporting so that failing color comparison tests will print the color in hex

Co-authored-by: bi4k8 <bi4k8@github>
This commit is contained in:
bi4k8 2023-04-05 13:07:32 +00:00 committed by GitHub
parent 468488677a
commit df16eeabf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -57,6 +57,7 @@ Colour gradient_factory::convert_to_rgb(long *const array) {
c.red = scaled_rgb[0] / SCALE;
c.green = scaled_rgb[1] / SCALE;
c.blue = scaled_rgb[2] / SCALE;
c.alpha = 255;
return c;
}

View File

@ -32,8 +32,11 @@
#include <conky.h>
#include <gradient.h>
#include <iomanip>
#include <iostream>
const int width = 4;
const Colour colour = Colour::from_argb32(0x996633); // brown
const Colour colour = Colour::from_argb32(0xff996633); // brown
const long expected_hue = 256;
const long expected_value = 0x99; // max(0x99, 0x66, 0x33)
const long expected_chroma = 0x66; // (0x99 - 0x33)
@ -45,6 +48,15 @@ const long expected_blue = 0x33;
const long full_scale = conky::gradient_factory::SCALE360;
std::ostream& operator<<(std::ostream& s, const Colour& c) {
s << '#';
s << std::setfill('0');
s << std::setw(2);
s << std::setbase(16);
s << (int)c.alpha << (int)c.red << (int)c.green << (int)c.blue;
return s;
}
TEST_CASE("gradient_factory::convert_from_rgb returns correct value") {
#ifdef BUILD_X11
state = nullptr;