END_TEST START_TEST (test_strip_comp) { std::string filename(TestDataDirectory); std::string fileIn = filename + "package1.xml"; SBMLDocument* d = readSBMLFromFile(fileIn.c_str()); fail_unless(d != NULL); ConversionProperties props; props.addOption("package", "comp"); SBMLConverter* converter = new SBMLStripPackageConverter(); converter->setProperties(&props); converter->setDocument(d); fail_unless (converter->convert() == LIBSBML_OPERATION_SUCCESS); std::string newModel = writeSBMLToStdString(d); std::string fileOut = filename + "package1-comp_stripped.xml"; SBMLDocument* fdoc = readSBMLFromFile(fileOut.c_str()); string stripped = writeSBMLToStdString(fdoc); fail_unless(stripped == newModel); delete converter; delete fdoc; delete d; }
END_TEST START_TEST (test_conversion_ruleconverter_with_alg) { // create test model SBMLDocument doc; 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* parameter2 = model->createParameter(); parameter2->setId("k"); parameter2->setConstant(false); parameter2->setValue(0); AlgebraicRule* rule0 = model->createAlgebraicRule(); rule0->setFormula("k + 2"); rule0->setMetaId("m0"); AssignmentRule* rule1 = model->createAssignmentRule(); rule1->setVariable("s"); rule1->setFormula("p + 1"); rule1->setMetaId("m1"); AssignmentRule* rule2 = model->createAssignmentRule(); rule2->setVariable("p"); rule2->setFormula("1"); rule2->setMetaId("m2"); ConversionProperties props; props.addOption("sortRules", true, "sort rules"); SBMLConverter* converter = new SBMLRuleConverter(); converter->setProperties(&props); converter->setDocument(&doc); fail_unless (converter->convert() == LIBSBML_OPERATION_SUCCESS); fail_unless (model->getNumRules() == 3); fail_unless (model->getRule(0)->getMetaId() == "m2"); fail_unless (model->getRule(1)->getMetaId() == "m1"); fail_unless (model->getRule(2)->getMetaId() == "m0"); delete converter; }
END_TEST START_TEST (test_conversion_ruleconverter_sortIA) { // create test model SBMLDocument doc; 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); InitialAssignment* ia1 = model->createInitialAssignment(); ia1->setSymbol("s"); ASTNode * math = SBML_parseFormula("p + 1"); ia1->setMath(math); delete math; ia1->setMetaId("m1"); InitialAssignment* ia2 = model->createInitialAssignment(); ia2->setSymbol("p"); math = SBML_parseFormula("1"); ia2->setMath(math); delete math; ia2->setMetaId("m2"); ConversionProperties props; props.addOption("sortRules", true, "sort rules"); SBMLConverter* converter = new SBMLRuleConverter(); converter->setProperties(&props); converter->setDocument(&doc); fail_unless (converter->convert() == LIBSBML_OPERATION_SUCCESS); fail_unless (model->getNumInitialAssignments() == 2); fail_unless (model->getInitialAssignment(0)->getMetaId() == "m2"); fail_unless (model->getInitialAssignment(1)->getMetaId() == "m1"); delete converter; }
SBMLConverter* SBMLConverterRegistry::getConverterFor(const ConversionProperties& props) const { std::vector<const SBMLConverter*>::const_iterator it; for (it = mConverters.begin(); it != mConverters.end(); it++) { if ((*it)->matchesProperties(props)) { SBMLConverter* converter = (*it)->clone(); converter->setProperties(&props); return converter; } } return NULL; }