Add multi-user support
[apps/core/preloaded/print-service.git] / TC / print-test-opmap.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             local _OUT=$(test-opmap "$_PPD")
45             if [ "$?" -eq "0" ]
46             then
47                 print-pass "$_PPD";
48                 rm -f "$_PPD";
49             else
50                 print-fail "[$_MODEL] $_PPD";
51             fi
52         else
53             print-error "[$_MODEL] getppd did not extracted file"
54         fi
55     else
56         print-error "getppd extracting failed on $_PPD"
57     fi
58 }
59
60 function run-test {
61     local _PLIST="$1";
62     local _DRVFILE="$2"
63     if [ -f "$_PLIST" ] && [ -f "$_DRVFILE" ]
64     then
65         while read printer; do
66             run-opmap-test "$printer" "$_DRVFILE"
67         done < "$_PLIST"
68     else
69         print-error "file $_PLIST or $_DRVFILE doesn't exist"
70     fi
71 }
72
73 function run-test-on-epson {
74     run-test "$PLIST_PATH$EPSON_LIST" "$PLIST_PATH$EPSON_DRV"
75 }
76
77 function run-test-on-samsung {
78     run-test "$PLIST_PATH$SAMSUNG_LIST" "$PLIST_PATH$SAMSUNG_DRV"
79 }
80
81 function run-test-on-hp {
82     run-test "$PLIST_PATH$HP_LIST" "$PLIST_PATH$HP_DRV"
83 }
84
85 function run-all-tests {
86     run-test-on-epson;
87     run-test-on-samsung;
88     run-test-on-hp;
89 }
90
91 function echoerr() { echo "$@" 1>&2; }
92
93 function print-help {
94     echo "usage: $0 [file]" >&2;
95     exit 2;
96 }
97
98 case "$1" in
99     "help") print-help ;;
100     "-h") print-help ;;
101     "--help") print-help ;;
102     *) run-all-tests  ;;
103 esac