Hash :
8ff0508a
Author :
Date :
2025-04-26T10:41:43
Silence gcc 15 -Wunterminated-string-initialization warnings. * tests/test-gc-arctwo.c (main): Mark arrays as _GL_ATTRIBUTE_NONSTRING. * tests/test-sf-istream.c (test_open_stream): Likewise. * tests/test-sfl-istream.c (test_open_stream): Likewise. * tests/unilbrk/test-u8-possible-linebreaks.c (test_function): Likewise. * tests/unilbrk/test-u8-width-linebreaks.c (test_function): Likewise. * tests/unilbrk/test-ulc-possible-linebreaks.c (test_function): Likewise. * tests/unilbrk/test-ulc-width-linebreaks.c (test_function): Likewise. * tests/uniwbrk/test-u8-wordbreaks.c (main): Likewise. * tests/uniwbrk/test-ulc-wordbreaks.c (main): Likewise.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
/* Test of string or file based input stream with line number.
Copyright (C) 2024-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 2, 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>, 2024. */
#include <config.h>
/* Specification. */
#include "sfl-istream.h"
#include <unistd.h>
#include "macros.h"
#define CONTENTS_LEN 9
#define CONTENTS "Hello\377\n\nW"
static void
test_open_stream (sfl_istream_t *stream)
{
int c;
ASSERT (sfl_get_line_number (stream) == 1);
c = sfl_getc (stream);
ASSERT (c == 'H');
ASSERT (sfl_get_line_number (stream) == 1);
c = sfl_getc (stream);
ASSERT (c == 'e');
ASSERT (sfl_get_line_number (stream) == 1);
c = sfl_getc (stream);
ASSERT (c == 'l');
ASSERT (sfl_get_line_number (stream) == 1);
c = sfl_getc (stream);
ASSERT (c == 'l');
ASSERT (sfl_get_line_number (stream) == 1);
c = sfl_getc (stream);
ASSERT (c == 'o');
ASSERT (sfl_get_line_number (stream) == 1);
sfl_ungetc (stream, c);
c = sfl_getc (stream);
ASSERT (c == 'o');
ASSERT (sfl_get_line_number (stream) == 1);
c = sfl_getc (stream);
ASSERT (c == 0xff);
ASSERT (sfl_get_line_number (stream) == 1);
sfl_ungetc (stream, c);
c = sfl_getc (stream);
ASSERT (c == 0xff);
ASSERT (sfl_get_line_number (stream) == 1);
c = sfl_getc (stream);
ASSERT (c == '\n');
ASSERT (sfl_get_line_number (stream) == 2);
c = sfl_getc (stream);
ASSERT (c == '\n');
ASSERT (sfl_get_line_number (stream) == 3);
sfl_ungetc (stream, c);
ASSERT (sfl_get_line_number (stream) == 2);
c = sfl_getc (stream);
ASSERT (c == '\n');
ASSERT (sfl_get_line_number (stream) == 3);
c = sfl_getc (stream);
ASSERT (c == 'W');
ASSERT (sfl_get_line_number (stream) == 3);
c = sfl_getc (stream);
ASSERT (c == EOF);
ASSERT (sfl_get_line_number (stream) == 3);
c = sfl_getc (stream);
ASSERT (c == EOF);
ASSERT (sfl_get_line_number (stream) == 3);
sfl_ungetc (stream, c);
c = sfl_getc (stream);
ASSERT (c == EOF);
ASSERT (sfl_get_line_number (stream) == 3);
ASSERT (!sfl_ferror (stream));
}
int
main ()
{
char const contents[CONTENTS_LEN] _GL_ATTRIBUTE_NONSTRING = CONTENTS;
/* Test reading from a file. */
{
const char *filename = "test-sfl-istream.tmp";
unlink (filename);
{
FILE *fp = fopen (filename, "wb");
ASSERT (fwrite (contents, 1, CONTENTS_LEN, fp) == CONTENTS_LEN);
ASSERT (fclose (fp) == 0);
}
{
FILE *fp = fopen (filename, "rb");
sfl_istream_t stream;
sfl_istream_init_from_file (&stream, fp);
test_open_stream (&stream);
sfl_free (&stream);
}
unlink (filename);
}
/* Test reading from a string in memory. */
{
sfl_istream_t stream;
sfl_istream_init_from_string_desc (&stream,
sd_new_addr (CONTENTS_LEN,
(char *) contents));
test_open_stream (&stream);
sfl_free (&stream);
}
/* Test reading from a NUL-terminated string in memory. */
{
sfl_istream_t stream;
sfl_istream_init_from_string (&stream, CONTENTS);
test_open_stream (&stream);
sfl_free (&stream);
}
return 0;
}