Add multi-user support
[apps/core/preloaded/print-service.git] / scripts / print-test-getppd.sh
1 #!/bin/bash
2
3 eval $(tzplatform-get TZ_SYS_ETC)
4
5 PLIST_PATH=$TZ_SYS_ETC"/cups/ppd/"
6 HP_LIST="hp.list"
7 EPSON_LIST="epson.list"
8 SAMSUNG_LIST="samsung.list"
9 HP_DRV="hp/hp.drv"
10 EPSON_DRV="epson/epson.drv"
11 SAMSUNG_DRV="samsung/samsung.drv"
12
13 function print-pass {
14     printf '[\E[32mPASS\E[0m] %s\n' "$1"
15 }
16
17 function print-fail {
18     printf '[\E[31mFAIL\E[0m] %s\n' "$1"
19 }
20
21 function print-red {
22     printf '\E[31m%s\E[0m' "$1"
23 }
24
25 function print-green {
26     printf '\E[32m%s\E[0m' "$1"
27 }
28
29 function print-error {
30     printf '[\E[31mERROR\E[0m] %s\n' "$1"
31 }
32
33 function run-opmap-test {
34     local _MODEL="$1"
35     local _FPATH="$2"
36     local _OUTPUT=`getppd -m "$_MODEL" -i "$_FPATH" 2> /dev/null`
37     if [ "$?" -eq "0" ];
38     then
39         local _PPD=`echo "$_OUTPUT" | sed "s/.*\/\(.*\)\./\1/"`
40         #echo "[GETDRV:OK] Model:$_MODEL, PPD file: $_PPD";
41         if [ -f "$_PPD" ]
42         then
43             #echo "PPD PASS"
44             print-pass "$_PPD";
45             rm -f "$_PPD";
46             #local _OUT=$(test-opmap "$_PPD")
47         else
48             print-error "[$_MODEL] getppd did not extracted file"
49         fi
50     else
51         print-error "getppd extracting failed on $_PPD"
52     fi
53 }
54
55 function run-test {
56     local _PLIST="$1";
57     local _DRVFILE="$2"
58     if [ -f "$_PLIST" ] && [ -f "$_DRVFILE" ]
59     then
60         while read printer; do
61             run-opmap-test "$printer" "$_DRVFILE"
62         done < "$_PLIST"
63     else
64         print-error "file $_PLIST or $_DRVFILE doesn't exist"
65     fi
66 }
67
68 function run-test-on-epson {
69     run-test "$PLIST_PATH$EPSON_LIST" "$PLIST_PATH$EPSON_DRV"
70 }
71
72 function run-test-on-samsung {
73     run-test "$PLIST_PATH$SAMSUNG_LIST" "$PLIST_PATH$SAMSUNG_DRV"
74 }
75
76 function run-test-on-hp {
77     run-test "$PLIST_PATH$HP_LIST" "$PLIST_PATH$HP_DRV"
78 }
79
80 function run-all-tests {
81     run-test-on-epson;
82     run-test-on-samsung;
83     run-test-on-hp;
84 }
85
86 function echoerr() { echo "$@" 1>&2; }
87
88 function print-help {
89     echo "usage: $0 [file]" >&2;
90     exit 2;
91 }
92
93 case "$1" in
94     "help") print-help ;;
95     "-h") print-help ;;
96     "--help") print-help ;;
97     *) run-all-tests  ;;
98 esac