]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add PASS-IF-[NOT-]DEFINED directive to ipptool.
authorMichael R Sweet <michael.r.sweet@gmail.com>
Wed, 7 Apr 2021 13:35:15 +0000 (09:35 -0400)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Wed, 7 Apr 2021 13:35:15 +0000 (09:35 -0400)
doc/help/man-ipptoolfile.html
man/ipptoolfile.5
tools/ipptool.c

index 35ad6f873573d6533b22fa81f01e8981da987cc7..36171127f66a611c9d6ebf06f7c0d4960b446081 100644 (file)
@@ -182,6 +182,9 @@ The monitoring tests will run until all of the <b>EXPECT</b> conditions are sati
 <dd style="margin-left: 5.0em">Specifies the human-readable name of the test.
 <dt><b>OPERATION </b><i>operation-code</i>
 <dd style="margin-left: 5.0em">Specifies the operation to be performed.
+<dt><b>PASS-IF-DEFINED </b><i>variable-name</i>
+<dd style="margin-left: 5.0em"><dt><b>PASS-IF-NOT-DEFINED </b><i>variable-name</i>
+<dd style="margin-left: 5.0em">Specifies that the current test should be passed automatically when the variable is or is not defined.
 <dt><b>PAUSE "</b><i>message</i><b>"</b>
 <dd style="margin-left: 5.0em">Displays the provided message and waits for the user to press a key to continue.
 <dt><b>REQUEST-ID </b><i>number</i>
index 000eaa5323ba1f42c93747b394e659a28403e125..3392242919c6f72ecd3b7106082e838ffb117b31 100644 (file)
@@ -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
index 11945077fa1489251446b5efa8d9ed7d0cb1f9a8..25a34d2b60f8eada0a819644b60a3180c4629987 100644 (file)
@@ -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, "<key>Successful</key>\n");
       cupsFilePuts(data->outfile, "<true />\n");
       cupsFilePuts(data->outfile, "<key>Skipped</key>\n");
-      cupsFilePuts(data->outfile, "<true />\n");
+      if (data->pass_test)
+       cupsFilePuts(data->outfile, "<false />\n");
+      else
+       cupsFilePuts(data->outfile, "<true />\n");
       cupsFilePuts(data->outfile, "<key>StatusCode</key>\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, "<key>ResponseAttributes</key>\n");
       cupsFilePuts(data->outfile, "<dict />\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;