END_TEST


START_TEST (test_GroupsExtension_read_L3V1V1_defaultNS)
{
  char *filename = safe_strcat(TestDataDirectory, "groups-example1-defaultNS.xml");
  SBMLDocument *document = readSBMLFromFile(filename);
  
  fail_unless(document->getPackageName() == "core");

  Model *model = document->getModel();

  document->printErrors();

  fail_unless(model != NULL);
  fail_unless(document->getNumErrors() == 0);

  // get the Group

  GroupsModelPlugin* mplugin = static_cast<GroupsModelPlugin*>(model->getPlugin("groups"));
  fail_unless(mplugin != NULL);

  fail_unless(mplugin->getNumGroups() == 1);
  fail_unless(mplugin->getListOfGroups()->getPackageName() == "groups");

  Group* group = mplugin->getGroup(0);
  fail_unless(group->getId()          == "ATP");
  fail_unless(group->getSBOTermID()   == "SBO:0000252");
  fail_unless(group->getKind()        == GROUP_KIND_CLASSIFICATION);
  fail_unless(group->isSetKind()      == true);
  fail_unless(!strcmp(GroupKind_toString(group->getKind()), "classification"));
  fail_unless(group->getNumMembers()  == 2);
  fail_unless(group->getPackageName() == "groups");

  fail_unless(group->getListOfMembers()->getPackageName() == "groups");

  Member* member = group->getMember(0);
  fail_unless(member->getIdRef()      == "ATPc");
  fail_unless(member->getPackageName() == "groups");

  member = group->getMember(1);
  fail_unless(member->getIdRef()      == "ATPm");
  fail_unless(member->getPackageName() == "groups");

  delete document;  
  safe_free(filename);
}
END_TEST


START_TEST (test_GroupsModelPlugin_copyNesting2)
{
  //GroupsPkgNamespaces gpn;
  //SBMLDocument doc(&gpn);
  char *filename = safe_strcat(TestDataDirectory, "groups-nested1.xml");
  SBMLDocument *document = readSBMLFromFile(filename);
  Model* model = document->getModel();
  fail_unless(model != NULL);
  GroupsModelPlugin* mplugin = static_cast<GroupsModelPlugin*>(model->getPlugin("groups"));
  fail_unless(mplugin != NULL);

  fail_unless(mplugin->getNumGroups() == 4);
  Group* group1 = mplugin->getGroup(0);
  Group* group2 = mplugin->getGroup(1);
  Group* group3 = mplugin->getGroup(2);
  Group* group4 = mplugin->getGroup(3);
  group3->getListOfMembers()->setSBOTerm(5);
  mplugin->copyInformationToNestedLists();
  fail_unless(!group1->getListOfMembers()->isSetSBOTerm());
  fail_unless( group2->getListOfMembers()->getSBOTerm() == 5);
  fail_unless( group3->getListOfMembers()->getSBOTerm() == 5);
  fail_unless( group4->getListOfMembers()->getSBOTerm() == 252);

  group4->getListOfMembers()->setNotes("These are some notes, v1.", true);
  group3->getListOfMembers()->setNotes("These are some notes, v2.", true);
  mplugin->copyInformationToNestedLists();
  fail_unless(!group1->getListOfMembers()->isSetNotes());
  fail_unless( group2->getListOfMembers()->getNotesString().find("These are some notes, v2.") != string::npos);
  fail_unless( group3->getListOfMembers()->getNotesString().find("These are some notes, v2.") != string::npos);
  fail_unless( group4->getListOfMembers()->getNotesString().find("These are some notes, v1.") != string::npos);

  group4->getListOfMembers()->setAnnotation("This is a malformed annotation, v1.");
  group3->getListOfMembers()->setAnnotation("This is a malformed annotation, v2.");
  mplugin->copyInformationToNestedLists();
  fail_unless(!group1->getListOfMembers()->isSetAnnotation());
  fail_unless( group2->getListOfMembers()->getAnnotationString().find("This is a malformed annotation, v2.") != string::npos);
  fail_unless( group3->getListOfMembers()->getAnnotationString().find("This is a malformed annotation, v2.") != string::npos);
  fail_unless( group4->getListOfMembers()->getAnnotationString().find("This is a malformed annotation, v1.") != string::npos);

  delete document;
  safe_free((void*)(filename));
}
END_TEST


START_TEST (test_GroupsExtension_read_memberConstraints)
{
  char *filename = safe_strcat(TestDataDirectory, "groups_speciestype_example.xml");
  SBMLDocument *document = readSBMLFromFile(filename);
  fail_unless(document->getPackageName() == "core");

  Model *model = document->getModel();

  fail_unless(model != NULL);
  fail_unless(model->getPackageName() == "core");
  fail_unless(document->getNumErrors() == 0);

  // get the Group

  GroupsModelPlugin* mplugin = static_cast<GroupsModelPlugin*>(model->getPlugin("groups"));
  fail_unless(mplugin != NULL);

  fail_unless(mplugin->getNumGroups() == 1);
  fail_unless(mplugin->getListOfGroups()->getPackageName() == "groups");

  Group* group = mplugin->getGroup(0);
  fail_unless(group->getId()          == "ATP");
  fail_unless(group->getKind()        == GROUP_KIND_CLASSIFICATION);
  fail_unless(group->getNumMembers()  == 2);
  fail_unless(group->getNumMemberConstraints() == 3);
  fail_unless(group->getPackageName() == "groups");

  fail_unless(group->getListOfMembers()->getPackageName() == "groups");
  fail_unless(group->getListOfMembers()->getSBOTermID()   == "SBO:0000248");

  Member* member = group->getMember(0);
  fail_unless(member->getIdRef()      == "ATPc");
  fail_unless(member->getPackageName() == "groups");

  member = group->getMember(1);
  fail_unless(member->getIdRef()      == "ATPm");
  fail_unless(member->getPackageName() == "groups");

  ListOfMemberConstraints* lomcs = group->getListOfMemberConstraints();
  fail_unless(lomcs->getPackageName() == "groups");
  fail_unless(lomcs->isSetMembersShareType() == true);
  fail_unless(lomcs->getMembersShareType() == true);

  MemberConstraint* mc = group->getMemberConstraint(0);
  fail_unless(mc->isSetDistinctAttribute() == true);
  fail_unless(mc->isSetIdenticalAttribute() == false);
  fail_unless(mc->getDistinctAttribute() == "compartment");
  fail_unless(mc->getPackageName() == "groups");

  mc = group->getMemberConstraint(1);
  fail_unless(mc->isSetDistinctAttribute() == false);
  fail_unless(mc->isSetIdenticalAttribute() == true);
  fail_unless(mc->getIdenticalAttribute() == "initialConcentration");
  fail_unless(mc->getPackageName() == "groups");

  mc = group->getMemberConstraint(2);
  fail_unless(mc->isSetDistinctAttribute() == false);
  fail_unless(mc->isSetIdenticalAttribute() == true);
  fail_unless(mc->getIdenticalAttribute() == "constant");
  fail_unless(mc->getPackageName() == "groups");


  delete document;  
}
示例#4
0
LIBSBML_CPP_NAMESPACE_USE

int main(int argc,char** argv){

//
// Creates an SBMLNamespaces object with the given SBML level, version
// package name, package version.
//
// (NOTE) By defualt, the name of package (i.e. "groups") will be used
// if the arugment for the prefix is missing or empty. Thus the argument
// for the prefix can be added as follows:
//
//    SBMLNamespaces sbmlns(3,1,"groups",1,"GROUP");
//

SBMLNamespaces sbmlns(3,1,"groups",1);

//
// (NOTES) The above code creating an SBMLNamespaces object can be replaced 
//         with one of the following other styles.
//
// (1) Creates an SBMLNamespace object with a SBML core namespace and then
//     adds a groups package namespace to the object. 
//
//         SBMLNamespaces sbmlns(3,1);
//         sbmlns.addPkgNamespace("groups",1);
//
//          OR
//
//         SBMLNamespaces sbmlns(3,1);
//         sbmlns.addNamespace(GroupsExtension::XmlnsL3V1V1,"groups");
//
// (2) Creates a GroupsPkgNamespaces object (SBMLNamespace derived class for
//     groups package. The class is basically used for createing an SBase derived
//     objects defined in the groups package) with the given SBML level, version, 
//     and package version
//
//        GroupsPkgNamespaces sbmlns(3,1,1);
//     


// create the document

SBMLDocument *document = new SBMLDocument(&sbmlns);

// create the Model

Model* model=document->createModel();

// create the Compartment

Compartment* compartment = model->createCompartment();
compartment->setId("cytosol");
compartment->setConstant(true);

compartment=model->createCompartment();
compartment->setId("mitochon");
compartment->setConstant(true);

// create the Species

Species* species = model->createSpecies();
species->setId("ATPc");
species->setCompartment("cytosol");
species->setInitialConcentration(1);
species->setHasOnlySubstanceUnits(false);
species->setBoundaryCondition(false);
species->setConstant(false);

species = model->createSpecies();
species->setId("ATPm");
species->setCompartment("mitochon");
species->setInitialConcentration(2);
species->setHasOnlySubstanceUnits(false);
species->setBoundaryCondition(false);
species->setConstant(false);

// create the Groups

//
// Get a GroupsModelPlugin object plugged in the model object.
//
// The type of the returned value of SBase::getPlugin() function is SBasePlugin*, and
// thus the value needs to be casted for the corresponding derived class. 
//
GroupsModelPlugin* mplugin = static_cast<GroupsModelPlugin*>(model->getPlugin("groups"));

//
// Creates a Group object via GroupsModelPlugin object.
//
Group* group = mplugin->createGroup();

group->setId("ATP");
group->setKind(GROUP_KIND_CLASSIFICATION);
group->setSBOTerm("SBO:0000252");

Member* member = group->createMember();
member->setIdRef("ATPc");

member = group->createMember();
member->setIdRef("ATPm");

writeSBML(document,"groups_example1.xml");
delete document;

}