Blame gnulib-tests/test-getopt_long.h

Packit Service fdd496
/* Test of command line argument processing.
Packit Service fdd496
   Copyright (C) 2009-2017 Free Software Foundation, Inc.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
/* Written by Bruno Haible <bruno@clisp.org>, 2009.  */
Packit Service fdd496
Packit Service fdd496
static int a_seen;
Packit Service fdd496
static int b_seen;
Packit Service fdd496
static int q_seen;
Packit Service fdd496
Packit Service fdd496
static const struct option long_options_required[] =
Packit Service fdd496
  {
Packit Service fdd496
    { "alpha",    no_argument,       NULL, 'a' },
Packit Service fdd496
    { "beta",     no_argument,       &b_seen, 1 },
Packit Service fdd496
    { "prune",    required_argument, NULL, 'p' },
Packit Service fdd496
    { "quetsche", required_argument, &q_seen, 1 },
Packit Service fdd496
    { "xtremely-",no_argument,       NULL, 1003 },
Packit Service fdd496
    { "xtra",     no_argument,       NULL, 1001 },
Packit Service fdd496
    { "xtreme",   no_argument,       NULL, 1002 },
Packit Service fdd496
    { "xtremely", no_argument,       NULL, 1003 },
Packit Service fdd496
    { NULL,       0,                 NULL, 0 }
Packit Service fdd496
  };
Packit Service fdd496
Packit Service fdd496
static const struct option long_options_optional[] =
Packit Service fdd496
  {
Packit Service fdd496
    { "alpha",    no_argument,       NULL, 'a' },
Packit Service fdd496
    { "beta",     no_argument,       &b_seen, 1 },
Packit Service fdd496
    { "prune",    optional_argument, NULL, 'p' },
Packit Service fdd496
    { "quetsche", optional_argument, &q_seen, 1 },
Packit Service fdd496
    { NULL,       0,                 NULL, 0 }
Packit Service fdd496
  };
Packit Service fdd496
Packit Service fdd496
static void
Packit Service fdd496
getopt_long_loop (int argc, const char **argv,
Packit Service fdd496
                  const char *options, const struct option *long_options,
Packit Service fdd496
                  const char **p_value, const char **q_value,
Packit Service fdd496
                  int *non_options_count, const char **non_options,
Packit Service fdd496
                  int *unrecognized)
Packit Service fdd496
{
Packit Service fdd496
  int option_index = -1;
Packit Service fdd496
  int c;
Packit Service fdd496
Packit Service fdd496
  opterr = 0;
Packit Service fdd496
  q_seen = 0;
Packit Service fdd496
  while ((c = getopt_long (argc, (char **) argv, options, long_options,
Packit Service fdd496
                           &option_index))
Packit Service fdd496
         != -1)
Packit Service fdd496
    {
Packit Service fdd496
      switch (c)
Packit Service fdd496
        {
Packit Service fdd496
        case 0:
Packit Service fdd496
          /* An option with a non-NULL flag pointer was processed.  */
Packit Service fdd496
          if (q_seen)
Packit Service fdd496
            *q_value = optarg;
Packit Service fdd496
          break;
Packit Service fdd496
        case 'a':
Packit Service fdd496
          a_seen++;
Packit Service fdd496
          break;
Packit Service fdd496
        case 'b':
Packit Service fdd496
          b_seen = 1;
Packit Service fdd496
          break;
Packit Service fdd496
        case 'p':
Packit Service fdd496
          *p_value = optarg;
Packit Service fdd496
          break;
Packit Service fdd496
        case 'q':
Packit Service fdd496
          *q_value = optarg;
Packit Service fdd496
          break;
Packit Service fdd496
        case '\1':
Packit Service fdd496
          /* Must only happen with option '-' at the beginning.  */
Packit Service fdd496
          ASSERT (options[0] == '-');
Packit Service fdd496
          non_options[(*non_options_count)++] = optarg;
Packit Service fdd496
          break;
Packit Service fdd496
        case ':':
Packit Service fdd496
          /* Must only happen with option ':' at the beginning.  */
Packit Service fdd496
          ASSERT (options[0] == ':'
Packit Service fdd496
                  || ((options[0] == '-' || options[0] == '+')
Packit Service fdd496
                      && options[1] == ':'));
Packit Service fdd496
          FALLTHROUGH;
Packit Service fdd496
        case '?':
Packit Service fdd496
          *unrecognized = optopt;
Packit Service fdd496
          break;
Packit Service fdd496
        default:
Packit Service fdd496
          *unrecognized = c;
Packit Service fdd496
          break;
Packit Service fdd496
        }
Packit Service fdd496
    }
Packit Service fdd496
}
Packit Service fdd496
Packit Service fdd496
/* Reduce casting, so we can use string literals elsewhere.
Packit Service fdd496
   getopt_long takes an array of char*, but luckily does not modify
Packit Service fdd496
   those elements, so we can pass const char*.  */
Packit Service fdd496
static int
Packit Service fdd496
do_getopt_long (int argc, const char **argv, const char *shortopts,
Packit Service fdd496
                const struct option *longopts, int *longind)
Packit Service fdd496
{
Packit Service fdd496
  return getopt_long (argc, (char **) argv, shortopts, longopts, longind);
Packit Service fdd496
}
Packit Service fdd496
Packit Service fdd496
static void
Packit Service fdd496
test_getopt_long (void)
Packit Service fdd496
{
Packit Service fdd496
  int start;
Packit Service fdd496
Packit Service fdd496
  /* Test disambiguation of options.  */
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--x";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
Packit Service fdd496
    ASSERT (c == '?');
Packit Service fdd496
    ASSERT (optopt == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--xt";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
Packit Service fdd496
    ASSERT (c == '?');
Packit Service fdd496
    ASSERT (optopt == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--xtr";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
Packit Service fdd496
    ASSERT (c == '?');
Packit Service fdd496
    ASSERT (optopt == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--xtra";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
Packit Service fdd496
    ASSERT (c == 1001);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--xtre";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
Packit Service fdd496
    ASSERT (c == '?');
Packit Service fdd496
    ASSERT (optopt == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--xtrem";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
Packit Service fdd496
    ASSERT (c == '?');
Packit Service fdd496
    ASSERT (optopt == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--xtreme";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
Packit Service fdd496
    ASSERT (c == 1002);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--xtremel";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
Packit Service fdd496
    ASSERT (c == 1003);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--xtremely";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "ab", long_options_required, &option_index);
Packit Service fdd496
    ASSERT (c == 1003);
Packit Service fdd496
  }
Packit Service fdd496
Packit Service fdd496
  /* Check that -W handles unknown options.  */
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-W";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "W;", long_options_required, &option_index);
Packit Service fdd496
    ASSERT (c == '?');
Packit Service fdd496
    ASSERT (optopt == 'W');
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-Wunknown";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "W;", long_options_required, &option_index);
Packit Service fdd496
    /* glibc and BSD behave differently here, but for now, we allow
Packit Service fdd496
       both behaviors since W support is not frequently used.  */
Packit Service fdd496
    if (c == '?')
Packit Service fdd496
      {
Packit Service fdd496
        ASSERT (optopt == 0);
Packit Service fdd496
        ASSERT (optarg == NULL);
Packit Service fdd496
      }
Packit Service fdd496
    else
Packit Service fdd496
      {
Packit Service fdd496
        ASSERT (c == 'W');
Packit Service fdd496
        ASSERT (strcmp (optarg, "unknown") == 0);
Packit Service fdd496
      }
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-W";
Packit Service fdd496
    argv[argc++] = "unknown";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "W;", long_options_required, &option_index);
Packit Service fdd496
    /* glibc and BSD behave differently here, but for now, we allow
Packit Service fdd496
       both behaviors since W support is not frequently used.  */
Packit Service fdd496
    if (c == '?')
Packit Service fdd496
      {
Packit Service fdd496
        ASSERT (optopt == 0);
Packit Service fdd496
        ASSERT (optarg == NULL);
Packit Service fdd496
      }
Packit Service fdd496
    else
Packit Service fdd496
      {
Packit Service fdd496
        ASSERT (c == 'W');
Packit Service fdd496
        ASSERT (strcmp (optarg, "unknown") == 0);
Packit Service fdd496
      }
Packit Service fdd496
  }
Packit Service fdd496
Packit Service fdd496
  /* Test that 'W' does not dump core:
Packit Service fdd496
     http://sourceware.org/bugzilla/show_bug.cgi?id=12922  */
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-W";
Packit Service fdd496
    argv[argc++] = "dummy";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long (argc, argv, "W;", NULL, &option_index);
Packit Service fdd496
    ASSERT (c == 'W');
Packit Service fdd496
    ASSERT (optind == 2);
Packit Service fdd496
  }
Packit Service fdd496
Packit Service fdd496
  /* Test processing of boolean short options.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "ab", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-b";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "ab", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ba";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "ab", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ab";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "ab", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 2);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Test processing of boolean long options.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "--alpha";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "ab", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "--beta";
Packit Service fdd496
      argv[argc++] = "--alpha";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "ab", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "--alpha";
Packit Service fdd496
      argv[argc++] = "--beta";
Packit Service fdd496
      argv[argc++] = "--alpha";
Packit Service fdd496
      argv[argc++] = "--beta";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "ab", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 2);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Test processing of boolean long options via -W.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-Walpha";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abW;", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-W";
Packit Service fdd496
      argv[argc++] = "beta";
Packit Service fdd496
      argv[argc++] = "-W";
Packit Service fdd496
      argv[argc++] = "alpha";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "aW;b", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-Walpha";
Packit Service fdd496
      argv[argc++] = "-Wbeta";
Packit Service fdd496
      argv[argc++] = "-Walpha";
Packit Service fdd496
      argv[argc++] = "-Wbeta";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "W;ab", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 2);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Test processing of short options with arguments.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-pfoo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ab";
Packit Service fdd496
      argv[argc++] = "-q";
Packit Service fdd496
      argv[argc++] = "baz";
Packit Service fdd496
      argv[argc++] = "-pfoo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value != NULL && strcmp (q_value, "baz") == 0);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Test processing of long options with arguments.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "--p=foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "--p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ab";
Packit Service fdd496
      argv[argc++] = "--q";
Packit Service fdd496
      argv[argc++] = "baz";
Packit Service fdd496
      argv[argc++] = "--p=foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value != NULL && strcmp (q_value, "baz") == 0);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Test processing of long options with arguments via -W.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-Wp=foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p:q:W;", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-W";
Packit Service fdd496
      argv[argc++] = "p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p:W;q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 4);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-ab";
Packit Service fdd496
      argv[argc++] = "-Wq";
Packit Service fdd496
      argv[argc++] = "baz";
Packit Service fdd496
      argv[argc++] = "-W";
Packit Service fdd496
      argv[argc++] = "p=foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "W;abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value != NULL && strcmp (q_value, "baz") == 0);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 6);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Test processing of short options with optional arguments.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-pfoo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p::q::", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p::q::", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp::q::", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Test processing of long options with optional arguments.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "--p=foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p::q::", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "--p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p::q::", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "--p=";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p::q::", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && *p_value == '\0');
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "--p";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp::q::", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Test processing of long options with optional arguments via -W.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-Wp=foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p::q::W;", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-Wp";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p::q::W;", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-Wp=";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "W;p::q::", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && *p_value == '\0');
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-W";
Packit Service fdd496
      argv[argc++] = "p=";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "W;p::q::", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && *p_value == '\0');
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 3);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-W";
Packit Service fdd496
      argv[argc++] = "p";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "W;abp::q::", long_options_optional,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      /* ASSERT (p_value == NULL); */
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 4);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that invalid options are recognized.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-x";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 'x');
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-:";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == ':');
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that unexpected arguments are recognized.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "--a=";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 'a');
Packit Service fdd496
      ASSERT (optind == 4);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "--b=";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      /* When flag is non-zero, glibc sets optopt anyway, but BSD
Packit Service fdd496
         leaves optopt unchanged.  */
Packit Service fdd496
      ASSERT (unrecognized == 1 || unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 4);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that by default, non-options arguments are moved to the end.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[7] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 4);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that '--' ends the argument processing.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[20];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "--";
Packit Service fdd496
      argv[argc++] = "-b";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-q";
Packit Service fdd496
      argv[argc++] = "johnny";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "--") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[7], "-b") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[8], "foo") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[9], "-q") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[10], "johnny") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[11], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[12] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 5);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that the '-' flag causes non-options to be returned in order.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "-abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[7] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 3);
Packit Service fdd496
      ASSERT (strcmp (non_options[0], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (non_options[1], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (non_options[2], "bar") == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 7);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that '--' ends the argument processing.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[20];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "--";
Packit Service fdd496
      argv[argc++] = "-b";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-q";
Packit Service fdd496
      argv[argc++] = "johnny";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "-abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "--") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[7], "-b") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[8], "foo") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[9], "-q") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[10], "johnny") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[11], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[12] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      if (non_options_count == 2)
Packit Service fdd496
      {
Packit Service fdd496
        /* glibc behaviour.  */
Packit Service fdd496
        ASSERT (non_options_count == 2);
Packit Service fdd496
        ASSERT (strcmp (non_options[0], "donald") == 0);
Packit Service fdd496
        ASSERT (strcmp (non_options[1], "duck") == 0);
Packit Service fdd496
        ASSERT (unrecognized == 0);
Packit Service fdd496
        ASSERT (optind == 7);
Packit Service fdd496
      }
Packit Service fdd496
      else
Packit Service fdd496
      {
Packit Service fdd496
        /* Another valid behaviour.  */
Packit Service fdd496
        ASSERT (non_options_count == 7);
Packit Service fdd496
        ASSERT (strcmp (non_options[0], "donald") == 0);
Packit Service fdd496
        ASSERT (strcmp (non_options[1], "duck") == 0);
Packit Service fdd496
        ASSERT (strcmp (non_options[2], "-b") == 0);
Packit Service fdd496
        ASSERT (strcmp (non_options[3], "foo") == 0);
Packit Service fdd496
        ASSERT (strcmp (non_options[4], "-q") == 0);
Packit Service fdd496
        ASSERT (strcmp (non_options[5], "johnny") == 0);
Packit Service fdd496
        ASSERT (strcmp (non_options[6], "bar") == 0);
Packit Service fdd496
        ASSERT (unrecognized == 0);
Packit Service fdd496
        ASSERT (optind == 12);
Packit Service fdd496
      }
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that the '-' flag has to come first.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:-", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[7] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 4);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that the '+' flag causes the first non-option to terminate the
Packit Service fdd496
     loop.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "+abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[7] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 1);
Packit Service fdd496
    }
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-+";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "+abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == '+');
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that '--' ends the argument processing.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[20];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "--";
Packit Service fdd496
      argv[argc++] = "-b";
Packit Service fdd496
      argv[argc++] = "foo";
Packit Service fdd496
      argv[argc++] = "-q";
Packit Service fdd496
      argv[argc++] = "johnny";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "+abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "--") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[7], "-b") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[8], "foo") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[9], "-q") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[10], "johnny") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[11], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[12] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 1);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that the '+' flag has to come first.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:+", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[7] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value != NULL && strcmp (p_value, "billy") == 0);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 4);
Packit Service fdd496
    }
Packit Service fdd496
}
Packit Service fdd496
Packit Service fdd496
/* Test behavior of getopt_long when POSIXLY_CORRECT is set in the
Packit Service fdd496
   environment.  Options with optional arguments should not change
Packit Service fdd496
   behavior just because of an environment variable.
Packit Service fdd496
   http://lists.gnu.org/archive/html/bug-m4/2006-09/msg00028.html  */
Packit Service fdd496
static void
Packit Service fdd496
test_getopt_long_posix (void)
Packit Service fdd496
{
Packit Service fdd496
  int start;
Packit Service fdd496
Packit Service fdd496
  /* Check that POSIXLY_CORRECT stops parsing the same as leading '+'.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "donald";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "duck";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "bar";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "abp:q:", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (strcmp (argv[0], "program") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[1], "donald") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[2], "-p") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[3], "billy") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[4], "duck") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[5], "-a") == 0);
Packit Service fdd496
      ASSERT (strcmp (argv[6], "bar") == 0);
Packit Service fdd496
      ASSERT (argv[7] == NULL);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 1);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that POSIXLY_CORRECT doesn't change optional arguments.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-p";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "p::", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 0);
Packit Service fdd496
      ASSERT (b_seen == 0);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 2);
Packit Service fdd496
    }
Packit Service fdd496
Packit Service fdd496
  /* Check that leading - still sees options after non-options.  */
Packit Service fdd496
  for (start = 0; start <= 1; start++)
Packit Service fdd496
    {
Packit Service fdd496
      const char *p_value = NULL;
Packit Service fdd496
      const char *q_value = NULL;
Packit Service fdd496
      int non_options_count = 0;
Packit Service fdd496
      const char *non_options[10];
Packit Service fdd496
      int unrecognized = 0;
Packit Service fdd496
      int argc = 0;
Packit Service fdd496
      const char *argv[10];
Packit Service fdd496
      a_seen = 0;
Packit Service fdd496
      b_seen = 0;
Packit Service fdd496
Packit Service fdd496
      argv[argc++] = "program";
Packit Service fdd496
      argv[argc++] = "-a";
Packit Service fdd496
      argv[argc++] = "billy";
Packit Service fdd496
      argv[argc++] = "-b";
Packit Service fdd496
      argv[argc] = NULL;
Packit Service fdd496
      optind = start;
Packit Service fdd496
      getopt_long_loop (argc, argv, "-ab", long_options_required,
Packit Service fdd496
                        &p_value, &q_value,
Packit Service fdd496
                        &non_options_count, non_options, &unrecognized);
Packit Service fdd496
      ASSERT (a_seen == 1);
Packit Service fdd496
      ASSERT (b_seen == 1);
Packit Service fdd496
      ASSERT (p_value == NULL);
Packit Service fdd496
      ASSERT (q_value == NULL);
Packit Service fdd496
      ASSERT (non_options_count == 1);
Packit Service fdd496
      ASSERT (strcmp (non_options[0], "billy") == 0);
Packit Service fdd496
      ASSERT (unrecognized == 0);
Packit Service fdd496
      ASSERT (optind == 4);
Packit Service fdd496
    }
Packit Service fdd496
}
Packit Service fdd496
Packit Service fdd496
/* Reduce casting, so we can use string literals elsewhere.
Packit Service fdd496
   getopt_long_only takes an array of char*, but luckily does not
Packit Service fdd496
   modify those elements, so we can pass const char*.  */
Packit Service fdd496
static int
Packit Service fdd496
do_getopt_long_only (int argc, const char **argv, const char *shortopts,
Packit Service fdd496
                     const struct option *longopts, int *longind)
Packit Service fdd496
{
Packit Service fdd496
  return getopt_long_only (argc, (char **) argv, shortopts, longopts, longind);
Packit Service fdd496
}
Packit Service fdd496
Packit Service fdd496
static void
Packit Service fdd496
test_getopt_long_only (void)
Packit Service fdd496
{
Packit Service fdd496
  /* Test disambiguation of options.  */
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-x";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "ab", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    ASSERT (c == '?');
Packit Service fdd496
    ASSERT (optopt == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-x";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "abx", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    ASSERT (c == 'x');
Packit Service fdd496
    ASSERT (optopt == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--x";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "abx", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    ASSERT (c == '?');
Packit Service fdd496
    ASSERT (optopt == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-b";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    b_seen = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "abx", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    ASSERT (c == 'b');
Packit Service fdd496
    ASSERT (b_seen == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "--b";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    b_seen = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "abx", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    ASSERT (c == 0);
Packit Service fdd496
    ASSERT (b_seen == 1);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-xt";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "ab", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    ASSERT (c == '?');
Packit Service fdd496
    ASSERT (optopt == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-xt";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "abx", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    ASSERT (c == '?');
Packit Service fdd496
    ASSERT (optopt == 0);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-xtra";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "ab", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    ASSERT (c == 1001);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-xtreme";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "abx:", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    ASSERT (c == 1002);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-xtremel";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "ab", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    /* glibc getopt_long_only is intentionally different from
Packit Service fdd496
       getopt_long when handling a prefix that is common to two
Packit Service fdd496
       spellings, when both spellings have the same option directives.
Packit Service fdd496
       BSD getopt_long_only treats both cases the same.  */
Packit Service fdd496
    ASSERT (c == 1003 || c == '?');
Packit Service fdd496
    ASSERT (optind == 2);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-xtremel";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "abx::", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    /* glibc getopt_long_only is intentionally different from
Packit Service fdd496
       getopt_long when handling a prefix that is common to two
Packit Service fdd496
       spellings, when both spellings have the same option directives.
Packit Service fdd496
       BSD getopt_long_only treats both cases the same.  */
Packit Service fdd496
    ASSERT (c == 1003 || c == '?');
Packit Service fdd496
    ASSERT (optind == 2);
Packit Service fdd496
    ASSERT (optarg == NULL);
Packit Service fdd496
  }
Packit Service fdd496
  {
Packit Service fdd496
    int argc = 0;
Packit Service fdd496
    const char *argv[10];
Packit Service fdd496
    int option_index;
Packit Service fdd496
    int c;
Packit Service fdd496
Packit Service fdd496
    argv[argc++] = "program";
Packit Service fdd496
    argv[argc++] = "-xtras";
Packit Service fdd496
    argv[argc] = NULL;
Packit Service fdd496
    optind = 1;
Packit Service fdd496
    opterr = 0;
Packit Service fdd496
    c = do_getopt_long_only (argc, argv, "abx::", long_options_required,
Packit Service fdd496
                             &option_index);
Packit Service fdd496
    ASSERT (c == 'x');
Packit Service fdd496
    ASSERT (strcmp (optarg, "tras") == 0);
Packit Service fdd496
  }
Packit Service fdd496
}