Home | History | Annotate | Line # | Download | only in tests
format-c-1 revision 1.1
      1  1.1  christos #! /bin/sh
      2  1.1  christos 
      3  1.1  christos # Test recognition of C format strings.
      4  1.1  christos 
      5  1.1  christos tmpfiles=""
      6  1.1  christos trap 'rm -fr $tmpfiles' 1 2 3 15
      7  1.1  christos 
      8  1.1  christos tmpfiles="$tmpfiles f-c-1.data"
      9  1.1  christos cat <<\EOF > f-c-1.data
     10  1.1  christos # Valid: no argument
     11  1.1  christos "abc%%"
     12  1.1  christos # Valid: one character argument
     13  1.1  christos "abc%c"
     14  1.1  christos # Valid: one string argument
     15  1.1  christos "abc%s"
     16  1.1  christos # Valid: one integer argument
     17  1.1  christos "abc%i"
     18  1.1  christos # Valid: one integer argument
     19  1.1  christos "abc%d"
     20  1.1  christos # Valid: one integer argument
     21  1.1  christos "abc%o"
     22  1.1  christos # Valid: one integer argument
     23  1.1  christos "abc%u"
     24  1.1  christos # Valid: one integer argument
     25  1.1  christos "abc%x"
     26  1.1  christos # Valid: one integer argument
     27  1.1  christos "abc%X"
     28  1.1  christos # Valid: one floating-point argument
     29  1.1  christos "abc%e"
     30  1.1  christos # Valid: one floating-point argument
     31  1.1  christos "abc%E"
     32  1.1  christos # Valid: one floating-point argument
     33  1.1  christos "abc%f"
     34  1.1  christos # Valid: one floating-point argument
     35  1.1  christos "abc%F"
     36  1.1  christos # Valid: one floating-point argument
     37  1.1  christos "abc%g"
     38  1.1  christos # Valid: one floating-point argument
     39  1.1  christos "abc%G"
     40  1.1  christos # Valid: one floating-point argument
     41  1.1  christos "abc%a"
     42  1.1  christos # Valid: one floating-point argument
     43  1.1  christos "abc%A"
     44  1.1  christos # Valid: one pointer argument
     45  1.1  christos "abc%p"
     46  1.1  christos # Valid: one argument with flags
     47  1.1  christos "abc%0#g"
     48  1.1  christos # Valid: one argument with width
     49  1.1  christos "abc%2g"
     50  1.1  christos # Valid: one argument with width
     51  1.1  christos "abc%*g"
     52  1.1  christos # Valid: one argument with precision
     53  1.1  christos "abc%.4g"
     54  1.1  christos # Valid: one argument with precision
     55  1.1  christos "abc%.*g"
     56  1.1  christos # Valid: one argument with width and precision
     57  1.1  christos "abc%14.4g"
     58  1.1  christos # Valid: one argument with width and precision
     59  1.1  christos "abc%14.*g"
     60  1.1  christos # Valid: one argument with width and precision
     61  1.1  christos "abc%*.4g"
     62  1.1  christos # Valid: one argument with width and precision
     63  1.1  christos "abc%*.*g"
     64  1.1  christos # Valid: one argument with size specifier
     65  1.1  christos "abc%hhi"
     66  1.1  christos # Valid: one argument with size specifier
     67  1.1  christos "abc%hi"
     68  1.1  christos # Valid: one argument with size specifier
     69  1.1  christos "abc%li"
     70  1.1  christos # Valid: one argument with size specifier
     71  1.1  christos "abc%lli"
     72  1.1  christos # Valid: one argument with size specifier
     73  1.1  christos "abc%Lg"
     74  1.1  christos # Valid: one argument with size specifier
     75  1.1  christos "abc%qi"
     76  1.1  christos # Valid: one argument with size specifier
     77  1.1  christos "abc%ji"
     78  1.1  christos # Valid: one argument with size specifier
     79  1.1  christos "abc%zi"
     80  1.1  christos # Valid: one argument with size specifier
     81  1.1  christos "abc%ti"
     82  1.1  christos # Invalid: unterminated
     83  1.1  christos "abc%"
     84  1.1  christos # Invalid: unknown format specifier
     85  1.1  christos "abc%y"
     86  1.1  christos # Invalid: flags after width
     87  1.1  christos "abc%*0g"
     88  1.1  christos # Invalid: twice precision
     89  1.1  christos "abc%.4.2g"
     90  1.1  christos # Valid: three arguments
     91  1.1  christos "abc%d%u%u"
     92  1.1  christos # Valid: a numbered argument
     93  1.1  christos "abc%1$d"
     94  1.1  christos # Invalid: zero
     95  1.1  christos "abc%0$d"
     96  1.1  christos # Valid: two-digit numbered arguments
     97  1.1  christos "abc%11$def%10$dgh%9$dij%8$dkl%7$dmn%6$dop%5$dqr%4$dst%3$duv%2$dwx%1$dyz"
     98  1.1  christos # Invalid: unterminated number
     99  1.1  christos "abc%1"
    100  1.1  christos # Invalid: flags before number
    101  1.1  christos "abc%+1$d"
    102  1.1  christos # Valid: three arguments, two with same number
    103  1.1  christos "abc%1$4x,%2$c,%1$u"
    104  1.1  christos # Invalid: argument with conflicting types
    105  1.1  christos "abc%1$4x,%2$c,%1$s"
    106  1.1  christos # Valid: no conflict
    107  1.1  christos "abc%1$4x,%2$c,%1$u"
    108  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
    109  1.1  christos "abc%d%2$x"
    110  1.1  christos # Valid: numbered argument with constant precision
    111  1.1  christos "abc%1$.9x"
    112  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
    113  1.1  christos "abc%1$.*x"
    114  1.1  christos # Invalid: missing non-final argument
    115  1.1  christos "abc%2$x%3$s"
    116  1.1  christos # Valid: permutation
    117  1.1  christos "abc%2$ddef%1$d"
    118  1.1  christos # Valid: multiple uses of same argument
    119  1.1  christos "abc%2$xdef%1$pghi%2$x"
    120  1.1  christos # Valid: one argument with width
    121  1.1  christos "abc%2$#*1$g"
    122  1.1  christos # Valid: one argument with width and precision
    123  1.1  christos "abc%3$*2$.*1$g"
    124  1.1  christos # Invalid: zero
    125  1.1  christos "abc%2$*0$.*1$g"
    126  1.1  christos EOF
    127  1.1  christos 
    128  1.1  christos : ${XGETTEXT=xgettext}
    129  1.1  christos n=0
    130  1.1  christos while read comment; do
    131  1.1  christos   read string
    132  1.1  christos   n=`expr $n + 1`
    133  1.1  christos   tmpfiles="$tmpfiles f-c-1-$n.in f-c-1-$n.po"
    134  1.1  christos   cat <<EOF > f-c-1-$n.in
    135  1.1  christos gettext(${string});
    136  1.1  christos EOF
    137  1.1  christos   ${XGETTEXT} -L C -o f-c-1-$n.po f-c-1-$n.in || exit 1
    138  1.1  christos   test -f f-c-1-$n.po || exit 1
    139  1.1  christos   fail=
    140  1.1  christos   if echo "$comment" | grep 'Valid:' > /dev/null; then
    141  1.1  christos     if grep c-format f-c-1-$n.po > /dev/null; then
    142  1.1  christos       :
    143  1.1  christos     else
    144  1.1  christos       fail=yes
    145  1.1  christos     fi
    146  1.1  christos   else
    147  1.1  christos     if grep c-format f-c-1-$n.po > /dev/null; then
    148  1.1  christos       fail=yes
    149  1.1  christos     else
    150  1.1  christos       :
    151  1.1  christos     fi
    152  1.1  christos   fi
    153  1.1  christos   if test -n "$fail"; then
    154  1.1  christos     echo "Format string recognition error:" 1>&2
    155  1.1  christos     cat f-c-1-$n.in 1>&2
    156  1.1  christos     echo "Got:" 1>&2
    157  1.1  christos     cat f-c-1-$n.po 1>&2
    158  1.1  christos     exit 1
    159  1.1  christos   fi
    160  1.1  christos   rm -f f-c-1-$n.in f-c-1-$n.po
    161  1.1  christos done < f-c-1.data
    162  1.1  christos 
    163  1.1  christos rm -fr $tmpfiles
    164  1.1  christos 
    165  1.1  christos exit 0
    166