annotate tests/test-binary-io.c @ 40057:b06060465f09

maint: Run 'make update-copyright'
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 01 Jan 2019 00:25:11 +0100
parents 10eb9086bea0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of binary mode I/O.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2005, 2007-2019 Free Software Foundation, Inc.
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8910
diff changeset
4 This program is free software: you can redistribute it and/or modify
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8910
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8910
diff changeset
7 (at your option) any later version.
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18700
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2005. */
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 8754
diff changeset
19 #include <config.h>
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "binary-io.h"
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <sys/types.h>
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <sys/stat.h>
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <fcntl.h>
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdio.h>
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <stdlib.h>
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <unistd.h>
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
30 #include "macros.h"
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 int
16851
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
33 main (int argc, char *argv[])
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 {
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 /* Test the O_BINARY macro. */
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 {
8910
a7e0b65d5c78 Attempt to fix a test failure on Solaris (open fails with EACCES).
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
37 int fd =
16851
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
38 open ("t-bin-out0.tmp", O_CREAT | O_TRUNC | O_RDWR | O_BINARY, 0600);
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 if (write (fd, "Hello\n", 6) < 0)
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 exit (1);
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 close (fd);
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 }
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 {
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 struct stat statbuf;
16851
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
45 if (stat ("t-bin-out0.tmp", &statbuf) < 0)
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 exit (1);
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 ASSERT (statbuf.st_size == 6);
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 }
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
16851
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
50 switch (argv[1][0])
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
51 {
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
52 case '1':
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
53 /* Test the set_binary_mode() function. */
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
54 set_binary_mode (1, O_BINARY);
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
55 fputs ("Hello\n", stdout);
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
56 break;
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
57
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
58 default:
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
59 break;
2ef869fa79b4 binary-io: Define set_binary_mode function.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
60 }
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 return 0;
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 }