Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/sbml/packages/comp/extension/CompSBMLDocumentPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,6 @@ CompSBMLDocumentPlugin::checkConsistency()
/* create dummy documents for the modelDefinitions */
for (unsigned int i = 0; i < numMD; i++)
{
mCheckingDummyDoc = true;
mFlattenAndCheck = false;
SBMLDocument dummyDoc = *doc;

/* a document clone does not clone the error log as this was deemed
Expand All @@ -893,6 +891,14 @@ CompSBMLDocumentPlugin::checkConsistency()
CompSBMLDocumentPlugin * dummyPlugin =
static_cast<CompSBMLDocumentPlugin*>(dummyDoc.getPlugin("comp"));

/* the dummy document checks its model only: the other model
* definitions and the flat model are checked by this document.
* The flags are set on the dummy alone, so that this document,
* a later check of it and its copies check everything again.
*/
dummyPlugin->mCheckingDummyDoc = true;
dummyPlugin->mFlattenAndCheck = false;

/* now swap the existing model with the modeldefinition */
ModelDefinition dummyDef(*dummyModel);
dummyPlugin->addModelDefinition(&dummyDef);
Expand Down Expand Up @@ -948,8 +954,6 @@ CompSBMLDocumentPlugin::checkConsistency()
return total_errors;
}
}

mFlattenAndCheck = true;
}


Expand Down
62 changes: 61 additions & 1 deletion src/sbml/packages/comp/extension/test/TestCheckConsistency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ END_TEST
START_TEST (test_comp_fail_whenflat)
{
string filename(TestDataDirectory);
string cfile = filename + "valid.xml";
string cfile = filename + "valid.xml";
SBMLDocument* doc = readSBMLFromFile(cfile.c_str());
doc->checkConsistency();
unsigned int nerrors = doc->getNumErrors();
Expand All @@ -118,6 +118,64 @@ START_TEST (test_comp_fail_whenflat)
}
END_TEST

/* an assignment rule of an undefined variable inside a model definition */
static const char* INVALID_MODEL_DEFINITION =
"<?xml version='1.0' encoding='UTF-8'?>"
"<sbml xmlns='http://www.sbml.org/sbml/level3/version1/core' "
"xmlns:comp='http://www.sbml.org/sbml/level3/version1/comp/version1' "
"level='3' version='1' comp:required='true'>"
"<model id='top'><comp:listOfSubmodels>"
"<comp:submodel comp:id='s0' comp:modelRef='md0'/>"
"</comp:listOfSubmodels></model>"
"<comp:listOfModelDefinitions><comp:modelDefinition id='md0'>"
"<listOfRules><assignmentRule variable='x'>"
"<math xmlns='http://www.w3.org/1998/Math/MathML'><cn>1</cn></math>"
"</assignmentRule></listOfRules>"
"</comp:modelDefinition></comp:listOfModelDefinitions></sbml>";


START_TEST (test_comp_fail_moddef_repeated)
{
SBMLDocument* doc = readSBMLFromString(INVALID_MODEL_DEFINITION);
doc->getErrorLog()->clearLog();

fail_unless (doc->checkConsistency() > 0);
fail_unless (doc->getErrorLog()->contains(InvalidAssignRuleVariable));

/* a second check of the same document checks the model definitions again */
doc->getErrorLog()->clearLog();
fail_unless (doc->checkConsistency() > 0);
fail_unless (doc->getErrorLog()->contains(InvalidAssignRuleVariable));

/* and so does a copy of a document which was checked */
SBMLDocument copy(*doc);
fail_unless (copy.checkConsistency() > 0);
fail_unless (copy.getErrorLog()->contains(InvalidAssignRuleVariable));

delete doc;
}
END_TEST


START_TEST (test_comp_fail_whenflat_repeated)
{
string filename(TestDataDirectory);
string cfile = filename + "valid.xml";
SBMLDocument* doc = readSBMLFromFile(cfile.c_str());
doc->checkConsistency();
fail_unless (doc->getNumErrors() == 6);

doc->getErrorLog()->clearLog();
doc->checkConsistency();
fail_unless (doc->getNumErrors() == 6);
fail_unless (doc->getError(0)->getErrorId() == 1090106);
fail_unless (doc->getError(1)->getErrorId() == 1090105);
fail_unless (doc->getError(2)->getErrorId() == 21111);

delete doc;
}
END_TEST

Suite *
create_suite_TestCheckConsistency(void)
{
Expand All @@ -128,6 +186,8 @@ create_suite_TestCheckConsistency(void)
tcase_add_test(tcase, test_comp_fail_20212);
tcase_add_test(tcase, test_comp_fail_90104);
tcase_add_test(tcase, test_comp_fail_whenflat);
tcase_add_test(tcase, test_comp_fail_moddef_repeated);
tcase_add_test(tcase, test_comp_fail_whenflat_repeated);

suite_add_tcase(suite, tcase);

Expand Down
20 changes: 14 additions & 6 deletions src/sbml/packages/comp/util/CompFlatteningConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,19 +529,27 @@ CompFlatteningConverter::reconstructDocument(Model * flatmodel,
if (dummyRecon == true)
{
result = dummyDoc.setModel(flatmodel);
dummyDoc.enablePackage
(CompExtension::getXmlnsL3V1V1(), "comp", true);
// need to make sure comp required attribute is set
// or validation of dummyDoc will fail
// the copied model has no comp plugins: give it empty ones
if (result == LIBSBML_OPERATION_SUCCESS)
{
dummyDoc.getModel()->enablePackageInternal
(CompExtension::getXmlnsL3V1V1(), "comp", true);
}
// need to make sure comp required attribute is set
// or validation of dummyDoc will fail
docPlug = static_cast<CompSBMLDocumentPlugin *>
(dummyDoc.getPlugin("comp"));
docPlug->setRequired(true);
}
else
{
result = mDocument->setModel(flatmodel);
mDocument->enablePackage
(CompExtension::getXmlnsL3V1V1(), "comp", true);
// the copied model has no comp plugins: give it empty ones
if (result == LIBSBML_OPERATION_SUCCESS)
{
mDocument->getModel()->enablePackageInternal
(CompExtension::getXmlnsL3V1V1(), "comp", true);
}
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions src/sbml/packages/comp/util/test/TestCompFlatteningConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,51 @@ START_TEST (test_comp_flatten_converter_properties3)
END_TEST


START_TEST (test_comp_flatten_converter_definitions_model_plugin)
{
string filename(TestDataDirectory);

ConversionProperties props;

props.addOption("flatten comp");
props.addOption("basePath", filename);
props.addOption("listModelDefinitions", true);

SBMLConverter* converter = SBMLConverterRegistry::getInstance().getConverterFor(props);

string cfile = filename + "test14.xml";
SBMLDocument* doc = readSBMLFromFile(cfile.c_str());

fail_unless(doc->getModel() != NULL);

converter->setDocument(doc);
int result = converter->convert();

fail_unless(result == LIBSBML_OPERATION_SUCCESS);

// the document keeps comp, so its flat model must have a comp plugin
CompSBMLDocumentPlugin* docPlug =
static_cast<CompSBMLDocumentPlugin*>(doc->getPlugin("comp"));
fail_unless(docPlug != NULL);
fail_unless(docPlug->getNumModelDefinitions() > 0);

CompModelPlugin* modelPlug =
dynamic_cast<CompModelPlugin*>(doc->getModel()->getPlugin("comp"));
fail_unless(modelPlug != NULL);
fail_unless(modelPlug->getNumSubmodels() == 0);
fail_unless(modelPlug->getNumPorts() == 0);

// checking the converted document swaps its model into the model definitions
doc->getErrorLog()->clearLog();
doc->checkConsistency();
fail_unless(doc->getErrorLog()->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) == 0);

delete doc;
delete converter;
}
END_TEST


START_TEST (test_comp_flatten_converter_properties4)
{
string filename(TestDataDirectory);
Expand Down Expand Up @@ -2223,6 +2268,7 @@ create_suite_TestFlatteningConverter (void)
tcase_add_test(tcase, test_comp_flatten_converter_properties1);
tcase_add_test(tcase, test_comp_flatten_converter_properties2);
tcase_add_test(tcase, test_comp_flatten_converter_properties3);
tcase_add_test(tcase, test_comp_flatten_converter_definitions_model_plugin);
tcase_add_test(tcase, test_comp_flatten_converter_properties4);
tcase_add_test(tcase, test_comp_flatten_converter_properties5);
tcase_add_test(tcase, test_comp_flatten_converter_properties6);
Expand Down
Loading