Home | History | Annotate | Download | only in ltrace.minor
      1 # This file is part of ltrace.
      2 # Copyright (C) 2013 Petr Machata, Red Hat Inc.
      3 #
      4 # This program is free software; you can redistribute it and/or
      5 # modify it under the terms of the GNU General Public License as
      6 # published by the Free Software Foundation; either version 2 of the
      7 # License, or (at your option) any later version.
      8 #
      9 # This program is distributed in the hope that it will be useful, but
     10 # WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12 # General Public License for more details.
     13 #
     14 # You should have received a copy of the GNU General Public License
     15 # along with this program; if not, write to the Free Software
     16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
     17 # 02110-1301 USA
     18 
     19 set bin [ltraceCompile {} [ltraceSource c {
     20     #include <sys/time.h>
     21     #include <assert.h>
     22     #include <locale.h>
     23     #include <stdio.h>
     24     #include <stdlib.h>
     25     #include <string.h>
     26     #include <time.h>
     27     #include <wchar.h>
     28     #include <wctype.h>
     29 
     30     int main(int argc, char *argv[])
     31     {
     32       setlocale(LC_ALL, "");
     33 
     34       FILE *rd_stream, *wr_stream, *wr_stream_2;
     35       {
     36 	int fds[2];
     37 	pipe (fds);
     38 	rd_stream = fdopen (fds[0], "r");
     39 	wr_stream = fdopen (fds[1], "w");
     40 	wr_stream_2 = fdopen (fds[1], "w");
     41       }
     42 
     43       wcslen(L"  !");
     44 
     45       fprintf(wr_stream_2, "something %s\n", "something");
     46       fprintf(wr_stream_2, "something %ls\n", L"-");
     47 
     48       fputwc(L'', wr_stream);
     49       putwc(L'', wr_stream);
     50       fflush(wr_stream);
     51       fgetwc(rd_stream);
     52       ungetwc(getwc(rd_stream), rd_stream);
     53 
     54       fputws(L"-.\n", wr_stream);
     55       fflush(wr_stream);
     56       wchar_t wbuf[64];
     57       fgetws(wbuf, 64, rd_stream);
     58 
     59       fwprintf(wr_stream, L"- %ls %s.\n", L"-", "something");
     60       swprintf(wbuf, 64, L"zwlf groe %ls %zd", L"Boxkmpfe", wcslen(wbuf));
     61 
     62       int i = iswalnum(L'1');
     63       assert(!!i);
     64       i = iswalpha(L'A');
     65       assert(!!i);
     66       i = iswcntrl(L'\t');
     67       assert(!!i);
     68       i = iswdigit(L'1');
     69       assert(!!i);
     70       i = iswgraph(L'=');
     71       assert(!!i);
     72       i = iswlower(L'');
     73       assert(!!i);
     74       i = iswupper(L'');
     75       assert(!!i);
     76       i = iswprint(L'');
     77       assert(!!i);
     78       i = iswpunct(L'');
     79       assert(!!i);
     80       i = iswspace(L'\t');
     81       assert(!!i);
     82       i = iswxdigit(L'A');
     83       assert(!!i);
     84 
     85       i = mbrlen("", sizeof "", NULL);
     86       assert(i == 2);
     87       wchar_t wc;
     88       i = mbrtowc(&wc, "", sizeof "", NULL);
     89 
     90       const char *str = "";
     91       i = mbsrtowcs(wbuf, &str, 64, NULL);
     92       assert(i >= 0);
     93 
     94       i = towlower(towupper(L'')) == L'';
     95       assert(!!i);
     96 
     97       char buf[64] = {};
     98       wctomb(buf, L'');
     99       wcrtomb(buf, L'', NULL);
    100 
    101       wbuf[0] = 0;
    102       i = wcscmp(wcschr(wcsncat(wcscat(wbuf, L"luouk "),
    103 				L"k", 64), L''), L"");
    104       assert(i == 0);
    105       i = wcsncmp(wbuf, L"luk", 4);
    106       assert(i == 0);
    107 
    108       i = wcscoll(wcscpy(wbuf, L"/l/"), L"/d/");
    109       assert(i != 0);
    110       i = wcsspn(wbuf, L"/");
    111       assert(i == 1);
    112       i = wcscspn(wbuf, L"");
    113       assert(i == 1);
    114       *wcsrchr(wcspbrk(wbuf, L""), L'') = L'i';
    115 
    116       struct timeval tv;
    117       gettimeofday(&tv, NULL);
    118       struct tm *tm = gmtime(&tv.tv_sec);
    119       wbuf[0] = L'\0';
    120       wcsftime(wbuf, 64, L"%F  %T", tm);
    121       { const wchar_t *ptr = wbuf; wcsrtombs(buf, &ptr, 64, NULL); }
    122       { wchar_t *ptr = NULL; wcstod(wcsstr(wbuf, L"") + 2, &ptr); }
    123       wcsncpy(wbuf, L"1234", 64);
    124       { wchar_t *ptr = NULL; wcstof(wbuf, &ptr); }
    125       { wchar_t *ptr = NULL; wcstold(wbuf, &ptr); }
    126       { wchar_t *ptr = NULL; wcstol(wbuf, &ptr, 10); }
    127       { wchar_t *ptr = NULL; wcstoll(wbuf, &ptr, 10); }
    128       { wchar_t *ptr = NULL; wcstoul(wbuf, &ptr, 10); }
    129       { wchar_t *ptr = NULL; wcstoull(wbuf, &ptr, 10); }
    130       i = wmemcmp(wmemchr(wbuf, L'', 64), L"", 2);
    131       assert(i == 0);
    132 
    133       i = wcswidth(L"") + wcwidth(L'') + wctob(L'1');;
    134       assert(i == 6 + '1');
    135 
    136       i = iswctype(L'', wctype("alpha"));
    137       assert(!!i);
    138 
    139       wmemcpy(wbuf, L"Dobr den", 6);
    140       wmemmove(wbuf, L"  ", 2);
    141       { wchar_t *ptr = NULL; wmemset(wcstok(wbuf, L" ", &ptr), L'', 5); }
    142 
    143       return 0;
    144     }
    145 }]]
    146 
    147 ltraceMatch [ltraceRun -F $srcdir/../etc/ -- $bin] {
    148     {{^fprintf\(.*, "something %s\\n", "something"\)} == 1}
    149     {{^fprintf\(.*, "something %ls\\n", "-"\)} == 1}
    150     {{^fputwc\('', .*\).*= ''} == 1}
    151     {{^putwc\('', .*\).*= ''} == 1}
    152     {{^fgetwc\(.*\).*= ''} == 1}
    153     {{^getwc\(.*\).*= ''} == 1}
    154     {{^ungetwc\('', .*\).*= ''} == 1}
    155     {{^fputws\("-.\\n", .*\)} == 1}
    156     {{^fgetws\("-.\\n", 64, .*\).*= "-.\\n"} == 1}
    157     {{^fwprintf\(.*, "- %ls %s.\\n", "-", "something"\).*= 27} == 1}
    158     {{^wcslen\("-.\\n"\).*= 9} == 1}
    159     {{^swprintf\("zwlf groe Boxkmpfe 9", 64, "zwlf groe %ls %zd", "Boxkmpfe", 9\).*= 23} == 1}
    160     {{^iswalnum\('1'\).*= 8} == 1}
    161     {{^iswalpha\('A'\).*= 1024} == 1}
    162     {{^iswcntrl\('\\t'\).*= 2} == 1}
    163     {{^iswdigit\('1'\).*= 1} == 1}
    164     {{^iswgraph\('='\).*= 32768} == 1}
    165     {{^iswlower\(''\).*= 1} == 1}
    166     {{^iswupper\(''\).*= 1} == 1}
    167     {{^iswprint\(''\).*= 1} == 1}
    168     {{^iswpunct\(''\).*= 1} == 1}
    169     {{^iswspace\('\\t'\).*= 8192} == 1}
    170     {{^iswxdigit\('A'\).*= 4096} == 1}
    171     {{^mbrtowc\('', ".*", 7, nil\)} == 1}
    172     {{^mbsrtowcs\("", nil, 64, nil\).*= 3} == 1}
    173     {{^towupper\(''\).*= ''} == 1}
    174     {{^towlower\(''\).*= ''} == 1}
    175     {{^wctomb\(".*", ''\)} == 1}
    176     {{^wcrtomb\(".*", '', nil\)} == 1}
    177     {{^wcscat\("", "luouk "\).*= "luouk "} == 1}
    178     {{^wcsncat\("luouk ", "k", 64\).*= "luouk k"} == 1}
    179     {{^wcschr\("luouk k", ''\).*= ""} == 1}
    180     {{^wcscmp\("", ""\).*= 0} == 1}
    181     {{^wcsncmp\("lu", "lu", 4\).*= 0} == 1}
    182     {{^wcscpy\(.*, "/l/"\).*= .*} == 1}
    183     {{^wcscoll\("/l/", "/d/"\).*= 10} == 1}
    184     {{^wcsspn\("/l/", "/"\).*= 1} == 1}
    185     {{^wcscspn\("/l/", ""\).*= 1} == 1}
    186     {{^wcspbrk\("/l/", ""\).*= "l/"} == 1}
    187     {{^wcsrchr\("l/", ''\).*= "/"} == 1}
    188     {{^gettimeofday\(.*, nil\).*= 0} == 1}
    189     {{^gmtime\(.*\).*= .*} == 1}
    190     {{^wcsftime\(".*  .*", 64, "%F  %T", .*\)} == 1}
    191     {{^wcsrtombs\(".*", nil, 64, nil\)} == 1}
    192     {{^wcsstr\(".*  .*", ""\).*= " .*"} == 1}
    193     {{^wcstod\(".*", ".*"\).*= [0-9]+} == 1}
    194     {{^wcsncpy\(.*, "1234", 64\).*= .*} == 1}
    195     {{^wcstof\("1234", ""\).*= 1234} == 1}
    196     {{^wcstold\("1234", ""\).*= 1234} == 1}
    197     {{^wcstol\("1234", "", 10\).*= 1234} == 1}
    198     {{^wcstoll\("1234", "", 10\).*= 1234} == 1}
    199     {{^wcstoul\("1234", "", 10\).*= 1234} == 1}
    200     {{^wcstoull\("1234", "", 10\).*= 1234} == 1}
    201     {{^wmemchr\("1234", '', 64\).*= ""} == 1}
    202     {{^wmemcmp\("", "", 2\).*= 0} == 1}
    203     {{^wcswidth\("", .*\).*= 4} == 1}
    204     {{^wcwidth\(''\).*= 2} == 1}
    205     {{^wctob\('1'\).*= 49} == 1}
    206     {{^wctype\("alpha"\).*= .*} == 1}
    207     {{^iswctype\('', .*\).*= 1} == 1}
    208     {{^wmemcpy\(.*, "Dobr ", 6\).*= "Dobr "} == 1}
    209     {{^wmemmove\(.*, "  ", 2\).*= "  "} == 1}
    210     {{^wcstok\("  br ", " ", ""\).*= "br"} == 1}
    211     {{^wmemset\(.*, '', 5\).*= ""} == 1}
    212 }
    213 
    214 ltraceDone
    215