Debian Codegraph @

debian/tests/test-frontend-vs-cups-backend

raw symbols SCIP
1 #!/bin/bash
2
3 # skip test
4 exit 0
5
6 set -e -u
7
8 LOG=log.txt
9 QUEUE=testprinter_cpdb_libs
10 FRONTEND=/usr/bin/cpdb-text-frontend
11 FILE_TO_PRINT=/usr/share/cups/data/default-testpage.pdf
12 CUPS_SPOOL_DIR=/var/spool/cups
13
14 # Create temporary work directory
15 WORKDIR=$(mktemp -d)
16 cd $WORKDIR
17
18 cleanup() {
19 # Remove the log file
20 rm -f $LOG
21 # Remove the temporary directory
22 rm -rf $WORKDIR
23 # Delete the printer
24 lpadmin -x $QUEUE 2>/dev/null || :
25 }
26
27 trap cleanup 0 EXIT INT QUIT ABRT PIPE TERM
28
29 # Create the log file
30 rm -f $LOG
31 touch $LOG
32
33 # Configure the running CUPS server to do debug2 logging
34 sed -e 's/^.*LogLevel.*$/LogLevel debug2/g' -i /etc/cups/cupsd.conf
35 # Configure the running CUPS server to set FileDevice to Yes
36 sed -e 's/^.*FileDevice.*$/FileDevice Yes/g' -i /etc/cups/cups-files.conf
37 # Configure the running CUPS server to allow root to do administrative tasks
38 sed -e 's/^.*SystemGroup.*$/SystemGroup lpadmin root/g' -i /etc/cups/cups-files.conf
39 service cups restart
40
41 # Create a test print queue (disabled, but accepting jobs)
42 #cupsctl --debug-logging
43 lpadmin -p $QUEUE -v file:/dev/null -m drv:///sample.drv/laserjet.ppd -o PageSize=Env10 2>/dev/null
44 cupsaccept $QUEUE
45
46 # Wait for CUPS to DNS-SD-broadcast the queue
47 sleep 5
48
49 # Run the demo with a session D-Bus and feed in commands, in parallel
50 # do a kill on the demo process after a timeout, for the case that the
51 # commands take too long or stopping the demo does not work. Ignore the
52 # error of the kill command if the demo gets stopped correctly.
53 ( \
54 sleep 5; \
55 echo get-all-options $QUEUE CUPS; \
56 sleep 2; \
57 echo print-file $FILE_TO_PRINT $QUEUE CUPS; \
58 sleep 1; \
59 echo stop \
60 ) | dbus-run-session -- $FRONTEND >> $LOG 2>&1
61
62 cat $LOG
63
64 echo
65
66 # Does the printer appear in the initial list of available printers?
67 echo "Initial listing of the printer:"
68 if ! grep '^Printer '$QUEUE'$' $LOG; then
69 echo "FAIL: CUPS queue $QUEUE not listed!"
70 exit 1
71 fi
72
73 echo
74
75 # Does the attribute "printer-resolution" appear in the list of options?
76 echo "Attribute listing of \"printer-resolution\":"
77 if ! grep 'printer-resolution' $LOG; then
78 echo "FAIL: Attribute \"printer-resolution\" not listed!"
79 exit 1
80 fi
81
82 echo
83
84 # Does the attribute "print-quality" appear in the list of options?
85 echo "Attribute listing of \"print-quality\":"
86 if ! grep 'print-quality' $LOG; then
87 echo "FAIL: Attribute \"print-quality\" not listed!"
88 exit 1
89 fi
90
91 echo
92
93 # Does the setting "na_number-10_4.125x9.5in" appear as a default setting?
94 echo "\"na_number-10_4.125x9.5in\" as a default setting:"
95 if ! grep 'DEFAULT: *na_number-10_4.125x9.5in' $LOG; then
96 echo "Setting \"na_number-10_4.125x9.5in\" not listed as default!"
97 exit 1
98 fi
99
100 echo
101
102 # Did the successful submission of a print job get confirmed?
103 echo "Confirmation message for job submission:"
104 if ! grep -i 'Document send succeeded' $LOG; then
105 echo "No confirmation of job submission!"
106 exit 1
107 fi
108
109 grep '\[Job [0-9]' /var/log/cups/error_log | tail -50
110
111 JOBNUM=
112 COUNT=1
113 echo "Trying to find the job ... "
114 while [ -z "$JOBNUM" ]; do
115 # Find the job
116 sleep 5
117 echo "Attempt: $COUNT";
118 echo "Jobs submitted:"
119 lpstat -o $QUEUE
120 echo "Jobs completed:"
121 lpstat -W completed -o
122 echo
123 JOBNUM=`lpstat -o $QUEUE | tail -1 | cut -d ' ' -f 1 | cut -d - -f 2`
124 COUNT=$(( $COUNT + 1 ))
125 if test $COUNT -gt 20; then
126 echo "Job not found!"
127 exit 1
128 fi
129 done
130 echo "Job number: $JOBNUM"
131 if [ -n "$JOBNUM" ]; then
132 SPOOLFILE=`printf "%s/d%05d-001" $CUPS_SPOOL_DIR $JOBNUM`
133 echo "Job spool file: $SPOOLFILE"
134 if [ -f "$SPOOLFILE" ]; then
135 echo "diff $FILE_TO_PRINT $SPOOLFILE"
136 diff -q $FILE_TO_PRINT $SPOOLFILE || ( \
137 echo "Submitted job data and spooled job data differ!"; \
138 exit 1; \
139 )
140 else
141 echo "Spool file does not exist!"
142 exit 1
143 fi
144 else
145 echo "Job number not found!"
146 exit 1
147 fi
148
149 echo
150
151 echo "SUCCESS: All tests were successful."
152
153 echo
154
155 exit 0