COPASI API  4.16.103
test000052.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000052.cpp,v $
3 // $Revision: 1.9 $
4 // $Name: $
5 // $Author: bergmann $
6 // $Date: 2012/05/16 06:24:49 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #include "test000052.h"
20 
21 #include <sstream>
22 #include "utilities.hpp"
24 #include "copasi/model/CModel.h"
25 #include "copasi/model/CMetab.h"
28 #include "copasi/model/CReaction.h"
31 
33 
34 CCopasiDataModel* test000052::pCOPASIDATAMODEL = NULL;
35 
37 {
38  // Create the root container.
39  CCopasiRootContainer::init(0, NULL, false);
40  // Create the global data model.
42 }
43 
45 {
47 }
48 
50 {
51  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
52  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING));
53  CModel* pModel = pDataModel->getModel();
54  CPPUNIT_ASSERT(pModel != NULL);
55  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
56  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
57  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
58  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
59  const CCompartment* pCompartment = pModel->getCompartments()[0];
60  CPPUNIT_ASSERT(pCompartment != NULL);
61  CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED);
62  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
63  CMetab* pA = pModel->getMetabolites()[0];
64  CPPUNIT_ASSERT(pA != NULL);
65  CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::ASSIGNMENT);
66  const CExpression* pExpr = pA->getExpressionPtr();
67  // check the expression
68  const CEvaluationNode* pNode = pExpr->getRoot();
69  CPPUNIT_ASSERT(pNode != NULL);
70  const CEvaluationNodeChoice* pChoiceNode = dynamic_cast<const CEvaluationNodeChoice*>(pNode);
71  CPPUNIT_ASSERT(pChoiceNode != NULL);
72  pNode = dynamic_cast<const CEvaluationNode*>(pChoiceNode->getChild());
73  CPPUNIT_ASSERT(pNode != NULL);
74  const CEvaluationNodeLogical* pLogicalNode = dynamic_cast<const CEvaluationNodeLogical*>(pNode);
75  CPPUNIT_ASSERT(pLogicalNode != NULL);
77  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pLogicalNode->getChild());
78  CPPUNIT_ASSERT(pObjectNode != NULL);
79  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
80  CPPUNIT_ASSERT(!objectCN.empty());
81  std::vector<CCopasiContainer*> listOfContainers;
82  listOfContainers.push_back(pModel);
83  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
84  CPPUNIT_ASSERT(pObject != NULL);
85  CPPUNIT_ASSERT(pObject->isReference() == true);
86  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
87  CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
88  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling());
89  CPPUNIT_ASSERT(pNumberNode != NULL);
91  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 5.0) / 5.0) < 1e-3);
92  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pLogicalNode->getSibling());
93  CPPUNIT_ASSERT(pNumberNode != NULL);
95  CPPUNIT_ASSERT(pNumberNode->getValue() < 1e-3);
96  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNumberNode->getSibling());
97  CPPUNIT_ASSERT(pNumberNode != NULL);
99  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 10.0) / 10.0) < 1e-3);
100 
101  CPPUNIT_ASSERT(pModel->getModelValues().size() == 0);
102  CPPUNIT_ASSERT(pModel->getReactions().size() == 0);
103 }
104 
105 const char* test000052::MODEL_STRING =
106  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
107  "<sbml xmlns=\"http://www.sbml.org/sbml/level2\" level=\"2\" version=\"1\">\n"
108  " <model id=\"Model_1\" name=\"New Model\">\n"
109  " <notes>\n"
110  " <body xmlns=\"http://www.w3.org/1999/xhtml\"/>\n"
111  " </notes>\n"
112  " <listOfUnitDefinitions>\n"
113  " <unitDefinition id=\"volume\">\n"
114  " <listOfUnits>\n"
115  " <unit kind=\"litre\" scale=\"-3\"/>\n"
116  " </listOfUnits>\n"
117  " </unitDefinition>\n"
118  " <unitDefinition id=\"substance\">\n"
119  " <listOfUnits>\n"
120  " <unit kind=\"mole\" scale=\"-3\"/>\n"
121  " </listOfUnits>\n"
122  " </unitDefinition>\n"
123  " </listOfUnitDefinitions>\n"
124  " <listOfCompartments>\n"
125  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
126  " </listOfCompartments>\n"
127  " <listOfSpecies>\n"
128  " <species id=\"species_1\" name=\"species\" compartment=\"compartment_1\" initialConcentration=\"0\" boundaryCondition=\"true\"/>\n"
129  " </listOfSpecies>\n"
130  " <listOfRules>\n"
131  " <assignmentRule variable=\"species_1\">\n"
132  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
133  " <piecewise>\n"
134  " <piece>\n"
135  " <cn> 0 </cn>\n"
136  " <apply>\n"
137  " <lt/>\n"
138  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/time\"> time </csymbol>\n"
139  " <cn> 5 </cn>\n"
140  " </apply>\n"
141  " </piece>\n"
142  " <otherwise>\n"
143  " <cn> 10 </cn>\n"
144  " </otherwise>\n"
145  " </piecewise>\n"
146  " </math>\n"
147  " </assignmentRule>\n"
148  " </listOfRules>\n"
149  " </model>\n"
150  "</sbml>\n"
151  ;
Header file of class CExpression.
Header file of class CModelEntity and CModelValue.
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000052.h:32
const std::string & getObjectName() const
const Type & getType() const
Definition: CMetab.h:178
bool isReference() const
void test_bug988()
Definition: test000052.cpp:49
static CCopasiDataModel * addDatamodel()
static Type subType(const Type &type)
void setUp()
Definition: test000052.cpp:36
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
static void init(int argc, char *argv[], const bool &withGui=false)
Definition: CModel.h:50
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
CCopasiContainer * getObjectParent() const
static const char * MODEL_STRING
Definition: test000052.h:31
void tearDown()
Definition: test000052.cpp:44