Lumiera  0.pre.03
»edit your freedom«
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)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/cmdline.hpp"
21 #include "lib/util-foreach.hpp"
22 #include "lib/format-cout.hpp"
23 
24 #include <sstream>
25 #include <string>
26 
27 using util::for_each;
28 using std::string;
29 
30 
31 
32 namespace lib {
33 namespace test{
34 
35 
36 
38  class CmdlineWrapper_test : public Test
39  {
40  void
41  run (Arg)
42  {
43  testLine("");
44  testLine("\n\t ");
45  testLine("spam");
46  testLine("\nspam");
47  testLine("eat more spam");
48  testLine(" oo _O()O_ ☭ + €");
49  testLine("Ω\tooΩ\toΩo\tΩoo");
50 
52  }
53 
54  void
55  testLine (const string cmdline)
56  {
57  cout << "wrapping cmdline:" << cmdline << "..." << endl;
58 
59  int i=0;
60  Cmdline theCmdline (cmdline);
61  for_each(theCmdline, [&](string const& arg) { cout << i++ << "|" << arg << "|\n";});
62  cout << "-->" << theCmdline << endl;
63 
64  // consistency checks
65  std::ostringstream output;
66  output << theCmdline;
67  CHECK (output.str() == string(theCmdline));
68 
69  i=0;
70  string token;
71  std::istringstream input(theCmdline);
72  while (input >> token)
73  CHECK (token == theCmdline[i++]);
74  }
75 
79  void
81  {
82  const char* fakeArg[3] = {"CMD", "one ", "two"};
83  Cmdline theCmdline(3, fakeArg);
84  cout << "Standard Cmdlineformat:" << theCmdline << endl;
85  }
86  };
87 
88  LAUNCHER (CmdlineWrapper_test, "unit common");
89 
90 
91 }} // namespace lib::test
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:40
Implementation namespace for support and library code.
Class to encapsulate the typical C-style commandline definition.
Simplistic test class runner.
void for_each(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
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:48