Lumiera  0.pre.03
»edit your freedom«
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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)
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 
14 
30 
31 #include "lib/util.hpp"
32 #include "lib/depend.hpp"
33 #include "lib/time/mutation.hpp"
34 #include "lib/symbol.hpp"
35 
36 #include <vector>
37 #include <map>
38 
42 using lib::Literal;
43 using util::isnil;
44 using std::string;
45 using std::vector;
46 using std::map;
47 
48 
49 namespace vault {
50 namespace test {
51 
52  typedef MediaAccessFacade::ChanHandle ChanHandle;
53 
54 
55  namespace { // implementation details
56 
57  struct Response
58  {
59  MediaDesc globalDesc;
60  vector<ChanDesc> channels;
61 
62  Response&
63  globalLength (Duration length)
64  {
65  globalDesc.length.accept (Mutation::changeDuration(length));
66  return *this;
67  }
68 
69  Response&
70  channel (Literal name, Literal id)
71  {
72  channels.push_back (ChanDesc (name, id, genH()));
73  return *this;
74  }
75 
76  private:
77  static int _i_;
78 
79  ChanHandle
80  genH()
81  {
82  return reinterpret_cast<ChanHandle> (++_i_);
83  }
84  };
85  int Response::_i_(0);
86  const ChanDesc NULLResponse;
87  using steam::mobject::session::test::LENGTH_TestClip;
88 
89 
90  struct TestCases : map<string,Response>
91  {
92  TestCases ()
93  {
94  // ----------------------------------------------------------------------TESTCASES
95  (*this)["test-1"].globalLength(LENGTH_TestClip).channel("video","ID");
96 
97  (*this)["test-2"].globalLength(LENGTH_TestClip).channel("video","H264")
98  .channel("audio-L","PCM")
99  .channel("audio-R","PCM");
100  (*this)["test-3"].globalLength(LENGTH_TestClip).channel("audio","PCM");
101  (*this)["test-4"].globalLength(LENGTH_TestClip).channel("audio-W","PCM")
102  .channel("audio-X","PCM")
103  .channel("audio-Y","PCM")
104  .channel("audio-Z","PCM");
105  // ----------------------------------------------------------------------TESTCASES
106  }
107 
108  bool
109  known (string key)
110  {
111  const_iterator i = find (key);
112  return (i != end());
113  }
114  };
115 
116  // instantiate TestCasses table
117  lib::Depend<TestCases> testCases;
118 
119  } // (end) implementation namespace
120 
121 
122 
123  MediaDesc&
124  MediaAccessMock::queryFile (string const& name) const
125  {
126  if (isnil (name))
127  throw Invalid ("empty filename passed to MediaAccessFacade.");
128 
129  if (!testCases().known(name))
130  throw Invalid ("unable to use media file \""+name+"\"."
131  "Hint: you're using a test-mock file access, "
132  "which responds only to some magical names.");
133 
134  return testCases()[name].globalDesc;
135  }
136 
137 
138  ChanDesc
139  MediaAccessMock::queryChannel (MediaDesc& h, uint chanNo) const
140  {
141  Response const& res (*reinterpret_cast<Response*> (&h));
142 
143  if (res.channels.size() <= chanNo)
144  return NULLResponse;
145  else
146  return res.channels[chanNo];
147  }
148 
149 
150 }} // namespace vault::test
Modifying time and timecode values.
Definition: run.hpp:40
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:76
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:91
Unit test helper to access an emulated media file.
Access point to singletons and other kinds of dependencies designated by type.
Definition: depend.hpp:280
Duration length
effectively usable duration.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
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:468
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