summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Figuière <hub@figuiere.net>2020-06-23 22:46:33 -0400
committerHubert Figuière <hub@figuiere.net>2020-06-23 23:16:12 -0400
commit9dfb9a03ff72c18d4dd30de2302295cee1070d02 (patch)
tree5f4b9ef123cc9d1e9c3ff83c25a7e8fa94ac54b0
parentd1a475c5714219994046c3e2dcab2257c10f6f51 (diff)
Issue #20 - Test file formats and convert GIF samples to GIF89a
https://gitlab.freedesktop.org/libopenraw/exempi/-/issues/20
-rw-r--r--exempi/Makefile.am8
-rw-r--r--exempi/tests/test-xmpformat.cpp98
-rw-r--r--samples/testfiles/BlueSquare-FAIL.gifbin0 -> 3858 bytes
-rw-r--r--samples/testfiles/BlueSquare.gifbin3858 -> 3858 bytes
4 files changed, 104 insertions, 2 deletions
diff --git a/exempi/Makefile.am b/exempi/Makefile.am
index c118897..4efd9a7 100644
--- a/exempi/Makefile.am
+++ b/exempi/Makefile.am
@@ -88,13 +88,13 @@ check_PROGRAMS = testexempicore testserialise \
testtiffleak testxmpfiles testxmpfileswrite \
testparse testiterator testinit testfdo18635\
testfdo83313 testcpp testwebp \
- testadobesdk \
+ testadobesdk testxmpformat \
$(NULL)
TESTS = tests/testcore.sh testinit testexempicore testserialise \
testwritenewprop \
testtiffleak testxmpfiles testxmpfileswrite \
testparse testiterator testfdo18635 testfdo83313 testcpp testwebp \
- testadobesdk \
+ testadobesdk testxmpformat \
$(NULL)
TESTS_ENVIRONMENT = TEST_DIR=$(srcdir)/tests BOOST_TEST_CATCH_SYSTEM_ERRORS=no VALGRIND="$(VALGRIND)"
LOG_COMPILER = $(VALGRIND)
@@ -165,3 +165,7 @@ testwebp_LDFLAGS = -static @BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS@
testadobesdk_SOURCES = tests/test-adobesdk.cpp
testadobesdk_LDADD = libexempi.la @BOOST_UNIT_TEST_FRAMEWORK_LIBS@
testadobesdk_LDFLAGS = -static @BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS@
+
+testxmpformat_SOURCES = tests/test-xmpformat.cpp
+testxmpformat_LDADD = libexempi.la @BOOST_UNIT_TEST_FRAMEWORK_LIBS@
+testxmpformat_LDFLAGS = -static @BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS@
diff --git a/exempi/tests/test-xmpformat.cpp b/exempi/tests/test-xmpformat.cpp
new file mode 100644
index 0000000..af13cb1
--- /dev/null
+++ b/exempi/tests/test-xmpformat.cpp
@@ -0,0 +1,98 @@
+/*
+ * exempi - test-xmpformat.cpp
+ *
+ * Copyright (C) 2020 Hubert Figuière
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1 Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2 Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3 Neither the name of the Authors, nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software wit hout specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <map>
+#include <string>
+
+#include <boost/test/minimal.hpp>
+
+#include "xmp.h"
+
+const std::map<const char*, XmpFileType> TEST_CASES = {
+ { "avi", XMP_FT_AVI },
+ { "eps", XMP_FT_EPS },
+ { "gif", XMP_FT_GIF },
+ { "indd", XMP_FT_INDESIGN },
+ { "jpg", XMP_FT_JPEG },
+ { "mov", XMP_FT_MOV },
+ { "mp3", XMP_FT_MP3 },
+ { "png", XMP_FT_PNG },
+ { "psd", XMP_FT_PHOTOSHOP },
+ { "tif", XMP_FT_TIFF },
+ { "webp", XMP_FT_WEBP },
+ { "wav", XMP_FT_WAV }
+};
+
+const std::map<const char*, XmpFileType> FAILING_CASES = {
+ // This is a GIF87a. Not supported.
+ { "gif", XMP_FT_UNKNOWN }
+};
+
+// Test that the sample files match the file type.
+//
+// This test would have caught:
+// https://gitlab.freedesktop.org/libopenraw/exempi/-/issues/20
+//
+int test_main(int , char *[])
+{
+ const char* srcdir = getenv("srcdir");
+ if (!srcdir) {
+ srcdir = ".";
+ }
+
+ BOOST_CHECK(xmp_init());
+
+ for (auto testcase : TEST_CASES) {
+ std::string imagepath(srcdir);
+ imagepath += "/../samples/testfiles/BlueSquare.";
+ imagepath += testcase.first;
+
+ printf("%s\n", imagepath.c_str());
+ auto xft = xmp_files_check_file_format(imagepath.c_str());
+ BOOST_CHECK(xft == testcase.second);
+ }
+
+ for (auto testcase : FAILING_CASES) {
+ std::string imagepath(srcdir);
+ imagepath += "/../samples/testfiles/BlueSquare-FAIL.";
+ imagepath += testcase.first;
+
+ printf("%s\n", imagepath.c_str());
+ auto xft = xmp_files_check_file_format(imagepath.c_str());
+ BOOST_CHECK(xft == testcase.second);
+ }
+
+ return 0;
+}
diff --git a/samples/testfiles/BlueSquare-FAIL.gif b/samples/testfiles/BlueSquare-FAIL.gif
new file mode 100644
index 0000000..7dcc9e7
--- /dev/null
+++ b/samples/testfiles/BlueSquare-FAIL.gif
Binary files differ
diff --git a/samples/testfiles/BlueSquare.gif b/samples/testfiles/BlueSquare.gif
index 7dcc9e7..862bc24 100644
--- a/samples/testfiles/BlueSquare.gif
+++ b/samples/testfiles/BlueSquare.gif
Binary files differ