Add simple wxColourDatabase unit test

Notably check that the recently added UseScheme() works.
This commit is contained in:
Vadim Zeitlin
2024-12-14 01:22:54 +01:00
parent 1c06d46a9f
commit 7a7610713d
+27
View File
@@ -159,3 +159,30 @@ TEST_CASE("wxColour::GetLuminance", "[colour][luminance]")
CHECK( wxRED->GetLuminance() > 0 );
CHECK( wxRED->GetLuminance() < 1 );
}
TEST_CASE("wxColour::Database", "[colour][database]")
{
wxColourDatabase db;
// Check that we can add custom colours.
db.AddColour("NQB", wxColour(0x010203)); // Not quite black.
CHECK_THAT( db.Find("nqb"), RGBSameAs(0x03, 0x02, 0x01) );
// Unfortunately we can't check that all colours round trip because this is
// not the case for the colours present in the database under multiple
// names, such as "GREY" and "GRAY" for example. But we can at least check
// that the name found for all colours uses the same colour.
for ( const auto& name : db.GetAllNames() )
{
const wxColour& colour = db.Find(name);
const wxString& maybeOtherName = db.FindName(colour);
CHECK( db.Find(maybeOtherName) == colour );
}
// Check that green uses CSS value by default.
CHECK_THAT( db.Find("green"), RGBSameAs(0, 0x80, 0) );
// But we can use the legacy value for it too.
db.UseScheme(wxColourDatabase::Traditional);
CHECK_THAT( db.Find("green"), RGBSameAs(0, 0xff, 0) );
}