]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - test/ipptest.c
Load cups into easysw/current.
[thirdparty/cups.git] / test / ipptest.c
index 1f4a966bae5f62e78418ebde6ee61121c1337181..708d1a69f37bb2b94324c5337c12dc060b5d705b 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id$"
+ * "$Id: ipptest.c 6503 2007-05-01 23:06:44Z mike $"
  *
  *   IPP test command for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2006 by Easy Software Products.
+ *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
  *   property of Easy Software Products and are protected by Federal
@@ -122,6 +122,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   int          status;                 /* Status of tests... */
   const char   *uri;                   /* URI to use */
   const char   *testfile;              /* Test file to use */
+  int          interval;               /* Test interval */
 
 
  /*
@@ -133,6 +134,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   uri      = NULL;
   testfile = NULL;
   status   = 0;
+  interval = 0;
 
   for (i = 1; i < argc; i ++)
   {
@@ -140,6 +142,24 @@ main(int  argc,                            /* I - Number of command-line arguments */
     {
       if (!strcmp(argv[i], "-v"))
         Verbosity ++;
+      else if (!strcmp(argv[i], "-d"))
+      {
+        i ++;
+
+       if (i >= argc)
+         usage(NULL);
+       else
+         putenv(argv[i]);
+      }
+      else if (!strcmp(argv[i], "-i"))
+      {
+        i++;
+
+       if (i >= argc)
+         usage(NULL);
+       else
+         interval = atoi(argv[i]);
+      }
       else
         usage(argv[i]);
     }
@@ -173,6 +193,19 @@ main(int  argc,                            /* I - Number of command-line arguments */
   if (!uri || !testfile)
     usage(NULL);
 
+ /*
+  * Loop if the interval is set...
+  */
+
+  if (interval)
+  {
+    for (;;)
+    {
+      sleep(interval);
+      do_tests(uri, testfile);
+    }
+  }
+
  /*
   * Exit...
   */
@@ -430,9 +463,28 @@ do_tests(const char *uri,          /* I - URI to connect on */
              strlcpy(tokenptr, cupsUser(), sizeof(token) - (tokenptr - token));
              tempptr += 5;
            }
+           else if (!strncasecmp(tempptr + 1, "ENV[", 4))
+           {
+             char *end;                /* End of $ENV[name] */
+
+
+             if ((end = strchr(tempptr + 5, ']')) != NULL)
+             {
+               *end++ = '\0';
+               strlcpy(tokenptr,
+                       getenv(tempptr + 5) ? getenv(tempptr + 5) : tempptr + 5,
+                       sizeof(token) - (tokenptr - token));
+               tempptr = end;
+             }
+             else
+             {
+               *tokenptr++ = *tempptr++;
+               *tokenptr   = '\0';
+             }
+           }
             else
            {
-             *tokenptr++ = *tempptr ++;
+             *tokenptr++ = *tempptr++;
              *tokenptr   = '\0';
            }
 
@@ -569,7 +621,8 @@ do_tests(const char *uri,           /* I - URI to connect on */
     if (filename[0])
       response = cupsDoFileRequest(http, request, resource, filename);
     else
-      response = cupsDoRequest(http, request, resource);
+      response = cupsDoIORequest(http, request, resource, -1,
+                                 Verbosity ? 1 : -1);
 
     if (response == NULL)
     {
@@ -647,7 +700,7 @@ do_tests(const char *uri,           /* I - URI to connect on */
          puts("        BAD STATUS");
 
        printf("        status-code = %04x (%s)\n",
-              cupsLastError(), cupsLastErrorString());
+              cupsLastError(), ippErrorString(cupsLastError()));
 
         for (i = 0; i < num_expects; i ++)
          if (ippFindAttribute(response, expects[i], IPP_TAG_ZERO) == NULL)
@@ -814,7 +867,9 @@ print_attr(ipp_attribute_t *attr)   /* I - Attribute to print */
     return;
   }
 
-  printf("        %s (%s) = ", attr->name, get_tag_string(attr->value_tag));
+  printf("        %s (%s%s) = ", attr->name,
+         attr->num_values > 1 ? "1setOf " : "",
+        get_tag_string(attr->value_tag));
 
   switch (attr->value_tag)
   {
@@ -890,12 +945,13 @@ usage(const char *option)         /* I - Option string or NULL */
   fputs("Usage: ipptest [options] URL testfile [ ... testfileN ]\n", stderr);
   fputs("Options:\n", stderr);
   fputs("\n", stderr);
-  fputs("-v     Show all attributes in response, even on success.\n", stderr);
+  fputs("-i N    Repeat the last test file once every N seconds.\n", stderr);
+  fputs("-v      Show all attributes in response, even on success.\n", stderr);
 
   exit(1);
 }
 
 
 /*
- * End of "$Id$".
+ * End of "$Id: ipptest.c 6503 2007-05-01 23:06:44Z mike $".
  */