x86: Add SSE2 optimized chacha20
[glibc.git] / libio / tst_swprintf.c
blob8a2ffe60ecf208b41d1b6ad4cf7c0593b976a8bc
1 #include <array_length.h>
2 #include <stdio.h>
3 #include <support/check.h>
4 #include <sys/types.h>
5 #include <wchar.h>
8 static wchar_t buf[100];
9 static const struct
11 size_t n;
12 const char *str;
13 ssize_t exp;
14 } tests[] =
16 { array_length (buf), "hello world", 11 },
17 { 0, "hello world", -1 },
18 { 1, "hello world", -1 },
19 { 2, "hello world", -1 },
20 { 11, "hello world", -1 },
21 { 12, "hello world", 11 },
22 { 0, "", -1 },
23 { array_length (buf), "", 0 }
26 static int
27 do_test (void)
29 size_t n;
31 TEST_COMPARE (swprintf (buf, array_length (buf), L"Hello %s", "world"), 11);
32 TEST_COMPARE_STRING_WIDE (buf, L"Hello world");
34 TEST_COMPARE (swprintf (buf, array_length (buf), L"Is this >%g< 3.1?", 3.1),
35 18);
36 TEST_COMPARE_STRING_WIDE (buf, L"Is this >3.1< 3.1?");
38 for (n = 0; n < array_length (tests); ++n)
40 ssize_t res = swprintf (buf, tests[n].n, L"%s", tests[n].str);
42 if (tests[n].exp < 0 && res >= 0)
44 support_record_failure ();
45 printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to fail\n",
46 tests[n].n, tests[n].str);
48 else if (tests[n].exp >= 0 && tests[n].exp != res)
50 support_record_failure ();
51 printf ("\
52 swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to return %Zd, but got %Zd\n",
53 tests[n].n, tests[n].str, tests[n].exp, res);
55 else
56 printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") OK\n",
57 tests[n].n, tests[n].str);
60 TEST_COMPARE (swprintf (buf, array_length (buf), L"%.0s", "foo"), 0);
61 TEST_COMPARE_STRING_WIDE (buf, L"");
63 TEST_COMPARE (swprintf (buf, array_length (buf), L"%.0ls", L"foo"), 0);
64 TEST_COMPARE_STRING_WIDE (buf, L"");
66 return 0;
69 #include <support/test-driver.c>