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)
5  2010, 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/test/test-helper.hpp"
22 #include "steam/asset/pipe.hpp"
23 #include "lib/format-string.hpp"
24 #include "lib/util.hpp"
25 
26 #include <string>
27 
28 using util::_Fmt;
29 using util::isnil;
30 using std::string;
31 
32 
33 namespace steam {
34 namespace mobject {
35 namespace test {
36 
37  using asset::Pipe;
38  using asset::PPipe;
39  using mobject::OutputMapping;
40 
41  typedef asset::ID<Pipe> PID;
42 
43 
44  /*****************************************************************************/
61  class OutputMapping_test : public Test
62  {
63  struct DummyDef
64  {
65  string
66  output (PID target)
67  {
68  return Pipe::lookup(target)->ident.name;
69  }
70 
72  buildQuery (PID sourcePipeID, uint seqNr =0)
73  {
74  PPipe srcP = Pipe::lookup (sourcePipeID);
75  _Fmt queryPattern{"id(master_%1%), stream(%1%), ord(%2%)"};
76  return Query<Pipe> (queryPattern % srcP->getStreamID().getSym() % seqNr);
77  }
78  };
79 
81 
82  virtual void
83  run (Arg)
84  {
85  map_and_retrieve();
86  instance_copy();
87  default_mapping();
88  }
89 
90 
91  void
92  map_and_retrieve()
93  {
94  Mapping map;
95  CHECK (isnil (map));
96 
97  PPipe p1 = Pipe::query("id(hairy)");
98  PPipe p2 = Pipe::query("id(furry)");
99  PPipe pX = Pipe::query("id(curly)");
100 
101  map[p1] = p2;
102  CHECK (!isnil (map));
103  CHECK (1 == map.size());
104  CHECK (map[p1] == "furry");
105  CHECK (map[p1].isValid());
106  CHECK (map[p1]);
107 
108  CHECK (!map.contains (pX));
109  CHECK (!map.contains (p2));
110 
111  // create an unconnected mapping
112  map[pX].disconnect();
113  CHECK (map.contains (pX));
114  CHECK (!map[pX].isValid());
115  CHECK (!map[pX]);
116  }
117 
118 
119  void
120  instance_copy()
121  {
122  Mapping m1;
123 
124  PPipe p1 = Pipe::query("id(hairy)");
125  PPipe p2 = Pipe::query("id(furry)");
126  PPipe pi = Pipe::query("id(nappy)");
127 
128  m1[pi] = p1;
129  Mapping m2(m1);
130  CHECK (!isnil (m2));
131  CHECK (1 == m2.size());
132  CHECK (m1[pi] == "hairy");
133  CHECK (m2[pi] == "hairy");
134 
135  m1[pi] = p2;
136  CHECK (m1[pi] == "furry");
137  CHECK (m2[pi] == "hairy");
138 
139  m2 = m1;
140  CHECK (m1[pi] == "furry");
141  CHECK (m2[pi] == "furry");
142 
143  m1.clear();
144  CHECK (isnil(m1));
145  CHECK (!isnil(m2));
146  CHECK (m2[pi] == "furry");
147  CHECK (!m1.contains (pi));
148  }
149 
150 
151  void
152  default_mapping()
153  {
154  Mapping map;
155  CHECK (isnil (map));
156 
157  PPipe p1 = Pipe::query("stream(hairy)");
158  PPipe p2 = Pipe::query("stream(furry)");
159 
160  CHECK (map[p1] == "master_hairy");
161  CHECK (map[p2] == "master_furry");
162 
163  // create new mapping to an explicitly queried target
164  Query<Pipe> some_pipe ("pipe(super_curly)");
165  CHECK (map[some_pipe] == "super_curly");
166 
167  // create a new mapping to the 2nd master for "furry" data
168  Query<Pipe> special_bus ("stream(furry), ord(2)");
169  CHECK (map[special_bus] == "master_furry.2");
170  }
171  };
172 
173 
175  LAUNCHER (OutputMapping_test, "unit session");
176 
177 
178 
179 }}} // namespace steam::mobject::test
A "processing pipe" represented as Asset.
Definition: run.hpp:40
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:70
static PPipe lookup(ID< Pipe > id)
convenience shortcut for lookup by id
Definition: pipe.cpp:67
Simplistic 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:57
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:71
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:270