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 19set 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"zwölf große %ls %zd", L"Boxkämpfe", 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"žluťoučký "), 103 L"kůň", 64), L'ů'), L"ůň"); 104 assert(i == 0); 105 i = wcsncmp(wbuf, L"žluťák", 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 147ltraceMatch [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\("zwölf große Boxkämpfe 9", 64, "zwölf große %ls %zd", "Boxkämpfe", 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\("", "žluťoučký "\).*= "žluťoučký "} == 1} 178 {{^wcsncat\("žluťoučký ", "kůň", 64\).*= "žluťoučký kůň"} == 1} 179 {{^wcschr\("žluťoučký 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 214ltraceDone 215