aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qpdf-ctest.c59
-rw-r--r--qpdf/qpdf.testcov1
2 files changed, 58 insertions, 2 deletions
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c
index 30e7af2f..0797d9a2 100644
--- a/qpdf/qpdf-ctest.c
+++ b/qpdf/qpdf-ctest.c
@@ -3,7 +3,9 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
+static char* whoami = 0;
static qpdf_data qpdf = 0;
static void report_errors()
@@ -42,6 +44,57 @@ static void report_errors()
}
}
+static void read_file_into_memory(char const* filename,
+ char** buf, unsigned long* size)
+{
+ char* buf_p = 0;
+ FILE* f = NULL;
+ size_t bytes_read = 0;
+ size_t len = 0;
+
+ f = fopen(filename, "rb");
+ if (f == NULL)
+ {
+ fprintf(stderr, "%s: unable to open %s: %s\n",
+ whoami, filename, strerror(errno));
+ exit(2);
+ }
+ fseek(f, 0, SEEK_END);
+ *size = (unsigned long) ftell(f);
+ fseek(f, 0, SEEK_SET);
+ *buf = malloc(*size);
+ if (*buf == NULL)
+ {
+ fprintf(stderr, "%s: unable to allocate %lu bytes\n",
+ whoami, *size);
+ exit(2);
+ }
+ buf_p = *buf;
+ bytes_read = 0;
+ len = 0;
+ while ((len = fread(buf_p + bytes_read, 1, *size - bytes_read, f)) > 0)
+ {
+ bytes_read += len;
+ }
+ if (bytes_read != *size)
+ {
+ if (ferror(f))
+ {
+ fprintf(stderr, "%s: failure reading file %s into memory:",
+ whoami, filename);
+ }
+ else
+ {
+ fprintf(stderr, "%s: premature EOF reading file %s:",
+ whoami, filename);
+ }
+ fprintf(stderr, " read %lu, wanted %lu\n",
+ (unsigned long) bytes_read, (unsigned long) size);
+ exit(2);
+ }
+ fclose(f);
+}
+
static void test01(char const* infile,
char const* password,
char const* outfile,
@@ -135,7 +188,10 @@ static void test06(char const* infile,
char const* outfile,
char const* outfile2)
{
- qpdf_read(qpdf, infile, password);
+ char* buf = NULL;
+ unsigned long size = 0;
+ read_file_into_memory(infile, &buf, &size);
+ qpdf_read_memory(qpdf, infile, buf, size, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_object_stream_mode(qpdf, qpdf_o_generate);
@@ -271,7 +327,6 @@ static void test15(char const* infile,
int main(int argc, char* argv[])
{
- char* whoami = 0;
char* p = 0;
int n = 0;
char const* infile = 0;
diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov
index 85455a68..f0b3e06a 100644
--- a/qpdf/qpdf.testcov
+++ b/qpdf/qpdf.testcov
@@ -186,3 +186,4 @@ QPDFObjectHandle append page contents 0
QPDF_Stream getRawStreamData 0
QPDF_Stream getStreamData 0
QPDF_Stream expand filter abbreviation 0
+qpdf-c called qpdf_read_memory 0