00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00036 #include "backend/mediaaccessmock.hpp"
00037
00038 #include "common/util.hpp"
00039
00040 #include <iostream>
00041 #include <vector>
00042 #include <map>
00043
00044 using lumiera::error::Invalid;
00045 using util::for_each;
00046 using util::isnil;
00047 using std::cout;
00048 using std::string;
00049 using std::vector;
00050 using std::map;
00051
00052
00053 namespace backend_interface
00054 {
00055 namespace test
00056 {
00057 typedef MediaAccessFacade::FileHandle FileHandle;
00058 typedef MediaAccessFacade::ChanHandle ChanHandle;
00059
00060
00061 namespace
00062 {
00063 typedef vector<ChanDesc> Response;
00064 const ChanDesc NULLResponse;
00065
00066 struct TestCases : map<string,Response>
00067 {
00068 TestCases ()
00069 {
00070
00071 (*this)["test-1"].push_back (ChanDesc ("video","ID", genH()));
00072
00073 (*this)["test-2"].push_back (ChanDesc ("video","H264", genH()));
00074 (*this)["test-2"].push_back (ChanDesc ("audio-L","PCM", genH()));
00075 (*this)["test-2"].push_back (ChanDesc ("audio-R","PCM", genH()));
00076
00077 }
00078
00079 bool known (string key)
00080 {
00081 const_iterator i = find (key);
00082 return (i != end());
00083 }
00084 private:
00085 int _i_;
00086 ChanHandle genH()
00087 {
00088 return reinterpret_cast<ChanHandle> (++_i_);
00089 }
00090 };
00091
00092
00093 TestCases testCases;
00094
00095 }
00096
00097
00098 FileHandle
00099 MediaAccessMock::queryFile (const char* name) throw(Invalid)
00100 {
00101 if (isnil (name))
00102 throw Invalid ("empty filename passed to MediaAccessFacade.");
00103
00104 if (!testCases.known(name))
00105 return 0;
00106 else
00107 return reinterpret_cast<void*> (&testCases[name]);
00108 }
00109
00110 ChanDesc
00111 MediaAccessMock::queryChannel (FileHandle h, uint chanNo) throw()
00112 {
00113 const Response* res (reinterpret_cast<Response*> (h));
00114
00115 if (!res || res->size() <= chanNo)
00116 return NULLResponse;
00117 else
00118 return (*res)[chanNo];
00119 }
00120
00121
00122 }
00123
00124 }