Skip to content

Commit 2f3e6e0

Browse files
committed
#43 : return failure if metadata is not added
1 parent f52e483 commit 2f3e6e0

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.12
1+
0.2.13

src/combine/combinearchive.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ std::string CombineArchive::getNextFilename(const std::string& prefix,
190190
return fileName;
191191
}
192192

193-
void CombineArchive::addMetadataToArchive(OmexDescription& desc, Zipper *zipper)
193+
int
194+
CombineArchive::addMetadataToArchive(OmexDescription& desc, Zipper *zipper)
194195
{
195196
if (desc.isEmpty() || zipper == NULL || mpManifest == NULL)
196-
return;
197+
return LIBCOMBINE_OPERATION_FAILED;
197198

198199
std::string fileName = getNextFilename("metadata", ".rdf");
199200
std::stringstream content; content << desc.toXML();
@@ -203,7 +204,8 @@ void CombineArchive::addMetadataToArchive(OmexDescription& desc, Zipper *zipper)
203204
entry->setLocation(fileName);
204205
entry->setFormat(KnownFormats::lookupFormat("omex"));
205206
entry->setMaster(false);
206-
207+
208+
return LIBCOMBINE_OPERATION_SUCCESS;
207209
}
208210

209211
bool CombineArchive::writeToFile(const std::string &fileName)
@@ -488,11 +490,16 @@ CombineArchive::addFile(std::istream &stream,
488490
return addFile(tempFilename, targetName, format, isMaster);
489491
}
490492

491-
void
493+
int
492494
CombineArchive::addMetadata(const std::string &targetName,
493495
const OmexDescription &description)
494496
{
497+
if (description.isEmpty())
498+
return LIBCOMBINE_OPERATION_FAILED;
499+
495500
mMetadataMap[targetName] = description;
501+
502+
return LIBCOMBINE_OPERATION_SUCCESS;
496503
}
497504

498505
bool

src/combine/combinearchive.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ class LIBCOMBINE_EXTERN CombineArchive
123123
*
124124
* @param targetName the name of the entry that the metadata is about
125125
* @param description the metadata description
126+
*
127+
* @return status code indicating success or failure.
128+
* @li @omexconstant{LIBCOMBINE_OPERATION_SUCCESS, OperationReturnValues_t}
129+
* @li @omexconstant{LIBCOMBINE_OPERATION_FAILED, OperationReturnValues_t}
126130
*/
127-
void addMetadata(const std::string& targetName,
131+
int addMetadata(const std::string& targetName,
128132
const OmexDescription& description);
129133

130134
/**
@@ -361,8 +365,13 @@ class LIBCOMBINE_EXTERN CombineArchive
361365
*
362366
* @param desc the description to be added
363367
* @param zipper the zipper to be used
368+
*
369+
* @return status code indicating success or failure.
370+
* @li @omexconstant{LIBCOMBINE_OPERATION_SUCCESS, OperationReturnValues_t}
371+
* @li @omexconstant{LIBCOMBINE_OPERATION_FAILED, OperationReturnValues_t}
372+
*
364373
*/
365-
void addMetadataToArchive(OmexDescription& desc, zipper::Zipper* zipper);
374+
int addMetadataToArchive(OmexDescription& desc, zipper::Zipper* zipper);
366375
};
367376

368377
LIBCOMBINE_CPP_NAMESPACE_END

src/test/combine_test_create.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,30 @@ SCENARIO("reading an existing archive", "[combine]")
194194

195195
}
196196
}
197+
198+
SCENARIO("creating a combine archive", "[combine]")
199+
{
200+
CombineArchive archive;
201+
REQUIRE(archive.getManifest() == NULL);
202+
203+
GIVEN("user adds invalid omex data")
204+
{
205+
OmexDescription desc;
206+
REQUIRE(desc.getAbout().empty());
207+
REQUIRE(desc.getDescription().empty());
208+
REQUIRE(desc.getCreators().size() == 0);
209+
210+
THEN("it can not be added to the archive")
211+
{
212+
REQUIRE(archive.addMetadata("file", desc) == LIBCOMBINE_OPERATION_FAILED);
213+
}
214+
215+
AND_WHEN("a description and created date is added it can be added")
216+
{
217+
desc.setDescription("some description");
218+
desc.setCreated(OmexDescription::getCurrentDateAndTime());
219+
REQUIRE(archive.addMetadata("file", desc) == LIBCOMBINE_OPERATION_SUCCESS);
220+
}
221+
222+
}
223+
}

0 commit comments

Comments
 (0)