annotate tests/test-binary-io.c @ 13575:34fed8ca014c

autoupdate
author Karl Berry <karl@freefriends.org>
date Thu, 26 Aug 2010 06:33:40 -0700
parents c2cbabec01dd
children 97fc9a21a8fb
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.
12559
c2cbabec01dd update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents: 12496
diff changeset
2 Copyright (C) 2005, 2007-2010 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
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8910
diff changeset
15 along with this program. If not, see <http://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
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 main ()
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 =
a7e0b65d5c78 Attempt to fix a test failure on Solaris (open fails with EACCES).
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
38 open ("t-bin-out2.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;
8412
6db7303a6033 Choose better temporary filenames.
Bruno Haible <bruno@clisp.org>
parents: 7869
diff changeset
45 if (stat ("t-bin-out2.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 }
8412
6db7303a6033 Choose better temporary filenames.
Bruno Haible <bruno@clisp.org>
parents: 7869
diff changeset
49 unlink ("t-bin-out2.tmp");
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 /* Test the SET_BINARY macro. */
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 SET_BINARY (1);
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 fputs ("Hello\n", stdout);
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 fclose (stdout);
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 fclose (stderr);
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 {
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 struct stat statbuf;
8412
6db7303a6033 Choose better temporary filenames.
Bruno Haible <bruno@clisp.org>
parents: 7869
diff changeset
58 if (stat ("t-bin-out1.tmp", &statbuf) < 0)
7869
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 exit (1);
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 ASSERT (statbuf.st_size == 6);
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
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 return 0;
d612855198c2 Test for the binary-io module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 }