~ubuntu-branches/ubuntu/hardy/gengetopt/hardy

« back to all changes in this revision

Viewing changes to tests/test_multiple.cc

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-01-29 14:55:40 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080129145540-bkah1bl330gpelmh
Tags: 2.22-1ubuntu1
* Merge with Debian; remaining changes:
  - Fix build failures with g++-4.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* test_multiple.c test */
 
2
 
 
3
/* test options that can be given more than once */
 
4
 
 
5
#include <stdlib.h>
 
6
#include <stdio.h>
 
7
#include <iostream>
 
8
 
 
9
#include "test_multiple_cmd.h"
 
10
 
 
11
static struct gengetopt_args_info args_info;
 
12
 
 
13
using namespace std;
 
14
 
 
15
int
 
16
main (int argc, char **argv)
 
17
 
18
  unsigned int i = 0;
 
19
  int result = 0;
 
20
 
 
21
  if (test_multiple_cmd_parser (argc, argv, &args_info) != 0) {
 
22
    result = 1;
 
23
    goto end;
 
24
  }
 
25
 
 
26
  for (i = 0; i < args_info.string_given; ++i)
 
27
    printf ("passed string: %s\n", args_info.string_arg[i]);
 
28
 
 
29
  for (i = 0; i < args_info.int_given; ++i)
 
30
    printf ("passed int: %d\n", args_info.int_arg[i]);
 
31
 
 
32
  if (args_info.float_given)
 
33
    {
 
34
      for (i = 0; i < args_info.float_given; ++i)
 
35
        printf ("passed float: %f\n", args_info.float_arg[i]);
 
36
    }
 
37
  else
 
38
    if (args_info.float_arg)
 
39
      printf ("default float: %f\n", args_info.float_arg[0]);
 
40
 
 
41
  for (i = 0; i < args_info.no_short_opt_given; ++i)
 
42
    printf ("passed no-short-opt: %s\n", args_info.no_short_opt_arg[i]);
 
43
 
 
44
  printf ("noarg given %d times\n", args_info.noarg_given);
 
45
  printf ("noarg_noshort given %d times\n", args_info.noarg_noshort_given);
 
46
 
 
47
  printf ("optarg_given %d times\n", args_info.optarg_given);
 
48
  for (i = 0; i < args_info.optarg_given; ++i)
 
49
    printf ("optarg argument: %s\n", 
 
50
            (args_info.optarg_arg[i] ? args_info.optarg_arg[i] : "no arg given"));
 
51
 
 
52
  printf ("longlong_given %d times\n", args_info.longlong_given);
 
53
  for (i = 0; i < args_info.longlong_given; ++i)
 
54
    cout << "longlong argument: " << 
 
55
      args_info.longlong_arg[i] << endl;
 
56
 
 
57
  printf ("optarg_noshort_given %d times\n", args_info.optarg_noshort_given);
 
58
  for (i = 0; i < args_info.optarg_noshort_given; ++i)
 
59
    printf ("optarg_noshort argument: %s\n", 
 
60
            (args_info.optarg_noshort_arg[i] ? args_info.optarg_noshort_arg[i] : "no arg given"));
 
61
 
 
62
  if (args_info.file_save_given && test_multiple_cmd_parser_file_save (args_info.file_save_arg, &args_info) != EXIT_SUCCESS) {
 
63
    result = 1;
 
64
    goto end;
 
65
  }
 
66
 
 
67
 end:
 
68
  test_multiple_cmd_parser_free (&args_info);
 
69
 
 
70
  return result;
 
71
}