Lumiera  0.pre.03
»edit your freedom«
output-mapping-test.cpp
Go to the documentation of this file.
1 /*
2  OutputMapping(Test) - verify generic output designation mapping
3 
4  Copyright (C) Lumiera.org
5  2010, 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"
31 #include "steam/asset/pipe.hpp"
32 #include "lib/format-string.hpp"
33 #include "lib/util.hpp"
34 
35 #include <string>
36 
37 using util::_Fmt;
38 using util::isnil;
39 using std::string;
40 
41 
42 namespace steam {
43 namespace mobject {
44 namespace test {
45 
46  using asset::Pipe;
47  using asset::PPipe;
48  using mobject::OutputMapping;
49 
50  typedef asset::ID<Pipe> PID;
51 
52 
53  /*****************************************************************************/
70  class OutputMapping_test : public Test
71  {
72  struct DummyDef
73  {
74  string
75  output (PID target)
76  {
77  return Pipe::lookup(target)->ident.name;
78  }
79 
81  buildQuery (PID sourcePipeID, uint seqNr =0)
82  {
83  PPipe srcP = Pipe::lookup (sourcePipeID);
84  _Fmt queryPattern{"id(master_%1%), stream(%1%), ord(%2%)"};
85  return Query<Pipe> (queryPattern % srcP->getStreamID().getSym() % seqNr);
86  }
87  };
88 
90 
91  virtual void
92  run (Arg)
93  {
94  map_and_retrieve();
95  instance_copy();
96  default_mapping();
97  }
98 
99 
100  void
101  map_and_retrieve()
102  {
103  Mapping map;
104  CHECK (isnil (map));
105 
106  PPipe p1 = Pipe::query("id(hairy)");
107  PPipe p2 = Pipe::query("id(furry)");
108  PPipe pX = Pipe::query("id(curly)");
109 
110  map[p1] = p2;
111  CHECK (!isnil (map));
112  CHECK (1 == map.size());
113  CHECK (map[p1] == "furry");
114  CHECK (map[p1].isValid());
115  CHECK (map[p1]);
116 
117  CHECK (!map.contains (pX));
118  CHECK (!map.contains (p2));
119 
120  // create an unconnected mapping
121  map[pX].disconnect();
122  CHECK (map.contains (pX));
123  CHECK (!map[pX].isValid());
124  CHECK (!map[pX]);
125  }
126 
127 
128  void
129  instance_copy()
130  {
131  Mapping m1;
132 
133  PPipe p1 = Pipe::query("id(hairy)");
134  PPipe p2 = Pipe::query("id(furry)");
135  PPipe pi = Pipe::query("id(nappy)");
136 
137  m1[pi] = p1;
138  Mapping m2(m1);
139  CHECK (!isnil (m2));
140  CHECK (1 == m2.size());
141  CHECK (m1[pi] == "hairy");
142  CHECK (m2[pi] == "hairy");
143 
144  m1[pi] = p2;
145  CHECK (m1[pi] == "furry");
146  CHECK (m2[pi] == "hairy");
147 
148  m2 = m1;
149  CHECK (m1[pi] == "furry");
150  CHECK (m2[pi] == "furry");
151 
152  m1.clear();
153  CHECK (isnil(m1));
154  CHECK (!isnil(m2));
155  CHECK (m2[pi] == "furry");
156  CHECK (!m1.contains (pi));
157  }
158 
159 
160  void
161  default_mapping()
162  {
163  Mapping map;
164  CHECK (isnil (map));
165 
166  PPipe p1 = Pipe::query("stream(hairy)");
167  PPipe p2 = Pipe::query("stream(furry)");
168 
169  CHECK (map[p1] == "master_hairy");
170  CHECK (map[p2] == "master_furry");
171 
172  // create new mapping to an explicitly queried target
173  Query<Pipe> some_pipe ("pipe(super_curly)");
174  CHECK (map[some_pipe] == "super_curly");
175 
176  // create a new mapping to the 2nd master for "furry" data
177  Query<Pipe> special_bus ("stream(furry), ord(2)");
178  CHECK (map[special_bus] == "master_furry.2");
179  }
180  };
181 
182 
184  LAUNCHER (OutputMapping_test, "unit session");
185 
186 
187 
188 }}} // namespace steam::mobject::test
A "processing pipe" represented as Asset.
Definition: run.hpp:49
Front-end for printf-style string template interpolation.
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
structural asset corresponding to the part of the model forming a processing pipe for generating medi...
Definition: pipe.hpp:79
static PPipe lookup(ID< Pipe > id)
convenience shortcut for lookup by id
Definition: pipe.cpp:76
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
Translating and wiring output designations.
static PPipe query(string const &properties)
convenience shortcut for retrieving default configured pipes
Definition: pipe.cpp:66
OutputMapping is a facility to resolve output designations.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:80
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:279