freelocale: Add tests.
authorBruno Haible <bruno@clisp.org>
Fri, 14 Feb 2025 02:06:56 +0000 (03:06 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 14 Feb 2025 02:08:28 +0000 (03:08 +0100)
* tests/test-freelocale.c: New file.
* modules/freelocale-tests: New file.

ChangeLog
modules/freelocale-tests [new file with mode: 0644]
tests/test-freelocale.c [new file with mode: 0644]

index a0e305906681f01a23d5a1e74ce994a2b7ca7132..79089e44709b423e754da3b7a3296c422c6cff70 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2025-02-14  Bruno Haible  <bruno@clisp.org>
 
+       freelocale: Add tests.
+       * tests/test-freelocale.c: New file.
+       * modules/freelocale-tests: New file.
+
        freelocale: New module.
        * lib/locale.in.h (freelocale): Consider GNULIB_FREELOCALE. Declare if
        not declared.
diff --git a/modules/freelocale-tests b/modules/freelocale-tests
new file mode 100644 (file)
index 0000000..9c4c322
--- /dev/null
@@ -0,0 +1,13 @@
+Files:
+tests/test-freelocale.c
+tests/signature.h
+tests/macros.h
+
+Depends-on:
+newlocale
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-freelocale
+check_PROGRAMS += test-freelocale
diff --git a/tests/test-freelocale.c b/tests/test-freelocale.c
new file mode 100644 (file)
index 0000000..65c70b1
--- /dev/null
@@ -0,0 +1,101 @@
+/* Test of freeing a locale object.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2025.  */
+
+#include <config.h>
+
+#include <locale.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (freelocale, void, (locale_t));
+
+#include "macros.h"
+
+#if defined _WIN32 && !defined __CYGWIN__
+
+# define ENGLISH  "English_United States"
+# define FRENCH   "French_France"
+# define ENCODING ".1252"
+
+# define LOCALE1 ENGLISH ENCODING
+# define LOCALE2 FRENCH ENCODING
+
+#else
+
+# define LOCALE1 "en_US.UTF-8"
+# define LOCALE2 "fr_FR.UTF-8"
+
+#endif
+
+int
+main ()
+{
+  {
+    locale_t l1 = newlocale (LC_CTYPE_MASK, "C", NULL);
+    ASSERT (l1 != NULL);
+    freelocale (l1);
+  }
+  {
+    locale_t l1 = newlocale (LC_MESSAGES_MASK, "C", NULL);
+    ASSERT (l1 != NULL);
+    freelocale (l1);
+  }
+  {
+    locale_t l1 = newlocale (LC_ALL_MASK, "C", NULL);
+    ASSERT (l1 != NULL);
+    freelocale (l1);
+  }
+  {
+    locale_t l1 = newlocale (LC_CTYPE_MASK, LOCALE1, NULL);
+    if (l1 != NULL)
+      freelocale (l1);
+  }
+  {
+    locale_t l1 = newlocale (LC_MESSAGES_MASK, LOCALE1, NULL);
+    if (l1 != NULL)
+      freelocale (l1);
+  }
+  {
+    locale_t l1 = newlocale (LC_ALL_MASK, LOCALE1, NULL);
+    if (l1 != NULL)
+      freelocale (l1);
+  }
+  {
+    locale_t l1 = newlocale (LC_ALL_MASK, LOCALE1, NULL);
+    if (l1 != NULL)
+      {
+        locale_t l2 = newlocale (LC_TIME_MASK, LOCALE2, l1);
+        if (l2 != NULL)
+          freelocale (l2);
+        else
+          freelocale (l1);
+      }
+  }
+  {
+    locale_t l1 = newlocale (LC_MESSAGES_MASK, LOCALE1, NULL);
+    if (l1 != NULL)
+      {
+        locale_t l2 = newlocale (LC_TIME_MASK, LOCALE2, l1);
+        if (l2 != NULL)
+          freelocale (l2);
+        else
+          freelocale (l1);
+      }
+  }
+
+  return test_exit_status;
+}