Lumiera  0.pre.03
»edityourfreedom«
cmdline-wrapper-test.cpp
Go to the documentation of this file.
1 /*
2  CmdlineWrapper(Test) - build vector of tokens from cmdline, various conversions
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/cmdline.hpp"
30 #include "lib/util-foreach.hpp"
31 #include "lib/format-cout.hpp"
32 
33 #include <sstream>
34 #include <string>
35 
36 using util::for_each;
37 using std::string;
38 
39 
40 
41 namespace lib {
42 namespace test{
43 
44 
45 
47  class CmdlineWrapper_test : public Test
48  {
49  void
50  run (Arg)
51  {
52  testLine("");
53  testLine("\n\t ");
54  testLine("spam");
55  testLine("\nspam");
56  testLine("eat more spam");
57  testLine(" oo _O()O_ ☭ + €");
58  testLine("Ω\tooΩ\toΩo\tΩoo");
59 
61  }
62 
63  void
64  testLine (const string cmdline)
65  {
66  cout << "wrapping cmdline:" << cmdline << "..." << endl;
67 
68  int i=0;
69  Cmdline theCmdline (cmdline);
70  for_each(theCmdline, [&](string const& arg) { cout << i++ << "|" << arg << "|\n";});
71  cout << "-->" << theCmdline << endl;
72 
73  // consistency checks
74  std::ostringstream output;
75  output << theCmdline;
76  CHECK (output.str() == string(theCmdline));
77 
78  i=0;
79  string token;
80  std::istringstream input(theCmdline);
81  while (input >> token)
82  CHECK (token == theCmdline[i++]);
83  }
84 
88  void
90  {
91  const char* fakeArg[3] = {"CMD", "one ", "two"};
92  Cmdline theCmdline(3, fakeArg);
93  cout << "Standard Cmdlineformat:" << theCmdline << endl;
94  }
95  };
96 
97  LAUNCHER (CmdlineWrapper_test, "unit common");
98 
99 
100 }} // namespace lib::test
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:49
void testLine(const string cmdline)
Implementation namespace for support and library code.
Class to encapsulate the typical C-style commandline definition.
std::vector< string > & Arg
Definition: run.hpp:54
Simple test class runner.
LAUNCHER(SyncClasslock_test, "unit common")
Register this test class...
disable_if< can_IterForEach< Container >, FUN > for_each(Container const &coll, FUN doIt)
operate on all elements of a STL container.
Perform operations "for each element" of a collection.
Abstraction of the usual int argc, int** argv-Commandline, to be able to treat it as a vector of stri...
Definition: cmdline.hpp:56