Skip to content

Commit

Permalink
#43 : return failure if metadata is not added
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Jul 20, 2021
1 parent f52e483 commit 2f3e6e0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.12
0.2.13
15 changes: 11 additions & 4 deletions src/combine/combinearchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,11 @@ std::string CombineArchive::getNextFilename(const std::string& prefix,
return fileName;
}

void CombineArchive::addMetadataToArchive(OmexDescription& desc, Zipper *zipper)
int
CombineArchive::addMetadataToArchive(OmexDescription& desc, Zipper *zipper)
{
if (desc.isEmpty() || zipper == NULL || mpManifest == NULL)
return;
return LIBCOMBINE_OPERATION_FAILED;

std::string fileName = getNextFilename("metadata", ".rdf");
std::stringstream content; content << desc.toXML();
Expand All @@ -203,7 +204,8 @@ void CombineArchive::addMetadataToArchive(OmexDescription& desc, Zipper *zipper)
entry->setLocation(fileName);
entry->setFormat(KnownFormats::lookupFormat("omex"));
entry->setMaster(false);


return LIBCOMBINE_OPERATION_SUCCESS;
}

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

void
int
CombineArchive::addMetadata(const std::string &targetName,
const OmexDescription &description)
{
if (description.isEmpty())
return LIBCOMBINE_OPERATION_FAILED;

mMetadataMap[targetName] = description;

return LIBCOMBINE_OPERATION_SUCCESS;
}

bool
Expand Down
13 changes: 11 additions & 2 deletions src/combine/combinearchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ class LIBCOMBINE_EXTERN CombineArchive
*
* @param targetName the name of the entry that the metadata is about
* @param description the metadata description
*
* @return status code indicating success or failure.
* @li @omexconstant{LIBCOMBINE_OPERATION_SUCCESS, OperationReturnValues_t}
* @li @omexconstant{LIBCOMBINE_OPERATION_FAILED, OperationReturnValues_t}
*/
void addMetadata(const std::string& targetName,
int addMetadata(const std::string& targetName,
const OmexDescription& description);

/**
Expand Down Expand Up @@ -361,8 +365,13 @@ class LIBCOMBINE_EXTERN CombineArchive
*
* @param desc the description to be added
* @param zipper the zipper to be used
*
* @return status code indicating success or failure.
* @li @omexconstant{LIBCOMBINE_OPERATION_SUCCESS, OperationReturnValues_t}
* @li @omexconstant{LIBCOMBINE_OPERATION_FAILED, OperationReturnValues_t}
*
*/
void addMetadataToArchive(OmexDescription& desc, zipper::Zipper* zipper);
int addMetadataToArchive(OmexDescription& desc, zipper::Zipper* zipper);
};

LIBCOMBINE_CPP_NAMESPACE_END
Expand Down
27 changes: 27 additions & 0 deletions src/test/combine_test_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,30 @@ SCENARIO("reading an existing archive", "[combine]")

}
}

SCENARIO("creating a combine archive", "[combine]")
{
CombineArchive archive;
REQUIRE(archive.getManifest() == NULL);

GIVEN("user adds invalid omex data")
{
OmexDescription desc;
REQUIRE(desc.getAbout().empty());
REQUIRE(desc.getDescription().empty());
REQUIRE(desc.getCreators().size() == 0);

THEN("it can not be added to the archive")
{
REQUIRE(archive.addMetadata("file", desc) == LIBCOMBINE_OPERATION_FAILED);
}

AND_WHEN("a description and created date is added it can be added")
{
desc.setDescription("some description");
desc.setCreated(OmexDescription::getCurrentDateAndTime());
REQUIRE(archive.addMetadata("file", desc) == LIBCOMBINE_OPERATION_SUCCESS);
}

}
}

0 comments on commit 2f3e6e0

Please sign in to comment.