summaryrefslogtreecommitdiffstats
path: root/filters/tests/global-filter-test.sh
blob: ee622bb04227e2b165ca9df21bff24da36cce30c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash

# This script helps finding out problems in filter of kspread/kword/kpresenter
# by converting .ksp/.kpr/.kwd -> filter extension -> .ksp/.kpr/.kwd and comparing the initial and final .ksp/.kpr/.kwd files.
# We use the ksp/kpr/kwd format as a "dump" of the KSpread data, to check if everything is correct
# in memory, but the point is of course to ensure that the filter extension has all the information.

# To use this script, you need to pass the full path to an existing ksp file as argument.
# Don't use a relative path, dcopstart won't handle it
input="$2"


case "$1" in 
	kspread)
	appname=kspread
	oldextension=ksp
	case "$3" in 
	    gnumeric)
	    newextension=gnumeric
	    newmimetype=application/x-gnumeric
	    ;;
	    opencalc)
	    newextension=sxc
	    newmimetype=application/vnd.sun.xml.calc
	    ;;
	    *)
	    printf "Usage: %s {kspread|kword|kpresenter} <file name> {gnumeric|opencalc}\n" "$0"
	    exit 1;
	esac
	;;
	kword)
	appname=kword
	oldextension=kwd
	case "$3" in 
	    rtf)
	    newextension=rtf
	    newmimetype=text/rtf
	    ;;
	    amipro)
	    newextension=sam
	    newmimetype=application/x-amipro
	    ;;
	    oowriter)
	    newextension=sxw
	    newmimetype=application/vnd.sun.xml.writer
	    ;;
	    latex)
	    newextension=tex
	    newmimetype=text/x-tex
	    ;;
	    paldoc)
	    newextension=pdb
	    newmimetype=application/vnd.palm
	    ;;
	    abiword)
	    newextension=abw
	    newmimetype=application/x-abiword
	    ;;
	    wml)
	    newextension=wml
	    newmimetype=application/text/vnd.wap.wml
	    ;;
	    wordperfect)
	    newextension=wpd
	    newmimetype=application/wordperfect
	    ;;
            ascii)
            newextension=txt
            newmimetype=text/plain
	    ;;
	    *)
	    printf "Usage: %s {kspread|kword|kpresenter} <file name> {rtf|amipro|oowriter|latex|paldoc|abiword|wml|wordperfect|ascii}\n" "$0"
	    exit 1;
	esac
	;;
	chalk)
	appname=chalk
	oldextension=kra
	case "$3" in
		magick-png)
		newextension=png
		newmimetype=image/png
		;;
                magick-gif)
                newextension=gif
                newmimetype=image/gif
                ;;
                magick-jpeg)
                newextension=jpg
                newmimetype=image/jpeg
                ;;
                magick-tiff)
                newextension=tiff
                newmimetype=image/tiff
                ;;
		*)
		printf "Usage: %s {kspread|kword|kpresenter|chalk} <file name> {magick-png}\n" "$0"
		exit1;
	esac
	;;
	kpresenter)
	appname=kpresenter
	oldextension=kpr
	case "$3" in 
	    ooimpress)
	    newextension=sxi
	    newmimetype=application/vnd.sun.xml.impress
	    ;;
	    *)
	    printf "Usage: %s {kspread|kword|kpresenter} <file name> {ooimpress}\n" "$0"
	    exit 1;
	esac
	;;
	*)
	printf "Usage: %s {kspread|kword|kpresenter|chalk} <file name> <type of filter>\n" "$0"
	exit 1;
esac
	
test -f "$input" || { echo "No such file $input"; exit 1; }

# Load old native file
appid=`dcopstart $appname $input`
test -n "$appid" || { echo "Error starting $appname!"; exit 1; }
while `dcop $appid Document-0 isLoading` == "true"; do
    sleep 1;
done

# Save again (in case of changes in syntax etc.)
origfile=$PWD/regtest-initial.$oldextension
dcop $appid Document-0 saveAs $origfile || exit 1
test -f $origfile || exit 1

# Save to filter extension
tmpfile=$PWD/regtest.$newextension
dcop $appid Document-0 setOutputMimeType $newmimetype || exit 1
dcop $appid Document-0 saveAs $tmpfile || exit 1
test -f $tmpfile || exit 1

dcopquit $appid

# Load resulting filter file, convert to old native format
tmpnativefile=$PWD/regtest-final.$oldextension
appid=`dcopstart $appname $tmpfile`
while `dcop $appid Document-0 isLoading` == "true"; do
    sleep 1;
done
dcop $appid Document-0 setOutputMimeType "application/x-$appname" || exit 1
dcop $appid Document-0 saveAs $tmpnativefile || exit 1
test -f $tmpnativefile || exit 1

# Unpack everything
rm -rf regtest-orig
mkdir regtest-orig
rm -rf regtest-final
mkdir regtest-final

cd regtest-orig || exit 1
unzip $origfile || exit 1
cd ..

cd regtest-final || exit 1
unzip $tmpnativefile || exit 1
cd ..

# Compare initial and final "native format" files
diff -urp regtest-orig regtest-final 2>&1 | tee filterdiff | less

echo "For a better diffing mechanism, launch xemacs and paste into a terminal:"
echo "gnudoit '(ediff-files \"$PWD/regtest-orig/maindoc.xml\" \"$PWD/regtest-final/maindoc.xml\")'"