Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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
42using lib::Literal;
43using util::isnil;
44using std::string;
45using std::vector;
46using std::map;
47
48
49namespace vault {
50namespace test {
51
53
54
55 namespace { // implementation details
56
57 struct Response
58 {
60 vector<ChanDesc> channels;
61
64 {
65 globalDesc.length.accept (Mutation::changeDuration(length));
66 return *this;
67 }
68
71 {
72 channels.push_back (ChanDesc (name, id, genH()));
73 return *this;
74 }
75
76 private:
77 static int _i_;
78
81 {
82 return reinterpret_cast<ChanHandle> (++_i_);
83 }
84 };
85 int Response::_i_(0);
88
89
90 struct TestCases : map<string,Response>
91 {
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
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
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
Access point to singletons and other kinds of dependencies designated by type.
Definition depend.hpp:281
Inline string literal.
Definition symbol.hpp:78
Duration is the internal Lumiera time metric.
void accept(Mutation const &)
Definition mutation.hpp:122
Interface: an opaque change imposed onto some time value.
Definition mutation.hpp:92
Derived specific exceptions within Lumiera's exception hierarchy.
Definition error.hpp:193
MediaDesc & queryFile(string const &name) const override
request for testing the denoted files accessibility
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.
unsigned int uint
Definition integral.hpp:29
Unit test helper to access an emulated media file.
Modifying time and timecode values.
const Duration LENGTH_TestClip(Time(0, 25, 0, 0))
Definition testclip.hpp:77
Test runner and basic definitions for tests.
bool isnil(lib::time::Duration const &dur)
MediaAccessFacade::ChanHandle ChanHandle
Vault-Layer implementation namespace root.
Description of one channel found in a media file; result of querying the channel.
Descriptor holding the global information record required for further handling this kind of media wit...
Duration length
effectively usable duration.
Marker types to indicate a literal string and a Symbol.
A stub implementation of the Clip interface for unit testing.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...