]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Separate building unit test programs from running them.
authorMichael R Sweet <msweet@msweet.org>
Sun, 10 Sep 2023 21:57:57 +0000 (17:57 -0400)
committerMichael R Sweet <msweet@msweet.org>
Sun, 10 Sep 2023 21:58:50 +0000 (17:58 -0400)
Fix typo in cupsGetDests unit test.

cups/Makefile
cups/testgetdests.c

index 4c041aa67272538bc0a3e666c9be37d46af9c055..a9ff5075cfb8631fbac208511999f8b8b5446531 100644 (file)
@@ -219,6 +219,46 @@ all:               $(TARGETS)
 libs:          $(LIBTARGETS)
 
 
+#
+# Run unit tests...
+#
+
+test:          unittests
+       echo "Tests started at $(date)..." >test.log
+       echo Running array API tests...
+       ./testarray >>test.log
+       echo Running file API tests...
+       ./testfile >>test.log
+       echo Running HTTP API tests...
+       ./testhttp >>test.log
+       echo Running IPP API tests...
+       ./testipp >>test.log
+       echo Running internationalization API tests...
+       ./testi18n >>test.log
+       echo Creating locale directory structure...
+       $(RM) -r locale
+       for po in ../locale/cups_*.po; do \
+               lang=`basename $$po .po | sed -e '1,$$s/^cups_//'`; \
+               $(MKDIR) locale/$$lang; \
+               $(LN) ../../$$po locale/$$lang; \
+       done
+       echo Running language API tests...
+       echo ls -al locale >>test.log
+       ls -al locale >>test.log
+       LOCALEDIR=locale ./testlang >>test.log
+       echo Running option API tests...
+       ./testoptions >>test.log
+       echo Running PPD API tests...
+       ./testppd >>test.log
+       echo Running PWG API tests...
+       ./testpwg test.ppd >>test.log
+       echo Running raster API tests...
+       ./testraster >>test.log
+#      echo Fuzzing IPP API...
+#      ./fuzzipp >>test.log
+       echo "Tests finished at $(date)..." >>test.log
+
+
 #
 # Make unit tests...
 #
@@ -476,8 +516,6 @@ fuzzipp:    fuzzipp.o $(LIBCUPSSTATIC)
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ fuzzipp.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Fuzzing IPP API...
-       ./fuzzipp
 
 
 #
@@ -508,8 +546,6 @@ testarray:  testarray.o $(LIBCUPSSTATIC)
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ testarray.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Running array API tests...
-       ./testarray
 
 
 #
@@ -590,8 +626,6 @@ testfile:   testfile.o $(LIBCUPSSTATIC)
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ testfile.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Running file API tests...
-       ./testfile
 
 
 #
@@ -612,8 +646,6 @@ testhttp:   testhttp.o $(LIBCUPSSTATIC)
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ testhttp.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Running HTTP API tests...
-       ./testhttp
 
 
 #
@@ -624,8 +656,6 @@ testipp:    testipp.o $(LIBCUPSSTATIC)
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ testipp.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Running IPP API tests...
-       ./testipp
 
 
 #
@@ -636,8 +666,6 @@ testi18n:   testi18n.o $(LIBCUPSSTATIC)
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ testi18n.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Running internationalization API tests...
-       ./testi18n
 
 
 #
@@ -648,17 +676,6 @@ testlang:  testlang.o $(LIBCUPSSTATIC)
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ testlang.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Creating locale directory structure...
-       $(RM) -r locale
-       for po in ../locale/cups_*.po; do \
-               lang=`basename $$po .po | sed -e '1,$$s/^cups_//'`; \
-               $(MKDIR) locale/$$lang; \
-               $(LN) ../../$$po locale/$$lang; \
-       done
-       echo Running language API tests...
-       echo ls -al locale
-       ls -al locale
-       LOCALEDIR=locale ./testlang
 
 
 #
@@ -669,8 +686,6 @@ testoptions:        testoptions.o $(LIBCUPSSTATIC)
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ testoptions.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Running option API tests...
-       ./testoptions
 
 
 #
@@ -681,8 +696,6 @@ testppd:    testppd.o $(LIBCUPSSTATIC) test.ppd test2.ppd
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ testppd.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Running PPD API tests...
-       ./testppd
 
 
 #
@@ -693,8 +706,6 @@ testpwg:    testpwg.o $(LIBCUPSSTATIC) test.ppd
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ testpwg.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Running PWG API tests...
-       ./testpwg test.ppd
 
 
 #
@@ -705,8 +716,6 @@ testraster: testraster.o $(LIBCUPSSTATIC)
        echo Linking $@...
        $(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ testraster.o $(LINKCUPSSTATIC)
        $(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
-       echo Running raster API tests...
-       ./testraster
 
 
 #
@@ -750,7 +759,7 @@ apihelp:
                cupspm.xml \
                array.[ch] auth.c cups.h dest*.c dir.[ch] encode.c file.[ch] \
                http.h http*.c ipp.h ipp*.c options.c pwg.[ch] \
-               raster.h raster-stubs.c tls-darwin.c usersys.c util.c \
+               raster.h raster-stubs.c string.c tempfile.c thread.[ch] tls.c tls-openssl.c usersys.c util.c \
                --coverimage cupspm.png \
                --epub ../doc/help/cupspm.epub
        codedoc --section "Programming" --body cupspm.md \
index 5b9069568b5da9fa66738ef23ae46695e8362f9b..15f34c7f537543dff9639f01cbe31f7ecb71620f 100644 (file)
@@ -1,45 +1,68 @@
-/*
- * CUPS cupsGetDests API test program for CUPS.
- *
- * Copyright 2017 by Apple Inc.
- *
- * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
- */
-
-/*
- * Include necessary headers...
- */
+//
+// CUPS cupsGetDests API test program for CUPS.
+//
+// Copyright © 2023 by OpenPrinting.
+// Copyright © 2017 by Apple Inc.
+//
+// Licensed under Apache License v2.0.  See the file "LICENSE" for more
+// information.
+//
 
 #include <stdio.h>
-#include "cups.h"
+#include <stdlib.h>
 #include <sys/time.h>
+#include "cups.h"
+#include "test-internal.h"
 
 
-/*
- * 'main()' - Loop calling cupsGetDests.
- */
+//
+// 'main()' - Loop calling cupsGetDests.
+//
 
-int                                     /* O - Exit status */
-main(void)
+int                                     // O - Exit status
+main(int  argc,                                // I - Number of command-line arguments
+     char *argv[])                     // I - Command-line arguments
 {
-  int           num_dests;              /* Number of destinations */
-  cups_dest_t   *dests;                 /* Destinations */
-  struct timeval start, end;            /* Start and stop time */
-  double        secs;                   /* Total seconds to run cupsGetDests */
+  size_t       count = 1;              // Number of times
+  size_t       num_dests;              // Number of destinations
+  cups_dest_t  *dests;                 // Destinations
+  struct timeval start, end;           // Start and stop time
+  double       secs;                   // Total seconds to run cupsGetDests
+
+
+  // Parse command-line...
+  if (argc > 2 || (argc == 2 && (argv[1][0] < '1' || argv[1][0] > '9')))
+  {
+    fputs("Usage: ./testgetdests [COUNT]\n", stderr);
+    return (1);
+  }
 
+  if (argc == 2)
+    count = strtoul(argv[1], NULL, 10);
+  else
+    count = 5;
 
-  for (;;)
+  // Run tests...
+  while (count > 0)
   {
+    testBegin("cupsGetDests");
     gettimeofday(&start, NULL);
-    num_dests = cupsGetDests(&dests);
+    num_dests = cupsGetDests2(CUPS_HTTP_DEFAULT, &dests);
     gettimeofday(&end, NULL);
     secs = end.tv_sec - start.tv_sec + 0.000001 * (end.tv_usec - start.tv_usec);
 
-    printf("Found %d printers in %.3f seconds...\n", num_dests, secs);
+    if (cupsGetError() != IPP_STATUS_OK)
+      testEndMessage(false, "%s", cupsGetErrorString());
+    else
+      testEndMessage(secs < 2.0, "%u printers in %.3f seconds", (unsigned)num_dests, secs);
 
     cupsFreeDests(num_dests, dests);
-    sleep(1);
+
+    count --;
+
+    if (count > 0)
+      sleep(1);
   }
 
-  return (0);
+  return (testsPassed ? 0 : 1);
 }