From cc9423e68245eeab3a2ff5813368a33e82984812 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Sun, 6 May 2018 17:52:06 +0200 Subject: [PATCH] bar: Add geom_format_to_pixels tests --- tests/CMakeLists.txt | 1 + tests/unit_tests/components/bar.cpp | 47 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/unit_tests/components/bar.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4df92193..f5e52f59 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -82,6 +82,7 @@ unit_test(components/command_line unit_tests SOURCES components/command_line.cpp utils/string.cpp) +unit_test(components/bar unit_tests) # Compile all unit tests with 'make all_unit_tests' add_custom_target("all_unit_tests" DEPENDS ${unit_tests}) diff --git a/tests/unit_tests/components/bar.cpp b/tests/unit_tests/components/bar.cpp new file mode 100644 index 00000000..8b98b262 --- /dev/null +++ b/tests/unit_tests/components/bar.cpp @@ -0,0 +1,47 @@ +#include "common/test.hpp" +#include "components/bar.hpp" + +using namespace polybar; + + + +/** + * \brief Class for parameterized tests on geom_format_to_pixels + * + * The first element in the tuple is the expected return value, the second + * value is the format string. The max value is always 1000 + */ +class GeomFormatToPixelsTest : + public ::testing::Test, + public ::testing::WithParamInterface> {}; + +vector> to_pixels_no_offset_list = { + {1000, "100%"}, + {0, "0%"}, + {1000, "150%"}, + {100, "10%"}, + {0, "0"}, + {1234, "1234"}, + {1.234, "1.234"}, +}; + +vector> to_pixels_with_offset_list = { + {1000, "100%:-0"}, + {1000, "100%:+0"}, + {1010, "100%:+10"}, + {990, "100%:-10"}, + {10, "0%:+10"}, + {1000, "99%:+10"}, +}; + +INSTANTIATE_TEST_CASE_P(NoOffset, GeomFormatToPixelsTest, + ::testing::ValuesIn(to_pixels_no_offset_list),); + +INSTANTIATE_TEST_CASE_P(WithOffset, GeomFormatToPixelsTest, + ::testing::ValuesIn(to_pixels_with_offset_list),); + +TEST_P(GeomFormatToPixelsTest, correctness) { + double exp = GetParam().first; + std::string str = GetParam().second; + EXPECT_DOUBLE_EQ(exp, geom_format_to_pixels(str, 1000)); +}