Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
21.cwchar.cpp
Go to the documentation of this file.
1
29// used in the EVAL() macro below purely to make diagnostic messages
30// more informative (i.e., to display which config macros are defined
31// when a function isn't declared -- it may not make sense to declare
32// some functions if they are not defined in the C library)
33enum {
86};
87
88
90#include <cwchar>
91
92#include <rw_any.h> // for rw_any_t
93#include <rw_driver.h> // for rw_test(), ...
94
95
97// detect missing macros
98const char* const missing_macros [] = {
99
100#ifndef NULL
101 "NULL",
102#else // if defined (NULL)
103 "",
104#endif // NULL
105
106#ifndef WCHAR_MIN
107 "WCHAR_MIN",
108#else // if defined (WCHAR_MIN)
109 "",
110#endif // WCHAR_MIN
111
112#ifndef WCHAR_MAX
113 "WCHAR_MAX",
114#else // if defined (WCHAR_MAX)
115 "",
116#endif // WCHAR_MAX
117
118#ifndef WEOF
119 "WEOF",
120#else // if defined (WEOF)
121 "",
122#endif // WEOF
123
124 0
125};
126
127
129// detect masking macros and undefine them to avoid compilation errors
130// they might cause otherwise
131const char* const masking_macros [] = {
132
133#ifdef fwprintf
134 "fwprintf",
135# undef fwprintf
136#else
137 "",
138#endif // fwprintf
139
140#ifdef fwscanf
141 "fwscanf",
142# undef fwscanf
143#else
144 "",
145#endif // fwscanf
146
147#ifdef wprintf
148 "wprintf",
149# undef wprintf
150#else
151 "",
152#endif // wprintf
153
154#ifdef wscanf
155 "wscanf",
156# undef wscanf
157#else
158 "",
159#endif // wscanf
160
161#ifdef swprintf
162 "swprintf",
163# undef swprintf
164#else
165 "",
166#endif // swprintf
167
168#ifdef swscanf
169 "swscanf",
170# undef swscanf
171#else
172 "",
173#endif // swscanf
174
175#ifdef vfwprintf
176 "vfwprintf",
177# undef vfwprintf
178#else
179 "",
180#endif // vfwprintf
181
182#ifdef vwprintf
183 "vwprintf",
184# undef vwprintf
185#else
186 "",
187#endif // vwprintf
188
189#ifdef vswprintf
190 "vswprintf",
191# undef vswprintf
192#else
193 "",
194#endif // vswprintf
195
196#ifdef fgetwc
197 "fgetwc",
198# undef fgetwc
199#else
200 "",
201#endif // fgetwc
202
203#ifdef fgetws
204 "fgetws",
205# undef fgetws
206#else
207 "",
208#endif // fgetws
209
210#ifdef fputwc
211 "fputwc",
212# undef fputwc
213#else
214 "",
215#endif // fputwc
216
217#ifdef fputws
218 "fputws",
219# undef fputws
220#else
221 "",
222#endif // fputws
223
224#ifdef getwc
225 "getwc",
226# undef getwc
227#else
228 "",
229#endif // getwc
230
231#ifdef getwchar
232 "getwchar",
233# undef getwchar
234#else
235 "",
236#endif // getwchar
237
238#ifdef putwc
239 "putwc",
240# undef putwc
241#else
242 "",
243#endif // putwc
244
245#ifdef putwchar
246 "putwchar",
247# undef putwchar
248#else
249 "",
250#endif // putwchar
251
252#ifdef ungetwc
253 "ungetwc",
254# undef ungetwc
255#else
256 "",
257#endif // ungetwc
258
259#ifdef fwide
260 "fwide",
261# undef fwide
262#else
263 "",
264#endif // fwide
265
266#ifdef wcstod
267 "wcstod",
268# undef wcstod
269#else
270 "",
271#endif // wcstod
272
273#ifdef wcstol
274 "wcstol",
275# undef wcstol
276#else
277 "",
278#endif // wcstol
279
280#ifdef wcstoul
281 "wcstoul",
282# undef wcstoul
283#else
284 "",
285#endif // wcstoul
286
287#ifdef wcscpy
288 "wcscpy",
289# undef wcscpy
290#else
291 "",
292#endif // wcscpy
293
294#ifdef wcsncpy
295 "wcsncpy",
296# undef wcsncpy
297#else
298 "",
299#endif // wcsncpy
300
301#ifdef wcscat
302 "wcscat",
303# undef wcscat
304#else
305 "",
306#endif // wcscat
307
308#ifdef wcsncat
309 "wcsncat",
310# undef wcsncat
311#else
312 "",
313#endif // wcsncat
314
315#ifdef wcscmp
316 "wcscmp",
317# undef wcscmp
318#else
319 "",
320#endif // wcscmp
321
322#ifdef wcscoll
323 "wcscoll",
324# undef wcscoll
325#else
326 "",
327#endif // wcscoll
328
329#ifdef wcsncmp
330 "wcsncmp",
331# undef wcsncmp
332#else
333 "",
334#endif // wcsncmp
335
336#ifdef wcsxfrm
337 "wcsxfrm",
338# undef wcsxfrm
339#else
340 "",
341#endif // wcsxfrm
342
343#ifdef wcschr
344 "wcschr",
345# undef wcschr
346#else
347 "",
348#endif // wcschr
349
350#ifdef wcscspn
351 "wcscspn",
352# undef wcscspn
353#else
354 "",
355#endif // wcscspn
356
357#ifdef wcspbrk
358 "wcspbrk",
359# undef wcspbrk
360#else
361 "",
362#endif // wcspbrk
363
364#ifdef wcsrchr
365 "wcsrchr",
366# undef wcsrchr
367#else
368 "",
369#endif // wcsrchr
370
371#ifdef wcsspn
372 "wcsspn",
373# undef wcsspn
374#else
375 "",
376#endif // wcsspn
377
378#ifdef wcsstr
379 "wcsstr",
380# undef wcsstr
381#else
382 "",
383#endif // wcsstr
384
385#ifdef wcstok
386 "wcstok",
387# undef wcstok
388#else
389 "",
390#endif // wcstok
391
392#ifdef wcslen
393 "wcslen",
394# undef wcslen
395#else
396 "",
397#endif // wcslen
398
399#ifdef wmemchr
400 "wmemchr",
401# undef wmemchr
402#else
403 "",
404#endif // wmemchr
405
406#ifdef wmemcmp
407 "wmemcmp",
408# undef wmemcmp
409#else
410 "",
411#endif // wmemcmp
412
413#ifdef wmemcpy
414 "wmemcpy",
415# undef wmemcpy
416#else
417 "",
418#endif // wmemcpy
419
420#ifdef wmemmove
421 "wmemmove",
422# undef wmemmove
423#else
424 "",
425#endif // wmemmove
426
427#ifdef wmemset
428 "wmemset",
429# undef wmemset
430#else
431 "",
432#endif // wmemset
433
434#ifdef wcsftime
435 "wcsftime",
436# undef wcsftime
437#else
438 "",
439#endif // wcsftime
440
441#ifdef btowc
442 "btowc",
443# undef btowc
444#else
445 "",
446#endif // btowc
447
448#ifdef wctob
449 "wctob",
450# undef wctob
451#else
452 "",
453#endif // wctob
454
455#ifdef mbsinit
456 "mbsinit",
457# undef mbsinit
458#else
459 "",
460#endif // mbsinit
461
462#ifdef mbrlen
463 "mbrlen",
464# undef mbrlen
465#else
466 "",
467#endif // mbrlen
468
469#ifdef mbrtowc
470 "mbrtowc",
471# undef mbrtowc
472#else
473 "",
474#endif // mbrtowc
475
476#ifdef wcrtomb
477 "wcrtomb",
478# undef wcrtomb
479#else
480 "",
481#endif // wcrtomb
482
483#ifdef mbsrtowcs
484 "mbsrtowcs",
485# undef mbsrtowcs
486#else
487 "",
488#endif // mbsrtowcs
489
490#ifdef wcsrtombs
491 "wcsrtombs",
492# undef wcsrtombs
493#else
494 "",
495#endif // wcsrtombs
496
497 0
498};
499
500
502static void
503test_macros ()
504{
505 rw_info (0, 0, 0, "checking for missing and masking macros");
506
507 for (unsigned i = 0; missing_macros [i]; ++i) {
508 rw_assert ('\0' == missing_macros [i][0], 0, __LINE__,
509 "macro %s not defined", missing_macros [i]);
510 }
511
512 for (unsigned i = 0; masking_macros [i]; ++i) {
513#ifdef _RWSTD_STRICT_ANSI
514 rw_assert ('\0' == masking_macros [i][0], 0, __LINE__,
515 "masking macro %s unexpectedly defined",
516 masking_macros [i]);
517#else
518 rw_warn ('\0' == masking_macros [i][0], 0, __LINE__,
519 "masking macro %s unexpectedly defined",
520 masking_macros [i]);
521#endif
522 }
523}
524
525
527#ifndef _RWSTD_NO_NAMESPACE
528
529// check types
530
531namespace Fallback {
532
533struct size_t {
534 int i_;
535 char dummy_ [256]; // make sure we're bigger than the real thing
536
537 // this (fake) size_t emulates a scalar type
538 size_t (int i): i_ (i) { }
539 operator int () const { return i_; }
540};
541
542struct mbstate_t {
543 char dummy_ [256]; // make sure we're bigger than the real thing
544};
545
546struct wint_t {
547 int i_;
548 char dummy_ [256]; // make sure we're bigger than the real thing
549
550 // this (fake) wint_t emulates a scalar type
551 wint_t (int i): i_ (i) { }
552 operator int () const { return i_; }
553};
554
555struct FILE;
556
557struct tm;
558
559} // namespace Fallback
560
561namespace std {
562
563// define test functions in namespace std to detect the presece
564// or absence of the required types
565
566namespace Nested {
567
568using namespace Fallback;
569
570// each test_xxx_t typedef aliases std::xxx_t if the corresponding
571// type is defined in namespace std, or Fallback::xxx_t otherwise
572typedef size_t test_size_t;
575typedef tm test_tm;
576
577} // namespace Nested
578
579} // namespace std
580
581typedef std::Nested::test_size_t test_size_t;
582typedef std::Nested::test_mbstate_t test_mbstate_t;
583typedef std::Nested::test_wint_t test_wint_t;
584typedef std::Nested::test_tm test_tm;
585
586
587template <class StructTm>
588int tm_defined (const StructTm*) { return 1; }
589int tm_defined (const Fallback::tm*) { return 0; }
590
591
592const char std_name[] = "std";
593
594static void
595test_types ()
596{
597 rw_info (0, 0, 0,
598 "types %s::size_t, %1$s::mbstate_t, %1$s::wint_t, and %1$s::tm",
599 std_name);
600
601 rw_assert (sizeof (test_size_t) != sizeof (Fallback::size_t), 0, 0,
602 "%s::size_t not defined", std_name);
603 rw_assert (sizeof (test_mbstate_t) != sizeof (Fallback::mbstate_t), 0, 0,
604 "%s::mbstate_t not defined", std_name);
605 rw_assert (sizeof (test_wint_t) != sizeof (Fallback::wint_t), 0, 0,
606 "%s::wint_t not defined", std_name);
607
608 rw_assert (tm_defined ((const test_tm*)0), 0, 0,
609 "%s::tm not defined", std_name);
610}
611
612#else // if defined (_RWSTD_NO_NAMESPACE)
613
614const char std_name[] = "";
615
616static void
617test_types ()
618{
619 rw_info (0, 0, 0,
620 "types %s::size_t, %1$s::mbstate_t, %1$s::wint_t, and %1$s::tm",
621 std_name);
622
623 rw_note (0, 0, 0, "_RWSTD_NO_NAMESPACE defined, cannot test");
624}
625
626#endif // _RWSTD_NO_NAMESPACE
627
628
631
633
634template <class FileT, class WCharT>
635int fwprintf (FileT*, const WCharT*, ...) { return ncalls++; }
636
637template <class FileT, class WCharT>
638int fwscanf (FileT*, const WCharT*, ...) { return ncalls++; }
639
640template <class WCharT>
641int wprintf (const WCharT* dummy, ...) { return ncalls++; }
642
643template <class WCharT>
644int wscanf (const WCharT* dummy, ...) { return ncalls++; }
645
646template <class WCharT, class SizeT>
647int swprintf (WCharT*, SizeT, const WCharT* dummy, ...) { return ncalls++; }
648
649template <class WCharT>
650int swscanf (const WCharT*, const WCharT* dummy, ...) { return ncalls++; }
651
652template <class FileT, class WCharT, class VAList>
653int vfwprintf (FileT*, const WCharT*, VAList) { return ncalls++; }
654
655template <class WCharT, class VAList>
656int vwprintf (const WCharT*, VAList) { return ncalls++; }
657
658template <class WCharT, class SizeT, class VAList>
659int vswprintf (WCharT*, SizeT, const WCharT*, VAList) { return ncalls++; }
660
661template <class FileT>
662wint_t fgetwc (FileT*) { return ncalls++; }
663
664template <class WCharT, class FileT>
665WCharT* fgetws (WCharT*, int, FileT*) { ncalls++; return 0; }
666
667template <class WCharT, class FileT>
668test_wint_t fputwc (WCharT, FileT*) { return ncalls++; }
669
670template <class WCharT, class FileT>
671int fputws (const WCharT*, FileT*) { return ncalls++; }
672
673template <class FileT>
674test_wint_t getwc (FileT*) { return ncalls++; }
675
676// cannot exercise
677// test_wint_t getwchar();
678
679template <class WCharT, class FileT>
680test_wint_t putwc (WCharT, FileT*) { return ncalls++; }
681
682template <class WCharT>
683test_wint_t putwchar (WCharT) { return ncalls++; }
684
685template <class WIntT, class FileT>
686test_wint_t ungetwc (WIntT, FileT*) { return ncalls++; }
687
688template <class FileT>
689int fwide (FileT*, int) { return ncalls++; }
690
691template <class WCharT>
692double wcstod (const WCharT*, WCharT**) { return ncalls++; }
693
694template <class WCharT>
695long wcstol (const WCharT*, WCharT**, int) { return ncalls++; }
696
697template <class WCharT>
698unsigned long wcstoul (const WCharT*, WCharT**, int) { return ncalls++; }
699
700template <class WCharT>
701WCharT* wcscpy (WCharT*, const WCharT*) { ncalls++; return 0; }
702
703template <class WCharT, class SizeT>
704WCharT* wcsncpy (WCharT*, const WCharT*, SizeT) { ncalls++; return 0; }
705
706template <class WCharT>
707WCharT* wcscat (WCharT*, const WCharT*) { ncalls++; return 0; }
708
709template <class WCharT, class SizeT>
710WCharT* wcsncat (WCharT*, const WCharT*, SizeT) { ncalls++; return 0; }
711
712template <class WCharT>
713int wcscmp (const WCharT*, const WCharT*) { return ncalls++; }
714
715template <class WCharT>
716int wcscoll (const WCharT*, const WCharT*) { return ncalls++; }
717
718template <class WCharT, class SizeT>
719int wcsncmp (const WCharT*, const WCharT*, SizeT) { return ncalls++; }
720
721template <class WCharT, class SizeT>
722SizeT wcsxfrm (WCharT*, const WCharT*, SizeT) { return ncalls++; }
723
724template <class WCharT>
725WCharT* wcschr (WCharT*, WCharT) { ncalls++; return 0; }
726
727template <class WCharT>
728test_size_t wcscspn (const WCharT*, const WCharT*) { return ncalls++; }
729
730template <class WCharT>
731WCharT* wcspbrk (WCharT*, const WCharT*) { ncalls++; return 0; }
732
733template <class WCharT>
734WCharT* wcsrchr (WCharT*, WCharT) { ncalls++; return 0; }
735
736template <class WCharT>
737test_size_t wcsspn (const WCharT*, const WCharT*) { return ncalls++; }
738
739template <class WCharT>
740WCharT* wcsstr (WCharT*, const WCharT*) { ncalls++; return 0; }
741
742template <class WCharT>
743WCharT* wcstok (WCharT*, const WCharT*, WCharT**) { ncalls++; return 0; }
744
745template <class WCharT>
746test_size_t wcslen (const WCharT*) { return ncalls++; }
747
748template <class WCharT, class SizeT>
749WCharT* wmemchr (WCharT*, WCharT, SizeT) { ncalls++; return 0; }
750
751template <class WCharT, class SizeT>
752int wmemcmp (const WCharT*, const WCharT*, SizeT) { return ncalls++; }
753
754template <class WCharT, class SizeT>
755WCharT* wmemcpy (WCharT*, const WCharT*, SizeT) { ncalls++; return 0; }
756
757template <class WCharT, class SizeT>
758WCharT* wmemmove (WCharT*, const WCharT*, SizeT) { ncalls++; return 0; }
759
760template <class WCharT, class SizeT>
761WCharT* wmemset (WCharT*, WCharT, SizeT) { ncalls++; return 0; }
762
763template <class WCharT, class SizeT, class StructTm>
764SizeT wcsftime (WCharT*, SizeT, const WCharT*, const StructTm*)
765{ return ncalls++; }
766
767template <class IntT>
768test_wint_t btowc (IntT) { return ncalls++; }
769
770template <class WIntT>
771int wctob (WIntT) { return ncalls++; }
772
773template <class MBStateT>
774int mbsinit (const MBStateT*) { return ncalls++; }
775
776template <class SizeT, class MBStateT>
777SizeT mbrlen (const char*, SizeT, MBStateT*) { return ncalls++; }
778
779template <class WCharT, class SizeT, class MBStateT>
780SizeT mbrtowc (WCharT*, const char*, SizeT, MBStateT*) { return ncalls++; }
781
782template <class WCharT, class MBStateT>
783test_size_t wcrtomb (char*, WCharT, MBStateT*) { return ncalls++; }
784
785template <class WCharT, class SizeT, class MBStateT>
786SizeT mbsrtowcs (WCharT*, const char**, SizeT, MBStateT*) { return ncalls++; }
787
788template <class WCharT, class SizeT, class MBStateT>
789SizeT wcsrtombs (char*, const WCharT**, SizeT, MBStateT*) { return ncalls++; }
790
791
792template <class WCharT>
793const WCharT* wcschr (const WCharT*, WCharT) { ncalls++; return 0; }
794
795template <class WCharT>
796const WCharT* wcspbrk (const WCharT*, const WCharT*) { ncalls++; return 0; }
797
798template <class WCharT>
799const WCharT* wcsrchr (const WCharT*, WCharT) { ncalls++; return 0; }
800
801template <class WCharT>
802const WCharT* wcsstr (const WCharT*, const WCharT*) { ncalls++; return 0; }
803
804template <class WCharT, class SizeT>
805const WCharT* wmemchr (const WCharT*, WCharT, SizeT) { ncalls++; return 0; }
806
807} // namespace std
808
809
810struct UniqType;
811
812#define GET_TYPE_NAME(T) \
813 template <class Type> \
814 const char* get_type_name (T, Type) { \
815 return rw_any_t (Type ()).type_name (); \
816 } \
817 const char* get_type_name (T, T) { return 0; } \
818 typedef void unused_typedef /* allow a terminating semicolon */
819
821GET_TYPE_NAME (unsigned short);
823GET_TYPE_NAME (unsigned int);
825GET_TYPE_NAME (unsigned long);
827
828#ifndef _RWSTD_NO_LONG_LONG
831#endif
832
833#ifndef _RWSTD_NO_NATIVE_WCHAR_T
834GET_TYPE_NAME (wchar_t);
835#endif
836
837GET_TYPE_NAME (wchar_t*);
838GET_TYPE_NAME (const wchar_t*);
839
840
841#define EVAL2(macro) !!(macro - 1)
842#define EVAL(name) EVAL2 (_RWSTD_NO_ ## name + 0)
843#define EVAL_IN_LIBC(name) EVAL (name ## _IN_LIBC)
844
845
846static int rw_opt_no_macros; // for --no-macros
847static int rw_opt_no_types; // for --no-types
848static int rw_opt_no_functions; // for --no-functions
849static int rw_opt_no_overloads; // for --no-overloads
850
851
853{
854#define TEST(T, fun, args, macro, overload) \
855 do { \
856 cstr = (str = array); \
857 wcstr = (wstr = warray); \
858 *str = '\0'; *wstr = L'\0'; \
859 ncalls = 0; \
860 rw_info (0, 0, __LINE__, "%s::%s(" \
861 "%{?}%{:}/* %{?}non-%{;}const overload */%{;})", \
862 std_name, #fun, overload < 0, 0 == overload); \
863 const char* const return_type_name = \
864 get_type_name ((T)0, std::fun args); \
865 rw_warn (0 == ncalls, 0, __LINE__, \
866 "%s::%s(" \
867 "%{?}%{:}/* %{?}non-%{;}const overload */%{;}) " \
868 "not declared (_RWSTD_NO_%s = %d, " \
869 "_RWSTD_NO_%s_IN_LIBC = %d)", \
870 std_name, #fun, overload < 0, 0 == overload, \
871 #macro, EVAL (macro), #macro, EVAL_IN_LIBC (macro)); \
872 if (0 == ncalls) \
873 rw_assert (0 == return_type_name, 0, __LINE__, "%s::%s(" \
874 "%{?}%{:}/* %{?}non-%{;}const overload */%{;}) " \
875 "expected return type %s, got %s", \
876 std_name, #fun, overload < 0, 0 == overload, \
877 #T, return_type_name); \
878 } while (0)
879
880 char array [4] = "";
881
882 char* str = array;
883 const char* cstr = array;
884
885 wchar_t warray [32] = L"";
886
887 /* */ wchar_t* /* */ wstr = warray;
888 const wchar_t* /* */ wcstr = warray;
889
890 test_size_t size = 0;
891
892 const UniqType* const uniqptr = 0;
893
894 const test_wint_t wi = 0;
895
896 const int i = 0;
897 TEST (int, wprintf, (L""), WPRINTF, -1);
898 TEST (int, wprintf, (L"", uniqptr), WPRINTF, -1);
899
900 TEST (int, wscanf, (L""), WSCANF, -1);
901 TEST (int, wscanf, (L"", uniqptr), WSCANF, -1);
902
903 TEST (int, swprintf, (wstr, size, L""), SWPRINTF, -1);
904 TEST (int, swprintf, (wstr, size, L"", uniqptr), SWPRINTF, -1);
905
906 TEST (int, swscanf, (wstr, L""), SWSCANF, -1);
907 TEST (int, swscanf, (wstr, L"", uniqptr), SWSCANF, -1);
908
909 TEST (double, wcstod, (L"", &wstr), WCSTOD, -1);
910 TEST (long, wcstol, (L"", &wstr, i), WCSTOL, -1);
911 TEST (unsigned long, wcstoul, (L"", &wstr, i), WCSTOUL, -1);
912
913 TEST (wchar_t*, wcscpy, (wstr, L""), WCSCPY, -1);
914 TEST (wchar_t*, wcsncpy, (wstr, L"", size), WCSNCPY, -1);
915 TEST (wchar_t*, wcscat, (wstr, L""), WCSCAT, -1);
916 TEST (int, wcscmp, (wstr, L""), WCSCMP, -1);
917 TEST (int, wcsncmp, (wstr, L"", size), WCSNCMP, -1);
918 TEST (test_size_t, wcsxfrm, (wstr, L"", size), WCSXFRM, -1);
919
920 TEST (test_size_t, wcscspn, (L"", L""), WCSCSPN, -1);
921
922 TEST (test_size_t, wcsspn, (L"", L""), WCSSPN, -1);
923 TEST (wchar_t*, wcstok, (wstr, L"", &wstr), WCSTOK, -1);
924
925 TEST (test_size_t, wcslen, (L""), WCSLEN, -1);
926 TEST (int, wmemcmp, (L"", L"", size), WMEMCMP, -1);
927 TEST (wchar_t*, wmemcpy, (wstr, L"", size), WMEMCPY, -1);
928 TEST (wchar_t*, wmemmove, (wstr, L"", size), WMEMMOVE, -1);
929 TEST (wchar_t*, wmemset, (wstr, L'\0', size), WMEMSET, -1);
930
931 // const commented to prevent MSVC 7.0 error:
932 // error C2147: 'tm_buf' : const automatic array must be fully initialized
933 /* const */ int tm_buf [16] = { 0 };
934 const test_tm* tmb = (const test_tm*)&tm_buf;
935
936#ifdef _MSC_VER
937 // prevent MSVC parameter validation error:
938 // "Zero length output buffer passed to strftime"
939 size = 1;
940#endif
941
942 TEST (test_size_t, wcsftime, (wstr, size, L"", tmb), WCSFTIME, -1);
943
944#ifdef _MSC_VER
945 // restore size
946 size = 0;
947#endif
948
949 TEST (test_wint_t, btowc, (i), BTOWC, -1);
950 TEST (int, wctob, (wi), WCTOB, -1);
951
953
954 TEST (int, mbsinit, (&state), MBSINIT, -1);
955 TEST (test_size_t, mbrlen, ("", size, &state), MBRLEN, -1);
956 TEST (test_size_t, mbrtowc, (wstr, "", size, &state), MBRTOWC, -1);
957 TEST (test_size_t, wcrtomb, (str, L'\0', &state), WCRTOMB, -1);
958
959 TEST (test_size_t, mbsrtowcs, (wstr, &cstr, size, &state), MBSRTOWCS, -1);
960 TEST (test_size_t, wcsrtombs, (str, &wcstr, size, &state), WCSRTOMBS, -1);
961
962 if (rw_opt_no_overloads) {
963 // exercise the traditional C (const-incorrect) functions
964 TEST (/* const */ wchar_t*, wmemchr, (L"", L'\0', size), WMEMCHR, -1);
965 TEST (/* const */ wchar_t*, wcspbrk, (wcstr, L""), WCSPBRK, -1);
966 TEST (/* const */ wchar_t*, wcsrchr, (L"", L'\0'), WCSRCHR, -1);
967 TEST (/* const */ wchar_t*, wcsstr, (L"", L""), WCSSTR, -1);
968 TEST (/* const */ wchar_t*, wcschr, (L"", L'\0'), WCSCHR, -1);
969 }
970 else {
971 // exercise const and non-const overloads that C++ replaces
972 // the traditional C functions with
973 TEST (const wchar_t*, wmemchr, (L"", L'\0', size), WMEMCHR, 1);
974 TEST (wchar_t*, wmemchr, (wstr, L'\0', size), WMEMCHR, 0);
975
976 TEST (const wchar_t*, wcspbrk, (wcstr, L""), WCSPBRK, 1);
977 TEST (wchar_t*, wcspbrk, (wstr, L""), WCSPBRK, 0);
978
979 TEST (const wchar_t*, wcsrchr, (L"", L'\0'), WCSRCHR, 1);
980 TEST (wchar_t*, wcsrchr, (wstr, L'\0'), WCSRCHR, 0);
981
982 TEST (const wchar_t*, wcsstr, (L"", L""), WCSSTR, 1);
983 TEST (wchar_t*, wcsstr, (wstr, L""), WCSSTR, 0);
984
985 TEST (const wchar_t*, wcschr, (L"", L'\0'), WCSCHR, 1);
986 TEST (wchar_t*, wcschr, (wstr, L'\0'), WCSCHR, 0);
987 }
988}
989
990
992// included here to avoid namespace pollution
993#include <cstdarg> // for va_list
994#include <cstdio> // for FILE, fopen()
995
996#include <rw_file.h> // for DEV_NUL
997#include <rw_printf.h> // for rw_stdout
998
999namespace std {
1000
1001// define test types in namespace std to detect the presece
1002// or absence of the required types
1003
1004namespace Nested {
1005
1006using namespace Fallback;
1007
1009typedef va_list test_va_list;
1010
1011} // namespace Nested
1012
1013} // namespace std
1014
1015typedef std::Nested::test_FILE test_FILE;
1016typedef std::Nested::test_va_list test_va_list;
1017
1018
1019void test_file_functions (int dummy, ...)
1020{
1021 char array [4] = "";
1022
1023 /* */ char* str = array;
1024 const char* cstr = array;
1025
1026 wchar_t warray [32] = L"";
1027
1028 /* */ wchar_t* /* */ wstr = warray;
1029 const wchar_t* /* */ wcstr = warray;
1030
1031 const int i = 0;
1032
1033 const UniqType* const uniqptr = 0;
1034
1035 const test_wint_t wi = 0;
1036
1037 // cast rw_stdout to FILE* via void* since the latter may be
1038 // an incomplete type and casts between two non-void pointers
1039 // require that the types be complete (in case they are related
1040 // by inheritance and need to be adjusted)
1041 test_FILE* const fp = (test_FILE*)std::fopen (DEV_NULL, "w");
1042 test_va_list va;
1043 va_start (va, dummy);
1044
1045 // call fwide() first before any prior output since 7.19.2, p5
1046 // of C99 prohibits wide character I/O functions from being called
1047 // on a byte-oriented stream
1048 TEST (int, fwide, (fp, i), FWIDE, -1);
1049
1050 TEST (int, fwprintf, (fp, L""), FWPRINTF, -1);
1051 TEST (int, fwprintf, (fp, L"", uniqptr), FWPRINTF, -1);
1052
1053 TEST (int, fwscanf, (fp, L""), FWSCANF, -1);
1054 TEST (int, fwscanf, (fp, L"", uniqptr), FWSCANF, -1);
1055
1056 TEST (int, vfwprintf, (fp, L"", va), VFWPRINTF, -1);
1057
1058 TEST (test_wint_t, fgetwc, (fp), FGETWC, -1);
1059 TEST (wchar_t*, fgetws, (wstr, i, fp), FGETWS, -1);
1060 TEST (test_wint_t, fputwc, (L'\0', fp), FPUTWC, -1);
1061 TEST (int, fputws, (L"", fp), FPUTWS, -1);
1062 TEST (test_wint_t, getwc, (fp), GETWC, -1);
1063 TEST (test_wint_t, putwc, (L'\0', fp), PUTWC, -1);
1064 TEST (test_wint_t, ungetwc, (wi, fp), UNGETWC, -1);
1065
1067 _RWSTD_UNUSED (cstr);
1068 _RWSTD_UNUSED (wcstr);
1069}
1070
1071
1073static int
1074run_test (int, char**)
1075{
1076 if (rw_opt_no_macros)
1077 rw_note (0, 0, 0, "test for macros disabled");
1078 else
1079 test_macros ();
1080
1081 if (rw_opt_no_types)
1082 rw_note (0, 0, 0, "test for types disabled");
1083 else
1084 test_types ();
1085
1086 if (rw_opt_no_functions)
1087 rw_note (0, 0, 0, "test for functions disabled");
1088 else {
1089 test_functions ();
1090 test_file_functions (0 /* dummy */);
1091 }
1092
1093 return 0;
1094}
1095
1096
1098int main (int argc, char *argv[])
1099{
1100 return rw_test (argc, argv, __FILE__,
1101 "lib.c.strings",
1102 "header <cwchar>",
1103 run_test,
1104 "|-no-macros#0-1 "
1105 "|-no-types#0-1 "
1106 "|-no-functions#0-1 "
1107 "|-no-overloads#0-1 ",
1108 &rw_opt_no_macros,
1109 &rw_opt_no_types,
1110 &rw_opt_no_functions,
1111 &rw_opt_no_overloads);
1112}
#define i
Definition 17.names.cpp:126
#define array
Definition 17.names.cpp:447
#define TEST(T, fun, args, macro, overload)
void test_file_functions(int dummy,...)
int tm_defined(const StructTm *)
std::Nested::test_va_list test_va_list
#define GET_TYPE_NAME(T)
std::Nested::test_FILE test_FILE
std::Nested::test_size_t test_size_t
std::Nested::test_mbstate_t test_mbstate_t
const char *const missing_macros[]
Definition 21.cwchar.cpp:98
std::Nested::test_tm test_tm
std::Nested::test_wint_t test_wint_t
int ncalls
@ _RWSTD_NO_GETWC_IN_LIBC
Definition 21.cwchar.cpp:42
@ _RWSTD_NO_WCSFTIME_IN_LIBC
Definition 21.cwchar.cpp:63
@ _RWSTD_NO_WCSNCMP_IN_LIBC
Definition 21.cwchar.cpp:66
@ _RWSTD_NO_SWSCANF_IN_LIBC
Definition 21.cwchar.cpp:51
@ _RWSTD_NO_VSWPRINTF
Definition 21.cwchar.cpp:54
@ _RWSTD_NO_WCSCSPN
Definition 21.cwchar.cpp:62
@ _RWSTD_NO_MBSINIT_IN_LIBC
Definition 21.cwchar.cpp:46
@ _RWSTD_NO_VWPRINTF_IN_LIBC
Definition 21.cwchar.cpp:55
@ _RWSTD_NO_WMEMCPY_IN_LIBC
Definition 21.cwchar.cpp:81
@ _RWSTD_NO_WCSTOL_IN_LIBC
Definition 21.cwchar.cpp:75
@ _RWSTD_NO_FWIDE_IN_LIBC
Definition 21.cwchar.cpp:39
@ _RWSTD_NO_WCSPBRK_IN_LIBC
Definition 21.cwchar.cpp:68
@ _RWSTD_NO_FPUTWS
Definition 21.cwchar.cpp:38
@ _RWSTD_NO_FGETWS
Definition 21.cwchar.cpp:36
@ _RWSTD_NO_WCSLEN_IN_LIBC
Definition 21.cwchar.cpp:64
@ _RWSTD_NO_FGETWS_IN_LIBC
Definition 21.cwchar.cpp:36
@ _RWSTD_NO_WCSSPN
Definition 21.cwchar.cpp:71
@ _RWSTD_NO_MBRTOWC_IN_LIBC
Definition 21.cwchar.cpp:45
@ _RWSTD_NO_WCSFTIME
Definition 21.cwchar.cpp:63
@ _RWSTD_NO_FWPRINTF
Definition 21.cwchar.cpp:40
@ _RWSTD_NO_WCSTOK_IN_LIBC
Definition 21.cwchar.cpp:74
@ _RWSTD_NO_WCSSTR_IN_LIBC
Definition 21.cwchar.cpp:72
@ _RWSTD_NO_WCSCSPN_IN_LIBC
Definition 21.cwchar.cpp:62
@ _RWSTD_NO_VWPRINTF
Definition 21.cwchar.cpp:55
@ _RWSTD_NO_PUTWC
Definition 21.cwchar.cpp:48
@ _RWSTD_NO_GETWC
Definition 21.cwchar.cpp:42
@ _RWSTD_NO_GETWCHAR
Definition 21.cwchar.cpp:43
@ _RWSTD_NO_FPUTWS_IN_LIBC
Definition 21.cwchar.cpp:38
@ _RWSTD_NO_WCSRCHR_IN_LIBC
Definition 21.cwchar.cpp:69
@ _RWSTD_NO_WMEMSET
Definition 21.cwchar.cpp:83
@ _RWSTD_NO_WCSTOD
Definition 21.cwchar.cpp:73
@ _RWSTD_NO_WMEMCHR
Definition 21.cwchar.cpp:79
@ _RWSTD_NO_WCSLEN
Definition 21.cwchar.cpp:64
@ _RWSTD_NO_PUTWC_IN_LIBC
Definition 21.cwchar.cpp:48
@ _RWSTD_NO_VSWPRINTF_IN_LIBC
Definition 21.cwchar.cpp:54
@ _RWSTD_NO_GETWCHAR_IN_LIBC
Definition 21.cwchar.cpp:43
@ _RWSTD_NO_WCSSPN_IN_LIBC
Definition 21.cwchar.cpp:71
@ _RWSTD_NO_VFWPRINTF_IN_LIBC
Definition 21.cwchar.cpp:53
@ _RWSTD_NO_WMEMCPY
Definition 21.cwchar.cpp:81
@ _RWSTD_NO_SWPRINTF_IN_LIBC
Definition 21.cwchar.cpp:50
@ _RWSTD_NO_WCSRCHR
Definition 21.cwchar.cpp:69
@ _RWSTD_NO_WCRTOMB
Definition 21.cwchar.cpp:56
@ _RWSTD_NO_WCSTOUL_IN_LIBC
Definition 21.cwchar.cpp:76
@ _RWSTD_NO_MBSRTOWCS
Definition 21.cwchar.cpp:47
@ _RWSTD_NO_WCSTOK
Definition 21.cwchar.cpp:74
@ _RWSTD_NO_FGETWC
Definition 21.cwchar.cpp:35
@ _RWSTD_NO_WCSCAT_IN_LIBC
Definition 21.cwchar.cpp:57
@ _RWSTD_NO_WCSCPY_IN_LIBC
Definition 21.cwchar.cpp:61
@ _RWSTD_NO_FPUTWC_IN_LIBC
Definition 21.cwchar.cpp:37
@ _RWSTD_NO_WMEMMOVE
Definition 21.cwchar.cpp:82
@ _RWSTD_NO_WCSXFRM
Definition 21.cwchar.cpp:77
@ _RWSTD_NO_MBRLEN_IN_LIBC
Definition 21.cwchar.cpp:44
@ _RWSTD_NO_BTOWC_IN_LIBC
Definition 21.cwchar.cpp:34
@ _RWSTD_NO_MBRLEN
Definition 21.cwchar.cpp:44
@ _RWSTD_NO_WPRINTF_IN_LIBC
Definition 21.cwchar.cpp:84
@ _RWSTD_NO_SWSCANF
Definition 21.cwchar.cpp:51
@ _RWSTD_NO_WCSTOL
Definition 21.cwchar.cpp:75
@ _RWSTD_NO_FWIDE
Definition 21.cwchar.cpp:39
@ _RWSTD_NO_WMEMCHR_IN_LIBC
Definition 21.cwchar.cpp:79
@ _RWSTD_NO_WCSTOUL
Definition 21.cwchar.cpp:76
@ _RWSTD_NO_WCSRTOMBS
Definition 21.cwchar.cpp:70
@ _RWSTD_NO_WCSSTR
Definition 21.cwchar.cpp:72
@ _RWSTD_NO_SWPRINTF
Definition 21.cwchar.cpp:50
@ _RWSTD_NO_WCSCOLL
Definition 21.cwchar.cpp:60
@ _RWSTD_NO_WCSNCAT_IN_LIBC
Definition 21.cwchar.cpp:65
@ _RWSTD_NO_PUTWCHAR_IN_LIBC
Definition 21.cwchar.cpp:49
@ _RWSTD_NO_WCSCMP
Definition 21.cwchar.cpp:59
@ _RWSTD_NO_PUTWCHAR
Definition 21.cwchar.cpp:49
@ _RWSTD_NO_WMEMCMP
Definition 21.cwchar.cpp:80
@ _RWSTD_NO_WCSRTOMBS_IN_LIBC
Definition 21.cwchar.cpp:70
@ _RWSTD_NO_WCSPBRK
Definition 21.cwchar.cpp:68
@ _RWSTD_NO_UNGETWC_IN_LIBC
Definition 21.cwchar.cpp:52
@ _RWSTD_NO_WCSXFRM_IN_LIBC
Definition 21.cwchar.cpp:77
@ _RWSTD_NO_WCSNCPY_IN_LIBC
Definition 21.cwchar.cpp:67
@ _RWSTD_NO_FPUTWC
Definition 21.cwchar.cpp:37
@ _RWSTD_NO_WCSCHR
Definition 21.cwchar.cpp:58
@ _RWSTD_NO_WMEMMOVE_IN_LIBC
Definition 21.cwchar.cpp:82
@ _RWSTD_NO_WCSCHR_IN_LIBC
Definition 21.cwchar.cpp:58
@ _RWSTD_NO_FWSCANF
Definition 21.cwchar.cpp:41
@ _RWSTD_NO_WCRTOMB_IN_LIBC
Definition 21.cwchar.cpp:56
@ _RWSTD_NO_WCSCOLL_IN_LIBC
Definition 21.cwchar.cpp:60
@ _RWSTD_NO_WMEMCMP_IN_LIBC
Definition 21.cwchar.cpp:80
@ _RWSTD_NO_WCSCMP_IN_LIBC
Definition 21.cwchar.cpp:59
@ _RWSTD_NO_FGETWC_IN_LIBC
Definition 21.cwchar.cpp:35
@ _RWSTD_NO_WCTOB_IN_LIBC
Definition 21.cwchar.cpp:78
@ _RWSTD_NO_UNGETWC
Definition 21.cwchar.cpp:52
@ _RWSTD_NO_WCSCPY
Definition 21.cwchar.cpp:61
@ _RWSTD_NO_WCSCAT
Definition 21.cwchar.cpp:57
@ _RWSTD_NO_WPRINTF
Definition 21.cwchar.cpp:84
@ _RWSTD_NO_MBRTOWC
Definition 21.cwchar.cpp:45
@ _RWSTD_NO_WSCANF
Definition 21.cwchar.cpp:85
@ _RWSTD_NO_WCSTOD_IN_LIBC
Definition 21.cwchar.cpp:73
@ _RWSTD_NO_MBSRTOWCS_IN_LIBC
Definition 21.cwchar.cpp:47
@ _RWSTD_NO_FWPRINTF_IN_LIBC
Definition 21.cwchar.cpp:40
@ _RWSTD_NO_WMEMSET_IN_LIBC
Definition 21.cwchar.cpp:83
@ _RWSTD_NO_WCSNCPY
Definition 21.cwchar.cpp:67
@ _RWSTD_NO_WSCANF_IN_LIBC
Definition 21.cwchar.cpp:85
@ _RWSTD_NO_WCSNCAT
Definition 21.cwchar.cpp:65
@ _RWSTD_NO_BTOWC
Definition 21.cwchar.cpp:34
@ _RWSTD_NO_WCTOB
Definition 21.cwchar.cpp:78
@ _RWSTD_NO_WCSNCMP
Definition 21.cwchar.cpp:66
@ _RWSTD_NO_VFWPRINTF
Definition 21.cwchar.cpp:53
@ _RWSTD_NO_MBSINIT
Definition 21.cwchar.cpp:46
@ _RWSTD_NO_FWSCANF_IN_LIBC
Definition 21.cwchar.cpp:41
const char *const masking_macros[]
const char std_name[]
void test_functions()
void test_types(Vector *, T *, Allocator)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define main
#define _RWSTD_LONG_LONG
#define va_start(va, name)
#define FILE
#define _RWSTD_UNUSED(arg)
Definition _defs.h:972
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
A TOML array.
Definition array.hpp:258
const char * str
Definition exec.cpp:170
Definition json.h:5363
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
Definition driver.cpp:1664
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
Definition driver.cpp:1647
#define DEV_NULL
Definition rw_file.h:40