1 #include <array_length.h>
3 #include <support/check.h>
8 static wchar_t buf
[100];
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 },
23 { array_length (buf
), "", 0 }
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),
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 ();
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
);
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
"");
69 #include <support/test-driver.c>