mirror of
				https://github.com/michaelrsweet/pdfio.git
				synced 2025-10-31 10:26:22 +01:00 
			
		
		
		
	Add decode testing to testpdfio
This commit is contained in:
		| @@ -448,6 +448,8 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|       st->flate.next_in  = (Bytef *)st->cbuffer; | ||||
|       st->flate.avail_in = (uInt)_pdfioFileRead(st->pdf, st->cbuffer, sizeof(st->cbuffer)); | ||||
|  | ||||
|       PDFIO_DEBUG("_pdfioStreamOpen: avail_in=%u\n", st->flate.avail_in); | ||||
|  | ||||
|       if (inflateInit(&(st->flate)) != Z_OK) | ||||
|       { | ||||
| 	_pdfioFileError(st->pdf, "Unable to start Flate filter."); | ||||
|   | ||||
							
								
								
									
										57
									
								
								testpdfio.c
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								testpdfio.c
									
									
									
									
									
								
							| @@ -6,6 +6,12 @@ | ||||
| // Licensed under Apache License v2.0.  See the file "LICENSE" for more | ||||
| // information. | ||||
| // | ||||
| // Usage: | ||||
| // | ||||
| //   ./testpdfio | ||||
| // | ||||
| //   ./testpdfio FILENAME [OBJECT-NUMBER] [FILENAME [OBJECT-NUMBER]] ... | ||||
| // | ||||
|  | ||||
| // | ||||
| // Include necessary headers... | ||||
| @@ -20,7 +26,7 @@ | ||||
| // Local functions... | ||||
| // | ||||
|  | ||||
| static int	do_test_file(const char *filename); | ||||
| static int	do_test_file(const char *filename, int objnum); | ||||
| static int	do_unit_tests(void); | ||||
| static int	draw_image(pdfio_stream_t *st, const char *name, double x, double y, double w, double h, const char *label); | ||||
| static bool	error_cb(pdfio_file_t *pdf, const char *message, bool *error); | ||||
| @@ -52,7 +58,15 @@ main(int  argc,				// I - Number of command-line arguments | ||||
|  | ||||
|     for (i = 1; i < argc; i ++) | ||||
|     { | ||||
|       if (do_test_file(argv[i])) | ||||
|       if ((i + 1) < argc && isdigit(argv[i + 1][0] & 255)) | ||||
|       { | ||||
|         // filename.pdf object-number | ||||
|         if (do_test_file(argv[i], atoi(argv[i + 1]))) | ||||
| 	  return (1); | ||||
|  | ||||
| 	i ++; | ||||
|       } | ||||
|       else if (do_test_file(argv[i], 0)) | ||||
|         return (1); | ||||
|     } | ||||
|   } | ||||
| @@ -70,7 +84,8 @@ main(int  argc,				// I - Number of command-line arguments | ||||
| // | ||||
|  | ||||
| static int				// O - Exit status | ||||
| do_test_file(const char *filename)	// I - PDF filename | ||||
| do_test_file(const char *filename,	// I - PDF filename | ||||
|              int        objnum)		// I - Object number to dump, if any | ||||
| { | ||||
|   bool		error = false;		// Have we shown an error yet? | ||||
|   pdfio_file_t	*pdf;			// PDF file | ||||
| @@ -82,8 +97,43 @@ do_test_file(const char *filename)	// I - PDF filename | ||||
|  | ||||
|  | ||||
|   // Try opening the file... | ||||
|   if (!objnum) | ||||
|     printf("pdfioFileOpen(\"%s\", ...): ", filename); | ||||
|  | ||||
|   if ((pdf = pdfioFileOpen(filename, (pdfio_error_cb_t)error_cb, &error)) != NULL) | ||||
|   { | ||||
|     if (objnum) | ||||
|     { | ||||
|       const char	*filter;	// Stream filter | ||||
|       pdfio_stream_t	*st;		// Stream | ||||
|       char		buffer[8192];	// Read buffer | ||||
|       ssize_t		bytes;		// Bytes read | ||||
|  | ||||
|       if ((obj = pdfioFileFindObj(pdf, (size_t)objnum)) == NULL) | ||||
|       { | ||||
|         puts("Not found."); | ||||
|         return (1); | ||||
|       } | ||||
|  | ||||
|       if ((dict = pdfioObjGetDict(obj)) == NULL) | ||||
|       { | ||||
|         puts("Not a stream."); | ||||
|         return (1); | ||||
|       } | ||||
|  | ||||
|       filter = pdfioDictGetName(dict, "Filter"); | ||||
|  | ||||
|       if ((st = pdfioObjOpenStream(obj, (filter && !strcmp(filter, "FlateDecode")) ? PDFIO_FILTER_FLATE : PDFIO_FILTER_NONE)) == NULL) | ||||
|         return (1); | ||||
|  | ||||
|       while ((bytes = pdfioStreamRead(st, buffer, sizeof(buffer))) > 0) | ||||
|         fwrite(buffer, 1, (size_t)bytes, stdout); | ||||
|  | ||||
|       pdfioStreamClose(st); | ||||
|  | ||||
|       return (0); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       puts("PASS"); | ||||
|  | ||||
| @@ -137,6 +187,7 @@ do_test_file(const char *filename)	// I - PDF filename | ||||
| 	  putchar('\n'); | ||||
| 	} | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     // Close the file and return success... | ||||
|     pdfioFileClose(pdf); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user