diff --git a/include/fluent_tray.hpp b/include/fluent_tray.hpp index 234f2d4..c3a53ee 100644 --- a/include/fluent_tray.hpp +++ b/include/fluent_tray.hpp @@ -75,6 +75,10 @@ typedef enum { #include #include +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + /** * @namespace fluent_tray @@ -191,8 +195,8 @@ namespace fluent_tray static constexpr auto bits = type2bit() ; static const auto lower_mask = util::bit2mask(bits) ; - upper = static_cast(reinterpret_cast(input) >> bits) ; - lower = static_cast(reinterpret_cast(input) & lower_mask) ; + upper = static_cast((std::size_t)(input) >> bits) ; + lower = static_cast((std::size_t)(input) & lower_mask) ; } /** @@ -209,7 +213,7 @@ namespace fluent_tray auto out_upper = static_cast(upper) << bits ; auto out_lower = static_cast(lower) & lower_mask ; - out = reinterpret_cast(out_upper | out_lower) ; + out = (OutType)(out_upper | out_lower) ; } /** * @brief Calculate grayscale value from RGB @@ -1685,4 +1689,8 @@ namespace fluent_tray unsigned int FluentTray::message_id_ ; } +#if defined(__GNUC__) +#pragma GCC diagnostic warning "-Wold-style-cast" +#endif + #endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 931de3a..0d9990b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -88,9 +88,11 @@ function(AddTest TEST_NAME) ) endfunction() -AddTest(string_test string_test.cpp) -AddTest(menu_test menu_test.cpp) -AddTest(tray_test tray_test.cpp) +AddTest(test_string test_string.cpp) +AddTest(test_menu test_menu.cpp) +AddTest(test_tray test_tray.cpp) +AddTest(test_bits test_bits.cpp) +AddTest(test_color test_color.cpp) set( CMAKE_CTEST_ARGUMENTS diff --git a/tests/test_bits.cpp b/tests/test_bits.cpp new file mode 100644 index 0000000..0185da7 --- /dev/null +++ b/tests/test_bits.cpp @@ -0,0 +1,65 @@ +#include "test.hpp" + +using namespace fluent_tray ; + + +TEST_CASE("Bits test: ") { + SUBCASE("bit2mask") { + CHECK_EQ(util::bit2mask(1), 0b1) ; + CHECK_EQ(util::bit2mask(2), 0b11) ; + CHECK_EQ(util::bit2mask(3), 0b111) ; + CHECK_EQ(util::bit2mask(4), 0b1111) ; + CHECK_EQ(util::bit2mask(5), 0b11111) ; + CHECK_EQ(util::bit2mask(6), 0b111111) ; + CHECK_EQ(util::bit2mask(7), 0b1111111) ; + CHECK_EQ(util::bit2mask(8), 0b11111111) ; + CHECK_EQ(util::bit2mask(9), 0b111111111) ; + CHECK_EQ(util::bit2mask(10), 0b1111111111) ; + CHECK_EQ(util::bit2mask(11), 0b11111111111) ; + CHECK_EQ(util::bit2mask(12), 0b111111111111) ; + CHECK_EQ(util::bit2mask(13), 0b1111111111111) ; + CHECK_EQ(util::bit2mask(14), 0b11111111111111) ; + CHECK_EQ(util::bit2mask(15), 0b111111111111111) ; + CHECK_EQ(util::bit2mask(16), 0b1111111111111111) ; + CHECK_EQ(util::bit2mask(17), 0b11111111111111111) ; + CHECK_EQ(util::bit2mask(18), 0b111111111111111111) ; + CHECK_EQ(util::bit2mask(19), 0b1111111111111111111) ; + CHECK_EQ(util::bit2mask(20), 0b11111111111111111111) ; + CHECK_EQ(util::bit2mask(21), 0b111111111111111111111) ; + CHECK_EQ(util::bit2mask(22), 0b1111111111111111111111) ; + CHECK_EQ(util::bit2mask(23), 0b11111111111111111111111) ; + CHECK_EQ(util::bit2mask(24), 0b111111111111111111111111) ; + CHECK_EQ(util::bit2mask(25), 0b1111111111111111111111111) ; + CHECK_EQ(util::bit2mask(26), 0b11111111111111111111111111) ; + CHECK_EQ(util::bit2mask(27), 0b111111111111111111111111111) ; + CHECK_EQ(util::bit2mask(28), 0b1111111111111111111111111111) ; + CHECK_EQ(util::bit2mask(29), 0b11111111111111111111111111111) ; + CHECK_EQ(util::bit2mask(30), 0b111111111111111111111111111111) ; + CHECK_EQ(util::bit2mask(31), 0b1111111111111111111111111111111) ; + CHECK_EQ(util::bit2mask(32), 0b11111111111111111111111111111111) ; + } + + SUBCASE("type2bit") { + CHECK_EQ(util::type2bit(), 32) ; + } + + SUBCASE("split_bits") { + std::uint32_t value = 0x11f97892 ; + std::uint16_t upper, lower ; + + util::split_bits(value, upper, lower) ; + + CHECK_EQ(upper, 0x11f9) ; + CHECK_EQ(lower, 0x7892) ; + } + + SUBCASE("concatenate_bits") { + std::uint16_t upper = 0x112f ; + std::uint16_t lower = 0x88fc ; + std::uint32_t value ; + + util::concatenate_bits(upper, lower, value) ; + + CHECK_EQ(value, 0x112f88fc) ; + } +} diff --git a/tests/test_color.cpp b/tests/test_color.cpp new file mode 100644 index 0000000..7005d8e --- /dev/null +++ b/tests/test_color.cpp @@ -0,0 +1,9 @@ +#include "test.hpp" + +using namespace fluent_tray ; + +TEST_CASE("Color test: ") { + auto color = RGB(124, 214, 122) ; + unsigned char expected_color = 188 ; + CHECK_EQ(util::rgb2gray(color), expected_color) ; +} diff --git a/tests/menu_test.cpp b/tests/test_menu.cpp similarity index 100% rename from tests/menu_test.cpp rename to tests/test_menu.cpp diff --git a/tests/string_test.cpp b/tests/test_string.cpp similarity index 100% rename from tests/string_test.cpp rename to tests/test_string.cpp diff --git a/tests/tray_test.cpp b/tests/test_tray.cpp similarity index 100% rename from tests/tray_test.cpp rename to tests/test_tray.cpp