Add UI core color parser tests
This commit is contained in:
@@ -146,6 +146,16 @@ add_test(NAME pp_paint_renderer_compositor_tests COMMAND pp_paint_renderer_compo
|
||||
set_tests_properties(pp_paint_renderer_compositor_tests PROPERTIES
|
||||
LABELS "renderer;paint;desktop-fast")
|
||||
|
||||
add_executable(pp_ui_core_color_tests
|
||||
ui_core/color_tests.cpp)
|
||||
target_link_libraries(pp_ui_core_color_tests PRIVATE
|
||||
pp_ui_core
|
||||
pp_test_harness)
|
||||
|
||||
add_test(NAME pp_ui_core_color_tests COMMAND pp_ui_core_color_tests)
|
||||
set_tests_properties(pp_ui_core_color_tests PROPERTIES
|
||||
LABELS "ui;desktop-fast")
|
||||
|
||||
add_executable(pp_ui_core_layout_value_tests
|
||||
ui_core/layout_value_tests.cpp)
|
||||
target_link_libraries(pp_ui_core_layout_value_tests PRIVATE
|
||||
|
||||
71
tests/ui_core/color_tests.cpp
Normal file
71
tests/ui_core/color_tests.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "test_harness.h"
|
||||
#include "ui_core/color.h"
|
||||
|
||||
using pp::foundation::StatusCode;
|
||||
using pp::ui::parse_hex_color;
|
||||
|
||||
namespace {
|
||||
|
||||
void parses_short_and_long_rgb_forms(pp::tests::Harness& h)
|
||||
{
|
||||
const auto short_rgb = parse_hex_color("#0f8");
|
||||
const auto long_rgb = parse_hex_color("#102aFF");
|
||||
|
||||
PP_EXPECT(h, short_rgb.ok());
|
||||
PP_EXPECT(h, short_rgb.value().r == 0x00);
|
||||
PP_EXPECT(h, short_rgb.value().g == 0xff);
|
||||
PP_EXPECT(h, short_rgb.value().b == 0x88);
|
||||
PP_EXPECT(h, short_rgb.value().a == 0xff);
|
||||
|
||||
PP_EXPECT(h, long_rgb.ok());
|
||||
PP_EXPECT(h, long_rgb.value().r == 0x10);
|
||||
PP_EXPECT(h, long_rgb.value().g == 0x2a);
|
||||
PP_EXPECT(h, long_rgb.value().b == 0xff);
|
||||
PP_EXPECT(h, long_rgb.value().a == 0xff);
|
||||
}
|
||||
|
||||
void parses_alpha_forms(pp::tests::Harness& h)
|
||||
{
|
||||
const auto short_rgba = parse_hex_color("#1234");
|
||||
const auto long_rgba = parse_hex_color("#11223344");
|
||||
|
||||
PP_EXPECT(h, short_rgba.ok());
|
||||
PP_EXPECT(h, short_rgba.value().r == 0x11);
|
||||
PP_EXPECT(h, short_rgba.value().g == 0x22);
|
||||
PP_EXPECT(h, short_rgba.value().b == 0x33);
|
||||
PP_EXPECT(h, short_rgba.value().a == 0x44);
|
||||
|
||||
PP_EXPECT(h, long_rgba.ok());
|
||||
PP_EXPECT(h, long_rgba.value().r == 0x11);
|
||||
PP_EXPECT(h, long_rgba.value().g == 0x22);
|
||||
PP_EXPECT(h, long_rgba.value().b == 0x33);
|
||||
PP_EXPECT(h, long_rgba.value().a == 0x44);
|
||||
}
|
||||
|
||||
void rejects_invalid_colors(pp::tests::Harness& h)
|
||||
{
|
||||
const auto empty = parse_hex_color("");
|
||||
const auto missing_hash = parse_hex_color("112233");
|
||||
const auto bad_length = parse_hex_color("#12");
|
||||
const auto bad_character = parse_hex_color("#12xz45");
|
||||
|
||||
PP_EXPECT(h, !empty.ok());
|
||||
PP_EXPECT(h, empty.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !missing_hash.ok());
|
||||
PP_EXPECT(h, missing_hash.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !bad_length.ok());
|
||||
PP_EXPECT(h, bad_length.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !bad_character.ok());
|
||||
PP_EXPECT(h, bad_character.status().code == StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pp::tests::Harness harness;
|
||||
harness.run("parses_short_and_long_rgb_forms", parses_short_and_long_rgb_forms);
|
||||
harness.run("parses_alpha_forms", parses_alpha_forms);
|
||||
harness.run("rejects_invalid_colors", rejects_invalid_colors);
|
||||
return harness.finish();
|
||||
}
|
||||
Reference in New Issue
Block a user