aboutsummaryrefslogtreecommitdiff
path: root/REORG.TODO/time/tst-ftime_l.c
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
committerZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
commit5046dbb4a7eba5eccfd258f92f4735c9ffc8d069 (patch)
tree4470480d904b65cf14ca524f96f79eca818c3eaf /REORG.TODO/time/tst-ftime_l.c
parent199fc19d3aaaf57944ef036e15904febe877fc93 (diff)
downloadglibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.gz
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.bz2
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.zip
Prepare for radical source tree reorganization.zack/build-layout-experiment
All top-level files and directories are moved into a temporary storage directory, REORG.TODO, except for files that will certainly still exist in their current form at top level when we're done (COPYING, COPYING.LIB, LICENSES, NEWS, README), all old ChangeLog files (which are moved to the new directory OldChangeLogs, instead), and the generated file INSTALL (which is just deleted; in the new order, there will be no generated files checked into version control).
Diffstat (limited to 'REORG.TODO/time/tst-ftime_l.c')
-rw-r--r--REORG.TODO/time/tst-ftime_l.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/REORG.TODO/time/tst-ftime_l.c b/REORG.TODO/time/tst-ftime_l.c
new file mode 100644
index 0000000000..6690efeb9c
--- /dev/null
+++ b/REORG.TODO/time/tst-ftime_l.c
@@ -0,0 +1,129 @@
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <wchar.h>
+
+
+static int
+do_test (void)
+{
+ locale_t l;
+ locale_t old;
+ struct tm tm;
+ char buf[1000];
+ wchar_t wbuf[1000];
+ int result = 0;
+ size_t n;
+
+ l = newlocale (LC_ALL_MASK, "de_DE.ISO-8859-1", NULL);
+ if (l == NULL)
+ {
+ puts ("newlocale failed");
+ exit (1);
+ }
+
+ memset (&tm, '\0', sizeof (tm));
+
+ tm.tm_year = 102;
+ tm.tm_mon = 2;
+ tm.tm_mday = 1;
+
+ if (strftime (buf, sizeof (buf), "%e %^B %Y", &tm) == 0)
+ {
+ puts ("initial strftime failed");
+ exit (1);
+ }
+ if (strcmp (buf, " 1 MARCH 2002") != 0)
+ {
+ printf ("initial strftime: expected \"%s\", got \"%s\"\n",
+ " 1 MARCH 2002", buf);
+ result = 1;
+ }
+ else
+ printf ("got \"%s\"\n", buf);
+
+ /* Now using the extended locale model. */
+ if (strftime_l (buf, sizeof (buf), "%e %^B %Y", &tm, l) == 0)
+ {
+ puts ("strftime_l failed");
+ result = 1;
+ }
+ else if (strcmp (buf, " 1 M\xc4RZ 2002") != 0)
+ {
+ printf ("strftime_l: expected \"%s\", got \"%s\"\n",
+ " 1 M\xc4RZ 2002", buf);
+ result = 1;
+ }
+ else
+ {
+ setlocale (LC_ALL, "de_DE.ISO-8859-1");
+ printf ("got \"%s\"\n", buf);
+ setlocale (LC_ALL, "C");
+ }
+
+ /* And the wide character version. */
+ if (wcsftime_l (wbuf, sizeof (wbuf) / sizeof (wbuf[0]), L"%e %^B %Y", &tm, l)
+ == 0)
+ {
+ puts ("wcsftime_l failed");
+ result = 1;
+ }
+ else if (wcscmp (wbuf, L" 1 M\x00c4RZ 2002") != 0)
+ {
+ printf ("wcsftime_l: expected \"%ls\", got \"%ls\"\n",
+ L" 1 M\x00c4RZ 2002", wbuf);
+ result = 1;
+ }
+ else
+ {
+ setlocale (LC_ALL, "de_DE.ISO-8859-1");
+ printf ("got \"%ls\"\n", wbuf);
+ setlocale (LC_ALL, "C");
+ }
+
+ old = uselocale (l);
+
+ n = strftime (buf, sizeof (buf), "%e %^B %Y", &tm);
+
+ /* Switch back. */
+ (void) uselocale (old);
+
+ if (n == 0)
+ {
+ puts ("strftime after first uselocale failed");
+ result = 1;
+ }
+ else if (strcmp (buf, " 1 M\xc4RZ 2002") != 0)
+ {
+ printf ("strftime in non-C locale: expected \"%s\", got \"%s\"\n",
+ " 1 M\xc4RZ 2002", buf);
+ result = 1;
+ }
+ else
+ {
+ setlocale (LC_ALL, "de_DE.ISO-8859-1");
+ printf ("got \"%s\"\n", buf);
+ setlocale (LC_ALL, "C");
+ }
+
+ if (strftime (buf, sizeof (buf), "%e %^B %Y", &tm) == 0)
+ {
+ puts ("strftime after second uselocale failed");
+ result = 1;
+ }
+ else if (strcmp (buf, " 1 MARCH 2002") != 0)
+ {
+ printf ("initial strftime: expected \"%s\", got \"%s\"\n",
+ " 1 MARCH 2002", buf);
+ result = 1;
+ }
+ else
+ printf ("got \"%s\"\n", buf);
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"