30 void SetRequestedRegion(const
itk::DataObject * )
42 DummyWriter(
const std::string &basedataType,
const std::string &extension,
int ranking)
43 :
mitk::
AbstractFileWriter(basedataType, extension,
"This is a dummy description"), m_Content(
"Hi there stream")
52 m_ServiceReg.Unregister();
63 std::
string m_Content;
66 DummyWriter *
Clone()
const {
return new DummyWriter(*
this); }
74 DummyWriter2(
const DummyWriter2 &other) :
mitk::AbstractFileWriter(other), m_Content(
"hi there file path") {}
75 DummyWriter2(
const std::string &basedataType,
const std::string &extension,
int ranking)
76 :
mitk::AbstractFileWriter(basedataType, extension,
"This is a dummy description"), m_Content(
"hi there file path")
78 this->SetRanking(ranking);
79 m_ServiceReg = this->RegisterService();
85 m_ServiceReg.Unregister();
88 using AbstractFileWriter::Write;
90 virtual void Write(
const mitk::BaseData *data,
const std::string &filePath)
93 std::ofstream fileStream(filePath.c_str());
94 fileStream << m_Content;
97 virtual
void Write(const
mitk::BaseData *data,
std::ostream &stream)
102 virtual bool CanWrite(
const mitk::BaseData *data)
const {
return dynamic_cast<const DummyBaseData *
>(data); }
103 std::string m_Content;
106 DummyWriter2 *
Clone()
const {
return new DummyWriter2(*
this); }
119 DummyBaseData dummyData;
120 std::stringstream oss;
121 writerRegistry.Write(&dummyData, oss);
126 std::ofstream tmpStream;
128 writerRegistry.Write(&dummyData, tmpFileName);
130 std::ifstream tmpInput(tmpFileName.c_str());
131 std::getline(tmpInput, content);
134 std::remove(tmpFileName.c_str());
140 std::stringstream oss2;
141 dummyWriter2.Write(&dummyData, oss2);
144 std::string content2;
146 std::ofstream tmpStream;
148 writerRegistry.Write(&dummyData, tmpFileName);
150 std::ifstream tmpInput(tmpFileName.c_str());
151 std::getline(tmpInput, content2);
153 std::remove(tmpFileName.c_str());
171 DummyWriter testDR(
"testdata",
"test", 1);
172 DummyWriter otherDR(
"testdata",
"other", 1);
183 "Testing correct retrieval of FileWriter 1/2");
185 returned = writerRegistry->
GetWriter(
"",
"other");
188 "Testing correct retrieval of FileWriter 2/2");
190 DummyWriter mediocreTestDR(
"testdata",
"test", 20);
191 DummyWriter prettyFlyTestDR(
"testdata",
"test", 50);
192 DummyWriter2 awesomeTestDR(
"testdata",
"test", 100);
194 returned = writerRegistry->
GetWriter(
"test");
196 "Testing correct priorized retrieval of FileWriter: Best Writer");
199 mitk::IFileWriter::OptionList options;
200 options.push_back(std::make_pair(
"isANiceGuy",
true));
201 mediocreTestDR.SetOptions(options);
203 options.push_back(std::make_pair(
"canFly",
true));
204 prettyFlyTestDR.SetOptions(options);
205 options.push_back(std::make_pair(
"isAwesome",
true));
206 awesomeTestDR.SetOptions(options);
209 mitk::IFileWriter::OptionNames optionFilter;
210 optionFilter.push_back(
"canFly");
211 returned = writerRegistry->
GetWriter(
"",
"test", optionFilter);
213 "Testing correct retrieval of FileWriter with Options: Best Writer with options");
215 optionFilter.push_back(
"isAwesome");
216 returned = writerRegistry->
GetWriter(
"",
"test", optionFilter);
218 returned && &static_cast<mitk::IFileWriter &>(awesomeTestDR) != returned,
219 "Testing correct retrieval of FileWriter with multiple Options: Best Writer with options");
221 optionFilter.clear();
222 optionFilter.push_back(
"isANiceGuy");
223 returned = writerRegistry->
GetWriter(
"",
"test", optionFilter);
225 returned && &static_cast<mitk::IFileWriter &>(mediocreTestDR) != returned,
226 "Testing correct retrieval of specific FileWriter with Options: Low priority Writer with specific option");
228 optionFilter.push_back(
"canFly");
229 returned = writerRegistry->
GetWriter(
"",
"test", optionFilter);
234 std::vector<mitk::IFileWriter *> returnedList;
235 returnedList = writerRegistry->
GetWriters(
"",
"test", optionFilter);
237 returnedList.empty(),
238 "Testing correct return of zero Writers when no matching Writer was found, asking for all compatibles");
240 optionFilter.clear();
241 optionFilter.push_back(
"canFly");
242 returnedList = writerRegistry->
GetWriters(
"",
"test", optionFilter);
244 returnedList.size() == 2,
245 "Testing correct return of two Writers when two matching Writer was found, asking for all compatibles");
247 "Testing correct priorization of returned Writers with options 1/2");
249 optionFilter.clear();
250 optionFilter.push_back(
"isAwesome");
251 returnedList = writerRegistry->
GetWriters(
"",
"test", optionFilter);
253 returnedList.size() == 1,
254 "Testing correct return of one Writers when one matching Writer was found, asking for all compatibles");
256 "Testing correctness of result from former query");
288 delete writerRegistry;
AbstractFileWriter(const AbstractFileWriter &other)
Base of all data objects.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
std::vector< IFileWriter * > GetWriters(const BaseData *baseData, const std::string &mimeType, us::ModuleContext *context=us::GetModuleContext())
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override=0
Determine whether the RequestedRegion is outside of the BufferedRegion.
DataCollection - Class to facilitate loading/accessing structured data.
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
void SetRanking(int ranking)
Set the service ranking for this file writer.
#define mitkClassMacro(className, SuperClassName)
IFileWriter * GetWriter(const WriterReference &ref, us::ModuleContext *context=us::GetModuleContext())
static const char * GetStaticNameOfClass()
virtual void Write() override=0
Write the base data to the specified location or output stream.
static std::string CreateTemporaryFile(std::ofstream &tmpStream, const std::string &templateName="XXXXXX", std::string path=std::string())
int mitkFileWriterRegistryTest(int, char *[])
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
virtual void SetRequestedRegionToLargestPossibleRegion() override=0
Set the RequestedRegion to the LargestPossibleRegion.
The common interface of all MITK file writers.
Base class for writing mitk::BaseData objects to files or streams.
virtual bool VerifyRequestedRegion() override=0
Verify that the RequestedRegion is within the LargestPossibleRegion.