~ubuntu-branches/ubuntu/quantal/config-manager/quantal

« back to all changes in this revision

Viewing changes to libgetopt/tests/BoolOptionTest.cc

  • Committer: Bazaar Package Importer
  • Author(s): Anand Kumria
  • Date: 2004-07-19 22:27:50 UTC
  • mto: (3.1.1 dapper)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040719222750-sztqdj1aoj2r6frr
Tags: upstream-0.1p83
ImportĀ upstreamĀ versionĀ 0.1p83

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2002 Robert Collins.
3
 
 * Copyright (c) 2003 Robert Collins.
4
 
 *
5
 
 *     This program is free software; you can redistribute it and/or modify
6
 
 *     it under the terms of the GNU General Public License as published by
7
 
 *     the Free Software Foundation; either version 2 of the License, or
8
 
 *     (at your option) any later version.
9
 
 *
10
 
 *     A copy of the GNU General Public License can be found at
11
 
 *     http://www.gnu.org/
12
 
 *
13
 
 * Written by Robert Collins <robertc@hotmail.com>
14
 
 *
15
 
 */
16
 
 
17
 
#include "getopt++/GetOption.h"
18
 
#include "getopt++/BoolOption.h"
19
 
 
20
 
#include <iostream>
21
 
 
22
 
static BoolOption testoption (false, 't', "testoption", "Tests the use of boolean options");
23
 
int
24
 
main (int anargc, char **anargv)
25
 
{
26
 
  int argc=2;
27
 
  char *argv[4];
28
 
  argv[0] = strdup("BoolOptionTest");
29
 
  argv[1] = strdup("-h");
30
 
    {
31
 
      BoolOption helpoption (false, 'h', "help", "Tests the use of help output.");
32
 
      if (!GetOption::GetInstance().Process (argc, argv, NULL))
33
 
        {
34
 
          std::cout << "Failed to process options" << std::endl;
35
 
          return 1;
36
 
        }
37
 
      if (!helpoption)
38
 
        {
39
 
          std::cout << "Did not recieve expected help option" << std::endl;
40
 
          return 1;
41
 
        }
42
 
      free(argv[1]);
43
 
      argc = 0;
44
 
    }
45
 
    {
46
 
      BoolOption helpoption (false, 'h', "help", "Tests the use of help output.");
47
 
      if (!GetOption::GetInstance().Process (argc, argv, NULL))
48
 
        {
49
 
          std::cout << "Failed to process options (2) " << std::endl;
50
 
          return 1;
51
 
        }
52
 
      if (helpoption)
53
 
        {
54
 
          std::cout << "Recieved unexpected  help option" << std::endl;
55
 
          return 1;
56
 
        }
57
 
    }
58
 
  return 0;
59
 
}