From: msweet Date: Wed, 29 Jan 2014 01:52:38 +0000 (+0000) Subject: Add PPD cache unit test program. X-Git-Tag: v2.2b1~772 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b2b9911d6d1d020b02cf900fcf3e47aaefdff3ee;p=thirdparty%2Fcups.git Add PPD cache unit test program. (Current focus is on finishings) git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11547 a1ca3aef-8c08-0410-bb20-df032aa958be --- diff --git a/cups/Makefile b/cups/Makefile index 084b1680e5..413e7b7ac4 100644 --- a/cups/Makefile +++ b/cups/Makefile @@ -3,7 +3,7 @@ # # API library Makefile for CUPS. # -# Copyright 2007-2013 by Apple Inc. +# Copyright 2007-2014 by Apple Inc. # Copyright 1997-2006 by Easy Software Products, all rights reserved. # # These coded instructions, statements, and computer programs are the @@ -147,6 +147,7 @@ LIBTARGETS = \ UNITTARGETS = \ testadmin \ testarray \ + testcache \ testconflicts \ testcups \ testfile \ @@ -372,6 +373,16 @@ testarray: testarray.o $(LIBCUPSSTATIC) ./testarray +# +# testcache (dependency on static CUPS library is intentional) +# + +testcache: testcache.o $(LIBCUPSSTATIC) + echo Linking $@... + $(CC) $(LDFLAGS) -o $@ testcache.o $(LIBCUPSSTATIC) \ + $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(COMMONLIBS) $(LIBZ) + + # # testconflicts (dependency on static CUPS library is intentional) # diff --git a/cups/ppd-cache.c b/cups/ppd-cache.c index ceae66df90..e13e73ab8d 100644 --- a/cups/ppd-cache.c +++ b/cups/ppd-cache.c @@ -1665,8 +1665,13 @@ _ppdCacheGetFinishingValues( * Range check input... */ + DEBUG_printf(("_ppdCacheGetFinishingValues(pc=%p, num_options=%d, options=%p, max_values=%d, values=%p)", pc, num_options, options, max_values, values)); + if (!pc || !pc->finishings || num_options < 1 || max_values < 1 || !values) + { + DEBUG_puts("_ppdCacheGetFinishingValues: Bad arguments, returning 0."); return (0); + } /* * Go through the finishings options and see what is set... @@ -1676,13 +1681,24 @@ _ppdCacheGetFinishingValues( f; f = (_pwg_finishings_t *)cupsArrayNext(pc->finishings)) { + DEBUG_printf(("_ppdCacheGetFinishingValues: Checking %d (%s)", f->value, ippEnumString("finishings", f->value))); + for (i = f->num_options, option = f->options; i > 0; i --, option ++) + { + DEBUG_printf(("_ppdCacheGetFinishingValues: %s=%s?", option->name, option->value)); + if ((val = cupsGetOption(option->name, num_options, options)) == NULL || _cups_strcasecmp(option->value, val)) + { + DEBUG_puts("_ppdCacheGetFinishingValues: NO"); break; + } + } if (i == 0) { + DEBUG_printf(("_ppdCacheGetFinishingValues: Adding %d.", f->value)); + values[num_values ++] = f->value; if (num_values >= max_values) @@ -1690,6 +1706,8 @@ _ppdCacheGetFinishingValues( } } + DEBUG_printf(("_ppdCacheGetFinishingValues: Returning %d.", num_values)); + return (num_values); } diff --git a/cups/testcache.c b/cups/testcache.c new file mode 100644 index 0000000000..96f05d7259 --- /dev/null +++ b/cups/testcache.c @@ -0,0 +1,90 @@ +/* + * "$Id$" + * + * PPD cache testing program for CUPS. + * + * Copyright 2009-2014 by Apple Inc. + * + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". + * + * This file is subject to the Apple OS-Developed Software exception. + */ + +/* + * Include necessary headers... + */ + +#include "ppd-private.h" +#include "file-private.h" + + +/* + * 'main()' - Main entry. + */ + +int /* O - Exit status */ +main(int argc, /* I - Number of command-line args */ + char *argv[]) /* I - Command-line arguments */ +{ + int i; /* Looping var */ + const char *ppdfile = NULL;/* PPD filename */ + ppd_file_t *ppd; /* PPD file */ + int num_options = 0;/* Number of options */ + cups_option_t *options = NULL;/* Options */ + _ppd_cache_t *pc; /* PPD cache and PWG mapping data */ + int num_finishings, /* Number of finishing options */ + finishings[20]; /* Finishing options */ + + + if (argc < 2) + { + puts("Usage: ./testcache filename.ppd [name=value ... name=value]"); + return (1); + } + + ppdfile = argv[1]; + if ((ppd = ppdOpenFile(ppdfile)) == NULL) + { + ppd_status_t err; /* Last error in file */ + int line; /* Line number in file */ + + + err = ppdLastError(&line); + + fprintf(stderr, "Unable to open \"%s\": %s on line %d\n", ppdfile, ppdErrorString(err), line); + return (1); + } + + if ((pc = _ppdCacheCreateWithPPD(ppd)) == NULL) + { + fprintf(stderr, "Unable to create PPD cache from \"%s\".\n", ppdfile); + return (1); + } + + for (i = 2; i < argc; i ++) + num_options = cupsParseOptions(argv[i], num_options, &options); + + ppdMarkDefaults(ppd); + cupsMarkOptions(ppd, num_options, options); + + num_finishings = _ppdCacheGetFinishingValues(pc, num_options, options, (int)sizeof(finishings) / sizeof(finishings[0]), finishings); + + fputs("finishings=", stdout); + for (i = 0; i < num_finishings; i ++) + if (i) + printf(",%d", finishings[i]); + else + printf("%d", finishings[i]); + fputs("\n", stdout); + + return (0); +} + + +/* + * End of "$Id$". + */