Tests: Add a test for Gfx::ICC::encode()

The test verifies that loading an icc file and serializing it
again produces exactly the same output as the input. That's not
always the case, but often. It requires the input file either
not having any padding or using null bytes as padding, it
requires the input file putting tag data in the order the
tag data is referenced in in the tag table, and it requires the
input file only using known tag types (which at the moment
means it only works for v4 profiles, but that part will change
in the future).

The new file p3-v4.icc was extracted from a jpeg taken by an
iPhone Mini.
This commit is contained in:
Nico Weber 2023-02-18 20:59:01 -05:00 committed by Sam Atkins
parent 19e91e5211
commit 2c8b3fed71
2 changed files with 11 additions and 0 deletions

View file

@ -5,6 +5,7 @@
*/
#include <LibCore/MappedFile.h>
#include <LibGfx/ICC/BinaryWriter.h>
#include <LibGfx/ICC/Profile.h>
#include <LibGfx/JPEGLoader.h>
#include <LibGfx/PNGLoader.h>
@ -39,3 +40,13 @@ TEST_CASE(jpg)
auto icc_profile = MUST(Gfx::ICC::Profile::try_load_from_externally_owned_memory(icc_bytes.value()));
EXPECT(icc_profile->is_v4());
}
TEST_CASE(serialize_icc)
{
auto file = MUST(Core::MappedFile::map(TEST_INPUT("p3-v4.icc"sv)));
auto icc_profile = MUST(Gfx::ICC::Profile::try_load_from_externally_owned_memory(file->bytes()));
EXPECT(icc_profile->is_v4());
auto serialized_bytes = MUST(Gfx::ICC::encode(*icc_profile));
EXPECT_EQ(serialized_bytes, file->bytes());
}

Binary file not shown.