polybar/tests/unit_tests/x11/color.cpp

51 lines
1.6 KiB
C++
Raw Normal View History

2016-10-24 23:47:00 +00:00
#include <csignal>
2016-11-20 22:04:31 +00:00
#include "utils/color.hpp"
#include "x11/color.cpp"
2016-10-24 23:47:00 +00:00
int main() {
2016-11-19 05:22:44 +00:00
using namespace polybar;
2016-10-24 23:47:00 +00:00
"color"_test = [] {
color test{"#33990022"};
2016-11-20 22:04:31 +00:00
expect(color_util::hex<uint8_t>(test) == "#1E0006");
expect(color_util::hex<uint16_t>(test) == "#33990022");
};
"channels"_test = [] {
color test{"#eefb9281"};
2016-11-20 22:04:31 +00:00
expect(color_util::alpha_channel<uint8_t>(test) == 0xee);
expect(color_util::red_channel<uint8_t>(test) == 0xfb);
expect(color_util::green_channel<uint8_t>(test) == 0x92);
expect(color_util::blue_channel<uint8_t>(test) == 0x81);
};
"base"_test = [] {
color test{"#eefb9281"};
2016-11-20 22:04:31 +00:00
auto hex = color_util::hex<uint8_t>(test);
expect(std::strtoul(&hex[0], 0, 16) == 0x0);
2016-10-24 23:47:00 +00:00
};
"cache"_test = [] {
expect(g_colorstore.size() == size_t{0});
auto c1 = color::parse("#100");
expect(g_colorstore.size() == size_t{1});
auto c2 = color::parse("#200");
expect(g_colorstore.size() == size_t{2});
auto c3 = color::parse("#200");
expect(g_colorstore.size() == size_t{2});
2016-11-20 22:04:31 +00:00
expect((uint32_t)g_colorstore.find("#100")->second == (uint32_t)c1);
2016-10-24 23:47:00 +00:00
};
"predefined"_test = [] {
2016-11-20 22:04:31 +00:00
expect(color_util::hex<uint16_t>(g_colorblack) == "#FF000000");
expect(color_util::hex<uint16_t>(g_colorwhite) == "#FFFFFFFF");
2016-10-24 23:47:00 +00:00
};
"parse"_test = [] {
2016-11-20 22:04:31 +00:00
expect(color_util::hex<uint16_t>(color::parse("#ff9900", g_colorblack)) == "#FFFF9900");
expect(color_util::hex<uint16_t>(color::parse("invalid", g_colorwhite)) == "#FFFFFFFF");
expect(color_util::hex<uint8_t>(color::parse("33990022", g_colorwhite)) == "#1E0006");
2016-10-24 23:47:00 +00:00
};
}