From 2c8b3fed717032ba021f4e0a997c07d1c7cbd2ef Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 18 Feb 2023 20:59:01 -0500 Subject: [PATCH] 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. --- Tests/LibGfx/TestICCProfile.cpp | 11 +++++++++++ Tests/LibGfx/test-inputs/p3-v4.icc | Bin 0 -> 536 bytes 2 files changed, 11 insertions(+) create mode 100644 Tests/LibGfx/test-inputs/p3-v4.icc diff --git a/Tests/LibGfx/TestICCProfile.cpp b/Tests/LibGfx/TestICCProfile.cpp index 4db30ac133..816d3d8e40 100644 --- a/Tests/LibGfx/TestICCProfile.cpp +++ b/Tests/LibGfx/TestICCProfile.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -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()); +} diff --git a/Tests/LibGfx/test-inputs/p3-v4.icc b/Tests/LibGfx/test-inputs/p3-v4.icc new file mode 100644 index 0000000000000000000000000000000000000000..e310029c37563341832703f0aa21f67adc23d2e3 GIT binary patch literal 536 zcmZQzV3J5ID9B-9U|`72D=7+ccT$Lmj8b5K#=ywH$N&b3$;AbZ0RcWB4vYq|5%}9R zh}z4#AhX{5UEF8U>V7zP%U=JgTN3&Rby!(kDXGQD3=9l^7#J7~k_(DT7#J9J7#J7= z%1a7B>>36J29ctO$S4K|#t9&HI)uFh#7=^+cYxSMAwkXz42)+O7#I|iGZIr67#QC$ zFfiyOA&I9Wv2$}uLH2?i1@b9RYF=nC$Q%X+1{nqyhD?THh608hhD3%+1_g!y24fuR zO~C4%8S)tl7%CZx7%~~s88R437!(*B84AEAq%tTlcrxTMBs1tS=rAZS7%>=u z!Wm>a1H-qg(D2hih&A75V6ff)|NsBp2r;ky3=A9185p>BBE&Q-7#IY(85mCNEJ!R$ z1e?dqz`($imd3#FX*mM}ZzKbQ@C612uIS=4V