summaryrefslogtreecommitdiff
path: root/tests/selftest.pl.in
blob: 69aba59bbc63a2be888ad851d87fc44f41585ead (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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!@PERL@ -w

#  Selftest for intltool
#
#  Copyright (C) 2000 Free Software Foundation.
#
#  This library 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 of the
#  License, or (at your option) any later version.
#
#  This script 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 library; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#  Author(s): Kenneth Christiansen
#             Rodney Dawes

## Unset LINGUAS environment variable
$ENV{"LINGUAS"} = "";

## Release information
my $PROGRAM  = "selftest";
my $VERSION  = "0.1";
my $result;
my $case;

## Loaded modules
use strict;

## Always print as the first thing
$| = 1;

my $failed = 0;

my $srcdir = $ENV{"srcdir"} || ".";

my $strip_trailing_cr = ($^O eq 'MSWin32' || $^O eq 'msys') ? '--strip-trailing-cr' : '';

sub check_command_result
{
    my ($command) = shift;
    my ($testcase) = shift;

    my $result =`$command`;
    
    if ($? == 0 && ($result eq "" || $result =~ /^No differences/)) { 
        print "[OK]\n"; ## diff was empty, ie. files were equal
    } else { 
        print "[FAILED] ($testcase)\n"; 
        open OUT, ">>errors";
        print OUT $result;
        close OUT;
        $failed = 1;
    }
}

sub check_extract_result($)
{
    my ($testcase) = @_;
    check_command_result("diff -u $strip_trailing_cr $srcdir/results/$testcase.h cases/$testcase.h", $testcase);
}

sub check_merge_result($)
{
    my ($testcase) = @_;

    $testcase =~ s/\.in$//;
    check_command_result("diff -u $strip_trailing_cr $srcdir/results/$testcase cases/$testcase", $testcase);
}


sub check_multimerge_result
{
    my ($testcase) = shift;
    my ($language) = shift;

    $testcase =~ s/\.in$//;
    check_command_result("diff -u $strip_trailing_cr $srcdir/results/multi.$testcase $language/$testcase", $testcase);
}


## SELFTESTS

my $INTLTOOL_MERGE="env LC_ALL=C @PERL@ ../intltool-merge";
my $INTLTOOL_EXTRACT="env LC_ALL=C @PERL@ ../intltool-extract";

## Welcome notice

print "Running self test of the intltool module\n\n";
unlink "errors";

system("cp $srcdir/cases/*.* cases") if $srcdir ne ".";

print " 1. Extract messages from simple desktop file:                       ";
$case = "extract1.desktop";
system("$INTLTOOL_EXTRACT --type=gettext/ini --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print " 2. Merge translations into a Bonobo UI style file:                  ";
$case = "merge1.xml";
system("$INTLTOOL_MERGE -o --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print " 3. Extract messages from a multi-line XML file:                     ";
$case = "extract7.xml";
system("$INTLTOOL_EXTRACT --type=gettext/xml --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print " 4. Merge translations into a multi-line XML file:                   ";
$case = "merge7.xml";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print " 5. Extract messages with unusual characters in the XML tag:         ";
$case = "extract3.xml.in";
system("$INTLTOOL_EXTRACT --type=gettext/xml --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print " 6. Merge translations into a pong style XML file:                   ";
$case = "merge4.xml";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print " 7. Extract messages from a glade style XML file:                    ";
$case = "extract6.glade";
system("$INTLTOOL_EXTRACT --type=gettext/glade --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print " 8. Merge translations into a dia sheet style XML file:              ";
$case = "merge5u.sheet";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print " 9. Merge translations into a dia sheet style XML file [broken XML]: ";
$case = "merge5p.sheet";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "10. Merge translations that include escaped .po strings:             ";
$case = "merge6.xml";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "11. Merge translations into a .keys file:                            ";
$case = "merge8.keys";
system("$INTLTOOL_MERGE -k --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "12. Extract messages from a glade 2.0 style XML file:                ";
$case = "extract8.glade";
system("$INTLTOOL_EXTRACT --type=gettext/glade --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "13. Extract messages from an rfc822 style file:                      ";
$case = "extract10.templates_";
system("$INTLTOOL_EXTRACT --type=gettext/rfc822deb --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "14. Merge translations into an rfc822 style file:                    ";
$case = "merge10.templates";
system("$INTLTOOL_MERGE -r --quiet cases cases/${case}_ cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "15. Extract messages from a gconf schema style file:                 ";
$case = "test.schemas.in";
system("$INTLTOOL_EXTRACT --type=gettext/schemas --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "16. Merge translations into a gconf schema  style file:              ";
$case = "test.schemas";
system("$INTLTOOL_MERGE -s --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "17. Extract messages from a xml file using the xml:space attribute:  ";
$case = "extract9.xml.in";
system("$INTLTOOL_EXTRACT --type=gettext/xml --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "18. Merge messages into xml file using the xml:space attribute:      ";
$case = "extract9.xml";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "19. Merge translations into multiple files:                          ";
$case = "merge6.xml";
system("$INTLTOOL_MERGE -x -s --quiet --multiple-output cases cases/$case.in $case") == 0 or $failed = 1;
check_multimerge_result($case, "merge6");

print "20. Extract comments for translators from XML file:                  ";
$case = "extract-comments.xml";
system("$INTLTOOL_EXTRACT --type=gettext/xml --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "21. Merge into file with CDATA sections:                             ";
$case = "merge-cdata.xml";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "22. Merge into XML file with deep translation/attribute nesting:     ";
$case = "merge-deepattr.xml";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "23. Ignore empty strings from XML file                               ";
$case = "extract12.xml.in";
system("$INTLTOOL_EXTRACT --type=gettext/xml --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "24. Extract messages from a xml file using inherited xml:space:      ";
$case = "space-preserve.xml.in";
system("$INTLTOOL_EXTRACT --type=gettext/xml --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "25. Merge messages into xml file using inherited xml:space:          ";
$case = "space-preserve.xml";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "26. Merge non-well-formed translations into xml file:                ";
$case = "merge11.xml";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);
 
print "27. Extract UTF-8 encoded messages/comments from xml file:           ";
$case = "unicodetext.xml.in";
system("$INTLTOOL_EXTRACT --type=gettext/xml --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "28. Extract iso-8859-1 encoded messages/comments from xml file:      ";
$case = "iso88591text.xml.in";
system("$INTLTOOL_EXTRACT --type=gettext/xml --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "29. Extract messages from a quoted style file:                       ";
$case = "test-quoted.dtd";
system("$INTLTOOL_EXTRACT --type=gettext/quoted --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "30. Merge translations into multiple quoted style files:             ";
$case = "test-quoted.dtd";
system("$INTLTOOL_MERGE --quoted-style --quiet --multiple-output cases cases/$case $case") == 0 or $failed = 1;
check_multimerge_result($case, "test-quoted");

print "31. Extract comments for translators from a .desktop.in file:        ";
$case = "extract13.desktop.in";
system("$INTLTOOL_EXTRACT --type=gettext/ini --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "32. Merge translations from a .desktop.in file:                      ";
$case = "extract13.desktop.in";
$result = $case;
($result = $case) =~ s/\.in//;
system("$INTLTOOL_MERGE -d --quiet cases cases/$case cases/$result") == 0 or $failed = 1;
check_merge_result($case);

print "33. Decode XML entities in the right order when extracting:          ";
$case = "extract14.xml.in";
system("$INTLTOOL_EXTRACT --type=gettext/xml --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "34. Merge XML translations, decoding entities in the right order:    ";
$case = "merge12.xml";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "35. Extract messages from an XML file with msgctxts:                 ";
$case = "context.xml.in";
system("$INTLTOOL_EXTRACT --type=gettext/xml --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "36. Merge translations into an XML file with msgctxts:               ";
$case = "context.xml";
system("$INTLTOOL_MERGE -x --quiet cases cases/$case.in cases/$case") == 0 or $failed = 1;
check_merge_result($case);

print "37. Extract messages from an GtkBuilder XML file with msgctxts:      ";
$case = "extract-gtkbuilder.ui";
system("$INTLTOOL_EXTRACT --type=gettext/glade --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "38. Extract messages from an GSettings gschema XML file:             ";
$case = "gsettings.gschema.xml";
system("$INTLTOOL_EXTRACT --type=gettext/gsettings --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "39. Allow single quotes, like translatable='yes':                    ";
$case = "extract-gtkbuilder-single.ui";
system("$INTLTOOL_EXTRACT --type=gettext/glade --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);

print "40. Extract messages from a Qt Designer UI file:                     ";
$case = "extract-qtdesigner.ui";
system("$INTLTOOL_EXTRACT --type=gettext/qtdesigner --quiet --update cases/$case") == 0 or $failed = 1;
check_extract_result($case);


system("rm -f cases/*.*") if $srcdir ne ".";
system("rm -rf C az extract9 fr fr_BE fr_FR merge6 schemasmerge1 schemasmerge2 spacepreserve test test-quoted merge6.xml");

exit $failed;