Skip to content

Commit

Permalink
- dont crash on unsupported math
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Aug 27, 2024
1 parent bc7264b commit e78c883
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/sbml/conversion/SBMLRateRuleConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ SBMLRateRuleConverter::isPositive(const ASTNode* node, bool& posDeriv)
{
bool signDetermined = false;

if (!node)
return signDetermined;

// node will be refactored so should be able to detect sign from first child
ASTNodeType_t type = node->getType();

Expand Down
51 changes: 51 additions & 0 deletions src/sbml/conversion/test/TestSBMLRateRuleConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,56 @@ START_TEST(test_conversion_raterule_converter)
}
END_TEST


START_TEST(test_crash_converter)
{
ConversionProperties props;
props.addOption("inferReactions", true);

SBMLConverter* converter = new SBMLRateRuleConverter();
converter->setProperties(&props);

SBMLDocument* doc = new SBMLDocument(3, 2);
Model* model = doc->createModel();
model->setId("m");

Parameter* parameter1 = model->createParameter();
parameter1->setId("s");
parameter1->setConstant(false);
parameter1->setValue(0);

Parameter* parameter = model->createParameter();
parameter->setId("p");
parameter->setConstant(false);
parameter->setValue(0);

parameter = model->createParameter();
parameter->setId("k");
parameter->setConstant(true);
parameter->setValue(0);

RateRule* rr1 = model->createRateRule();
rr1->setVariable("s");
ASTNode *math = SBML_parseL3Formula("cos(s)");
rr1->setMath(math);
delete math;

RateRule* rr2 = model->createRateRule();
rr1->setVariable("s");
math = SBML_parseL3Formula("sin(s)");
rr1->setMath(math);
delete math;

converter->setDocument(doc);
fail_unless(converter->convert() == LIBSBML_OPERATION_FAILED);

delete converter;
delete doc;
}
END_TEST



START_TEST(test_conversion_raterule_converter_non_standard_stoichiometry)
{
// example 3.13 in Fages et al, TCS, 2015
Expand Down Expand Up @@ -681,6 +731,7 @@ create_suite_TestSBMLRateRuleConverter (void)
tcase_add_test(tcase, test_conversion_raterule_converter);
tcase_add_test(tcase, test_conversion_raterule_converter_non_standard_stoichiometry);
tcase_add_test(tcase, test_conversion_raterule_converter_hidden_variable);
tcase_add_test(tcase, test_crash_converter);
tcase_add_test(tcase, test_model);
tcase_add_test(tcase, test_model1);
tcase_add_test(tcase, test_model2);
Expand Down

0 comments on commit e78c883

Please sign in to comment.