From c1f813c355d200a7bdd6073ad55a43588aec01a2 Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Tue, 27 Aug 2024 09:48:45 +0200 Subject: [PATCH] - add test --- src/sbml/SBMLDocument.h | 1 + src/sbml/test/TestConsistencyChecks.cpp | 46 +++++++++++++++++++++++++ src/sbml/validator/Validator.cpp | 3 +- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/sbml/SBMLDocument.h b/src/sbml/SBMLDocument.h index b8609589bb..676828e01d 100644 --- a/src/sbml/SBMLDocument.h +++ b/src/sbml/SBMLDocument.h @@ -344,6 +344,7 @@ class SBMLLevelVersionConverter; #define StrictUnitsCheckON 0x80 #define StrictUnitsCheckOFF 0x7f #define AllChecksON 0x7f +#define AllChecksONWithStrictUnits 0xff /** @endcond */ diff --git a/src/sbml/test/TestConsistencyChecks.cpp b/src/sbml/test/TestConsistencyChecks.cpp index 26a8c24a7d..55671d3b9c 100644 --- a/src/sbml/test/TestConsistencyChecks.cpp +++ b/src/sbml/test/TestConsistencyChecks.cpp @@ -150,10 +150,55 @@ START_TEST (test_strict_unit_consistency_checks) fail_unless(d->getError(0)->getErrorId() == 10513); fail_unless(d->getError(0)->getSeverity() == LIBSBML_SEV_ERROR); + d->getErrorLog()->clearLog(); + + // now once more as warning + errors = d->checkConsistencyWithStrictUnits(LIBSBML_OVERRIDE_WARNING); + + fail_unless(errors == 1); + fail_unless(d->getError(0)->getErrorId() == 10513); + fail_unless(d->getError(0)->getSeverity() == LIBSBML_SEV_WARNING); + + + delete d; } END_TEST +START_TEST (test_check_consistency_settings) +{ + SBMLReader reader; + SBMLDocument* d; + unsigned int errors; + std::string filename(TestDataDirectory); + filename += "l3v1-units.xml"; + + + d = reader.readSBML(filename); + + if (d == NULL) + { + fail("readSBML(\"l3v1-units.xml\") returned a NULL pointer."); + } + + errors = d->checkConsistency(); + + fail_unless(errors == 0); + + d->getErrorLog()->clearLog(); + + // now enable the strict units check + d->setConsistencyChecks(LIBSBML_CAT_STRICT_UNITS_CONSISTENCY, true); + + errors = d->checkConsistency(); + + fail_unless(errors == 1); + fail_unless(d->getError(0)->getErrorId() == 10513); + fail_unless(d->getError(0)->getSeverity() == LIBSBML_SEV_WARNING); + + delete d; +} +END_TEST Suite * create_suite_TestConsistencyChecks (void) @@ -164,6 +209,7 @@ create_suite_TestConsistencyChecks (void) tcase_add_test(tcase, test_consistency_checks); tcase_add_test(tcase, test_strict_unit_consistency_checks); + tcase_add_test(tcase, test_check_consistency_settings); suite_add_tcase(suite, tcase); diff --git a/src/sbml/validator/Validator.cpp b/src/sbml/validator/Validator.cpp index 8fbc809bc5..6bfc230e38 100644 --- a/src/sbml/validator/Validator.cpp +++ b/src/sbml/validator/Validator.cpp @@ -864,7 +864,8 @@ Validator::validate (const SBMLDocument& d) if (m != NULL) { - if (this->getCategory() == LIBSBML_CAT_UNITS_CONSISTENCY) + if (this->getCategory() == LIBSBML_CAT_UNITS_CONSISTENCY || + this->getCategory() == LIBSBML_CAT_STRICT_UNITS_CONSISTENCY) { /* create list of formula units for validation */ if (!m->isPopulatedListFormulaUnitsData())