1 /* Test mntent interface with escaped sequences.
2 Copyright (C) 2020-2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
23 #include <support/check.h>
27 const char *mnt_fsname
;
36 struct const_mntent tests
[] =
38 {"/dev/hda1", "/some dir", "ext2", "defaults", 1, 2,
39 "/dev/hda1 /some\\040dir ext2 defaults 1 2\n"},
40 {"device name", "/some dir", "tmpfs", "defaults", 1, 2,
41 "device\\040name /some\\040dir tmpfs defaults 1 2\n"},
42 {" ", "/some dir", "tmpfs", "defaults", 1, 2,
43 "\\040 /some\\040dir tmpfs defaults 1 2\n"},
44 {"\t", "/some dir", "tmpfs", "defaults", 1, 2,
45 "\\011 /some\\040dir tmpfs defaults 1 2\n"},
46 {"\\", "/some dir", "tmpfs", "defaults", 1, 2,
47 "\\134 /some\\040dir tmpfs defaults 1 2\n"},
53 for (int i
= 0; i
< sizeof (tests
) / sizeof (struct const_mntent
); i
++)
56 struct mntent
*ret
, curtest
;
57 FILE *fp
= fmemopen (buf
, sizeof (buf
), "w+");
61 printf ("Failed to open file\n");
65 curtest
.mnt_fsname
= strdupa (tests
[i
].mnt_fsname
);
66 curtest
.mnt_dir
= strdupa (tests
[i
].mnt_dir
);
67 curtest
.mnt_type
= strdupa (tests
[i
].mnt_type
);
68 curtest
.mnt_opts
= strdupa (tests
[i
].mnt_opts
);
69 curtest
.mnt_freq
= tests
[i
].mnt_freq
;
70 curtest
.mnt_passno
= tests
[i
].mnt_passno
;
72 if (addmntent (fp
, &curtest
) != 0)
74 support_record_failure ();
78 TEST_COMPARE_STRING (buf
, tests
[i
].expected
);
84 support_record_failure ();
88 TEST_COMPARE_STRING(tests
[i
].mnt_fsname
, ret
->mnt_fsname
);
89 TEST_COMPARE_STRING(tests
[i
].mnt_dir
, ret
->mnt_dir
);
90 TEST_COMPARE_STRING(tests
[i
].mnt_type
, ret
->mnt_type
);
91 TEST_COMPARE_STRING(tests
[i
].mnt_opts
, ret
->mnt_opts
);
92 TEST_COMPARE(tests
[i
].mnt_freq
, ret
->mnt_freq
);
93 TEST_COMPARE(tests
[i
].mnt_passno
, ret
->mnt_passno
);
101 #include <support/test-driver.c>