[poppler] test/CMakeLists.txt test/image-embedding.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Nov 29 17:55:46 UTC 2021
test/CMakeLists.txt | 123 ++++++++++++++++++++++++++----------------------
test/image-embedding.cc | 12 +++-
2 files changed, 78 insertions(+), 57 deletions(-)
New commits:
commit 30eb3508c0b698901234db2e4752d369741393b4
Author: Georgiy Sgibnev <georgiy at lab50.net>
Date: Mon Nov 29 16:17:44 2021 +0300
New unit-tests for the image embedding API (for the error handling)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index a365babb..a9ee29c6 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -55,8 +55,8 @@ set (pdf_fullrewrite_SRCS
add_executable(pdf-fullrewrite ${pdf_fullrewrite_SRCS})
target_link_libraries(pdf-fullrewrite poppler)
-# Test image embedding API.
-if(ENABLE_LIBJPEG AND ENABLE_LIBPNG)
+# Tests for the image embedding API.
+if(ENABLE_LIBPNG OR ENABLE_LIBJPEG)
set(image_embedding_SRCS
image-embedding.cc
../utils/parseargs.cc
@@ -67,58 +67,73 @@ if(ENABLE_LIBJPEG AND ENABLE_LIBPNG)
set(INPUT_PDF ${TESTDATADIR}/unittestcases/xr01.pdf)
set(IMG_DIR ${TESTDATADIR}/unittestcases/images)
set(IMAGE_EMBEDDING_PATH ${EXECUTABLE_OUTPUT_PATH}/image-embedding)
- add_test(
- NAME embed-png-g1
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-g1.png -depth 8 -colorspace DeviceGray
- )
- add_test(
- NAME embed-png-g2
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-g2.png -depth 8 -colorspace DeviceGray
- )
- add_test(
- NAME embed-png-g4
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-g4.png -depth 8 -colorspace DeviceGray
- )
- add_test(
- NAME embed-png-g8
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-g8.png -depth 8 -colorspace DeviceGray
- )
- add_test(
- NAME embed-png-g16
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-g16.png -depth 16 -colorspace DeviceGray
- )
- add_test(
- NAME embed-png-ga8
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-ga8.png -depth 8 -colorspace DeviceGray -smask
- )
- add_test(
- NAME embed-png-ga16
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-ga16.png -depth 16 -colorspace DeviceGray -smask
- )
- add_test(
- NAME embed-png-palette
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-palette.png -depth 8 -colorspace DeviceRGB
- )
- add_test(
- NAME embed-png-rgb8
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-rgb8.png -depth 8 -colorspace DeviceRGB
- )
- add_test(
- NAME embed-png-rgb16
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-rgb16.png -depth 16 -colorspace DeviceRGB
- )
- add_test(
- NAME embed-png-rgba8
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-rgba8.png -depth 8 -colorspace DeviceRGB -smask
- )
- add_test(
- NAME embed-png-rgba16
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-rgba16.png -depth 16 -colorspace DeviceRGB -smask
- )
- add_test(
- NAME embed-jpeg
- COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/jpeg.jpg -depth 8 -colorspace DeviceRGB -filter DCTDecode
- )
+
+ if (ENABLE_LIBPNG)
+ add_test(
+ NAME embed-png-g1
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-g1.png -depth 8 -colorspace DeviceGray
+ )
+ add_test(
+ NAME embed-png-g2
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-g2.png -depth 8 -colorspace DeviceGray
+ )
+ add_test(
+ NAME embed-png-g4
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-g4.png -depth 8 -colorspace DeviceGray
+ )
+ add_test(
+ NAME embed-png-g8
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-g8.png -depth 8 -colorspace DeviceGray
+ )
+ add_test(
+ NAME embed-png-g16
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-g16.png -depth 16 -colorspace DeviceGray
+ )
+ add_test(
+ NAME embed-png-ga8
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-ga8.png -depth 8 -colorspace DeviceGray -smask
+ )
+ add_test(
+ NAME embed-png-ga16
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-ga16.png -depth 16 -colorspace DeviceGray -smask
+ )
+ add_test(
+ NAME embed-png-palette
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-palette.png -depth 8 -colorspace DeviceRGB
+ )
+ add_test(
+ NAME embed-png-rgb8
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-rgb8.png -depth 8 -colorspace DeviceRGB
+ )
+ add_test(
+ NAME embed-png-rgb16
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-rgb16.png -depth 16 -colorspace DeviceRGB
+ )
+ add_test(
+ NAME embed-png-rgba8
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-rgba8.png -depth 8 -colorspace DeviceRGB -smask
+ )
+ add_test(
+ NAME embed-png-rgba16
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/png-rgba16.png -depth 16 -colorspace DeviceRGB -smask
+ )
+ add_test(
+ NAME embed-malformed-png
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/malformed.png -fail
+ )
+ endif()
+
+ if(ENABLE_LIBJPEG)
+ add_test(
+ NAME embed-jpeg
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/jpeg.jpg -depth 8 -colorspace DeviceRGB -filter DCTDecode
+ )
+ add_test(
+ NAME embed-malformed-jpeg
+ COMMAND ${IMAGE_EMBEDDING_PATH} ${INPUT_PDF} ${IMG_DIR}/malformed.jpg -fail
+ )
+ endif()
+
unset(IMAGE_EMBEDDING_PATH)
unset(IMG_DIR)
unset(INPUT_PDF)
diff --git a/test/image-embedding.cc b/test/image-embedding.cc
index 6ffcdb2d..a028d186 100644
--- a/test/image-embedding.cc
+++ b/test/image-embedding.cc
@@ -25,12 +25,14 @@ static int depth = 0;
static GooString colorSpace;
static GooString filter;
static bool smask = false;
+static bool fail = false;
static bool printHelp = false;
static const ArgDesc argDesc[] = { { "-depth", argInt, &depth, 0, "XObject's property 'BitsPerComponent'" },
{ "-colorspace", argGooString, &colorSpace, 0, "XObject's property 'ColorSpace'" },
{ "-filter", argGooString, &filter, 0, "XObject's property 'Filter'" },
{ "-smask", argFlag, &smask, 0, "SMask should exist" },
+ { "-fail", argFlag, &fail, 0, "the image embedding API is expected to fail" },
{ "-h", argFlag, &printHelp, 0, "print usage information" },
{ "-help", argFlag, &printHelp, 0, "print usage information" },
{ "--help", argFlag, &printHelp, 0, "print usage information" },
@@ -57,11 +59,15 @@ int main(int argc, char *argv[])
// Embed an image.
Ref baseImageRef = ImageEmbeddingUtils::embed(doc->getXRef(), imagePath.toStr());
if (baseImageRef == Ref::INVALID()) {
- fprintf(stderr, "embedImage() failed.\n");
- return 1;
+ if (fail) {
+ return 0;
+ } else {
+ fprintf(stderr, "ImageEmbeddingUtils::embed() failed.\n");
+ return 1;
+ }
}
- // Save updated PDF document.
+ // Save the updated PDF document.
// const GooString outputPathSuffix(".pdf");
// const GooString outputPath = GooString(&imagePath, &outputPathSuffix);
// doc->saveAs(&outputPath, writeForceRewrite);
More information about the poppler
mailing list