summaryrefslogtreecommitdiff
path: root/archiver/tests/test-2.sh
blob: deac5de629b3669f7a363bc2cdb997fce6e26363 (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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/sh
#
# test-2.sh
# Copyright (C) 2001 Ximian, Inc.
# Written by Bradford Hovinen <hovinen@ximian.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
# Test suite, part II
#
# Given an archive to work with (global or per-user):
#
#  - Destroy the entire archive forcibly (rm -rf)
#  - Create a new location inheriting from the default location
#    (the default location should be created automatically in this case)
#  - Sets the new location as the current one
#  - Stores data for a backend not contained in the new location
#    (this should pass the data through to default)
#  - Adds a backend to the new location (full containment)
#  - Stores data for that backend in the new location

XIMIAN_ARCHIVER=${XIMIAN_ARCHIVER:-'../ximian-archiver'}

function get_unused_tmpfile () {
    tmp_file_no=0

    while [ -e "/tmp/$1-$tmp_file_no" ]; do
	let 'tmp_file_no=tmp_file_no+1'
    done

    echo "/tmp/$1-$tmp_file_no";
}

function run_command () {
    input_param=$1
    shift

    if [ "x$use_gdb" == "xyes" ]; then
	commands_file=`get_unused_tmpfile gdb-commands-file`
	echo "set args $extra_args $@ <$input_param" >$commands_file
	gdb ../.libs/ximian-archiver -x $commands_file
	rm -f $commands_file
    else
	echo "Running archiver program with the following command line:" >&2
	echo "$XIMIAN_ARCHIVER $extra_args $@ <$input_param" >&2
	$XIMIAN_ARCHIVER $extra_args $@ <$input_param
	echo
    fi
}

if [ "x$1" == "x" ]; then
    echo "Usage: test-2.sh --global|--per-user [--gdb]"
    exit 1
fi

for test_option; do
    case "$test_option" in
	--global)
	    extra_args="--global"
	    archive_dir=/usr/share/ximian-config
	    ;;

	--per-user)
	    extra_args=""
	    archive_dir=$HOME/.gnome/ximian-config
	    ;;

	--gdb)
	    use_gdb=yes
	    ;;

	*)
	    echo "Error -- invalid option: $test_option"
	    exit 1
    esac
done

if [ -d $archive_dir ]; then
    mv $archive_dir "$archive_dir-backup"
fi

##############################################################################
# Test proper
##############################################################################

# Test 1: Creating a new location

run_command /dev/null --add-location --parent=default --location=Boston-Office
run_command /dev/null --change-location --location=Boston-Office

# Test 2: Storing data that should "pass through" to the parent

archiver_test_data_file1=`get_unused_tmpfile ximian-archiver-test-data`;

cat >$archiver_test_data_file1 <<EOF
<?xml version="1.0"?>
<background-properties>
  <bg-color1>#111128</bg-color1>
  <bg-color2>#796dff</bg-color2>
  <enabled/>
  <wallpaper/>
  <gradient/>
  <orientation>vertical</orientation>
  <wallpaper-type>0</wallpaper-type>
  <wallpaper-filename>/home/hovinen/media/Propaganda/Vol3/9a.jpg</wallpaper-filename>
  <wallpaper-sel-path>./</wallpaper-sel-path>
  <auto-apply/>
  <adjust-opacity/>
  <opacity>172</opacity>
</background-properties>

EOF

run_command $archiver_test_data_file1 \
	    --store --backend=background-properties-capplet

# Test 3: Adding a backend (full containment) and storing data that
# should be stored in the child location

run_command /dev/null --add-backend --full \
	    --backend=keyboard-properties-capplet

archiver_test_data_file2=`get_unused_tmpfile ximian-archiver-test-data`;

cat >$archiver_test_data_file2 <<EOF
<?xml version="1.0"?>
<keyboard-properties>
  <rate>255</rate>
  <delay>0</delay>
  <repeat/>
  <volume>0</volume>
</keyboard-properties>

EOF

run_command $archiver_test_data_file2 \
	    --store --backend=keyboard-properties-capplet

# Test 5: Retrieve the background properties data previously stored
# and compare it with the data we have here to see if everything is ok

archiver_test_data_file3=`get_unused_tmpfile ximian-archiver-test-data`

run_command /dev/null --rollback --show --last \
	    --backend=background-properties-capplet \
	    >$archiver_test_data_file3

##############################################################################
# Results check
##############################################################################

echo -n "Checking whether default location was created properly..."

if [ -d "$archive_dir/default" ]; then
    echo "yes -- good"
else
    echo "no -- error"
fi

echo -n "Checking whether derived location was created properly..."

if [ -d "$archive_dir/Boston-Office" ]; then
    echo "yes -- good"
else
    echo "no -- error"
fi

echo -n "Checking whether the XML data retrieved match the XML data given..."

differences_file=`get_unused_tmpfile differences`

diff -u $archiver_test_data_file3 $archiver_test_data_file1 >$differences_file

if [ ! -s $differences_file ]; then
    echo "yes -- good"
else
    echo "no -- error"
    echo "Differences are as follows:"
    cat $differences_file
    echo
fi

rm -f $differences_file

##############################################################################
# Putting the results together
##############################################################################

rm -f $archiver_test_data_file1
rm -f $archiver_test_data_file2
rm -f $archiver_test_data_file3

results_dir="ximian-config-results-`date +%Y%m%d`"
results_dir=`get_unused_tmpfile $results_dir`
mkdir $results_dir

(cd $archive_dir && tar cf - *) | (cd $results_dir && tar xf -)
rm -rf $archive_dir

if [ -d "$archive_dir-backup" ]; then
    mv "$archive_dir-backup" $archive_dir
fi

echo
echo "Test complete"
echo "Resulting archive data in $results_dir"