COPASI API  4.16.103
test000054.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000054.cpp,v $
3 // $Revision: 1.6 $
4 // $Name: $
5 // $Author: gauges $
6 // $Date: 2010/03/11 11:52:00 $
7 // End CVS Header
8 
9 // Copyright (C) 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 "test000054.h"
20 
21 #include <sstream>
22 #include "utilities.hpp"
24 
25 #include "sbml/SBMLDocument.h"
26 #include "sbml/Model.h"
27 #include "sbml/Rule.h"
28 #include "sbml/Species.h"
29 #include "sbml/Parameter.h"
30 #include "sbml/math/ASTNode.h"
31 
33 
34 CCopasiDataModel* test000054::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  // load the CPS file
52  // export to SBML
53  // check the resulting SBML model
54  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
55  std::istringstream iss(test000054::MODEL_STRING);
56  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
57  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
58  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 3).empty() == false);
59  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
60  CPPUNIT_ASSERT(pDocument != NULL);
61  Model* pSBMLModel = pDocument->getModel();
62  CPPUNIT_ASSERT(pSBMLModel != NULL);
63  CPPUNIT_ASSERT(pSBMLModel->getNumCompartments() == 0);
64  CPPUNIT_ASSERT(pSBMLModel->getNumSpecies() == 0);
65  CPPUNIT_ASSERT(pSBMLModel->getNumReactions() == 0);
66  CPPUNIT_ASSERT(pSBMLModel->getNumInitialAssignments() == 0);
67  CPPUNIT_ASSERT(pSBMLModel->getNumParameters() == 5);
68  const Parameter* pParameter1 = pSBMLModel->getParameter(0);
69  CPPUNIT_ASSERT(pParameter1 != NULL);
70  CPPUNIT_ASSERT(pParameter1->getConstant() == false);
71  const Parameter* pParameter2 = pSBMLModel->getParameter(1);
72  CPPUNIT_ASSERT(pParameter2 != NULL);
73  CPPUNIT_ASSERT(pParameter2->getConstant() == false);
74  const Parameter* pParameter3 = pSBMLModel->getParameter(2);
75  CPPUNIT_ASSERT(pParameter3 != NULL);
76  CPPUNIT_ASSERT(pParameter3->getConstant() == false);
77  const Parameter* pParameter4 = pSBMLModel->getParameter(3);
78  CPPUNIT_ASSERT(pParameter4 != NULL);
79  CPPUNIT_ASSERT(pParameter4->getConstant() == false);
80  const Parameter* pParameter5 = pSBMLModel->getParameter(4);
81  CPPUNIT_ASSERT(pParameter5 != NULL);
82  CPPUNIT_ASSERT(pParameter5->getConstant() == false);
83  CPPUNIT_ASSERT(pSBMLModel->getNumRules() == 5);
84 
85  const Rule* pRule = pSBMLModel->getRule(0);
86  CPPUNIT_ASSERT(pRule != NULL);
87  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
88  const AssignmentRule* pARule = dynamic_cast<const AssignmentRule*>(pRule);
89  CPPUNIT_ASSERT(pARule != NULL);
90  CPPUNIT_ASSERT(pARule->getVariable() == pParameter4->getId());
91  CPPUNIT_ASSERT(pARule->isSetMath() == true);
92  const ASTNode* pMath = pARule->getMath();
93  CPPUNIT_ASSERT(pMath != NULL);
94  CPPUNIT_ASSERT(pMath->getType() == AST_PLUS);
95  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
96  const ASTNode* pChild1 = pMath->getChild(0);
97  CPPUNIT_ASSERT(pChild1 != NULL);
98  CPPUNIT_ASSERT(pChild1->getType() == AST_REAL);
99  CPPUNIT_ASSERT(fabs((pChild1->getReal() - 2.0) / 2.0) < 1e-15);
100  const ASTNode* pChild2 = pMath->getChild(1);
101  CPPUNIT_ASSERT(pChild2 != NULL);
102  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
103  CPPUNIT_ASSERT(fabs((pChild2->getReal() - 4.0) / 4.0) < 1e-15);
104 
105  pRule = pSBMLModel->getRule(1);
106  CPPUNIT_ASSERT(pRule != NULL);
107  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
108  pARule = dynamic_cast<const AssignmentRule*>(pRule);
109  CPPUNIT_ASSERT(pARule != NULL);
110  CPPUNIT_ASSERT(pARule->getVariable() == pParameter1->getId());
111  CPPUNIT_ASSERT(pARule->isSetMath() == true);
112  pMath = pARule->getMath();
113  CPPUNIT_ASSERT(pMath != NULL);
114  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
115  CPPUNIT_ASSERT(pMath->getName() == pParameter4->getId());
116  CPPUNIT_ASSERT(pMath->getNumChildren() == 0);
117 
118  pRule = pSBMLModel->getRule(2);
119  CPPUNIT_ASSERT(pRule != NULL);
120  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
121  pARule = dynamic_cast<const AssignmentRule*>(pRule);
122  CPPUNIT_ASSERT(pARule != NULL);
123  CPPUNIT_ASSERT(pARule->getVariable() == pParameter3->getId());
124  CPPUNIT_ASSERT(pARule->isSetMath() == true);
125  pMath = pARule->getMath();
126  CPPUNIT_ASSERT(pMath != NULL);
127  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
128  CPPUNIT_ASSERT(pMath->getName() == pParameter1->getId());
129  CPPUNIT_ASSERT(pMath->getNumChildren() == 0);
130 
131  pRule = pSBMLModel->getRule(3);
132  CPPUNIT_ASSERT(pRule != NULL);
133  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
134  pARule = dynamic_cast<const AssignmentRule*>(pRule);
135  CPPUNIT_ASSERT(pARule != NULL);
136  CPPUNIT_ASSERT(pARule->getVariable() == pParameter5->getId());
137  CPPUNIT_ASSERT(pARule->isSetMath() == true);
138  pMath = pARule->getMath();
139  CPPUNIT_ASSERT(pMath != NULL);
140  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
141  CPPUNIT_ASSERT(pMath->getName() == pParameter3->getId());
142  CPPUNIT_ASSERT(pMath->getNumChildren() == 0);
143 
144  pRule = pSBMLModel->getRule(4);
145  CPPUNIT_ASSERT(pRule != NULL);
146  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
147  pARule = dynamic_cast<const AssignmentRule*>(pRule);
148  CPPUNIT_ASSERT(pARule != NULL);
149  CPPUNIT_ASSERT(pARule->getVariable() == pParameter2->getId());
150  CPPUNIT_ASSERT(pARule->isSetMath() == true);
151  pMath = pARule->getMath();
152  CPPUNIT_ASSERT(pMath != NULL);
153  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
154  CPPUNIT_ASSERT(pMath->getName() == pParameter5->getId());
155  CPPUNIT_ASSERT(pMath->getNumChildren() == 0);
156 }
157 
158 const char* test000054::MODEL_STRING =
159  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
160  "<!-- generated with COPASI 4.3.25 (Debug) (http://www.copasi.org) at 2008-03-08 18:49:47 UTC -->\n"
161  "<COPASI xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.copasi.org/static/schema.xsd\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"25\">\n"
162  " <Model key=\"Model_1\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"mmol\" type=\"deterministic\">\n"
163  " <Comment>\n"
164  " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
165  " \n"
166  " </body>\n"
167  " </Comment>\n"
168  " <ListOfModelValues>\n"
169  " <ModelValue key=\"ModelValue_0\" name=\"A\" simulationType=\"assignment\">\n"
170  " <Expression>\n"
171  " &lt;CN=Root,Model=New Model,Vector=Values[D],Reference=Value&gt;\n"
172  " </Expression>\n"
173  " </ModelValue>\n"
174  " <ModelValue key=\"ModelValue_1\" name=\"B\" simulationType=\"assignment\">\n"
175  " <Expression>\n"
176  " &lt;CN=Root,Model=New Model,Vector=Values[E],Reference=Value&gt;\n"
177  " </Expression>\n"
178  " </ModelValue>\n"
179  " <ModelValue key=\"ModelValue_2\" name=\"C\" simulationType=\"assignment\">\n"
180  " <Expression>\n"
181  " &lt;CN=Root,Model=New Model,Vector=Values[A],Reference=Value&gt;\n"
182  " </Expression>\n"
183  " </ModelValue>\n"
184  " <ModelValue key=\"ModelValue_3\" name=\"D\" simulationType=\"assignment\">\n"
185  " <Expression>\n"
186  " 2+4\n"
187  " </Expression>\n"
188  " </ModelValue>\n"
189  " <ModelValue key=\"ModelValue_4\" name=\"E\" simulationType=\"assignment\">\n"
190  " <Expression>\n"
191  " &lt;CN=Root,Model=New Model,Vector=Values[C],Reference=Value&gt;\n"
192  " </Expression>\n"
193  " </ModelValue>\n"
194  " </ListOfModelValues>\n"
195  " <StateTemplate>\n"
196  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
197  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
198  " <StateTemplateVariable objectReference=\"ModelValue_1\"/>\n"
199  " <StateTemplateVariable objectReference=\"ModelValue_2\"/>\n"
200  " <StateTemplateVariable objectReference=\"ModelValue_3\"/>\n"
201  " <StateTemplateVariable objectReference=\"ModelValue_4\"/>\n"
202  " </StateTemplate>\n"
203  " <InitialState type=\"initialState\">\n"
204  " 0 NaN NaN NaN 3 7\n"
205  " </InitialState>\n"
206  " </Model>\n"
207  "</COPASI>\n"
208  ;
void tearDown()
Definition: test000054.cpp:44
SBMLDocument * getCurrentSBMLDocument()
void test_bug1002()
Definition: test000054.cpp:49
void setUp()
Definition: test000054.cpp:36
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000054.h:32
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static const char * MODEL_STRING
Definition: test000054.h:31
static CCopasiDataModel * addDatamodel()
static void init(int argc, char *argv[], const bool &withGui=false)