~ubuntu-branches/ubuntu/natty/diffutils/natty

« back to all changes in this revision

Viewing changes to gnulib-tests/test-getopt.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2010-05-04 20:38:00 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100504203800-f67xd9rsa9xl9qqj
Tags: 1:3.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- buffer-read-only: t -*- vi: set ro: */
 
2
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
 
3
/* Test of command line argument processing.
 
4
   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
5
 
 
6
   This program is free software: you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 3 of the License, or
 
9
   (at your option) any later version.
 
10
 
 
11
   This program 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
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
18
 
 
19
/* Written by Bruno Haible <bruno@clisp.org>, 2009.  */
 
20
 
 
21
#include <config.h>
 
22
 
 
23
/* None of the files accessed by this test are large, so disable the
 
24
   ftell link warning if we are not using the gnulib ftell module.  */
 
25
#define _GL_NO_LARGE_FILES
 
26
 
 
27
#if GNULIB_TEST_GETOPT_GNU
 
28
# include <getopt.h>
 
29
 
 
30
# ifndef __getopt_argv_const
 
31
#  define __getopt_argv_const const
 
32
# endif
 
33
# include "signature.h"
 
34
SIGNATURE_CHECK (getopt_long, int, (int, char *__getopt_argv_const *,
 
35
                                    char const *, struct option const *,
 
36
                                    int *));
 
37
SIGNATURE_CHECK (getopt_long_only, int, (int, char *__getopt_argv_const *,
 
38
                                         char const *, struct option const *,
 
39
                                         int *));
 
40
 
 
41
#endif
 
42
 
 
43
#include <unistd.h>
 
44
 
 
45
#include "signature.h"
 
46
SIGNATURE_CHECK (getopt, int, (int, char * const[], char const *));
 
47
 
 
48
#include <stdio.h>
 
49
#include <stdlib.h>
 
50
#include <string.h>
 
51
 
 
52
/* This test intentionally remaps stderr.  So, we arrange to have fd 10
 
53
   (outside the range of interesting fd's during the test) set up to
 
54
   duplicate the original stderr.  */
 
55
 
 
56
#define BACKUP_STDERR_FILENO 10
 
57
#define ASSERT_STREAM myerr
 
58
#include "macros.h"
 
59
 
 
60
static FILE *myerr;
 
61
 
 
62
#include "test-getopt.h"
 
63
#if GNULIB_TEST_GETOPT_GNU
 
64
# include "test-getopt_long.h"
 
65
#endif
 
66
 
 
67
int
 
68
main (void)
 
69
{
 
70
   /* This test validates that stderr is used correctly, so move the
 
71
      original into fd 10.  */
 
72
  if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
 
73
      || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
 
74
    return 2;
 
75
 
 
76
  ASSERT (freopen ("test-getopt.tmp", "w", stderr) == stderr);
 
77
 
 
78
  /* These default values are required by POSIX.  */
 
79
  ASSERT (optind == 1);
 
80
  ASSERT (opterr != 0);
 
81
 
 
82
  setenv ("POSIXLY_CORRECT", "1", 1);
 
83
  test_getopt ();
 
84
 
 
85
#if GNULIB_TEST_GETOPT_GNU
 
86
  test_getopt_long_posix ();
 
87
#endif
 
88
 
 
89
  unsetenv ("POSIXLY_CORRECT");
 
90
  test_getopt ();
 
91
 
 
92
#if GNULIB_TEST_GETOPT_GNU
 
93
  test_getopt_long ();
 
94
  test_getopt_long_only ();
 
95
#endif
 
96
 
 
97
  ASSERT (fclose (stderr) == 0);
 
98
  ASSERT (remove ("test-getopt.tmp") == 0);
 
99
 
 
100
  return 0;
 
101
}