From: Michael R Sweet Date: Wed, 7 Apr 2021 13:35:15 +0000 (-0400) Subject: Add PASS-IF-[NOT-]DEFINED directive to ipptool. X-Git-Tag: v2.4b1~161 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff76ef857ac2396ef7e7d4fc999b0ec1bc7eeaef;p=thirdparty%2Fcups.git Add PASS-IF-[NOT-]DEFINED directive to ipptool. --- diff --git a/doc/help/man-ipptoolfile.html b/doc/help/man-ipptoolfile.html index 35ad6f8735..36171127f6 100644 --- a/doc/help/man-ipptoolfile.html +++ b/doc/help/man-ipptoolfile.html @@ -182,6 +182,9 @@ The monitoring tests will run until all of the EXPECT conditions are sati
Specifies the human-readable name of the test.
OPERATION operation-code
Specifies the operation to be performed. +
PASS-IF-DEFINED variable-name +
PASS-IF-NOT-DEFINED variable-name +
Specifies that the current test should be passed automatically when the variable is or is not defined.
PAUSE "message"
Displays the provided message and waits for the user to press a key to continue.
REQUEST-ID number diff --git a/man/ipptoolfile.5 b/man/ipptoolfile.5 index 000eaa5323..3392242919 100644 --- a/man/ipptoolfile.5 +++ b/man/ipptoolfile.5 @@ -7,7 +7,7 @@ .\" Licensed under Apache License v2.0. See the file "LICENSE" for more .\" information. .\" -.TH ipptoolfile 5 "CUPS" "2021-03-31" "OpenPrinting" +.TH ipptoolfile 5 "CUPS" "2021-04-07" "OpenPrinting" .SH NAME ipptoolfile \- ipptool file format .SH DESCRIPTION @@ -225,6 +225,11 @@ Specifies the human-readable name of the test. \fBOPERATION \fIoperation-code\fR Specifies the operation to be performed. .TP 5 +\fBPASS\-IF\-DEFINED \fIvariable-name\fR +.TP 5 +\fBPASS\-IF\-NOT\-DEFINED \fIvariable-name\fR +Specifies that the current test should be passed automatically when the variable is or is not defined. +.TP 5 \fBPAUSE "\fImessage\fB"\fR Displays the provided message and waits for the user to press a key to continue. .TP 5 diff --git a/tools/ipptool.c b/tools/ipptool.c index 11945077fa..25a34d2b60 100644 --- a/tools/ipptool.c +++ b/tools/ipptool.c @@ -149,7 +149,8 @@ typedef struct ipptool_test_s /**** Test Data ****/ useconds_t repeat_interval; /* Repeat interval (delay) */ int request_id; /* Current request ID */ char resource[512]; /* Resource for request */ - int skip_test, /* Skip this test? */ + int pass_test, /* Pass this test? */ + skip_test, /* Skip this test? */ num_statuses; /* Number of valid status codes */ ipptool_status_t statuses[100], /* Valid status codes */ *last_status; /* Last STATUS (for predicates) */ @@ -1191,7 +1192,7 @@ do_test(_ipp_file_t *f, /* I - IPP data file */ if (data->pause[0]) { - if (!data->skip_test) + if (!data->skip_test && !data->pass_test) pause_message(data->pause); data->pause[0] = '\0'; @@ -1266,9 +1267,10 @@ do_test(_ipp_file_t *f, /* I - IPP data file */ cupsFilePrintf(cupsFileStdout(), " %-68.68s [", data->name); } - if ((data->skip_previous && !data->prev_pass) || data->skip_test) + if ((data->skip_previous && !data->prev_pass) || data->skip_test || data->pass_test) { - data->skip_count ++; + if (!data->pass_test) + data->skip_count ++; ippDelete(request); request = NULL; @@ -1279,15 +1281,26 @@ do_test(_ipp_file_t *f, /* I - IPP data file */ cupsFilePuts(data->outfile, "Successful\n"); cupsFilePuts(data->outfile, "\n"); cupsFilePuts(data->outfile, "Skipped\n"); - cupsFilePuts(data->outfile, "\n"); + if (data->pass_test) + cupsFilePuts(data->outfile, "\n"); + else + cupsFilePuts(data->outfile, "\n"); cupsFilePuts(data->outfile, "StatusCode\n"); - print_xml_string(data->outfile, "string", "skip"); + if (data->pass_test) + print_xml_string(data->outfile, "string", "pass"); + else + print_xml_string(data->outfile, "string", "skip"); cupsFilePuts(data->outfile, "ResponseAttributes\n"); cupsFilePuts(data->outfile, "\n"); } if (data->output == IPPTOOL_OUTPUT_TEST || (data->output == IPPTOOL_OUTPUT_PLIST && data->outfile != cupsFileStdout())) - cupsFilePuts(cupsFileStdout(), "SKIP]\n"); + { + if (data->pass_test) + cupsFilePuts(cupsFileStdout(), "PASS]\n"); + else + cupsFilePuts(cupsFileStdout(), "SKIP]\n"); + } goto skip_error; } @@ -4061,6 +4074,40 @@ token_cb(_ipp_file_t *f, /* I - IPP file data */ return (0); } } + else if (!strcmp(token, "PASS-IF-DEFINED")) + { + /* + * PASS-IF-DEFINED variable + */ + + if (_ippFileReadToken(f, name, sizeof(name))) + { + if (_ippVarsGet(vars, name)) + data->pass_test = 1; + } + else + { + print_fatal_error(data, "Missing PASS-IF-DEFINED value on line %d of \"%s\".", f->linenum, f->filename); + return (0); + } + } + else if (!strcmp(token, "PASS-IF-NOT-DEFINED")) + { + /* + * PASS-IF-NOT-DEFINED variable + */ + + if (_ippFileReadToken(f, name, sizeof(name))) + { + if (!_ippVarsGet(vars, name)) + data->pass_test = 1; + } + else + { + print_fatal_error(data, "Missing PASS-IF-NOT-DEFINED value on line %d of \"%s\".", f->linenum, f->filename); + return (0); + } + } else if (!strcmp(token, "SKIP-IF-DEFINED")) { /* @@ -4890,6 +4937,7 @@ token_cb(_ipp_file_t *f, /* I - IPP file data */ data->repeat_interval = 5000000; strlcpy(data->resource, data->vars->resource, sizeof(data->resource)); data->skip_previous = 0; + data->pass_test = 0; data->skip_test = 0; data->num_statuses = 0; data->last_status = NULL;