diff --git a/src/sbml/conversion/test/TestInferUnitsConverter.cpp b/src/sbml/conversion/test/TestInferUnitsConverter.cpp index 2270f5df64..6f7cf819ea 100644 --- a/src/sbml/conversion/test/TestInferUnitsConverter.cpp +++ b/src/sbml/conversion/test/TestInferUnitsConverter.cpp @@ -392,6 +392,31 @@ START_TEST (test_infer_localParam_fromReaction) END_TEST +START_TEST (test_infer_reaction_with_4_params_func_call) +{ + string filename(TestDataDirectory); + filename += "inferUnits-4.xml"; + + SBMLDocument* d = readSBMLFromFile(filename.c_str()); + + fail_unless(d != NULL); + + SBMLInferUnitsConverter * units = new SBMLInferUnitsConverter(); + + units->setDocument(d); + + fail_unless (units->convert() == LIBSBML_OPERATION_SUCCESS); + + // TO DO infer units using the function formula + // fail_unless(d->getModel()->getParameter("k1")->isSetUnits() == true); + // fail_unless(d->getModel()->getParameter("k1")->getUnits() == "unitSid_0"); + + delete units; + delete d; +} +END_TEST + + Suite * create_suite_TestInferUnitsConverter (void) { @@ -409,6 +434,7 @@ create_suite_TestInferUnitsConverter (void) tcase_add_test(tcase, test_infer_baseUnit_fromMath); tcase_add_test(tcase, test_infer_fromReaction); tcase_add_test(tcase, test_infer_localParam_fromReaction); + tcase_add_test(tcase, test_infer_reaction_with_4_params_func_call); suite_add_tcase(suite, tcase); diff --git a/src/sbml/conversion/test/test-data/inferUnits-4.xml b/src/sbml/conversion/test/test-data/inferUnits-4.xml new file mode 100644 index 0000000000..c1c9900f96 --- /dev/null +++ b/src/sbml/conversion/test/test-data/inferUnits-4.xml @@ -0,0 +1,82 @@ + + + + + + + + + InR + + + Ins + + + cellsurface + + + extracellular + + + k1 + + + + k1 + Ins + extracellular + InR + cellsurface + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + function_1 + InR + Ins + cellsurface + extracellular + k1 + + + + + + + diff --git a/src/sbml/units/UnitFormulaFormatter.cpp b/src/sbml/units/UnitFormulaFormatter.cpp index dc0ea7b72e..3ccddaa060 100644 --- a/src/sbml/units/UnitFormulaFormatter.cpp +++ b/src/sbml/units/UnitFormulaFormatter.cpp @@ -377,7 +377,10 @@ UnitFormulaFormatter::getUnitDefinitionFromFunction(const ASTNode * node, if(node->getType() == AST_FUNCTION) { - const FunctionDefinition *fd = + // The function name get lost by ASTNode::reduceToBinary when it has more + // than one parameter. So we need to check we have a name before calling + // model->getFunctionDefinition to avoid crashing. + const FunctionDefinition *fd = node->getName() == NULL ? NULL : model->getFunctionDefinition(node->getName()); if (fd && fd->isSetMath()) {