annotate tests/test-getdomainname.c @ 17530:8981b79e1271

error: make the module depend on vfprintf-posix * modules/error (Depends-on): Add vfprintf-posix, since error calls vfprintf unconditionally, via error_tail.
author Jim Meyering <meyering@fb.com>
date Sat, 12 Oct 2013 19:28:40 -0700
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13912
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /*
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 * Copyright (C) 2008-2013 Free Software Foundation, Inc.
13912
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 * Written by Simon Josefsson.
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 *
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 * the Free Software Foundation; either version 3 of the License, or
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 * (at your option) any later version.
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 *
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 * GNU General Public License for more details.
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 *
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Get getdomainname() declaration. */
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <unistd.h>
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include "signature.h"
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 SIGNATURE_CHECK (getdomainname, int, (char *, size_t));
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdio.h>
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <string.h>
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <errno.h>
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #define YPMAXDOMAIN 64
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #define NODOMAINNAME "magic-gnulib-test-string"
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 int
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 main (int argc, char *argv[] _GL_UNUSED)
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 {
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 char buf[YPMAXDOMAIN];
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 int rc;
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 if (strlen (NODOMAINNAME) >= YPMAXDOMAIN)
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 printf ("YPMAXDOMAIN impossibly small?! %d\n", YPMAXDOMAIN);
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 return 2;
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 }
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 strcpy (buf, NODOMAINNAME);
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 rc = getdomainname (buf, sizeof (buf));
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 if (rc != 0)
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 {
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 printf ("getdomainname failed, rc %d errno %d\n", rc, errno);
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 return 1;
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 }
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 if (strcmp (buf, NODOMAINNAME) == 0)
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 {
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 printf ("getdomainname left buffer untouched.\n");
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 return 1;
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 }
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 if (argc > 1)
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 printf ("domainname: %s\n", buf);
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 return 0;
99a2ba825c9a Tests for module 'getdomainname'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 }