END_TEST START_TEST (test_comp_flatten_unknown_withValidation_nostrip_5) { SBMLDocument* doc = TestFlattenedUnknownValidateNoStrip("unknown5.xml", "unknown5_flat_stay.xml"); SBMLErrorLog* errors = doc->getErrorLog(); fail_unless(errors->getNumErrors() == 0); //fail_unless(errors->contains(UnrequiredPackagePresent) == true); //fail_unless(errors->contains(CompFlatteningNotRecognisedNotReqd) == true); delete doc; }
END_TEST START_TEST (test_comp_flatten_unknown_17) { SBMLDocument* doc = TestFlattenedUnknownNoValidate("unknown17.xml", "unknown17_flat.xml"); SBMLErrorLog* errors = doc->getErrorLog(); fail_unless(errors->getNumErrors() == 3); fail_unless(errors->contains(UnrequiredPackagePresent) == true); fail_unless(errors->contains(CompFlatteningNotRecognisedNotReqd) == true); fail_unless(errors->contains(CompIdRefMayReferenceUnknownPackage) == true); delete doc; }
END_TEST START_TEST (test_comp_flatten_unknown_20) { SBMLDocument* doc = TestFlattenedUnknownAbortNone("unknown20.xml", "unknown20_flat.xml"); SBMLErrorLog* errors = doc->getErrorLog(); fail_unless(errors->getNumErrors() == 4); fail_unless(errors->contains(RequiredPackagePresent) == true); fail_unless(errors->contains(CompFlatteningNotRecognisedReqd) == true); fail_unless(errors->contains(CompIdRefMayReferenceUnknownPackage) == true); delete doc; }
END_TEST START_TEST (test_comp_flatten_unknown_withValidation_nostrip_4) { SBMLDocument* doc = TestFlattenedUnknownValidateNoStrip("unknown4.xml", "unknown4_flat_stay.xml"); SBMLErrorLog* errors = doc->getErrorLog(); fail_unless(errors->getNumErrors() == 0); //fail_unless(errors->contains(RequiredPackagePresent) == true); //fail_unless(errors->contains(CompFlatteningNotRecognisedReqd) == true); //fail_unless(errors->contains(CompLineNumbersUnreliable) == true); //fail_unless(errors->contains(CompIdRefMayReferenceUnknownPackage) == true); delete doc; }
END_TEST START_TEST (test_comp_flatten_unknown_21) { string filename(TestDataDirectory); //string filename("C:\\Development\\libsbml\\src\\sbml\\packages\\comp\\util\\test\\test-data\\"); ConversionProperties props; props.addOption("flatten comp"); props.addOption("basePath", filename); props.addOption("performValidation", false); SBMLConverter* converter = SBMLConverterRegistry::getInstance().getConverterFor(props); // load document string cfile = filename + "flatten_fail_unknown.xml"; SBMLDocument* doc = readSBMLFromFile(cfile.c_str()); // fail if there is no model (readSBMLFromFile always returns a valid document) fail_unless(doc->getModel() != NULL); // write the doc before we attempt conversion string newModel = writeSBMLToStdString(doc); converter->setDocument(doc); int result = converter->convert(); // we should fail because we are testing the restoreNamespaces function fail_unless(result == LIBSBML_OPERATION_FAILED); string flatModel = writeSBMLToStdString(doc); fail_unless(flatModel == newModel); delete converter; SBMLErrorLog* errors = doc->getErrorLog(); fail_unless(errors->getNumErrors() == 2); fail_unless(errors->contains(RequiredPackagePresent) == true); fail_unless(errors->contains(CompFlatteningNotRecognisedReqd) == true); //fail_unless(errors->contains(CompModelFlatteningFailed) == true); //fail_unless(errors->contains(CompSubmodelMustReferenceModel) == true); delete doc; }
/* * Reads the expected attributes into the member data variables */ void ClassOne::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("vers", VersClassOneAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("vers", VersClassOneAllowedCoreAttributes, pkgVersion, level, version, details); } } if (pkgVersion == 1) { readV1Attributes(attributes); } else { readV2Attributes(attributes); } }
/* * Reads the expected attributes into the member data variables */ void CoordinateComponent::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); if (static_cast<ListOfCoordinateComponents*>(getParentSBMLObject())->size() < 2) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialGeometryLOCoordinateComponentsAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialGeometryLOCoordinateComponentsAllowedCoreAttributes, pkgVersion, level, version, details); } } } SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialCoordinateComponentAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialCoordinateComponentAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "required" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<CoordinateComponent>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { logError(SpatialIdSyntaxRule, level, version, "The id '" + mId + "' does " "not conform to the syntax."); } } else { std::string message = "Spatial attribute 'id' is missing from the " "<CoordinateComponent> element."; log->logPackageError("spatial", SpatialCoordinateComponentAllowedAttributes, pkgVersion, level, version, message); } // // type enum (use = "required" ) // std::string type; assigned = attributes.readInto("type", type); if (assigned == true) { if (type.empty() == true) { logEmptyString(type, level, version, "<CoordinateComponent>"); } else { mType = CoordinateKind_fromString(type.c_str()); if (CoordinateKind_isValid(mType) == 0) { std::string msg = "The type on the <CoordinateComponent> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + type + "', which is not a valid option."; log->logPackageError("spatial", SpatialCoordinateComponentTypeMustBeCoordinateKindEnum, pkgVersion, level, version, msg); } } } else { std::string message = "Spatial attribute 'type' is missing."; log->logPackageError("spatial", SpatialCoordinateComponentAllowedAttributes, pkgVersion, level, version, message); } // // unit UnitSIdRef (use = "optional" ) // assigned = attributes.readInto("unit", mUnit); if (assigned == true) { if (mUnit.empty() == true) { logEmptyString(mUnit, level, version, "<CoordinateComponent>"); } else if (SyntaxChecker::isValidSBMLSId(mUnit) == false) { logError(SpatialCoordinateComponentUnitMustBeUnitSId, level, version, "The attribute unit='" + mUnit + "' does not conform to the syntax."); } } }
/* * Reads the expected attributes into the member data variables */ void Group::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); if (static_cast<ListOfGroups*>(getParentSBMLObject())->size() < 2) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("groups", GroupsGroupAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("groups", GroupsModelLOGroupsAllowedCoreAttributes, pkgVersion, level, version, details); } } } SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("groups", GroupsGroupAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("groups", GroupsGroupAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "optional" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<Group>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { log->logPackageError("groups", GroupsIdSyntaxRule, pkgVersion, level, version, "The id on the <" + getElementName() + "> is '" + mId + "', which does not conform to the syntax.", getLine(), getColumn()); } } // // name string (use = "optional" ) // assigned = attributes.readInto("name", mName); if (assigned == true) { if (mName.empty() == true) { logEmptyString(mName, level, version, "<Group>"); } } // // kind enum (use = "required" ) // std::string kind; assigned = attributes.readInto("kind", kind); if (assigned == true) { if (kind.empty() == true) { logEmptyString(kind, level, version, "<Group>"); } else { mKind = GroupKind_fromString(kind.c_str()); if (GroupKind_isValid(mKind) == 0) { std::string msg = "The kind on the <Group> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + kind + "', which is not a valid option."; log->logPackageError("groups", GroupsGroupKindMustBeGroupKindEnum, pkgVersion, level, version, msg); } } } else { std::string message = "Groups attribute 'kind' is missing."; log->logPackageError("groups", GroupsGroupAllowedAttributes, pkgVersion, level, version, message); } }
/* * Reads the expected attributes into the member data variables */ void Uncertainty::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("distrib", DistribUncertaintyAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("distrib", DistribUncertaintyAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "optional" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<Uncertainty>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { logError(DistribIdSyntaxRule, level, version, "The id '" + mId + "' does " "not conform to the syntax."); } } // // name string (use = "optional" ) // assigned = attributes.readInto("name", mName); if (assigned == true) { if (mName.empty() == true) { logEmptyString(mName, level, version, "<Uncertainty>"); } } }
/* * Performs a set of semantic consistency checks on the document. Query * the results by calling getNumErrors() and getError(). * * @return the number of failed checks (errors) encountered. */ unsigned int SBMLInternalValidator::checkConsistency (bool writeDocument) { unsigned int nerrors = 0; unsigned int total_errors = 0; //if (getLevel() == 3) //{ // logError(L3NotSupported); // return 1; //} /* determine which validators to run */ bool id = ((mApplicableValidators & 0x01) == 0x01); bool sbml = ((mApplicableValidators & 0x02) == 0x02); bool sbo = ((mApplicableValidators & 0x04) == 0x04); bool math = ((mApplicableValidators & 0x08) == 0x08); bool units = ((mApplicableValidators & 0x10) == 0x10); bool over = ((mApplicableValidators & 0x20) == 0x20); bool practice = ((mApplicableValidators & 0x40) == 0x40); /* taken the state machine concept out for now if (LibSBMLStateMachine::isActive()) { units = LibSBMLStateMachine::getUnitState(); } */ IdentifierConsistencyValidator id_validator; ConsistencyValidator validator; SBOConsistencyValidator sbo_validator; MathMLConsistencyValidator math_validator; UnitConsistencyValidator unit_validator; OverdeterminedValidator over_validator; ModelingPracticeValidator practice_validator; SBMLDocument *doc; SBMLErrorLog *log = getErrorLog(); if (writeDocument) { char* sbmlString = writeSBMLToString(getDocument()); log->clearLog(); doc = readSBMLFromString(sbmlString); free (sbmlString); } else { doc = getDocument(); } /* calls each specified validator in turn * - stopping when errors are encountered */ if (id) { id_validator.init(); nerrors = id_validator.validate(*doc); if (nerrors > 0) { unsigned int origNum = log->getNumErrors(); log->add( id_validator.getFailures() ); if (origNum > 0 && log->contains(InvalidUnitIdSyntax) == true) { /* do not log dangling ref */ while (log->contains(DanglingUnitSIdRef) == true) { log->remove(DanglingUnitSIdRef); nerrors--; } total_errors += nerrors; if (nerrors > 0) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } else if (log->contains(DanglingUnitSIdRef) == false) { total_errors += nerrors; if (writeDocument) SBMLDocument_free(doc); return total_errors; } else { bool onlyDangRef = true; for (unsigned int a = 0; a < log->getNumErrors(); a++) { if (log->getError(a)->getErrorId() != DanglingUnitSIdRef) { onlyDangRef = false; break; } } total_errors += nerrors; if (onlyDangRef == false) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } } } if (sbml) { validator.init(); nerrors = validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add( validator.getFailures() ); /* only want to bail if errors not warnings */ if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } } if (sbo) { sbo_validator.init(); nerrors = sbo_validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add( sbo_validator.getFailures() ); /* only want to bail if errors not warnings */ if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } } if (math) { math_validator.init(); nerrors = math_validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add( math_validator.getFailures() ); /* at this point bail if any problems * unit checks may crash if there have been math errors/warnings */ if (writeDocument) SBMLDocument_free(doc); return total_errors; } } if (units) { unit_validator.init(); nerrors = unit_validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add( unit_validator.getFailures() ); /* only want to bail if errors not warnings */ if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } } /* do not even try if there have been unit warnings * changed this as would have bailed */ if (over) { over_validator.init(); nerrors = over_validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add( over_validator.getFailures() ); /* only want to bail if errors not warnings */ if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } } if (practice) { practice_validator.init(); nerrors = practice_validator.validate(*doc); if (nerrors > 0) { unsigned int errorsAdded = 0; const std::list<SBMLError> practiceErrors = practice_validator.getFailures(); list<SBMLError>::const_iterator end = practiceErrors.end(); list<SBMLError>::const_iterator iter; for (iter = practiceErrors.begin(); iter != end; ++iter) { if (SBMLError(*iter).getErrorId() != 80701) { log->add( SBMLError(*iter) ); errorsAdded++; } else { if (units) { log->add( SBMLError(*iter) ); errorsAdded++; } } } total_errors += errorsAdded; } } if (writeDocument) SBMLDocument_free(doc); return total_errors; }
/* * Reads the expected attributes into the member data variables */ void AnalyticVolume::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); if (static_cast<ListOfAnalyticVolumes*>(getParentSBMLObject())->size() < 2) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialAnalyticGeometryLOAnalyticVolumesAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialAnalyticGeometryLOAnalyticVolumesAllowedCoreAttributes, pkgVersion, level, version, details); } } } SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialAnalyticVolumeAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialAnalyticVolumeAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "required" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<AnalyticVolume>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { logError(SpatialIdSyntaxRule, level, version, "The id '" + mId + "' does " "not conform to the syntax."); } } else { std::string message = "Spatial attribute 'id' is missing from the " "<AnalyticVolume> element."; log->logPackageError("spatial", SpatialAnalyticVolumeAllowedAttributes, pkgVersion, level, version, message); } // // functionType enum (use = "required" ) // std::string functiontype; assigned = attributes.readInto("functionType", functiontype); if (assigned == true) { if (functiontype.empty() == true) { logEmptyString(functiontype, level, version, "<AnalyticVolume>"); } else { mFunctionType = FunctionKind_fromString(functiontype.c_str()); if (FunctionKind_isValid(mFunctionType) == 0) { std::string msg = "The functionType on the <AnalyticVolume> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + functiontype + "', which is not a valid option."; log->logPackageError("spatial", SpatialAnalyticVolumeFunctionTypeMustBeFunctionKindEnum, pkgVersion, level, version, msg); } } } else { std::string message = "Spatial attribute 'functionType' is missing."; log->logPackageError("spatial", SpatialAnalyticVolumeAllowedAttributes, pkgVersion, level, version, message); } // // ordinal int (use = "optional" ) // numErrs = log->getNumErrors(); mIsSetOrdinal = attributes.readInto("ordinal", mOrdinal); if ( mIsSetOrdinal == false) { if (log->getNumErrors() == numErrs + 1 && log->contains(XMLAttributeTypeMismatch)) { log->remove(XMLAttributeTypeMismatch); std::string message = "Spatial attribute 'ordinal' from the " "<AnalyticVolume> element must be an integer."; log->logPackageError("spatial", SpatialAnalyticVolumeOrdinalMustBeInteger, pkgVersion, level, version, message); } } // // domainType SIdRef (use = "required" ) // assigned = attributes.readInto("domainType", mDomainType); if (assigned == true) { if (mDomainType.empty() == true) { logEmptyString(mDomainType, level, version, "<AnalyticVolume>"); } else if (SyntaxChecker::isValidSBMLSId(mDomainType) == false) { logError(SpatialAnalyticVolumeDomainTypeMustBeDomainType, level, version, "The attribute domainType='" + mDomainType + "' does not conform to the " "syntax."); } } else { std::string message = "Spatial attribute 'domainType' is missing from the " "<AnalyticVolume> element."; log->logPackageError("spatial", SpatialAnalyticVolumeAllowedAttributes, pkgVersion, level, version, message); } }
/* * Reads the expected attributes into the member data variables */ void ListOfGlobalRenderInformation::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; SBMLErrorLog* log = getErrorLog(); ListOf::readAttributes(attributes, expectedAttributes); if (log) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("render", RenderListOfLayoutsLOGlobalRenderInformationAllowedAttributes, pkgVersion, level, version, details, getLine(), getColumn()); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("render", RenderListOfLayoutsLOGlobalRenderInformationAllowedCoreAttributes, pkgVersion, level, version, details, getLine(), getColumn()); } } } // // majorVersion uint (use = "optional" ) // if (log) { numErrs = log->getNumErrors(); } mIsSetMajorVersion = attributes.readInto("versionMajor", mMajorVersion); if ( mIsSetMajorVersion == false && log) { if (log->getNumErrors() == numErrs + 1 && log->contains(XMLAttributeTypeMismatch)) { log->remove(XMLAttributeTypeMismatch); std::string message = "Render attribute 'versionMajor' from the " "<ListOfGlobalRenderInformation> element must be an integer."; log->logPackageError("render", RenderListOfLayoutsVersionMajorMustBeNonNegativeInteger, pkgVersion, level, version, message, getLine(), getColumn()); } } // // minorVersion uint (use = "optional" ) // if (log) { numErrs = log->getNumErrors(); } mIsSetMinorVersion = attributes.readInto("versionMinor", mMinorVersion); if ( mIsSetMinorVersion == false && log) { if (log->getNumErrors() == numErrs + 1 && log->contains(XMLAttributeTypeMismatch)) { log->remove(XMLAttributeTypeMismatch); std::string message = "Render attribute 'versionMinor' from the " "<ListOfGlobalRenderInformation> element must be an integer."; log->logPackageError("render", RenderListOfLayoutsVersionMinorMustBeNonNegativeInteger, pkgVersion, level, version, message, getLine(), getColumn()); } } }
/* * Reads the expected attributes into the member data variables */ void CSGNode::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); if (static_cast<ListOfCSGNodes*>(getParentSBMLObject())->size() < 2) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialCSGObjectLOCSGNodesAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialCSGObjectLOCSGNodesAllowedCoreAttributes, pkgVersion, level, version, details); } } } SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialCSGNodeAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialCSGNodeAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "optional" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<CSGNode>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { logError(SpatialIdSyntaxRule, level, version, "The id '" + mId + "' does " "not conform to the syntax."); } } }
/* * Reads the expected attributes into the member data variables */ void ClassThree::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("test", TestClassThreeAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("test", TestClassThreeAllowedCoreAttributes, pkgVersion, level, version, details); } } // // number enum (use = "required" ) // std::string number; assigned = attributes.readInto("number", number); if (assigned == true) { if (number.empty() == true) { logEmptyString(number, level, version, "<ClassThree>"); } else { mNumber = Enum_fromString(number.c_str()); if (Enum_isValid(mNumber) == 0) { std::string msg = "The number on the <ClassThree> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + number + "', which is not a valid option."; log->logPackageError("test", TestClassThreeNumberMustBeEnumEnum, pkgVersion, level, version, msg); } } } else { std::string message = "Test attribute 'number' is missing."; log->logPackageError("test", TestClassThreeAllowedAttributes, pkgVersion, level, version, message); } // // name enum (use = "required" ) // std::string name; assigned = attributes.readInto("name", name); if (assigned == true) { if (name.empty() == true) { logEmptyString(name, level, version, "<ClassThree>"); } else { mName = Fred_fromString(name.c_str()); if (Fred_isValid(mName) == 0) { std::string msg = "The name on the <ClassThree> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + name + "', which is not a valid option."; log->logPackageError("test", TestClassThreeNameMustBeFredEnum, pkgVersion, level, version, msg); } } } else { std::string message = "Test attribute 'name' is missing."; log->logPackageError("test", TestClassThreeAllowedAttributes, pkgVersion, level, version, message); } // // badName enum (use = "optional" ) // std::string badname; assigned = attributes.readInto("badName", badname); if (assigned == true) { if (badname.empty() == true) { logEmptyString(badname, level, version, "<ClassThree>"); } else { mBadName = Fred_fromString(badname.c_str()); if (Fred_isValid(mBadName) == 0) { std::string msg = "The badName on the <ClassThree> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + badname + "', which is not a valid option."; log->logPackageError("test", TestClassThreeBadNameMustBeFredEnum, pkgVersion, level, version, msg); } } } // // otherNum enum (use = "optional" ) // std::string othernum; assigned = attributes.readInto("otherNum", othernum); if (assigned == true) { if (othernum.empty() == true) { logEmptyString(othernum, level, version, "<ClassThree>"); } else { mOtherNum = Enum_fromString(othernum.c_str()); if (Enum_isValid(mOtherNum) == 0) { std::string msg = "The otherNum on the <ClassThree> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + othernum + "', which is not a valid option."; log->logPackageError("test", TestClassThreeOtherNumMustBeEnumEnum, pkgVersion, level, version, msg); } } } }
/** @cond doxygenLibsbmlInternal */ int CompFlatteningConverter::validateFlatDocument(Model * flatmodel, unsigned int pkgVersion, unsigned int level, unsigned int version) { int result; // create a dummyDocument that will mirror what the user options are // we need the dummyDoc to know things about unknown packages // but dont want the original model/error log SBMLDocument dummy = SBMLDocument(*(mDocument)); dummy.setModel(NULL); dummy.getErrorLog()->clearLog(); // Otherwise, transfer only errors 1090107->1090110 SBMLErrorLog* log = mDocument->getErrorLog(); for (unsigned int en=0; en<log->getNumErrors(); en++) { unsigned int errid = mDocument->getError(en)->getErrorId(); if (errid == CompFlatteningNotRecognisedNotReqd || errid == CompFlatteningNotRecognisedReqd || errid == CompFlatteningNotImplementedNotReqd || errid == CompFlatteningNotImplementedReqd) { dummy.getErrorLog()->add(*(mDocument->getError(en))); } } log->clearLog(); result = reconstructDocument(flatmodel, dummy, true ); if (result != LIBSBML_OPERATION_SUCCESS) { //delete flatmodel; restoreNamespaces(); return result; } //Now check to see if the flat model is valid // run regular validation on the flattened document if requested. // override comp flattening if necessary CompSBMLDocumentPlugin * dummyPlugin = static_cast<CompSBMLDocumentPlugin*> (dummy.getPlugin("comp")); if (dummyPlugin != NULL) { dummyPlugin->setOverrideCompFlattening(true); } std::string sbml = writeSBMLToStdString(&dummy); SBMLDocument *tempdoc = readSBMLFromString(sbml.c_str()); unsigned int errors = tempdoc->getErrorLog()->getNumFailsWithSeverity(LIBSBML_SEV_ERROR); // take out the error about a requiredpackage // if the user has specified to not abort for any packages // NOTE: we cannot actually remove it since the flattening code // uses it to check whether references might come from // other packages if (getAbortForNone() == true) { if (tempdoc->getErrorLog()->contains(RequiredPackagePresent)) { errors--; } } if (errors > 0) { // we have serious errors so we are going to bail on the // flattening - log ONLY the errors //Transfer the errors to mDocument and don't reset the model. if (log->contains(CompLineNumbersUnreliable) == false) { log->logPackageError("comp", CompLineNumbersUnreliable, pkgVersion, level, version); } std::string message = "Errors that follow relate to the flattened "; message += "document produced using the CompFlatteningConverter."; log->logPackageError("comp", CompFlatModelNotValid, pkgVersion, level, version); unsigned int nerrors = tempdoc->getErrorLog()->getNumErrors(); for (unsigned int n = 0; n < nerrors; n++) { const SBMLError* error = tempdoc->getError(n); if (error->getSeverity() >= LIBSBML_SEV_ERROR) { log->add( *(error) ); } if (error->getErrorId() >= CompFlatteningNotRecognisedNotReqd && error->getErrorId() <= CompFlatteningNotImplementedReqd) { log->add( *(error) ); } else if (error->getErrorId() == UnrequiredPackagePresent || error->getErrorId() == RequiredPackagePresent) { log->add( *(error) ); } } //delete flatmodel; restoreNamespaces(); delete tempdoc; return LIBSBML_CONV_INVALID_SRC_DOCUMENT; } else { delete tempdoc; } dummy.checkConsistency(); if (dummyPlugin != NULL) { dummyPlugin->setOverrideCompFlattening(false); } errors = dummy.getErrorLog()->getNumFailsWithSeverity(LIBSBML_SEV_ERROR); if (errors > 0) { // we have serious errors so we are going to bail on the // flattening - log ONLY the errors //Transfer the errors to mDocument and don't reset the model. if (log->contains(CompLineNumbersUnreliable) == false) { log->logPackageError("comp", CompLineNumbersUnreliable, pkgVersion, level, version); } std::string message = "Errors that follow relate to the flattened "; message += "document produced using the CompFlatteningConverter."; log->logPackageError("comp", CompFlatModelNotValid, pkgVersion, level, version); unsigned int nerrors = dummy.getErrorLog()->getNumErrors(); for (unsigned int n = 0; n < nerrors; n++) { const SBMLError* error = dummy.getError(n); if (error->getSeverity() >= LIBSBML_SEV_ERROR) { log->add( *(error) ); } if (error->getErrorId() >= CompFlatteningNotRecognisedNotReqd && error->getErrorId() <= CompFlatteningNotImplementedReqd) { log->add( *(error) ); } else if (error->getErrorId() == UnrequiredPackagePresent || error->getErrorId() == RequiredPackagePresent) { log->add( *(error) ); } } //delete flatmodel; restoreNamespaces(); return LIBSBML_CONV_INVALID_SRC_DOCUMENT; } else { // put any warnings into the document that will be have the // flat model unsigned int nerrors = dummy.getErrorLog()->getNumErrors(); for (unsigned int n = 0; n < nerrors; n++) { const SBMLError* error = dummy.getError(n); log->add( *(error) ); } return LIBSBML_OPERATION_SUCCESS; } }
/* * Reads the expected attributes into the member data variables */ void Output::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); if (static_cast<ListOfOutputs*>(getParentSBMLObject())->size() < 2) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("qual", QualTransitionLOOutputsAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("qual", QualTransitionLOOutputsAllowedCoreAttributes, pkgVersion, level, version, details); } } } SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("qual", QualOutputAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("qual", QualOutputAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "optional" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<Output>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { logError(QualIdSyntaxRule, level, version, "The id '" + mId + "' does not " "conform to the syntax."); } } // // qualitativeSpecies SIdRef (use = "required" ) // assigned = attributes.readInto("qualitativeSpecies", mQualitativeSpecies); if (assigned == true) { if (mQualitativeSpecies.empty() == true) { logEmptyString(mQualitativeSpecies, level, version, "<Output>"); } else if (SyntaxChecker::isValidSBMLSId(mQualitativeSpecies) == false) { logError(QualOutputQualitativeSpeciesMustBeQualitativeSpecies, level, version, "The attribute qualitativeSpecies='" + mQualitativeSpecies + "' " "does not conform to the syntax."); } } else { std::string message = "Qual attribute 'qualitativeSpecies' is missing from " "the <Output> element."; log->logPackageError("qual", QualOutputAllowedAttributes, pkgVersion, level, version, message); } // // transitionEffect enum (use = "required" ) // std::string transitioneffect; assigned = attributes.readInto("transitionEffect", transitioneffect); if (assigned == true) { if (transitioneffect.empty() == true) { logEmptyString(transitioneffect, level, version, "<Output>"); } else { mTransitionEffect = TransitionOutputEffect_fromString(transitioneffect.c_str()); if (TransitionOutputEffect_isValid(mTransitionEffect) == 0) { std::string msg = "The transitionEffect on the <Output> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + transitioneffect + "', which is not a valid option."; log->logPackageError("qual", QualOutputTransitionEffectMustBeTransitionOutputEffectEnum, pkgVersion, level, version, msg); } } } else { std::string message = "Qual attribute 'transitionEffect' is missing."; log->logPackageError("qual", QualOutputAllowedAttributes, pkgVersion, level, version, message); } // // name string (use = "optional" ) // assigned = attributes.readInto("name", mName); if (assigned == true) { if (mName.empty() == true) { logEmptyString(mName, level, version, "<Output>"); } } // // outputLevel int (use = "optional" ) // numErrs = log->getNumErrors(); mIsSetOutputLevel = attributes.readInto("outputLevel", mOutputLevel); if ( mIsSetOutputLevel == false) { if (log->getNumErrors() == numErrs + 1 && log->contains(XMLAttributeTypeMismatch)) { log->remove(XMLAttributeTypeMismatch); std::string message = "Qual attribute 'outputLevel' from the <Output> " "element must be an integer."; log->logPackageError("qual", QualOutputOutputLevelMustBeInteger, pkgVersion, level, version, message); } } }