1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-18 13:55:11 -05:00

tests: Convert color test to gtest

This commit is contained in:
patrick96 2018-06-01 16:35:20 +02:00 committed by Patrick Ziegler
parent 78680a6832
commit 1965498e20

View file

@ -1,73 +1,71 @@
#include "common/test.hpp" #include "common/test.hpp"
#include "utils/color.hpp" #include "utils/color.hpp"
int main() { using namespace polybar;
using namespace polybar;
"rgb"_test = []{ TEST(String, rgb) {
unsigned int color{0x123456}; unsigned int color{0x123456};
expect(color_util::alpha_channel<unsigned char>(color) == 0); EXPECT_EQ(0, color_util::alpha_channel<unsigned char>(color));
expect(color_util::red_channel<unsigned char>(color) == 0x12); EXPECT_EQ(0x12, color_util::red_channel<unsigned char>(color));
expect(color_util::green_channel<unsigned char>(color) == 0x34); EXPECT_EQ(0x34, color_util::green_channel<unsigned char>(color));
expect(color_util::green_channel<unsigned short int>(color) == 0x3434); EXPECT_EQ(0x3434, color_util::green_channel<unsigned short int>(color));
expect(color_util::blue_channel<unsigned char>(color) == 0x56); EXPECT_EQ(0x56, color_util::blue_channel<unsigned char>(color));
expect(rgb{0xFF112233}.b == 0x33 / 255.0); EXPECT_TRUE(0x33 / 255.0 == rgb{0xFF112233}.b);
expect(rgb{0x88449933}.g == 0x51 / 255.0); EXPECT_TRUE(0x51 / 255.0 == rgb{0x88449933}.g);
expect(rgb{0xee111111} == 0xff0f0f0f); EXPECT_TRUE(0xff0f0f0f == rgb{0xee111111});
expect(rgb{0x99112233} == 0xff0a141e); EXPECT_TRUE(0xff0a141e == rgb{0x99112233});
}; }
"rgba"_test = []{ TEST(String, rgba) {
unsigned int color{0xCC123456}; unsigned int color{0xCC123456};
expect(color_util::alpha_channel<unsigned short int>(color) == 0xCCCC); EXPECT_EQ(0xCCCC, color_util::alpha_channel<unsigned short int>(color));
expect(color_util::red_channel<unsigned short int>(color) == 0x1212); EXPECT_EQ(0x1212, color_util::red_channel<unsigned short int>(color));
expect(color_util::red_channel<unsigned char>(color) == 0x12); EXPECT_EQ(0x12, color_util::red_channel<unsigned char>(color));
expect(color_util::green_channel<unsigned short int>(color) == 0x3434); EXPECT_EQ(0x3434, color_util::green_channel<unsigned short int>(color));
expect(color_util::blue_channel<unsigned short int>(color) == 0x5656); EXPECT_EQ(0x5656, color_util::blue_channel<unsigned short int>(color));
expect(rgba{0xCC112233}.a == 0xCC / 255.0); EXPECT_EQ(0xCC / 255.0, rgba{0xCC112233}.a);
expect(rgba{0x88449933}.g == 0x99 / 255.0); EXPECT_EQ(0x99 / 255.0, rgba{0x88449933}.g);
expect(static_cast<unsigned int>(rgba{0xFF111111}) == 0xFF111111); EXPECT_EQ(0xFF111111, static_cast<unsigned int>(rgba{0xFF111111}));
expect(static_cast<unsigned int>(rgba{0x00FFFFFF}) == 0x00FFFFFF); EXPECT_EQ(0x00FFFFFF, static_cast<unsigned int>(rgba{0x00FFFFFF}));
}; }
"hex"_test = [] { TEST(String, hex) {
unsigned int colorA{0x123456}; unsigned int colorA{0x123456};
expect(color_util::hex<unsigned char>(colorA) == "#123456"s); EXPECT_EQ("#123456"s, color_util::hex<unsigned char>(colorA));
unsigned int colorB{0xCC123456}; unsigned int colorB{0xCC123456};
expect(color_util::hex<unsigned short int>(colorB) == "#cc123456"s); EXPECT_EQ("#cc123456"s, color_util::hex<unsigned short int>(colorB));
unsigned int colorC{0x00ffffff}; unsigned int colorC{0x00ffffff};
expect(color_util::hex<unsigned short int>(colorC) == "#00ffffff"s); EXPECT_EQ("#00ffffff"s, color_util::hex<unsigned short int>(colorC));
}; }
"parse_hex"_test = [] { TEST(String, parseHex) {
expect(color_util::parse_hex("#fff") == "#ffffffff"); EXPECT_EQ("#ffffffff", color_util::parse_hex("#fff"));
expect(color_util::parse_hex("#123") == "#ff112233"); EXPECT_EQ("#ff112233", color_util::parse_hex("#123"));
expect(color_util::parse_hex("#888888") == "#ff888888"); EXPECT_EQ("#ff888888", color_util::parse_hex("#888888"));
expect(color_util::parse_hex("#00aa00aa") == "#00aa00aa"); EXPECT_EQ("#00aa00aa", color_util::parse_hex("#00aa00aa"));
}; }
"parse"_test = [] { TEST(String, parse) {
expect(color_util::parse("invalid") == 0); EXPECT_EQ(0, color_util::parse("invalid"));
expect(color_util::parse("#f") == 0); EXPECT_EQ(0, color_util::parse("#f"));
expect(color_util::parse("#ff") == 0); EXPECT_EQ(0, color_util::parse("#ff"));
expect(color_util::parse("invalid", 0xFF999999) == 0xFF999999); EXPECT_EQ(0xFF999999, color_util::parse("invalid", 0xFF999999));
expect(color_util::parse("invalid", 0x00111111) == 0x00111111); EXPECT_EQ(0x00111111, color_util::parse("invalid", 0x00111111));
expect(color_util::parse("invalid", 0xFF000000) == 0xFF000000); EXPECT_EQ(0xFF000000, color_util::parse("invalid", 0xFF000000));
expect(color_util::parse("#fff") == 0xffffffff); EXPECT_EQ(0xffffffff, color_util::parse("#fff"));
expect(color_util::parse("#890") == 0xFF889900); EXPECT_EQ(0xFF889900, color_util::parse("#890"));
expect(color_util::parse("#55888777") == 0x55888777); EXPECT_EQ(0x55888777, color_util::parse("#55888777"));
expect(color_util::parse("#88aaaaaa") == 0x88aaaaaa); EXPECT_EQ(0x88aaaaaa, color_util::parse("#88aaaaaa"));
expect(color_util::parse("#00aaaaaa") == 0x00aaaaaa); EXPECT_EQ(0x00aaaaaa, color_util::parse("#00aaaaaa"));
expect(color_util::parse("#00FFFFFF") == 0x00FFFFFF); EXPECT_EQ(0x00FFFFFF, color_util::parse("#00FFFFFF"));
}; }
"simplify"_test = [] { TEST(String, simplify) {
expect(color_util::simplify_hex("#FF111111") == "#111"); EXPECT_EQ("#111", color_util::simplify_hex("#FF111111"));
expect(color_util::simplify_hex("#ff223344") == "#234"); EXPECT_EQ("#234", color_util::simplify_hex("#ff223344"));
expect(color_util::simplify_hex("#ee223344") == "#ee223344"); EXPECT_EQ("#ee223344", color_util::simplify_hex("#ee223344"));
expect(color_util::simplify_hex("#ff234567") == "#234567"); EXPECT_EQ("#234567", color_util::simplify_hex("#ff234567"));
expect(color_util::simplify_hex("#00223344") == "#00223344"); EXPECT_EQ("#00223344", color_util::simplify_hex("#00223344"));
};
} }