COPASI API  4.16.103
test000082.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000082.cpp,v $
3 // $Revision: 1.3 $
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 "test000082.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 
32 #include "sbml/math/ASTNode.h"
33 #include "sbml/SBMLDocument.h"
34 #include "sbml/Model.h"
35 #include "sbml/Compartment.h"
36 #include "sbml/Species.h"
37 #include "sbml/Parameter.h"
38 #include "sbml/Rule.h"
39 #include "sbml/UnitDefinition.h"
40 #include "sbml/Unit.h"
41 #include "sbml/UnitKind.h"
42 #include "sbml/Event.h"
43 #include "sbml/Trigger.h"
44 #include "sbml/Delay.h"
45 #include "sbml/EventAssignment.h"
46 
48 
49 CCopasiDataModel* test000082::pCOPASIDATAMODEL = NULL;
50 
52 {
53  // Create the root container.
54  CCopasiRootContainer::init(0, NULL, false);
55  // Create the global data model.
57 }
58 
60 {
62 }
63 
65 {
66  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
67  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING1));
68  CModel* pModel = pDataModel->getModel();
69  CPPUNIT_ASSERT(pModel != NULL);
70  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
71  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
72  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
73  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
74  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
75  CMetab* pA = pModel->getMetabolites()[0];
76  CPPUNIT_ASSERT(pA != NULL);
77  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
78  const CModelValue* pModelValue = pModel->getModelValues()[0];
79  CPPUNIT_ASSERT(pModelValue != NULL);
80  CPPUNIT_ASSERT(pModel->getEvents().size() == 1);
81  const CEvent* pEvent = pModel->getEvents()[0];
82  CPPUNIT_ASSERT(pEvent != NULL);
83  // check the trigger expression
84  const CExpression* pExpr = pEvent->getTriggerExpressionPtr();
85  CPPUNIT_ASSERT(pExpr != NULL);
86  const CEvaluationNode* pNode = pExpr->getRoot();
87  CPPUNIT_ASSERT(pNode != NULL);
88  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::LOGICAL);
90  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
91  CPPUNIT_ASSERT(pNode != NULL);
92  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
93  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
94  CPPUNIT_ASSERT(pObjectNode != NULL);
95  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
96  CPPUNIT_ASSERT(!objectCN.empty());
97  std::vector<CCopasiContainer*> listOfContainers;
98  listOfContainers.push_back(pModel);
99  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
100  CPPUNIT_ASSERT(pObject != NULL);
101  CPPUNIT_ASSERT(pObject->isReference() == true);
102  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
103  CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
104  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getSibling());
105  CPPUNIT_ASSERT(pNode != NULL);
106  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
107  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
108  CPPUNIT_ASSERT(pNumberNode != NULL);
109  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 2.0) / 2.0) < 1e-6);
110  // check that there is a delay
111  pExpr = pEvent->getDelayExpressionPtr();
112  CPPUNIT_ASSERT(pExpr != NULL);
113  pNode = pExpr->getRoot();
114  CPPUNIT_ASSERT(pNode != NULL);
115  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
116  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
117  CPPUNIT_ASSERT(pNumberNode != NULL);
118  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 10.0) / 10.0) < 1e-6);
119  // check that the delayAssignment flag is set to true
120  CPPUNIT_ASSERT(pEvent->getDelayAssignment() == true);
121 
122  CPPUNIT_ASSERT(pEvent->getAssignments().size() == 1);
123  // check the event assignment
124  std::string key = pEvent->getAssignments()[0]->getTargetKey();
125  CPPUNIT_ASSERT(key == pA->getKey());
126  pExpr = pEvent->getAssignments()[0]->getExpressionPtr();
127  CPPUNIT_ASSERT(pExpr != NULL);
128  pNode = pExpr->getRoot();
129  CPPUNIT_ASSERT(pNode != NULL);
130  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
131  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
132  CPPUNIT_ASSERT(pObjectNode != NULL);
133  objectCN = pObjectNode->getObjectCN();
134  CPPUNIT_ASSERT(!objectCN.empty());
135  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
136  CPPUNIT_ASSERT(pObject != NULL);
137  CPPUNIT_ASSERT(pObject->isReference() == true);
138  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
139  CPPUNIT_ASSERT(pObject->getObjectParent() == pModelValue);
140 }
141 
142 const char* test000082::MODEL_STRING1 =
143  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
144  "<sbml xmlns=\"http://www.sbml.org/sbml/level2\" level=\"2\" version=\"1\">"
145  " <model id=\"Model_1\" name=\"New Model\">"
146  " <notes>"
147  " <body xmlns=\"http://www.w3.org/1999/xhtml\">"
148  " <p>L2V1 model with event and delay expression.</p>"
149  " </body>"
150  " </notes>"
151  " <listOfUnitDefinitions>"
152  " <unitDefinition id=\"volume\">"
153  " <listOfUnits>"
154  " <unit kind=\"litre\" scale=\"-3\"/>"
155  " </listOfUnits>"
156  " </unitDefinition>"
157  " <unitDefinition id=\"substance\">"
158  " <listOfUnits>"
159  " <unit kind=\"mole\" scale=\"-3\"/>"
160  " </listOfUnits>"
161  " </unitDefinition>"
162  " </listOfUnitDefinitions>"
163  " <listOfCompartments>"
164  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>"
165  " </listOfCompartments>"
166  " <listOfSpecies>"
167  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\" />"
168  " </listOfSpecies>"
169  " <listOfParameters>"
170  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"false\"/>"
171  " </listOfParameters>"
172  " <listOfEvents>"
173  " <event>"
174  " <trigger>"
175  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
176  " <apply>"
177  " <gt/>"
178  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/time\"> time </csymbol>"
179  " <cn> 2.0 </cn>"
180  " </apply>"
181  " </math>"
182  " </trigger>"
183  " <delay>"
184  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
185  " <cn> 10 </cn>"
186  " </math>"
187  " </delay>"
188  " <listOfEventAssignments>"
189  " <eventAssignment variable=\"species_1\">"
190  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
191  " <ci> parameter_1 </ci>"
192  " </math>"
193  " </eventAssignment>"
194  " </listOfEventAssignments>"
195  " </event>"
196  " </listOfEvents>"
197  " </model>"
198  "</sbml>"
199  ;
200 
202 {
203  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
204  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING2));
205  CModel* pModel = pDataModel->getModel();
206  CPPUNIT_ASSERT(pModel != NULL);
207  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
208  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
209  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
210  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
211  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
212  CMetab* pA = pModel->getMetabolites()[0];
213  CPPUNIT_ASSERT(pA != NULL);
214  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
215  const CModelValue* pModelValue = pModel->getModelValues()[0];
216  CPPUNIT_ASSERT(pModelValue != NULL);
217  CPPUNIT_ASSERT(pModel->getEvents().size() == 1);
218  const CEvent* pEvent = pModel->getEvents()[0];
219  CPPUNIT_ASSERT(pEvent != NULL);
220  // check the trigger expression
221  const CExpression* pExpr = pEvent->getTriggerExpressionPtr();
222  CPPUNIT_ASSERT(pExpr != NULL);
223  const CEvaluationNode* pNode = pExpr->getRoot();
224  CPPUNIT_ASSERT(pNode != NULL);
225  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::LOGICAL);
227  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
228  CPPUNIT_ASSERT(pNode != NULL);
229  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
230  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
231  CPPUNIT_ASSERT(pObjectNode != NULL);
232  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
233  CPPUNIT_ASSERT(!objectCN.empty());
234  std::vector<CCopasiContainer*> listOfContainers;
235  listOfContainers.push_back(pModel);
236  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
237  CPPUNIT_ASSERT(pObject != NULL);
238  CPPUNIT_ASSERT(pObject->isReference() == true);
239  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
240  CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
241  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getSibling());
242  CPPUNIT_ASSERT(pNode != NULL);
243  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
244  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
245  CPPUNIT_ASSERT(pNumberNode != NULL);
246  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 2.0) / 2.0) < 1e-6);
247  // check that there is a delay
248  pExpr = pEvent->getDelayExpressionPtr();
249  CPPUNIT_ASSERT(pExpr == NULL);
250  // check that the delayAssignment flag is set to true
251  CPPUNIT_ASSERT(pEvent->getDelayAssignment() == true);
252 
253  CPPUNIT_ASSERT(pEvent->getAssignments().size() == 1);
254  // check the event assignment
255  std::string key = pEvent->getAssignments()[0]->getTargetKey();
256  CPPUNIT_ASSERT(key == pA->getKey());
257  pExpr = pEvent->getAssignments()[0]->getExpressionPtr();
258  CPPUNIT_ASSERT(pExpr != NULL);
259  pNode = pExpr->getRoot();
260  CPPUNIT_ASSERT(pNode != NULL);
261  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
262  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
263  CPPUNIT_ASSERT(pObjectNode != NULL);
264  objectCN = pObjectNode->getObjectCN();
265  CPPUNIT_ASSERT(!objectCN.empty());
266  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
267  CPPUNIT_ASSERT(pObject != NULL);
268  CPPUNIT_ASSERT(pObject->isReference() == true);
269  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
270  CPPUNIT_ASSERT(pObject->getObjectParent() == pModelValue);
271 }
272 
273 const char* test000082::MODEL_STRING2 =
274  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
275  "<sbml xmlns=\"http://www.sbml.org/sbml/level2\" level=\"2\" version=\"1\">"
276  " <model id=\"Model_1\" name=\"New Model\">"
277  " <notes>"
278  " <body xmlns=\"http://www.w3.org/1999/xhtml\">"
279  " <p>L2V1 model with event and delay expression.</p>"
280  " </body>"
281  " </notes>"
282  " <listOfUnitDefinitions>"
283  " <unitDefinition id=\"volume\">"
284  " <listOfUnits>"
285  " <unit kind=\"litre\" scale=\"-3\"/>"
286  " </listOfUnits>"
287  " </unitDefinition>"
288  " <unitDefinition id=\"substance\">"
289  " <listOfUnits>"
290  " <unit kind=\"mole\" scale=\"-3\"/>"
291  " </listOfUnits>"
292  " </unitDefinition>"
293  " </listOfUnitDefinitions>"
294  " <listOfCompartments>"
295  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>"
296  " </listOfCompartments>"
297  " <listOfSpecies>"
298  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\" />"
299  " </listOfSpecies>"
300  " <listOfParameters>"
301  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"false\"/>"
302  " </listOfParameters>"
303  " <listOfEvents>"
304  " <event>"
305  " <trigger>"
306  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
307  " <apply>"
308  " <gt/>"
309  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/time\"> time </csymbol>"
310  " <cn> 2.0 </cn>"
311  " </apply>"
312  " </math>"
313  " </trigger>"
314  " <listOfEventAssignments>"
315  " <eventAssignment variable=\"species_1\">"
316  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
317  " <ci> parameter_1 </ci>"
318  " </math>"
319  " </eventAssignment>"
320  " </listOfEventAssignments>"
321  " </event>"
322  " </listOfEvents>"
323  " </model>"
324  "</sbml>"
325  ;
326 
328 {
329  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
330  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING3));
331  CModel* pModel = pDataModel->getModel();
332  CPPUNIT_ASSERT(pModel != NULL);
333  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
334  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
335  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
336  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
337  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
338  CMetab* pA = pModel->getMetabolites()[0];
339  CPPUNIT_ASSERT(pA != NULL);
340  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
341  const CModelValue* pModelValue = pModel->getModelValues()[0];
342  CPPUNIT_ASSERT(pModelValue != NULL);
343  CPPUNIT_ASSERT(pModel->getEvents().size() == 1);
344  const CEvent* pEvent = pModel->getEvents()[0];
345  CPPUNIT_ASSERT(pEvent != NULL);
346  // check the trigger expression
347  const CExpression* pExpr = pEvent->getTriggerExpressionPtr();
348  CPPUNIT_ASSERT(pExpr != NULL);
349  const CEvaluationNode* pNode = pExpr->getRoot();
350  CPPUNIT_ASSERT(pNode != NULL);
351  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::LOGICAL);
353  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
354  CPPUNIT_ASSERT(pNode != NULL);
355  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
356  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
357  CPPUNIT_ASSERT(pObjectNode != NULL);
358  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
359  CPPUNIT_ASSERT(!objectCN.empty());
360  std::vector<CCopasiContainer*> listOfContainers;
361  listOfContainers.push_back(pModel);
362  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
363  CPPUNIT_ASSERT(pObject != NULL);
364  CPPUNIT_ASSERT(pObject->isReference() == true);
365  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
366  CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
367  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getSibling());
368  CPPUNIT_ASSERT(pNode != NULL);
369  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
370  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
371  CPPUNIT_ASSERT(pNumberNode != NULL);
372  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 2.0) / 2.0) < 1e-6);
373  // check that there is a delay
374  pExpr = pEvent->getDelayExpressionPtr();
375  CPPUNIT_ASSERT(pExpr != NULL);
376  pNode = pExpr->getRoot();
377  CPPUNIT_ASSERT(pNode != NULL);
378  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
379  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
380  CPPUNIT_ASSERT(pNumberNode != NULL);
381  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 10.0) / 10.0) < 1e-6);
382  // check that the delayAssignment flag is set to true
383  CPPUNIT_ASSERT(pEvent->getDelayAssignment() == true);
384 
385  CPPUNIT_ASSERT(pEvent->getAssignments().size() == 1);
386  // check the event assignment
387  std::string key = pEvent->getAssignments()[0]->getTargetKey();
388  CPPUNIT_ASSERT(key == pA->getKey());
389  pExpr = pEvent->getAssignments()[0]->getExpressionPtr();
390  CPPUNIT_ASSERT(pExpr != NULL);
391  pNode = pExpr->getRoot();
392  CPPUNIT_ASSERT(pNode != NULL);
393  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
394  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
395  CPPUNIT_ASSERT(pObjectNode != NULL);
396  objectCN = pObjectNode->getObjectCN();
397  CPPUNIT_ASSERT(!objectCN.empty());
398  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
399  CPPUNIT_ASSERT(pObject != NULL);
400  CPPUNIT_ASSERT(pObject->isReference() == true);
401  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
402  CPPUNIT_ASSERT(pObject->getObjectParent() == pModelValue);
403 }
404 
405 const char* test000082::MODEL_STRING3 =
406  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
407  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version4\" level=\"2\" version=\"4\">"
408  " <model id=\"Model_1\" name=\"New Model\">"
409  " <notes>"
410  " <body xmlns=\"http://www.w3.org/1999/xhtml\">"
411  " <p>L2V4 model with event and delay expression.</p>"
412  " </body>"
413  " </notes>"
414  " <listOfUnitDefinitions>"
415  " <unitDefinition id=\"volume\">"
416  " <listOfUnits>"
417  " <unit kind=\"litre\" scale=\"-3\"/>"
418  " </listOfUnits>"
419  " </unitDefinition>"
420  " <unitDefinition id=\"substance\">"
421  " <listOfUnits>"
422  " <unit kind=\"mole\" scale=\"-3\"/>"
423  " </listOfUnits>"
424  " </unitDefinition>"
425  " </listOfUnitDefinitions>"
426  " <listOfCompartments>"
427  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>"
428  " </listOfCompartments>"
429  " <listOfSpecies>"
430  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\" />"
431  " </listOfSpecies>"
432  " <listOfParameters>"
433  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"false\"/>"
434  " </listOfParameters>"
435  " <listOfEvents>"
436  " <event>"
437  " <trigger>"
438  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
439  " <apply>"
440  " <gt/>"
441  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/time\"> time </csymbol>"
442  " <cn> 2.0 </cn>"
443  " </apply>"
444  " </math>"
445  " </trigger>"
446  " <delay>"
447  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
448  " <cn> 10 </cn>"
449  " </math>"
450  " </delay>"
451  " <listOfEventAssignments>"
452  " <eventAssignment variable=\"species_1\">"
453  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
454  " <ci> parameter_1 </ci>"
455  " </math>"
456  " </eventAssignment>"
457  " </listOfEventAssignments>"
458  " </event>"
459  " </listOfEvents>"
460  " </model>"
461  "</sbml>"
462  ;
463 
465 {
466  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
467  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING4));
468  CModel* pModel = pDataModel->getModel();
469  CPPUNIT_ASSERT(pModel != NULL);
470  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
471  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
472  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
473  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
474  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
475  CMetab* pA = pModel->getMetabolites()[0];
476  CPPUNIT_ASSERT(pA != NULL);
477  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
478  const CModelValue* pModelValue = pModel->getModelValues()[0];
479  CPPUNIT_ASSERT(pModelValue != NULL);
480  CPPUNIT_ASSERT(pModel->getEvents().size() == 1);
481  const CEvent* pEvent = pModel->getEvents()[0];
482  CPPUNIT_ASSERT(pEvent != NULL);
483  // check the trigger expression
484  const CExpression* pExpr = pEvent->getTriggerExpressionPtr();
485  CPPUNIT_ASSERT(pExpr != NULL);
486  const CEvaluationNode* pNode = pExpr->getRoot();
487  CPPUNIT_ASSERT(pNode != NULL);
488  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::LOGICAL);
490  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
491  CPPUNIT_ASSERT(pNode != NULL);
492  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
493  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
494  CPPUNIT_ASSERT(pObjectNode != NULL);
495  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
496  CPPUNIT_ASSERT(!objectCN.empty());
497  std::vector<CCopasiContainer*> listOfContainers;
498  listOfContainers.push_back(pModel);
499  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
500  CPPUNIT_ASSERT(pObject != NULL);
501  CPPUNIT_ASSERT(pObject->isReference() == true);
502  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
503  CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
504  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getSibling());
505  CPPUNIT_ASSERT(pNode != NULL);
506  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
507  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
508  CPPUNIT_ASSERT(pNumberNode != NULL);
509  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 2.0) / 2.0) < 1e-6);
510  // check that there is a delay
511  pExpr = pEvent->getDelayExpressionPtr();
512  CPPUNIT_ASSERT(pExpr != NULL);
513  pNode = pExpr->getRoot();
514  CPPUNIT_ASSERT(pNode != NULL);
515  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
516  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
517  CPPUNIT_ASSERT(pNumberNode != NULL);
518  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 10.0) / 10.0) < 1e-6);
519  // check that the delayAssignment flag is set to true
520  CPPUNIT_ASSERT(pEvent->getDelayAssignment() == true);
521 
522  CPPUNIT_ASSERT(pEvent->getAssignments().size() == 1);
523  // check the event assignment
524  std::string key = pEvent->getAssignments()[0]->getTargetKey();
525  CPPUNIT_ASSERT(key == pA->getKey());
526  pExpr = pEvent->getAssignments()[0]->getExpressionPtr();
527  CPPUNIT_ASSERT(pExpr != NULL);
528  pNode = pExpr->getRoot();
529  CPPUNIT_ASSERT(pNode != NULL);
530  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
531  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
532  CPPUNIT_ASSERT(pObjectNode != NULL);
533  objectCN = pObjectNode->getObjectCN();
534  CPPUNIT_ASSERT(!objectCN.empty());
535  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
536  CPPUNIT_ASSERT(pObject != NULL);
537  CPPUNIT_ASSERT(pObject->isReference() == true);
538  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
539  CPPUNIT_ASSERT(pObject->getObjectParent() == pModelValue);
540 }
541 
542 const char* test000082::MODEL_STRING4 =
543  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
544  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version4\" level=\"2\" version=\"4\">"
545  " <model id=\"Model_1\" name=\"New Model\">"
546  " <notes>"
547  " <body xmlns=\"http://www.w3.org/1999/xhtml\">"
548  " <p>L2V4 model with event and delay expression.</p>"
549  " </body>"
550  " </notes>"
551  " <listOfUnitDefinitions>"
552  " <unitDefinition id=\"volume\">"
553  " <listOfUnits>"
554  " <unit kind=\"litre\" scale=\"-3\"/>"
555  " </listOfUnits>"
556  " </unitDefinition>"
557  " <unitDefinition id=\"substance\">"
558  " <listOfUnits>"
559  " <unit kind=\"mole\" scale=\"-3\"/>"
560  " </listOfUnits>"
561  " </unitDefinition>"
562  " </listOfUnitDefinitions>"
563  " <listOfCompartments>"
564  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>"
565  " </listOfCompartments>"
566  " <listOfSpecies>"
567  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\" />"
568  " </listOfSpecies>"
569  " <listOfParameters>"
570  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"false\"/>"
571  " </listOfParameters>"
572  " <listOfEvents>"
573  " <event useValuesFromTriggerTime=\"true\">"
574  " <trigger>"
575  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
576  " <apply>"
577  " <gt/>"
578  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/time\"> time </csymbol>"
579  " <cn> 2.0 </cn>"
580  " </apply>"
581  " </math>"
582  " </trigger>"
583  " <delay>"
584  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
585  " <cn> 10 </cn>"
586  " </math>"
587  " </delay>"
588  " <listOfEventAssignments>"
589  " <eventAssignment variable=\"species_1\">"
590  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
591  " <ci> parameter_1 </ci>"
592  " </math>"
593  " </eventAssignment>"
594  " </listOfEventAssignments>"
595  " </event>"
596  " </listOfEvents>"
597  " </model>"
598  "</sbml>"
599  ;
600 
602 {
603  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
604  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING5));
605  CModel* pModel = pDataModel->getModel();
606  CPPUNIT_ASSERT(pModel != NULL);
607  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
608  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
609  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
610  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
611  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
612  CMetab* pA = pModel->getMetabolites()[0];
613  CPPUNIT_ASSERT(pA != NULL);
614  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
615  const CModelValue* pModelValue = pModel->getModelValues()[0];
616  CPPUNIT_ASSERT(pModelValue != NULL);
617  CPPUNIT_ASSERT(pModel->getEvents().size() == 1);
618  const CEvent* pEvent = pModel->getEvents()[0];
619  CPPUNIT_ASSERT(pEvent != NULL);
620  // check the trigger expression
621  const CExpression* pExpr = pEvent->getTriggerExpressionPtr();
622  CPPUNIT_ASSERT(pExpr != NULL);
623  const CEvaluationNode* pNode = pExpr->getRoot();
624  CPPUNIT_ASSERT(pNode != NULL);
625  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::LOGICAL);
627  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
628  CPPUNIT_ASSERT(pNode != NULL);
629  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
630  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
631  CPPUNIT_ASSERT(pObjectNode != NULL);
632  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
633  CPPUNIT_ASSERT(!objectCN.empty());
634  std::vector<CCopasiContainer*> listOfContainers;
635  listOfContainers.push_back(pModel);
636  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
637  CPPUNIT_ASSERT(pObject != NULL);
638  CPPUNIT_ASSERT(pObject->isReference() == true);
639  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
640  CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
641  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getSibling());
642  CPPUNIT_ASSERT(pNode != NULL);
643  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
644  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
645  CPPUNIT_ASSERT(pNumberNode != NULL);
646  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 2.0) / 2.0) < 1e-6);
647  // check that there is a delay
648  pExpr = pEvent->getDelayExpressionPtr();
649  CPPUNIT_ASSERT(pExpr != NULL);
650  pNode = pExpr->getRoot();
651  CPPUNIT_ASSERT(pNode != NULL);
652  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
653  pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
654  CPPUNIT_ASSERT(pNumberNode != NULL);
655  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 10.0) / 10.0) < 1e-6);
656  // check that the delayAssignment flag is set to false
657  CPPUNIT_ASSERT(pEvent->getDelayAssignment() == false);
658 
659  CPPUNIT_ASSERT(pEvent->getAssignments().size() == 1);
660  // check the event assignment
661  std::string key = pEvent->getAssignments()[0]->getTargetKey();
662  CPPUNIT_ASSERT(key == pA->getKey());
663  pExpr = pEvent->getAssignments()[0]->getExpressionPtr();
664  CPPUNIT_ASSERT(pExpr != NULL);
665  pNode = pExpr->getRoot();
666  CPPUNIT_ASSERT(pNode != NULL);
667  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
668  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
669  CPPUNIT_ASSERT(pObjectNode != NULL);
670  objectCN = pObjectNode->getObjectCN();
671  CPPUNIT_ASSERT(!objectCN.empty());
672  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
673  CPPUNIT_ASSERT(pObject != NULL);
674  CPPUNIT_ASSERT(pObject->isReference() == true);
675  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
676  CPPUNIT_ASSERT(pObject->getObjectParent() == pModelValue);
677 }
678 
679 const char* test000082::MODEL_STRING5 =
680  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
681  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version4\" level=\"2\" version=\"4\">"
682  " <model id=\"Model_1\" name=\"New Model\">"
683  " <notes>"
684  " <body xmlns=\"http://www.w3.org/1999/xhtml\">"
685  " <p>L2V4 model with event and delay expression.</p>"
686  " </body>"
687  " </notes>"
688  " <listOfUnitDefinitions>"
689  " <unitDefinition id=\"volume\">"
690  " <listOfUnits>"
691  " <unit kind=\"litre\" scale=\"-3\"/>"
692  " </listOfUnits>"
693  " </unitDefinition>"
694  " <unitDefinition id=\"substance\">"
695  " <listOfUnits>"
696  " <unit kind=\"mole\" scale=\"-3\"/>"
697  " </listOfUnits>"
698  " </unitDefinition>"
699  " </listOfUnitDefinitions>"
700  " <listOfCompartments>"
701  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>"
702  " </listOfCompartments>"
703  " <listOfSpecies>"
704  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\" />"
705  " </listOfSpecies>"
706  " <listOfParameters>"
707  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"false\"/>"
708  " </listOfParameters>"
709  " <listOfEvents>"
710  " <event useValuesFromTriggerTime=\"false\">"
711  " <trigger>"
712  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
713  " <apply>"
714  " <gt/>"
715  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/time\"> time </csymbol>"
716  " <cn> 2.0 </cn>"
717  " </apply>"
718  " </math>"
719  " </trigger>"
720  " <delay>"
721  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
722  " <cn> 10 </cn>"
723  " </math>"
724  " </delay>"
725  " <listOfEventAssignments>"
726  " <eventAssignment variable=\"species_1\">"
727  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
728  " <ci> parameter_1 </ci>"
729  " </math>"
730  " </eventAssignment>"
731  " </listOfEventAssignments>"
732  " </event>"
733  " </listOfEvents>"
734  " </model>"
735  "</sbml>"
736  ;
737 
739 {
740  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
741  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING6));
742  CModel* pModel = pDataModel->getModel();
743  CPPUNIT_ASSERT(pModel != NULL);
744  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
745  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
746  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
747  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
748  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
749  CMetab* pA = pModel->getMetabolites()[0];
750  CPPUNIT_ASSERT(pA != NULL);
751  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
752  const CModelValue* pModelValue = pModel->getModelValues()[0];
753  CPPUNIT_ASSERT(pModelValue != NULL);
754  CPPUNIT_ASSERT(pModel->getEvents().size() == 1);
755  const CEvent* pEvent = pModel->getEvents()[0];
756  CPPUNIT_ASSERT(pEvent != NULL);
757  // check the trigger expression
758  const CExpression* pExpr = pEvent->getTriggerExpressionPtr();
759  CPPUNIT_ASSERT(pExpr != NULL);
760  const CEvaluationNode* pNode = pExpr->getRoot();
761  CPPUNIT_ASSERT(pNode != NULL);
762  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::LOGICAL);
764  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
765  CPPUNIT_ASSERT(pNode != NULL);
766  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
767  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
768  CPPUNIT_ASSERT(pObjectNode != NULL);
769  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
770  CPPUNIT_ASSERT(!objectCN.empty());
771  std::vector<CCopasiContainer*> listOfContainers;
772  listOfContainers.push_back(pModel);
773  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
774  CPPUNIT_ASSERT(pObject != NULL);
775  CPPUNIT_ASSERT(pObject->isReference() == true);
776  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
777  CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
778  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getSibling());
779  CPPUNIT_ASSERT(pNode != NULL);
780  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
781  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
782  CPPUNIT_ASSERT(pNumberNode != NULL);
783  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 2.0) / 2.0) < 1e-6);
784  // check that there is a delay
785  pExpr = pEvent->getDelayExpressionPtr();
786  CPPUNIT_ASSERT(pExpr == NULL);
787  // check that the delayAssignment flag is set to true
788  CPPUNIT_ASSERT(pEvent->getDelayAssignment() == true);
789 
790  CPPUNIT_ASSERT(pEvent->getAssignments().size() == 1);
791  // check the event assignment
792  std::string key = pEvent->getAssignments()[0]->getTargetKey();
793  CPPUNIT_ASSERT(key == pA->getKey());
794  pExpr = pEvent->getAssignments()[0]->getExpressionPtr();
795  CPPUNIT_ASSERT(pExpr != NULL);
796  pNode = pExpr->getRoot();
797  CPPUNIT_ASSERT(pNode != NULL);
798  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
799  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
800  CPPUNIT_ASSERT(pObjectNode != NULL);
801  objectCN = pObjectNode->getObjectCN();
802  CPPUNIT_ASSERT(!objectCN.empty());
803  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
804  CPPUNIT_ASSERT(pObject != NULL);
805  CPPUNIT_ASSERT(pObject->isReference() == true);
806  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
807  CPPUNIT_ASSERT(pObject->getObjectParent() == pModelValue);
808 }
809 
810 const char* test000082::MODEL_STRING6 =
811  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
812  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version4\" level=\"2\" version=\"4\">"
813  " <model id=\"Model_1\" name=\"New Model\">"
814  " <notes>"
815  " <body xmlns=\"http://www.w3.org/1999/xhtml\">"
816  " <p>L2V4 model with event and delay expression.</p>"
817  " </body>"
818  " </notes>"
819  " <listOfUnitDefinitions>"
820  " <unitDefinition id=\"volume\">"
821  " <listOfUnits>"
822  " <unit kind=\"litre\" scale=\"-3\"/>"
823  " </listOfUnits>"
824  " </unitDefinition>"
825  " <unitDefinition id=\"substance\">"
826  " <listOfUnits>"
827  " <unit kind=\"mole\" scale=\"-3\"/>"
828  " </listOfUnits>"
829  " </unitDefinition>"
830  " </listOfUnitDefinitions>"
831  " <listOfCompartments>"
832  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>"
833  " </listOfCompartments>"
834  " <listOfSpecies>"
835  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\" />"
836  " </listOfSpecies>"
837  " <listOfParameters>"
838  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"false\"/>"
839  " </listOfParameters>"
840  " <listOfEvents>"
841  " <event>"
842  " <trigger>"
843  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
844  " <apply>"
845  " <gt/>"
846  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/time\"> time </csymbol>"
847  " <cn> 2.0 </cn>"
848  " </apply>"
849  " </math>"
850  " </trigger>"
851  " <listOfEventAssignments>"
852  " <eventAssignment variable=\"species_1\">"
853  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
854  " <ci> parameter_1 </ci>"
855  " </math>"
856  " </eventAssignment>"
857  " </listOfEventAssignments>"
858  " </event>"
859  " </listOfEvents>"
860  " </model>"
861  "</sbml>"
862  ;
863 
865 {
866  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
867  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING7));
868  CModel* pModel = pDataModel->getModel();
869  CPPUNIT_ASSERT(pModel != NULL);
870  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
871  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
872  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
873  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
874  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
875  CMetab* pA = pModel->getMetabolites()[0];
876  CPPUNIT_ASSERT(pA != NULL);
877  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
878  const CModelValue* pModelValue = pModel->getModelValues()[0];
879  CPPUNIT_ASSERT(pModelValue != NULL);
880  CPPUNIT_ASSERT(pModel->getEvents().size() == 1);
881  const CEvent* pEvent = pModel->getEvents()[0];
882  CPPUNIT_ASSERT(pEvent != NULL);
883  // check the trigger expression
884  const CExpression* pExpr = pEvent->getTriggerExpressionPtr();
885  CPPUNIT_ASSERT(pExpr != NULL);
886  const CEvaluationNode* pNode = pExpr->getRoot();
887  CPPUNIT_ASSERT(pNode != NULL);
888  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::LOGICAL);
890  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
891  CPPUNIT_ASSERT(pNode != NULL);
892  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
893  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
894  CPPUNIT_ASSERT(pObjectNode != NULL);
895  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
896  CPPUNIT_ASSERT(!objectCN.empty());
897  std::vector<CCopasiContainer*> listOfContainers;
898  listOfContainers.push_back(pModel);
899  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
900  CPPUNIT_ASSERT(pObject != NULL);
901  CPPUNIT_ASSERT(pObject->isReference() == true);
902  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
903  CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
904  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getSibling());
905  CPPUNIT_ASSERT(pNode != NULL);
906  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
907  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
908  CPPUNIT_ASSERT(pNumberNode != NULL);
909  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 2.0) / 2.0) < 1e-6);
910  // check that there is a delay
911  pExpr = pEvent->getDelayExpressionPtr();
912  CPPUNIT_ASSERT(pExpr == NULL);
913  // check that the delayAssignment flag is set to true
914  CPPUNIT_ASSERT(pEvent->getDelayAssignment() == true);
915 
916  CPPUNIT_ASSERT(pEvent->getAssignments().size() == 1);
917  // check the event assignment
918  std::string key = pEvent->getAssignments()[0]->getTargetKey();
919  CPPUNIT_ASSERT(key == pA->getKey());
920  pExpr = pEvent->getAssignments()[0]->getExpressionPtr();
921  CPPUNIT_ASSERT(pExpr != NULL);
922  pNode = pExpr->getRoot();
923  CPPUNIT_ASSERT(pNode != NULL);
924  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
925  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
926  CPPUNIT_ASSERT(pObjectNode != NULL);
927  objectCN = pObjectNode->getObjectCN();
928  CPPUNIT_ASSERT(!objectCN.empty());
929  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
930  CPPUNIT_ASSERT(pObject != NULL);
931  CPPUNIT_ASSERT(pObject->isReference() == true);
932  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
933  CPPUNIT_ASSERT(pObject->getObjectParent() == pModelValue);
934 }
935 
936 const char* test000082::MODEL_STRING7 =
937  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
938  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version4\" level=\"2\" version=\"4\">"
939  " <model id=\"Model_1\" name=\"New Model\">"
940  " <notes>"
941  " <body xmlns=\"http://www.w3.org/1999/xhtml\">"
942  " <p>L2V4 model with event and delay expression.</p>"
943  " </body>"
944  " </notes>"
945  " <listOfUnitDefinitions>"
946  " <unitDefinition id=\"volume\">"
947  " <listOfUnits>"
948  " <unit kind=\"litre\" scale=\"-3\"/>"
949  " </listOfUnits>"
950  " </unitDefinition>"
951  " <unitDefinition id=\"substance\">"
952  " <listOfUnits>"
953  " <unit kind=\"mole\" scale=\"-3\"/>"
954  " </listOfUnits>"
955  " </unitDefinition>"
956  " </listOfUnitDefinitions>"
957  " <listOfCompartments>"
958  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>"
959  " </listOfCompartments>"
960  " <listOfSpecies>"
961  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\" />"
962  " </listOfSpecies>"
963  " <listOfParameters>"
964  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"false\"/>"
965  " </listOfParameters>"
966  " <listOfEvents>"
967  " <event useValuesFromTriggerTime=\"true\">"
968  " <trigger>"
969  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
970  " <apply>"
971  " <gt/>"
972  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/time\"> time </csymbol>"
973  " <cn> 2.0 </cn>"
974  " </apply>"
975  " </math>"
976  " </trigger>"
977  " <listOfEventAssignments>"
978  " <eventAssignment variable=\"species_1\">"
979  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
980  " <ci> parameter_1 </ci>"
981  " </math>"
982  " </eventAssignment>"
983  " </listOfEventAssignments>"
984  " </event>"
985  " </listOfEvents>"
986  " </model>"
987  "</sbml>"
988  ;
989 
991 {
992  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
993  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING8));
994  CModel* pModel = pDataModel->getModel();
995  CPPUNIT_ASSERT(pModel != NULL);
996  CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CModel::mMol);
997  CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CModel::ml);
998  CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CModel::s);
999  CPPUNIT_ASSERT(pModel->getCompartments().size() == 1);
1000  CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1);
1001  CMetab* pA = pModel->getMetabolites()[0];
1002  CPPUNIT_ASSERT(pA != NULL);
1003  CPPUNIT_ASSERT(pModel->getModelValues().size() == 1);
1004  const CModelValue* pModelValue = pModel->getModelValues()[0];
1005  CPPUNIT_ASSERT(pModelValue != NULL);
1006  CPPUNIT_ASSERT(pModel->getEvents().size() == 1);
1007  const CEvent* pEvent = pModel->getEvents()[0];
1008  CPPUNIT_ASSERT(pEvent != NULL);
1009  // check the trigger expression
1010  const CExpression* pExpr = pEvent->getTriggerExpressionPtr();
1011  CPPUNIT_ASSERT(pExpr != NULL);
1012  const CEvaluationNode* pNode = pExpr->getRoot();
1013  CPPUNIT_ASSERT(pNode != NULL);
1014  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::LOGICAL);
1016  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
1017  CPPUNIT_ASSERT(pNode != NULL);
1018  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
1019  const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
1020  CPPUNIT_ASSERT(pObjectNode != NULL);
1021  CCopasiObjectName objectCN = pObjectNode->getObjectCN();
1022  CPPUNIT_ASSERT(!objectCN.empty());
1023  std::vector<CCopasiContainer*> listOfContainers;
1024  listOfContainers.push_back(pModel);
1025  const CCopasiObject* pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
1026  CPPUNIT_ASSERT(pObject != NULL);
1027  CPPUNIT_ASSERT(pObject->isReference() == true);
1028  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time"));
1029  CPPUNIT_ASSERT(pObject->getObjectParent() == pModel);
1030  pNode = dynamic_cast<const CEvaluationNode*>(pNode->getSibling());
1031  CPPUNIT_ASSERT(pNode != NULL);
1032  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
1033  const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNode);
1034  CPPUNIT_ASSERT(pNumberNode != NULL);
1035  CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 2.0) / 2.0) < 1e-6);
1036  // check that there is a delay
1037  pExpr = pEvent->getDelayExpressionPtr();
1038  CPPUNIT_ASSERT(pExpr == NULL);
1039  // check that the delayAssignment flag is set to true
1040  CPPUNIT_ASSERT(pEvent->getDelayAssignment() == true);
1041 
1042  CPPUNIT_ASSERT(pEvent->getAssignments().size() == 1);
1043  // check the event assignment
1044  std::string key = pEvent->getAssignments()[0]->getTargetKey();
1045  CPPUNIT_ASSERT(key == pA->getKey());
1046  pExpr = pEvent->getAssignments()[0]->getExpressionPtr();
1047  CPPUNIT_ASSERT(pExpr != NULL);
1048  pNode = pExpr->getRoot();
1049  CPPUNIT_ASSERT(pNode != NULL);
1050  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OBJECT);
1051  pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode);
1052  CPPUNIT_ASSERT(pObjectNode != NULL);
1053  objectCN = pObjectNode->getObjectCN();
1054  CPPUNIT_ASSERT(!objectCN.empty());
1055  pObject = pCOPASIDATAMODEL->ObjectFromName(listOfContainers, objectCN);
1056  CPPUNIT_ASSERT(pObject != NULL);
1057  CPPUNIT_ASSERT(pObject->isReference() == true);
1058  CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Value"));
1059  CPPUNIT_ASSERT(pObject->getObjectParent() == pModelValue);
1060 }
1061 
1062 const char* test000082::MODEL_STRING8 =
1063  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1064  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version4\" level=\"2\" version=\"4\">"
1065  " <model id=\"Model_1\" name=\"New Model\">"
1066  " <notes>"
1067  " <body xmlns=\"http://www.w3.org/1999/xhtml\">"
1068  " <p>L2V4 model with event and delay expression.</p>"
1069  " </body>"
1070  " </notes>"
1071  " <listOfUnitDefinitions>"
1072  " <unitDefinition id=\"volume\">"
1073  " <listOfUnits>"
1074  " <unit kind=\"litre\" scale=\"-3\"/>"
1075  " </listOfUnits>"
1076  " </unitDefinition>"
1077  " <unitDefinition id=\"substance\">"
1078  " <listOfUnits>"
1079  " <unit kind=\"mole\" scale=\"-3\"/>"
1080  " </listOfUnits>"
1081  " </unitDefinition>"
1082  " </listOfUnitDefinitions>"
1083  " <listOfCompartments>"
1084  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>"
1085  " </listOfCompartments>"
1086  " <listOfSpecies>"
1087  " <species id=\"species_1\" name=\"A\" compartment=\"compartment_1\" initialConcentration=\"1\" />"
1088  " </listOfSpecies>"
1089  " <listOfParameters>"
1090  " <parameter id=\"parameter_1\" name=\"K\" value=\"0\" constant=\"false\"/>"
1091  " </listOfParameters>"
1092  " <listOfEvents>"
1093  " <event useValuesFromTriggerTime=\"false\">"
1094  " <trigger>"
1095  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
1096  " <apply>"
1097  " <gt/>"
1098  " <csymbol encoding=\"text\" definitionURL=\"http://www.sbml.org/sbml/symbols/time\"> time </csymbol>"
1099  " <cn> 2.0 </cn>"
1100  " </apply>"
1101  " </math>"
1102  " </trigger>"
1103  " <listOfEventAssignments>"
1104  " <eventAssignment variable=\"species_1\">"
1105  " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
1106  " <ci> parameter_1 </ci>"
1107  " </math>"
1108  " </eventAssignment>"
1109  " </listOfEventAssignments>"
1110  " </event>"
1111  " </listOfEvents>"
1112  " </model>"
1113  "</sbml>"
1114  ;
1115 
1117 {
1118  // load the CPS file
1119  // export to SBML
1120  // check the resulting SBML model
1121  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
1122  std::istringstream iss(test000082::MODEL_STRING101);
1123  bool result = load_cps_model_from_stream(iss, *pDataModel);
1124  CPPUNIT_ASSERT(result == true);
1125  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
1126  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 4).empty() == false);
1127  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
1128  CPPUNIT_ASSERT(pDocument != NULL);
1129  CPPUNIT_ASSERT(pDocument->getLevel() == 2);
1130  CPPUNIT_ASSERT(pDocument->getVersion() == 4);
1131  Model* pModel = pDocument->getModel();
1132  CPPUNIT_ASSERT(pModel != NULL);
1133  // check the units
1134  UnitDefinition* pUDef = pModel->getUnitDefinition("time");
1135  Unit* pUnit = NULL;
1136 
1137  // since second is the default time unit, it does not have to be exported and
1138  // might be NULL
1139  if (pUDef != NULL)
1140  {
1141  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1142  pUnit = pUDef->getUnit(0);
1143  CPPUNIT_ASSERT(pUnit != NULL);
1144  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_SECOND);
1145  CPPUNIT_ASSERT(pUnit->getScale() == 0);
1146  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1147  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1148  }
1149 
1150  pUDef = pModel->getUnitDefinition("substance");
1151  CPPUNIT_ASSERT(pUDef != NULL);
1152  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1153  pUnit = pUDef->getUnit(0);
1154  CPPUNIT_ASSERT(pUnit != NULL);
1155  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_MOLE);
1156  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1157  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1158  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1159  pUDef = pModel->getUnitDefinition("volume");
1160  CPPUNIT_ASSERT(pUDef != NULL);
1161  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1162  pUnit = pUDef->getUnit(0);
1163  CPPUNIT_ASSERT(pUnit != NULL);
1164  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_LITRE);
1165  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1166  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1167  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1168  // assert that there is only one compartment and
1169  // assert the compartment is constant
1170  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
1171  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
1172  Parameter* pParameter1 = pModel->getParameter(0);
1173  CPPUNIT_ASSERT(pParameter1 != NULL);
1174  CPPUNIT_ASSERT(pParameter1->getName() == "K");
1175  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
1176  Species* pSpecies1 = pModel->getSpecies(0);
1177  CPPUNIT_ASSERT(pSpecies1->getName() == "A");
1178  Species* pSpecies2 = pModel->getSpecies(1);
1179  CPPUNIT_ASSERT(pSpecies2->getName() == "B");
1180  CPPUNIT_ASSERT(pModel->getNumRules() == 0);
1181  CPPUNIT_ASSERT(pModel->getNumReactions() == 0);
1182  CPPUNIT_ASSERT(pModel->getNumEvents() == 1);
1183  Event* pEvent = pModel->getEvent(0);
1184  CPPUNIT_ASSERT(pEvent != NULL);
1185  // check the trigger
1186  CPPUNIT_ASSERT(pEvent->isSetTrigger());
1187  Trigger* pTrigger = pEvent->getTrigger();
1188  CPPUNIT_ASSERT(pTrigger != NULL);
1189  CPPUNIT_ASSERT(pTrigger->isSetMath());
1190  const ASTNode* pMath = pTrigger->getMath();
1191  CPPUNIT_ASSERT(pMath != NULL);
1192  CPPUNIT_ASSERT(pMath->getType() == AST_RELATIONAL_GT);
1193  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
1194  const ASTNode* pChild = pMath->getChild(0);
1195  CPPUNIT_ASSERT(pChild != NULL);
1196  CPPUNIT_ASSERT(pChild->getType() == AST_NAME_TIME);
1197  pChild = pMath->getChild(1);
1198  CPPUNIT_ASSERT(pChild != NULL);
1199  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
1200  CPPUNIT_ASSERT(fabs((pChild->getReal() - 2.0) / 2.0) < 1e-6);
1201  // check the delay
1202  CPPUNIT_ASSERT(pEvent->isSetDelay());
1203  CPPUNIT_ASSERT(pEvent->getUseValuesFromTriggerTime() == true);
1204  Delay* pDelay = pEvent->getDelay();
1205  CPPUNIT_ASSERT(pDelay != NULL);
1206  CPPUNIT_ASSERT(pDelay->isSetMath());
1207  pMath = pDelay->getMath();
1208  CPPUNIT_ASSERT(pMath != NULL);
1209  CPPUNIT_ASSERT(pMath->getType() == AST_REAL);
1210  CPPUNIT_ASSERT(fabs((pMath->getReal() - 4.0) / 4.0) < 1e-6);
1211  // check the event assignment
1212  CPPUNIT_ASSERT(pEvent->getNumEventAssignments() == 1);
1213  EventAssignment* pEA = pEvent->getEventAssignment(0);
1214  CPPUNIT_ASSERT(pEA != NULL);
1215  CPPUNIT_ASSERT(pEA->getVariable() == pSpecies1->getId());
1216  pMath = pEA->getMath();
1217  CPPUNIT_ASSERT(pMath != NULL);
1218  // make sure the mathematical expression contains only one node that is a
1219  // reference to the global parameter
1220  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
1221  CPPUNIT_ASSERT(pMath->getName() == pParameter1->getId());
1222 }
1223 
1225 {
1226  // load the CPS file
1227  // export to SBML
1228  // check the resulting SBML model
1229  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
1230  std::istringstream iss(test000082::MODEL_STRING101);
1231  bool result = load_cps_model_from_stream(iss, *pDataModel);
1232  CPPUNIT_ASSERT(result == true);
1233  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
1234  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 1).empty() == false);
1235  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
1236  CPPUNIT_ASSERT(pDocument != NULL);
1237  CPPUNIT_ASSERT(pDocument->getLevel() == 2);
1238  CPPUNIT_ASSERT(pDocument->getVersion() == 1);
1239  Model* pModel = pDocument->getModel();
1240  CPPUNIT_ASSERT(pModel != NULL);
1241  // check the units
1242  UnitDefinition* pUDef = pModel->getUnitDefinition("time");
1243  Unit* pUnit = NULL;
1244 
1245  // since second is the default time unit, it does not have to be exported and
1246  // might be NULL
1247  if (pUDef != NULL)
1248  {
1249  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1250  pUnit = pUDef->getUnit(0);
1251  CPPUNIT_ASSERT(pUnit != NULL);
1252  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_SECOND);
1253  CPPUNIT_ASSERT(pUnit->getScale() == 0);
1254  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1255  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1256  }
1257 
1258  pUDef = pModel->getUnitDefinition("substance");
1259  CPPUNIT_ASSERT(pUDef != NULL);
1260  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1261  pUnit = pUDef->getUnit(0);
1262  CPPUNIT_ASSERT(pUnit != NULL);
1263  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_MOLE);
1264  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1265  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1266  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1267  pUDef = pModel->getUnitDefinition("volume");
1268  CPPUNIT_ASSERT(pUDef != NULL);
1269  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1270  pUnit = pUDef->getUnit(0);
1271  CPPUNIT_ASSERT(pUnit != NULL);
1272  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_LITRE);
1273  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1274  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1275  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1276  // assert that there is only one compartment and
1277  // assert the compartment is constant
1278  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
1279  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
1280  Parameter* pParameter1 = pModel->getParameter(0);
1281  CPPUNIT_ASSERT(pParameter1 != NULL);
1282  CPPUNIT_ASSERT(pParameter1->getName() == "K");
1283  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
1284  Species* pSpecies1 = pModel->getSpecies(0);
1285  CPPUNIT_ASSERT(pSpecies1->getName() == "A");
1286  Species* pSpecies2 = pModel->getSpecies(1);
1287  CPPUNIT_ASSERT(pSpecies2->getName() == "B");
1288  CPPUNIT_ASSERT(pModel->getNumRules() == 0);
1289  CPPUNIT_ASSERT(pModel->getNumReactions() == 0);
1290  CPPUNIT_ASSERT(pModel->getNumEvents() == 1);
1291  Event* pEvent = pModel->getEvent(0);
1292  CPPUNIT_ASSERT(pEvent != NULL);
1293  // check the trigger
1294  CPPUNIT_ASSERT(pEvent->isSetTrigger());
1295  Trigger* pTrigger = pEvent->getTrigger();
1296  CPPUNIT_ASSERT(pTrigger != NULL);
1297  CPPUNIT_ASSERT(pTrigger->isSetMath());
1298  const ASTNode* pMath = pTrigger->getMath();
1299  CPPUNIT_ASSERT(pMath != NULL);
1300  CPPUNIT_ASSERT(pMath->getType() == AST_RELATIONAL_GT);
1301  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
1302  const ASTNode* pChild = pMath->getChild(0);
1303  CPPUNIT_ASSERT(pChild != NULL);
1304  CPPUNIT_ASSERT(pChild->getType() == AST_NAME_TIME);
1305  pChild = pMath->getChild(1);
1306  CPPUNIT_ASSERT(pChild != NULL);
1307  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
1308  CPPUNIT_ASSERT(fabs((pChild->getReal() - 2.0) / 2.0) < 1e-6);
1309  // check the delay
1310  CPPUNIT_ASSERT(pEvent->isSetDelay());
1311  CPPUNIT_ASSERT(pEvent->getUseValuesFromTriggerTime() == true);
1312  Delay* pDelay = pEvent->getDelay();
1313  CPPUNIT_ASSERT(pDelay != NULL);
1314  CPPUNIT_ASSERT(pDelay->isSetMath());
1315  pMath = pDelay->getMath();
1316  CPPUNIT_ASSERT(pMath != NULL);
1317  CPPUNIT_ASSERT(pMath->getType() == AST_REAL);
1318  CPPUNIT_ASSERT(fabs((pMath->getReal() - 4.0) / 4.0) < 1e-6);
1319  // check the event assignment
1320  CPPUNIT_ASSERT(pEvent->getNumEventAssignments() == 1);
1321  EventAssignment* pEA = pEvent->getEventAssignment(0);
1322  CPPUNIT_ASSERT(pEA != NULL);
1323  CPPUNIT_ASSERT(pEA->getVariable() == pSpecies1->getId());
1324  pMath = pEA->getMath();
1325  CPPUNIT_ASSERT(pMath != NULL);
1326  // make sure the mathematical expression contains only one node that is a
1327  // reference to the global parameter
1328  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
1329  CPPUNIT_ASSERT(pMath->getName() == pParameter1->getId());
1330  // make sure there is actually no warning MCSBML + 77
1331  unsigned int i = 0, iMax = CCopasiMessage::size();
1332 
1333  while (i < iMax)
1334  {
1336  CPPUNIT_ASSERT(message.getNumber() != MCSBML + 77);
1337  ++i;
1338  }
1339 }
1340 
1341 const char* test000082::MODEL_STRING101 =
1342  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1343  "<!-- generated with COPASI 4.4.26 (Debug) (http://www.copasi.org) at 2008-06-12 09:00:21 UTC -->\n"
1344  "<COPASI xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.copasi.org/static/schema.xsd\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"26\">\n"
1345  " <Model key=\"Model_0\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"mmol\" type=\"deterministic\">\n"
1346  " <Comment>\n"
1347  " <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:9pt;font-family:Sans Serif\">\n"
1348  "<p>Simple model with two species and one global parameter. The compartment is fixed and one species is changed by an event assignment.</p>\n"
1349  "<p>The substance unit is set to mmol.</p>\n"
1350  "<p>On export both species should be exported with the hasOnlySubstanceUnits flag set to false and the expression for the event assignment should contain a reference to the global parameter.</p>\n"
1351  "</body></html>\n"
1352  " </Comment>\n"
1353  " <ListOfCompartments>\n"
1354  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"fixed\">\n"
1355  " </Compartment>\n"
1356  " </ListOfCompartments>\n"
1357  " <ListOfMetabolites>\n"
1358  " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
1359  " </Metabolite>\n"
1360  " <Metabolite key=\"Metabolite_1\" name=\"B\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
1361  " </Metabolite>\n"
1362  " </ListOfMetabolites>\n"
1363  " <ListOfModelValues>\n"
1364  " <ModelValue key=\"ModelValue_0\" name=\"K\" simulationType=\"fixed\">\n"
1365  " </ModelValue>\n"
1366  " </ListOfModelValues>\n"
1367  " <ListOfEvents>\n"
1368  " <Event key=\"Event_0\" name=\"event\" delayAssignment=\"true\" >\n"
1369  " <TriggerExpression>\n"
1370  " &lt;CN=Root,Model=New Model,Reference=Time&gt; gt 2.0\n"
1371  " </TriggerExpression>\n"
1372  " <DelayExpression>\n"
1373  " 4.0\n"
1374  " </DelayExpression>\n"
1375  " <ListOfAssignments>\n"
1376  " <Assignment targetKey=\"Metabolite_0\">\n"
1377  " <Expression>\n"
1378  " &lt;CN=Root,Model=New Model,Vector=Values[K],Reference=Value&gt;\n"
1379  " </Expression>\n"
1380  " </Assignment>\n"
1381  " </ListOfAssignments>\n"
1382  " </Event>\n"
1383  " </ListOfEvents>\n"
1384  " <StateTemplate>\n"
1385  " <StateTemplateVariable objectReference=\"Model_0\"/>\n"
1386  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
1387  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
1388  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
1389  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
1390  " </StateTemplate>\n"
1391  " <InitialState type=\"initialState\">\n"
1392  " 0 1.2044283e+21 6.022141500000001e+20 2 1\n"
1393  " </InitialState>\n"
1394  " </Model>\n"
1395  "</COPASI>\n"
1396  ;
1397 
1399 {
1400  // load the CPS file
1401  // export to SBML
1402  // check the resulting SBML model
1403  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
1404  std::istringstream iss(test000082::MODEL_STRING102);
1405  bool result = load_cps_model_from_stream(iss, *pDataModel);
1406  CPPUNIT_ASSERT(result == true);
1407  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
1408  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 4).empty() == false);
1409  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
1410  CPPUNIT_ASSERT(pDocument != NULL);
1411  CPPUNIT_ASSERT(pDocument->getLevel() == 2);
1412  CPPUNIT_ASSERT(pDocument->getVersion() == 4);
1413  Model* pModel = pDocument->getModel();
1414  CPPUNIT_ASSERT(pModel != NULL);
1415  // check the units
1416  UnitDefinition* pUDef = pModel->getUnitDefinition("time");
1417  Unit* pUnit = NULL;
1418 
1419  // since second is the default time unit, it does not have to be exported and
1420  // might be NULL
1421  if (pUDef != NULL)
1422  {
1423  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1424  pUnit = pUDef->getUnit(0);
1425  CPPUNIT_ASSERT(pUnit != NULL);
1426  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_SECOND);
1427  CPPUNIT_ASSERT(pUnit->getScale() == 0);
1428  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1429  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1430  }
1431 
1432  pUDef = pModel->getUnitDefinition("substance");
1433  CPPUNIT_ASSERT(pUDef != NULL);
1434  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1435  pUnit = pUDef->getUnit(0);
1436  CPPUNIT_ASSERT(pUnit != NULL);
1437  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_MOLE);
1438  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1439  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1440  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1441  pUDef = pModel->getUnitDefinition("volume");
1442  CPPUNIT_ASSERT(pUDef != NULL);
1443  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1444  pUnit = pUDef->getUnit(0);
1445  CPPUNIT_ASSERT(pUnit != NULL);
1446  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_LITRE);
1447  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1448  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1449  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1450  // assert that there is only one compartment and
1451  // assert the compartment is constant
1452  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
1453  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
1454  Parameter* pParameter1 = pModel->getParameter(0);
1455  CPPUNIT_ASSERT(pParameter1 != NULL);
1456  CPPUNIT_ASSERT(pParameter1->getName() == "K");
1457  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
1458  Species* pSpecies1 = pModel->getSpecies(0);
1459  CPPUNIT_ASSERT(pSpecies1->getName() == "A");
1460  Species* pSpecies2 = pModel->getSpecies(1);
1461  CPPUNIT_ASSERT(pSpecies2->getName() == "B");
1462  CPPUNIT_ASSERT(pModel->getNumRules() == 0);
1463  CPPUNIT_ASSERT(pModel->getNumReactions() == 0);
1464  CPPUNIT_ASSERT(pModel->getNumEvents() == 1);
1465  Event* pEvent = pModel->getEvent(0);
1466  CPPUNIT_ASSERT(pEvent != NULL);
1467  // check the trigger
1468  CPPUNIT_ASSERT(pEvent->isSetTrigger());
1469  Trigger* pTrigger = pEvent->getTrigger();
1470  CPPUNIT_ASSERT(pTrigger != NULL);
1471  CPPUNIT_ASSERT(pTrigger->isSetMath());
1472  const ASTNode* pMath = pTrigger->getMath();
1473  CPPUNIT_ASSERT(pMath != NULL);
1474  CPPUNIT_ASSERT(pMath->getType() == AST_RELATIONAL_GT);
1475  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
1476  const ASTNode* pChild = pMath->getChild(0);
1477  CPPUNIT_ASSERT(pChild != NULL);
1478  CPPUNIT_ASSERT(pChild->getType() == AST_NAME_TIME);
1479  pChild = pMath->getChild(1);
1480  CPPUNIT_ASSERT(pChild != NULL);
1481  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
1482  CPPUNIT_ASSERT(fabs((pChild->getReal() - 2.0) / 2.0) < 1e-6);
1483  // check the delay
1484  CPPUNIT_ASSERT(pEvent->isSetDelay());
1485  CPPUNIT_ASSERT(pEvent->getUseValuesFromTriggerTime() == false);
1486  Delay* pDelay = pEvent->getDelay();
1487  CPPUNIT_ASSERT(pDelay != NULL);
1488  CPPUNIT_ASSERT(pDelay->isSetMath());
1489  pMath = pDelay->getMath();
1490  CPPUNIT_ASSERT(pMath != NULL);
1491  CPPUNIT_ASSERT(pMath->getType() == AST_REAL);
1492  CPPUNIT_ASSERT(fabs((pMath->getReal() - 4.0) / 4.0) < 1e-6);
1493  // check the event assignment
1494  CPPUNIT_ASSERT(pEvent->getNumEventAssignments() == 1);
1495  EventAssignment* pEA = pEvent->getEventAssignment(0);
1496  CPPUNIT_ASSERT(pEA != NULL);
1497  CPPUNIT_ASSERT(pEA->getVariable() == pSpecies1->getId());
1498  pMath = pEA->getMath();
1499  CPPUNIT_ASSERT(pMath != NULL);
1500  // make sure the mathematical expression contains only one node that is a
1501  // reference to the global parameter
1502  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
1503  CPPUNIT_ASSERT(pMath->getName() == pParameter1->getId());
1504 }
1505 
1507 {
1508  // load the CPS file
1509  // export to SBML
1510  // check the resulting SBML model
1511  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
1512  std::istringstream iss(test000082::MODEL_STRING102);
1513  bool result = load_cps_model_from_stream(iss, *pDataModel);
1514  CPPUNIT_ASSERT(result == true);
1515  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
1516  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 1).empty() == false);
1517  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
1518  CPPUNIT_ASSERT(pDocument != NULL);
1519  CPPUNIT_ASSERT(pDocument->getLevel() == 2);
1520  CPPUNIT_ASSERT(pDocument->getVersion() == 1);
1521  Model* pModel = pDocument->getModel();
1522  CPPUNIT_ASSERT(pModel != NULL);
1523  // check the units
1524  UnitDefinition* pUDef = pModel->getUnitDefinition("time");
1525  Unit* pUnit = NULL;
1526 
1527  // since second is the default time unit, it does not have to be exported and
1528  // might be NULL
1529  if (pUDef != NULL)
1530  {
1531  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1532  pUnit = pUDef->getUnit(0);
1533  CPPUNIT_ASSERT(pUnit != NULL);
1534  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_SECOND);
1535  CPPUNIT_ASSERT(pUnit->getScale() == 0);
1536  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1537  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1538  }
1539 
1540  pUDef = pModel->getUnitDefinition("substance");
1541  CPPUNIT_ASSERT(pUDef != NULL);
1542  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1543  pUnit = pUDef->getUnit(0);
1544  CPPUNIT_ASSERT(pUnit != NULL);
1545  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_MOLE);
1546  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1547  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1548  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1549  pUDef = pModel->getUnitDefinition("volume");
1550  CPPUNIT_ASSERT(pUDef != NULL);
1551  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1552  pUnit = pUDef->getUnit(0);
1553  CPPUNIT_ASSERT(pUnit != NULL);
1554  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_LITRE);
1555  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1556  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1557  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1558  // assert that there is only one compartment and
1559  // assert the compartment is constant
1560  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
1561  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
1562  Parameter* pParameter1 = pModel->getParameter(0);
1563  CPPUNIT_ASSERT(pParameter1 != NULL);
1564  CPPUNIT_ASSERT(pParameter1->getName() == "K");
1565  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
1566  Species* pSpecies1 = pModel->getSpecies(0);
1567  CPPUNIT_ASSERT(pSpecies1->getName() == "A");
1568  Species* pSpecies2 = pModel->getSpecies(1);
1569  CPPUNIT_ASSERT(pSpecies2->getName() == "B");
1570  CPPUNIT_ASSERT(pModel->getNumRules() == 0);
1571  CPPUNIT_ASSERT(pModel->getNumReactions() == 0);
1572  CPPUNIT_ASSERT(pModel->getNumEvents() == 1);
1573  Event* pEvent = pModel->getEvent(0);
1574  CPPUNIT_ASSERT(pEvent != NULL);
1575  // check the trigger
1576  CPPUNIT_ASSERT(pEvent->isSetTrigger());
1577  Trigger* pTrigger = pEvent->getTrigger();
1578  CPPUNIT_ASSERT(pTrigger != NULL);
1579  CPPUNIT_ASSERT(pTrigger->isSetMath());
1580  const ASTNode* pMath = pTrigger->getMath();
1581  CPPUNIT_ASSERT(pMath != NULL);
1582  CPPUNIT_ASSERT(pMath->getType() == AST_RELATIONAL_GT);
1583  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
1584  const ASTNode* pChild = pMath->getChild(0);
1585  CPPUNIT_ASSERT(pChild != NULL);
1586  CPPUNIT_ASSERT(pChild->getType() == AST_NAME_TIME);
1587  pChild = pMath->getChild(1);
1588  CPPUNIT_ASSERT(pChild != NULL);
1589  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
1590  CPPUNIT_ASSERT(fabs((pChild->getReal() - 2.0) / 2.0) < 1e-6);
1591  // check the delay
1592  CPPUNIT_ASSERT(pEvent->isSetDelay());
1593  CPPUNIT_ASSERT(pEvent->getUseValuesFromTriggerTime() == true);
1594  Delay* pDelay = pEvent->getDelay();
1595  CPPUNIT_ASSERT(pDelay != NULL);
1596  CPPUNIT_ASSERT(pDelay->isSetMath());
1597  pMath = pDelay->getMath();
1598  CPPUNIT_ASSERT(pMath != NULL);
1599  CPPUNIT_ASSERT(pMath->getType() == AST_REAL);
1600  CPPUNIT_ASSERT(fabs((pMath->getReal() - 4.0) / 4.0) < 1e-6);
1601  // check the event assignment
1602  CPPUNIT_ASSERT(pEvent->getNumEventAssignments() == 1);
1603  EventAssignment* pEA = pEvent->getEventAssignment(0);
1604  CPPUNIT_ASSERT(pEA != NULL);
1605  CPPUNIT_ASSERT(pEA->getVariable() == pSpecies1->getId());
1606  pMath = pEA->getMath();
1607  CPPUNIT_ASSERT(pMath != NULL);
1608  // make sure the mathematical expression contains only one node that is a
1609  // reference to the global parameter
1610  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
1611  CPPUNIT_ASSERT(pMath->getName() == pParameter1->getId());
1612  // make sure there is actually a warning MCSBML + 77
1613  unsigned int i = 0, iMax = CCopasiMessage::size();
1614 
1615  while (i < iMax)
1616  {
1618 
1619  if (message.getNumber() == MCSBML + 77)
1620  {
1621  break;
1622  }
1623 
1624  ++i;
1625  }
1626 
1627  CPPUNIT_ASSERT(i != iMax);
1628 }
1629 
1630 const char* test000082::MODEL_STRING102 =
1631  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1632  "<!-- generated with COPASI 4.4.26 (Debug) (http://www.copasi.org) at 2008-06-12 09:00:21 UTC -->\n"
1633  "<COPASI xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.copasi.org/static/schema.xsd\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"26\">\n"
1634  " <Model key=\"Model_0\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"mmol\" type=\"deterministic\">\n"
1635  " <Comment>\n"
1636  " <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:9pt;font-family:Sans Serif\">\n"
1637  "<p>Simple model with two species and one global parameter. The compartment is fixed and one species is changed by an event assignment.</p>\n"
1638  "<p>The substance unit is set to mmol.</p>\n"
1639  "<p>On export both species should be exported with the hasOnlySubstanceUnits flag set to false and the expression for the event assignment should contain a reference to the global parameter.</p>\n"
1640  "</body></html>\n"
1641  " </Comment>\n"
1642  " <ListOfCompartments>\n"
1643  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"fixed\">\n"
1644  " </Compartment>\n"
1645  " </ListOfCompartments>\n"
1646  " <ListOfMetabolites>\n"
1647  " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
1648  " </Metabolite>\n"
1649  " <Metabolite key=\"Metabolite_1\" name=\"B\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
1650  " </Metabolite>\n"
1651  " </ListOfMetabolites>\n"
1652  " <ListOfModelValues>\n"
1653  " <ModelValue key=\"ModelValue_0\" name=\"K\" simulationType=\"fixed\">\n"
1654  " </ModelValue>\n"
1655  " </ListOfModelValues>\n"
1656  " <ListOfEvents>\n"
1657  " <Event key=\"Event_0\" name=\"event\" delayAssignment=\"false\" >\n"
1658  " <TriggerExpression>\n"
1659  " &lt;CN=Root,Model=New Model,Reference=Time&gt; gt 2.0\n"
1660  " </TriggerExpression>\n"
1661  " <DelayExpression>\n"
1662  " 4.0\n"
1663  " </DelayExpression>\n"
1664  " <ListOfAssignments>\n"
1665  " <Assignment targetKey=\"Metabolite_0\">\n"
1666  " <Expression>\n"
1667  " &lt;CN=Root,Model=New Model,Vector=Values[K],Reference=Value&gt;\n"
1668  " </Expression>\n"
1669  " </Assignment>\n"
1670  " </ListOfAssignments>\n"
1671  " </Event>\n"
1672  " </ListOfEvents>\n"
1673  " <StateTemplate>\n"
1674  " <StateTemplateVariable objectReference=\"Model_0\"/>\n"
1675  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
1676  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
1677  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
1678  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
1679  " </StateTemplate>\n"
1680  " <InitialState type=\"initialState\">\n"
1681  " 0 1.2044283e+21 6.022141500000001e+20 2 1\n"
1682  " </InitialState>\n"
1683  " </Model>\n"
1684  "</COPASI>\n"
1685  ;
1686 
1688 {
1689  // load the CPS file
1690  // export to SBML
1691  // check the resulting SBML model
1692  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
1693  std::istringstream iss(test000082::MODEL_STRING103);
1694  bool result = load_cps_model_from_stream(iss, *pDataModel);
1695  CPPUNIT_ASSERT(result == true);
1696  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
1697  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 4).empty() == false);
1698  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
1699  CPPUNIT_ASSERT(pDocument != NULL);
1700  CPPUNIT_ASSERT(pDocument->getLevel() == 2);
1701  CPPUNIT_ASSERT(pDocument->getVersion() == 4);
1702  Model* pModel = pDocument->getModel();
1703  CPPUNIT_ASSERT(pModel != NULL);
1704  // check the units
1705  UnitDefinition* pUDef = pModel->getUnitDefinition("time");
1706  Unit* pUnit = NULL;
1707 
1708  // since second is the default time unit, it does not have to be exported and
1709  // might be NULL
1710  if (pUDef != NULL)
1711  {
1712  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1713  pUnit = pUDef->getUnit(0);
1714  CPPUNIT_ASSERT(pUnit != NULL);
1715  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_SECOND);
1716  CPPUNIT_ASSERT(pUnit->getScale() == 0);
1717  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1718  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1719  }
1720 
1721  pUDef = pModel->getUnitDefinition("substance");
1722  CPPUNIT_ASSERT(pUDef != NULL);
1723  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1724  pUnit = pUDef->getUnit(0);
1725  CPPUNIT_ASSERT(pUnit != NULL);
1726  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_MOLE);
1727  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1728  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1729  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1730  pUDef = pModel->getUnitDefinition("volume");
1731  CPPUNIT_ASSERT(pUDef != NULL);
1732  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1733  pUnit = pUDef->getUnit(0);
1734  CPPUNIT_ASSERT(pUnit != NULL);
1735  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_LITRE);
1736  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1737  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1738  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1739  // assert that there is only one compartment and
1740  // assert the compartment is constant
1741  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
1742  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
1743  Parameter* pParameter1 = pModel->getParameter(0);
1744  CPPUNIT_ASSERT(pParameter1 != NULL);
1745  CPPUNIT_ASSERT(pParameter1->getName() == "K");
1746  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
1747  Species* pSpecies1 = pModel->getSpecies(0);
1748  CPPUNIT_ASSERT(pSpecies1->getName() == "A");
1749  Species* pSpecies2 = pModel->getSpecies(1);
1750  CPPUNIT_ASSERT(pSpecies2->getName() == "B");
1751  CPPUNIT_ASSERT(pModel->getNumRules() == 0);
1752  CPPUNIT_ASSERT(pModel->getNumReactions() == 0);
1753  CPPUNIT_ASSERT(pModel->getNumEvents() == 1);
1754  Event* pEvent = pModel->getEvent(0);
1755  CPPUNIT_ASSERT(pEvent != NULL);
1756  // check the trigger
1757  CPPUNIT_ASSERT(pEvent->isSetTrigger());
1758  Trigger* pTrigger = pEvent->getTrigger();
1759  CPPUNIT_ASSERT(pTrigger != NULL);
1760  CPPUNIT_ASSERT(pTrigger->isSetMath());
1761  const ASTNode* pMath = pTrigger->getMath();
1762  CPPUNIT_ASSERT(pMath != NULL);
1763  CPPUNIT_ASSERT(pMath->getType() == AST_RELATIONAL_GT);
1764  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
1765  const ASTNode* pChild = pMath->getChild(0);
1766  CPPUNIT_ASSERT(pChild != NULL);
1767  CPPUNIT_ASSERT(pChild->getType() == AST_NAME_TIME);
1768  pChild = pMath->getChild(1);
1769  CPPUNIT_ASSERT(pChild != NULL);
1770  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
1771  CPPUNIT_ASSERT(fabs((pChild->getReal() - 2.0) / 2.0) < 1e-6);
1772  // check the delay
1773  CPPUNIT_ASSERT(pEvent->isSetDelay() == false);
1774  CPPUNIT_ASSERT(pEvent->getUseValuesFromTriggerTime() == true);
1775  Delay* pDelay = pEvent->getDelay();
1776  CPPUNIT_ASSERT(pDelay == NULL);
1777  // check the event assignment
1778  CPPUNIT_ASSERT(pEvent->getNumEventAssignments() == 1);
1779  EventAssignment* pEA = pEvent->getEventAssignment(0);
1780  CPPUNIT_ASSERT(pEA != NULL);
1781  CPPUNIT_ASSERT(pEA->getVariable() == pSpecies1->getId());
1782  pMath = pEA->getMath();
1783  CPPUNIT_ASSERT(pMath != NULL);
1784  // make sure the mathematical expression contains only one node that is a
1785  // reference to the global parameter
1786  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
1787  CPPUNIT_ASSERT(pMath->getName() == pParameter1->getId());
1788 }
1789 
1791 {
1792  // load the CPS file
1793  // export to SBML
1794  // check the resulting SBML model
1795  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
1796  std::istringstream iss(test000082::MODEL_STRING103);
1797  bool result = load_cps_model_from_stream(iss, *pDataModel);
1798  CPPUNIT_ASSERT(result == true);
1799  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
1800  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 1).empty() == false);
1801  SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
1802  CPPUNIT_ASSERT(pDocument != NULL);
1803  CPPUNIT_ASSERT(pDocument->getLevel() == 2);
1804  CPPUNIT_ASSERT(pDocument->getVersion() == 1);
1805  Model* pModel = pDocument->getModel();
1806  CPPUNIT_ASSERT(pModel != NULL);
1807  // check the units
1808  UnitDefinition* pUDef = pModel->getUnitDefinition("time");
1809  Unit* pUnit = NULL;
1810 
1811  // since second is the default time unit, it does not have to be exported and
1812  // might be NULL
1813  if (pUDef != NULL)
1814  {
1815  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1816  pUnit = pUDef->getUnit(0);
1817  CPPUNIT_ASSERT(pUnit != NULL);
1818  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_SECOND);
1819  CPPUNIT_ASSERT(pUnit->getScale() == 0);
1820  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1821  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1822  }
1823 
1824  pUDef = pModel->getUnitDefinition("substance");
1825  CPPUNIT_ASSERT(pUDef != NULL);
1826  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1827  pUnit = pUDef->getUnit(0);
1828  CPPUNIT_ASSERT(pUnit != NULL);
1829  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_MOLE);
1830  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1831  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1832  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1833  pUDef = pModel->getUnitDefinition("volume");
1834  CPPUNIT_ASSERT(pUDef != NULL);
1835  CPPUNIT_ASSERT(pUDef->getNumUnits() == 1);
1836  pUnit = pUDef->getUnit(0);
1837  CPPUNIT_ASSERT(pUnit != NULL);
1838  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_LITRE);
1839  CPPUNIT_ASSERT(pUnit->getScale() == -3);
1840  CPPUNIT_ASSERT(pUnit->getExponent() == 1);
1841  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
1842  // assert that there is only one compartment and
1843  // assert the compartment is constant
1844  CPPUNIT_ASSERT(pModel->getNumCompartments() == 1);
1845  CPPUNIT_ASSERT(pModel->getNumParameters() == 1);
1846  Parameter* pParameter1 = pModel->getParameter(0);
1847  CPPUNIT_ASSERT(pParameter1 != NULL);
1848  CPPUNIT_ASSERT(pParameter1->getName() == "K");
1849  CPPUNIT_ASSERT(pModel->getNumSpecies() == 2);
1850  Species* pSpecies1 = pModel->getSpecies(0);
1851  CPPUNIT_ASSERT(pSpecies1->getName() == "A");
1852  Species* pSpecies2 = pModel->getSpecies(1);
1853  CPPUNIT_ASSERT(pSpecies2->getName() == "B");
1854  CPPUNIT_ASSERT(pModel->getNumRules() == 0);
1855  CPPUNIT_ASSERT(pModel->getNumReactions() == 0);
1856  CPPUNIT_ASSERT(pModel->getNumEvents() == 1);
1857  Event* pEvent = pModel->getEvent(0);
1858  CPPUNIT_ASSERT(pEvent != NULL);
1859  // check the trigger
1860  CPPUNIT_ASSERT(pEvent->isSetTrigger());
1861  Trigger* pTrigger = pEvent->getTrigger();
1862  CPPUNIT_ASSERT(pTrigger != NULL);
1863  CPPUNIT_ASSERT(pTrigger->isSetMath());
1864  const ASTNode* pMath = pTrigger->getMath();
1865  CPPUNIT_ASSERT(pMath != NULL);
1866  CPPUNIT_ASSERT(pMath->getType() == AST_RELATIONAL_GT);
1867  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
1868  const ASTNode* pChild = pMath->getChild(0);
1869  CPPUNIT_ASSERT(pChild != NULL);
1870  CPPUNIT_ASSERT(pChild->getType() == AST_NAME_TIME);
1871  pChild = pMath->getChild(1);
1872  CPPUNIT_ASSERT(pChild != NULL);
1873  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
1874  CPPUNIT_ASSERT(fabs((pChild->getReal() - 2.0) / 2.0) < 1e-6);
1875  // check the delay
1876  CPPUNIT_ASSERT(pEvent->isSetDelay() == false);
1877  CPPUNIT_ASSERT(pEvent->getUseValuesFromTriggerTime() == true);
1878  Delay* pDelay = pEvent->getDelay();
1879  CPPUNIT_ASSERT(pDelay == NULL);
1880  // check the event assignment
1881  CPPUNIT_ASSERT(pEvent->getNumEventAssignments() == 1);
1882  EventAssignment* pEA = pEvent->getEventAssignment(0);
1883  CPPUNIT_ASSERT(pEA != NULL);
1884  CPPUNIT_ASSERT(pEA->getVariable() == pSpecies1->getId());
1885  pMath = pEA->getMath();
1886  CPPUNIT_ASSERT(pMath != NULL);
1887  // make sure the mathematical expression contains only one node that is a
1888  // reference to the global parameter
1889  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
1890  CPPUNIT_ASSERT(pMath->getName() == pParameter1->getId());
1891  // make sure there is actually no warning MCSBML + 77
1892  unsigned int i = 0, iMax = CCopasiMessage::size();
1893 
1894  while (i < iMax)
1895  {
1897  CPPUNIT_ASSERT(message.getNumber() != MCSBML + 77);
1898  ++i;
1899  }
1900 }
1901 
1902 const char* test000082::MODEL_STRING103 =
1903  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1904  "<!-- generated with COPASI 4.4.26 (Debug) (http://www.copasi.org) at 2008-06-12 09:00:21 UTC -->\n"
1905  "<COPASI xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.copasi.org/static/schema.xsd\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"26\">\n"
1906  " <Model key=\"Model_0\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"mmol\" type=\"deterministic\">\n"
1907  " <Comment>\n"
1908  " <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:9pt;font-family:Sans Serif\">\n"
1909  "<p>Simple model with two species and one global parameter. The compartment is fixed and one species is changed by an event assignment.</p>\n"
1910  "<p>The substance unit is set to mmol.</p>\n"
1911  "<p>On export both species should be exported with the hasOnlySubstanceUnits flag set to false and the expression for the event assignment should contain a reference to the global parameter.</p>\n"
1912  "</body></html>\n"
1913  " </Comment>\n"
1914  " <ListOfCompartments>\n"
1915  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"fixed\">\n"
1916  " </Compartment>\n"
1917  " </ListOfCompartments>\n"
1918  " <ListOfMetabolites>\n"
1919  " <Metabolite key=\"Metabolite_0\" name=\"A\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
1920  " </Metabolite>\n"
1921  " <Metabolite key=\"Metabolite_1\" name=\"B\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
1922  " </Metabolite>\n"
1923  " </ListOfMetabolites>\n"
1924  " <ListOfModelValues>\n"
1925  " <ModelValue key=\"ModelValue_0\" name=\"K\" simulationType=\"fixed\">\n"
1926  " </ModelValue>\n"
1927  " </ListOfModelValues>\n"
1928  " <ListOfEvents>\n"
1929  " <Event key=\"Event_0\" name=\"event\" delayAssignment=\"true\" >\n"
1930  " <TriggerExpression>\n"
1931  " &lt;CN=Root,Model=New Model,Reference=Time&gt; gt 2.0\n"
1932  " </TriggerExpression>\n"
1933  " <ListOfAssignments>\n"
1934  " <Assignment targetKey=\"Metabolite_0\">\n"
1935  " <Expression>\n"
1936  " &lt;CN=Root,Model=New Model,Vector=Values[K],Reference=Value&gt;\n"
1937  " </Expression>\n"
1938  " </Assignment>\n"
1939  " </ListOfAssignments>\n"
1940  " </Event>\n"
1941  " </ListOfEvents>\n"
1942  " <StateTemplate>\n"
1943  " <StateTemplateVariable objectReference=\"Model_0\"/>\n"
1944  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
1945  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
1946  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
1947  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
1948  " </StateTemplate>\n"
1949  " <InitialState type=\"initialState\">\n"
1950  " 0 1.2044283e+21 6.022141500000001e+20 2 1\n"
1951  " </InitialState>\n"
1952  " </Model>\n"
1953  "</COPASI>\n"
1954  ;
Definition: CEvent.h:152
Header file of class CExpression.
SBMLDocument * getCurrentSBMLDocument()
void test_import_delayAssignment_2()
Definition: test000082.cpp:201
Header file of class CModelEntity and CModelValue.
void test_export_delayAssignment_1()
const std::string & getObjectName() const
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
const CRegisteredObjectName & getObjectCN() const
static const char * MODEL_STRING5
Definition: test000082.h:63
const C_FLOAT64 & getValue() const
const Type & getType() const
const size_t & getNumber() const
static const char * MODEL_STRING4
Definition: test000082.h:61
void test_import_delayAssignment_1()
Definition: test000082.cpp:64
static const char * MODEL_STRING103
Definition: test000082.h:78
void test_export_delayAssignment_6()
Definition: CMetab.h:178
void test_import_delayAssignment_3()
Definition: test000082.cpp:327
void test_import_delayAssignment_6()
Definition: test000082.cpp:738
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static Type type(const Type &type)
#define MCSBML
static const char * MODEL_STRING1
Definition: test000082.h:53
bool isReference() const
static size_t size()
void test_import_delayAssignment_7()
Definition: test000082.cpp:864
void test_import_delayAssignment_8()
Definition: test000082.cpp:990
void test_export_delayAssignment_3()
static CCopasiDataModel * addDatamodel()
static Type subType(const Type &type)
static const char * MODEL_STRING3
Definition: test000082.h:59
static const char * MODEL_STRING6
Definition: test000082.h:65
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000082.h:80
static CCopasiMessage getLastMessage()
void setUp()
Definition: test000082.cpp:51
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
static const char * MODEL_STRING101
Definition: test000082.h:74
void test_export_delayAssignment_2()
static void init(int argc, char *argv[], const bool &withGui=false)
Definition: CModel.h:50
void test_import_delayAssignment_4()
Definition: test000082.cpp:464
static const char * MODEL_STRING2
Definition: test000082.h:56
static const char * MODEL_STRING102
Definition: test000082.h:76
static const char * MODEL_STRING7
Definition: test000082.h:67
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
static const char * MODEL_STRING8
Definition: test000082.h:69
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
CEvaluationNode * getRoot()
void test_export_delayAssignment_4()
CCopasiContainer * getObjectParent() const
void test_export_delayAssignment_5()
void tearDown()
Definition: test000082.cpp:59
void test_import_delayAssignment_5()
Definition: test000082.cpp:601