VirtualBox

source: kBuild/vendor/grep/2.12/gnulib-tests/test-getopt.c@ 3576

Last change on this file since 3576 was 2595, checked in by bird, 13 years ago

gnu grep version 2.12 (grep-2.12.tar.xz, md5sum=8d2f0346d08b13c18afb81f0e8aa1e2f)

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette