IODA Bundle
TestCommandLineParsing.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 /// \file UnitTest.h
12 ///
13 /// @author Piotr Kuchta, ECMWF, July 2009
14 
15 #include "eckit/exception/Exceptions.h"
16 
17 #include "Tool.h"
18 #include "TestCase.h"
19 
20 using namespace std;
21 using namespace eckit;
22 using namespace odc;
23 
24 struct TestTool : public odc::tool::Tool {
25 
26  TestTool(int argc, char **argv) : odc::tool::Tool(argc, argv)
27  {
28  registerOptionWithArgument("-foo");
29  registerOptionWithArgument("-intOpt");
30  }
31 
32  static void help(std::ostream &o) { o << "No help available for this command yet." << std::endl; }
33 
34  void run() {
35  Log::info() << "test: run" << std::endl;
36 
37  ASSERT(optionArgument("-foo", std::string("NONE")) == "bar");
38  ASSERT(optionArgument("-intOpt", 0) == 69);
39 
40  ASSERT(optionIsSet("-blah"));
41  ASSERT(optionIsSet("-blahblah"));
42  ASSERT(! optionIsSet("-blahblahblah"));
43  ASSERT(optionIsSet("-lastOption"));
44 
45  ASSERT(parameters().size() == 3);
46  ASSERT(parameters()[0] == "p1");
47  ASSERT(parameters()[1] == "p2");
48  ASSERT(parameters()[2] == "p3");
49 
50  }
51 };
52 
53 static void test()
54 {
55  const char *args[] = {"-foo", "bar", "-intOpt", "69", "-blah", "-blahblah", "p1", "p2", "-lastOption", "p3", 0};
56 
57  TestTool testTool(sizeof(args) / sizeof(char *) - 1, const_cast<char **>(args));
58  testTool.run();
59 }
60 
61 
62 static void setUp(){}
63 static void tearDown(){}
64 
65 SIMPLE_TEST(CommandLineParsing)
#define SIMPLE_TEST(name)
Definition: TestCase.h:66
static void tearDown()
static void test()
static void setUp()
Definition: ColumnInfo.h:23
Definition: encode.cc:30
static void help(std::ostream &o)
TestTool(int argc, char **argv)