Lumiera  0.pre.03
»edit your freedom«
search-path-splitter-test.cpp
Go to the documentation of this file.
1 /*
2  SearchPathSplitter(Test) - iterating a search path specification
3 
4  Copyright (C) Lumiera.org
5  2011, 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/test/test-helper.hpp"
30 #include "lib/format-cout.hpp"
31 
32 #include "lib/searchpath.hpp"
33 
34 
35 
36 
37 namespace lib {
38 namespace test {
39 
40 
41  /**************************************************/
47  class SearchPathSplitter_test : public Test
48  {
49  void
50  run (Arg)
51  {
52  walkSimplePaths ();
53  resolveEmbeddedOriginToken ();
54  }
55 
56 
57  void
58  walkSimplePaths ()
59  {
60  walk ("");
61  walk (":");
62  walk ("a:");
63  walk (":a");
64  walk ("a:b");
65  walk (":a:b:c:");
66  walk (" d : e f");
67  walk ("/usr/bin:/usr/lib");
68 
69  SearchPathSplitter sp("");
70  VERIFY_ERROR (ITER_EXHAUST, sp.next() );
71  }
72 
73  void
74  walk (string spec)
75  {
76  SearchPathSplitter path(spec);
77  while (path)
78  cout << "➢➢" << path.next() << endl;
79  }
80 
81 
82 
83  void
84  resolveEmbeddedOriginToken ()
85  {
86  fsys::path exePath (findExePath());
87  string expected = (exePath.remove_leaf() / "modules").string();
88 
89  SearchPathSplitter sp("xyz:$ORIGIN/modules:abc");
90  CHECK ("xyz" == sp.next());
91  CHECK (sp.next() == expected);
92  CHECK ("abc" == sp.next());
93  CHECK (!sp.isValid());
94  }
95  };
96 
97 
98  LAUNCHER (SearchPathSplitter_test, "unit common");
99 
100 
101 }} // namespace lib::test
Helpers to handle directory search paths.
Automatically use custom string conversion in C++ stream output.
string findExePath()
retrieve the location of the executable
Definition: searchpath.cpp:53
Definition: run.hpp:49
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Implementation namespace for support and library code.
Simple test class runner.
A collection of frequently used helper functions to support unit testing.
Helper: Access a path Specification as a sequence of filesystem Paths.
Definition: searchpath.hpp:71