summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2023-02-18 20:59:01 -0500
committerSam Atkins <atkinssj@gmail.com>2023-02-19 08:12:04 +0000
commit2c8b3fed717032ba021f4e0a997c07d1c7cbd2ef (patch)
tree6926e5a284c428c81901bc44bbddd8dd21b492fa
parent19e91e5211ea2394af85e694b4925d5976f671b2 (diff)
downloadserenity-2c8b3fed717032ba021f4e0a997c07d1c7cbd2ef.zip
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.
-rw-r--r--Tests/LibGfx/TestICCProfile.cpp11
-rw-r--r--Tests/LibGfx/test-inputs/p3-v4.iccbin0 -> 536 bytes
2 files changed, 11 insertions, 0 deletions
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 <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());
+}
diff --git a/Tests/LibGfx/test-inputs/p3-v4.icc b/Tests/LibGfx/test-inputs/p3-v4.icc
new file mode 100644
index 0000000000..e310029c37
--- /dev/null
+++ b/Tests/LibGfx/test-inputs/p3-v4.icc
Binary files differ