Lumiera  0.pre.03
»edit your freedom«
media-access-mock.cpp
Go to the documentation of this file.
1 /*
2  MediaAccessMock - a test (stub) target object for testing the factories
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 
23 
39 
40 #include "lib/util.hpp"
41 #include "lib/depend.hpp"
42 #include "lib/time/mutation.hpp"
43 #include "lib/symbol.hpp"
44 
45 #include <vector>
46 #include <map>
47 
51 using lib::Literal;
52 using util::isnil;
53 using std::string;
54 using std::vector;
55 using std::map;
56 
57 
58 namespace vault {
59 namespace test {
60 
61  typedef MediaAccessFacade::ChanHandle ChanHandle;
62 
63 
64  namespace { // implementation details
65 
66  struct Response
67  {
68  MediaDesc globalDesc;
69  vector<ChanDesc> channels;
70 
71  Response&
72  globalLength (Duration length)
73  {
74  globalDesc.length.accept (Mutation::changeDuration(length));
75  return *this;
76  }
77 
78  Response&
79  channel (Literal name, Literal id)
80  {
81  channels.push_back (ChanDesc (name, id, genH()));
82  return *this;
83  }
84 
85  private:
86  static int _i_;
87 
88  ChanHandle
89  genH()
90  {
91  return reinterpret_cast<ChanHandle> (++_i_);
92  }
93  };
94  int Response::_i_(0);
95  const ChanDesc NULLResponse;
96  using steam::mobject::session::test::LENGTH_TestClip;
97 
98 
99  struct TestCases : map<string,Response>
100  {
101  TestCases ()
102  {
103  // ----------------------------------------------------------------------TESTCASES
104  (*this)["test-1"].globalLength(LENGTH_TestClip).channel("video","ID");
105 
106  (*this)["test-2"].globalLength(LENGTH_TestClip).channel("video","H264")
107  .channel("audio-L","PCM")
108  .channel("audio-R","PCM");
109  (*this)["test-3"].globalLength(LENGTH_TestClip).channel("audio","PCM");
110  (*this)["test-4"].globalLength(LENGTH_TestClip).channel("audio-W","PCM")
111  .channel("audio-X","PCM")
112  .channel("audio-Y","PCM")
113  .channel("audio-Z","PCM");
114  // ----------------------------------------------------------------------TESTCASES
115  }
116 
117  bool
118  known (string key)
119  {
120  const_iterator i = find (key);
121  return (i != end());
122  }
123  };
124 
125  // instantiate TestCasses table
126  lib::Depend<TestCases> testCases;
127 
128  } // (end) implementation namespace
129 
130 
131 
132  MediaDesc&
133  MediaAccessMock::queryFile (string const& name) const
134  {
135  if (isnil (name))
136  throw Invalid ("empty filename passed to MediaAccessFacade.");
137 
138  if (!testCases().known(name))
139  throw Invalid ("unable to use media file \""+name+"\"."
140  "Hint: you're using a test-mock file access, "
141  "which responds only to some magical names.");
142 
143  return testCases()[name].globalDesc;
144  }
145 
146 
147  ChanDesc
148  MediaAccessMock::queryChannel (MediaDesc& h, uint chanNo) const
149  {
150  Response const& res (*reinterpret_cast<Response*> (&h));
151 
152  if (res.channels.size() <= chanNo)
153  return NULLResponse;
154  else
155  return res.channels[chanNo];
156  }
157 
158 
159 }} // namespace vault::test
Modifying time and timecode values.
Definition: run.hpp:49
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
Descriptor holding the global information record required for further handling this kind of media wit...
Interface: an opaque change imposed onto some time value.
Definition: mutation.hpp:100
Unit test helper to access an emulated media file.
Access point to singletons and other kinds of dependencies designated by type.
Definition: depend.hpp:289
Duration length
effectively usable duration.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
Marker types to indicate a literal string and a Symbol.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A stub implementation of the Clip interface for unit testing.
ChanDesc queryChannel(MediaDesc &, uint chanNo) const override
request for information about the n-th channel of the file referred by FileHandle.
Singleton services and Dependency Injection.
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
Vault-Layer implementation namespace root.
Description of one channel found in a media file; result of querying the channel. ...
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption
MediaDesc & queryFile(string const &name) const override
request for testing the denoted files accessibility