mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2026-10-24 00:48:56 +03:00
* lib/argz.c (argz_next): Use strnul. * lib/cpu-supports.c (hwcap_allowed): Likewise. * lib/file-has-acl.c (aclinfo_has_xattr): Likewise. * lib/inet_ntop.c (inet_ntop6): Likewise. * lib/link.c (link): Likewise. * lib/localename-unsafe.c (enum_locales_fn): Likewise. * lib/mbspcasecmp.c (mbspcasecmp): Likewise. * lib/opendir.c (opendir): Likewise. * lib/parse-duration.c (parse_year_month_day, parse_hour_minute_second, trim): Likewise. * lib/setlocale.c (setlocale_unixlike): Likewise. * lib/strftime.c (__strftime_internal): Likewise. * lib/striconv.c (str_cd_iconv): Likewise. * lib/strncat.c (strncat): Likewise. * lib/term-style-control.c (log_signal_handler_called, tcsetattr_failed): Likewise. * lib/time_rz.c (save_abbr): Likewise. * lib/vc-mtime.c (git_mtime, max_vc_mtime): Likewise. * tests/test-savedir.c (test_savedir_sort_none, test_savedir_sort_name): Likewise. * modules/argz (Depends-on): Add strnul. * modules/cpu-supports (Depends-on): Likewise. * modules/file-has-acl (Depends-on): Likewise. * modules/inet_ntop (Depends-on): Likewise. * modules/link (Depends-on): Likewise. * modules/localename-unsafe (Depends-on): Likewise. * modules/localename-unsafe-limited (Depends-on): Likewise. * modules/mbspcasecmp (Depends-on): Likewise. * modules/opendir (Depends-on): Likewise. * modules/parse-duration (Depends-on): Likewise. * modules/setlocale (Depends-on): Likewise. * modules/nstrftime (Depends-on): Likewise. * modules/nstrftime-limited (Depends-on): Likewise. * modules/c-nstrftime (Depends-on): Likewise. * modules/fprintftime (Depends-on): Likewise. * modules/striconv (Depends-on): Likewise. * modules/strncat (Depends-on): Likewise. * modules/term-style-control (Depends-on): Likewise. * modules/time_rz (Depends-on): Likewise. * modules/vc-mtime (Depends-on): Likewise. * modules/savedir-tests (Depends-on): Likewise. Copyright-paperwork-exempt: Yes
112 lines
2.8 KiB
C
112 lines
2.8 KiB
C
/* Test the savedir module.
|
|
Copyright (C) 2025-2026 Free Software Foundation, Inc.
|
|
|
|
This file 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 file 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 Collin Funk <collin.funk1@gmail.com>, 2025. */
|
|
|
|
#include <config.h>
|
|
|
|
/* Specification. */
|
|
#include "savedir.h"
|
|
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
|
|
#include "ignore-value.h"
|
|
#include "macros.h"
|
|
|
|
/* Base directory. */
|
|
#define BASE "test-savedir.t"
|
|
|
|
static void
|
|
test_savedir_sort_none (void)
|
|
{
|
|
bool seen[('z' - 'a') + 1];
|
|
char *name_space = savedir (BASE, SAVEDIR_SORT_NONE);
|
|
ASSERT (name_space != NULL);
|
|
|
|
/* Set the table of file names we have seen to false. */
|
|
memset (seen, 0, sizeof seen);
|
|
|
|
/* Scan through the file names. */
|
|
for (char *namep = name_space; *namep != '\0'; namep = strnul (namep) + 1)
|
|
{
|
|
int index = *namep - 'a';
|
|
ASSERT (strlen (namep) == 1);
|
|
ASSERT (index < sizeof seen);
|
|
seen[index] = true;
|
|
}
|
|
|
|
/* Make sure all of them have been seen. */
|
|
for (int i = 0; i < sizeof seen; ++i)
|
|
ASSERT (seen[i]);
|
|
|
|
free (name_space);
|
|
}
|
|
|
|
static void
|
|
test_savedir_sort_name (void)
|
|
{
|
|
int i = 0;
|
|
char *name_space = savedir (BASE, SAVEDIR_SORT_NAME);
|
|
ASSERT (name_space != NULL);
|
|
|
|
/* Check that files "a" to "z" appear in order. */
|
|
for (char *namep = name_space; *namep != '\0';
|
|
namep = strnul (namep) + 1, i += 1)
|
|
{
|
|
ASSERT (strlen (namep) == 1);
|
|
ASSERT (*namep - 'a' == i);
|
|
}
|
|
|
|
/* Make sure no extra files were seen. */
|
|
ASSERT (i == ('z' - 'a') + 1);
|
|
|
|
free (name_space);
|
|
}
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
char buffer[sizeof BASE + 2];
|
|
|
|
/* Clean up any trash from prior testsuite runs. */
|
|
ignore_value (system ("rm -rf " BASE "*"));
|
|
|
|
/* Setup a directory with files "a" to "z". */
|
|
strcpy (buffer, BASE);
|
|
ASSERT (mkdir (buffer, 0700) == 0);
|
|
buffer[sizeof buffer - 1] = '\0';
|
|
for (int i = 'a'; i <= 'z'; ++i)
|
|
{
|
|
buffer[sizeof buffer - 3] = '/';
|
|
buffer[sizeof buffer - 2] = i;
|
|
int fd = creat (buffer, 0600);
|
|
ASSERT (0 <= fd);
|
|
ASSERT (close (fd) == 0);
|
|
}
|
|
|
|
test_savedir_sort_none ();
|
|
test_savedir_sort_name ();
|
|
|
|
/* Cleanup files created during the test. */
|
|
ignore_value (system ("rm -rf " BASE "*"));
|
|
|
|
return test_exit_status;
|
|
}
|