1#! /bin/sh
2
3# Test checking of Qt format strings.
4
5tmpfiles=""
6trap 'rm -fr $tmpfiles' 1 2 3 15
7
8tmpfiles="$tmpfiles f-qt-2.data"
9cat <<\EOF > f-qt-2.data
10# Valid: %% doesn't count
11msgid  "abc%%def"
12msgstr "xyz"
13# Invalid: invalid msgstr
14msgid  "abc%1def"
15msgstr "xyz%1%1"
16# Valid: same arguments
17msgid  "abc%2def"
18msgstr "xyz%2"
19# Valid: permutation
20msgid  "abc%3%1%2def"
21msgstr "xyz%2%1%3"
22# Invalid: too few arguments
23msgid  "abc%2def%1"
24msgstr "xyz%1"
25# Invalid: too many arguments
26msgid  "abc%1def"
27msgstr "xyz%1uvw%2"
28# Invalid: missing non-final argument
29msgid  "abc%2def%1"
30msgstr "xyz%2"
31# Invalid: added non-final argument
32msgid  "abc%2def"
33msgstr "xyz%1%2"
34EOF
35
36: ${MSGFMT=msgfmt}
37n=0
38while read comment; do
39  read msgid_line
40  read msgstr_line
41  n=`expr $n + 1`
42  tmpfiles="$tmpfiles f-qt-2-$n.po f-qt-2-$n.mo"
43  cat <<EOF > f-qt-2-$n.po
44#, qt-format
45${msgid_line}
46${msgstr_line}
47EOF
48  fail=
49  if echo "$comment" | grep 'Valid:' > /dev/null; then
50    if ${MSGFMT} --check-format -o f-qt-2-$n.mo f-qt-2-$n.po; then
51      :
52    else
53      fail=yes
54    fi
55  else
56    ${MSGFMT} --check-format -o f-qt-2-$n.mo f-qt-2-$n.po 2> /dev/null
57    if test $? = 1; then
58      :
59    else
60      fail=yes
61    fi
62  fi
63  if test -n "$fail"; then
64    echo "Format string checking error:" 1>&2
65    cat f-qt-2-$n.po 1>&2
66    exit 1
67  fi
68  rm -f f-qt-2-$n.po f-qt-2-$n.mo
69done < f-qt-2.data
70
71rm -fr $tmpfiles
72
73exit 0
74