COPASI API  4.16.103
test000077.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000077.cpp,v $
3 // $Revision: 1.4 $
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 "test000077.h"
20 
21 #include "utilities.hpp"
24 #include "copasi/model/CModel.h"
26 
27 #include "sbml/SBMLDocument.h"
28 #include "sbml/Model.h"
29 #include "sbml/Species.h"
30 
31 CCopasiDataModel* test000077::pCOPASIDATAMODEL = NULL;
32 
33 /**
34  * Test the export of models with references to local parameters in
35  * expressions.
36  */
38 {
39  // Create the root container.
40  CCopasiRootContainer::init(0, NULL, false);
41  // Create the global data model.
43 }
44 
46 {
48 }
49 
51 {
52  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
53 
54  try
55  {
56  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000077::MODEL_STRING1));
57  }
58  catch (...)
59  {
60  // there should not be an exception
61  CPPUNIT_ASSERT(false);
62  }
63 
64  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
65  CPPUNIT_ASSERT(pDataModel->getModel()->getVolumeUnitEnum() == CModel::dimensionlessVolume);
66  CPPUNIT_ASSERT(pDataModel->getModel()->getTimeUnitEnum() == CModel::dimensionlessTime);
67  CPPUNIT_ASSERT(pDataModel->getModel()->getQuantityUnitEnum() == CModel::dimensionlessQuantity);
68 }
69 
71 {
72  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
73 
74  try
75  {
76  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000077::MODEL_STRING2));
77  }
78  catch (...)
79  {
80  // there should not be an exception
81  CPPUNIT_ASSERT(false);
82  }
83 
84  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
85  CPPUNIT_ASSERT(pDataModel->getModel()->getVolumeUnitEnum() == CModel::dimensionlessVolume);
86  CPPUNIT_ASSERT(pDataModel->getModel()->getTimeUnitEnum() == CModel::dimensionlessTime);
87  CPPUNIT_ASSERT(pDataModel->getModel()->getQuantityUnitEnum() == CModel::dimensionlessQuantity);
88 }
89 
91 {
92  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
93 
94  try
95  {
96  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000077::MODEL_STRING3));
97  }
98  catch (...)
99  {
100  // there shouldn't be any reason for an exception
101  CPPUNIT_ASSERT(false);
102  }
103 
104  // check if a message MCSBML + 66 is on the message stack
105  bool found = false;
106  CCopasiMessage message;
107 
108  while (CCopasiMessage::size() > 0)
109  {
110  message = CCopasiMessage::getLastMessage();
111 
112  if (message.getNumber() == MCSBML + 66)
113  {
114  found = true;
115  break;
116  }
117  }
118 
119  CPPUNIT_ASSERT(found == true);
120  CPPUNIT_ASSERT(message.getText().find("volume") != std::string::npos);
121 }
122 
124 {
125  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
126 
127  try
128  {
129  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000077::MODEL_STRING4));
130  }
131  catch (...)
132  {
133  // there shouldn't be any reason for an exception
134  CPPUNIT_ASSERT(false);
135  }
136 
137  // check if a message MCSBML + 66 is on the message stack
138  bool found = false;
139  CCopasiMessage message;
140 
141  while (CCopasiMessage::size() > 0)
142  {
143  message = CCopasiMessage::getLastMessage();
144 
145  if (message.getNumber() == MCSBML + 66)
146  {
147  found = true;
148  break;
149  }
150  }
151 
152  CPPUNIT_ASSERT(found == true);
153  CPPUNIT_ASSERT(message.getText().find("time") != std::string::npos);
154 }
155 
157 {
158  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
159 
160  try
161  {
162  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000077::MODEL_STRING5));
163  }
164  catch (...)
165  {
166  // there shouldn't be any reason for an exception
167  CPPUNIT_ASSERT(false);
168  }
169 
170  // check if a message MCSBML + 66 is on the message stack
171  bool found = false;
172  CCopasiMessage message;
173 
174  while (CCopasiMessage::size() > 0)
175  {
176  message = CCopasiMessage::getLastMessage();
177 
178  if (message.getNumber() == MCSBML + 66)
179  {
180  found = true;
181  break;
182  }
183  }
184 
185  CPPUNIT_ASSERT(found == true);
186  CPPUNIT_ASSERT(message.getText().find("substance") != std::string::npos);
187 }
188 
190 {
191  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
192  std::istringstream iss(test000077::MODEL_STRING6);
193  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
194  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
195  const SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
196  CPPUNIT_ASSERT(pDocument == NULL);
197  std::string sbmlString;
198 
199  try
200  {
201  sbmlString = pDataModel->exportSBMLToString(NULL, 2, 1);
202  }
203  catch (...)
204  {
205  // fail if an uncaught exception occurs during export
206  CPPUNIT_ASSERT(false);
207  }
208 
209  CPPUNIT_ASSERT(!sbmlString.empty());
210  // check if the exported SBML model has two parameters
211  pDocument = pDataModel->getCurrentSBMLDocument();
212  CPPUNIT_ASSERT(pDocument != NULL);
213  const Model* pModel = pDocument->getModel();
214  CPPUNIT_ASSERT(pModel != NULL);
215  CPPUNIT_ASSERT(pModel->getListOfCompartments()->size() == 1);
216  CPPUNIT_ASSERT(pModel->getListOfSpecies()->size() == 1);
217  const UnitDefinition* pUDef = pModel->getUnitDefinition("time");
218  CPPUNIT_ASSERT(pUDef != NULL);
219  CPPUNIT_ASSERT(pUDef->getListOfUnits()->size() == 1);
220  const Unit* pUnit = pUDef->getUnit(0);
221  CPPUNIT_ASSERT(pUnit != NULL);
222  CPPUNIT_ASSERT(pUnit->getScale() == 0);
223  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
224  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_DIMENSIONLESS);
225  pUDef = pModel->getUnitDefinition("volume");
226  CPPUNIT_ASSERT(pUDef != NULL);
227  CPPUNIT_ASSERT(pUDef->getListOfUnits()->size() == 1);
228  pUnit = pUDef->getUnit(0);
229  CPPUNIT_ASSERT(pUnit != NULL);
230  CPPUNIT_ASSERT(pUnit->getScale() == 0);
231  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
232  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_DIMENSIONLESS);
233  pUDef = pModel->getUnitDefinition("substance");
234  CPPUNIT_ASSERT(pUDef != NULL);
235  CPPUNIT_ASSERT(pUDef->getListOfUnits()->size() == 1);
236  pUnit = pUDef->getUnit(0);
237  CPPUNIT_ASSERT(pUnit != NULL);
238  CPPUNIT_ASSERT(pUnit->getScale() == 0);
239  CPPUNIT_ASSERT(fabs((pUnit->getMultiplier() - 1.0) / 1.0) < 1e-6);
240  CPPUNIT_ASSERT(pUnit->getKind() == UNIT_KIND_DIMENSIONLESS);
241 }
242 
243 const char* test000077::MODEL_STRING1 =
244  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
245  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
246  " <model metaid=\"COPASI1\" id=\"Model_1\" name=\"test000077\">\n"
247  " <notes>\n"
248  " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
249  " <head>\n"
250  " <meta name=\"qrichtext\" content=\"1\"/>\n"
251  " </head>\n"
252  " <body style=\"font-size:13pt;font-family:Lucida Grande\">\n"
253  " <p>Model to test import of dimensionless units.</p>\n"
254  " </body>\n"
255  " </html>\n"
256  " </notes>\n"
257  " <listOfUnitDefinitions>\n"
258  " <unitDefinition id=\"volume\">\n"
259  " <listOfUnits>\n"
260  " <unit kind=\"dimensionless\"/>\n"
261  " </listOfUnits>\n"
262  " </unitDefinition>\n"
263  " <unitDefinition id=\"time\">\n"
264  " <listOfUnits>\n"
265  " <unit kind=\"dimensionless\"/>\n"
266  " </listOfUnits>\n"
267  " </unitDefinition>\n"
268  " <unitDefinition id=\"substance\">\n"
269  " <listOfUnits>\n"
270  " <unit kind=\"dimensionless\"/>\n"
271  " </listOfUnits>\n"
272  " </unitDefinition>\n"
273  " </listOfUnitDefinitions>\n"
274  " <listOfCompartments>\n"
275  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
276  " </listOfCompartments>\n"
277  " <listOfSpecies>\n"
278  " <species id=\"species_1\" name=\"S\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
279  " </listOfSpecies>\n"
280  " </model>\n"
281  "</sbml>\n";
282 
283 const char* test000077::MODEL_STRING2 =
284  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
285  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
286  " <model metaid=\"COPASI1\" id=\"Model_1\" name=\"test000077\">\n"
287  " <notes>\n"
288  " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
289  " <head>\n"
290  " <meta name=\"qrichtext\" content=\"1\"/>\n"
291  " </head>\n"
292  " <body style=\"font-size:13pt;font-family:Lucida Grande\">\n"
293  " <p>Model to test import of dimensionless units.</p>\n"
294  " </body>\n"
295  " </html>\n"
296  " </notes>\n"
297  " <listOfUnitDefinitions>\n"
298  " <unitDefinition id=\"volume\">\n"
299  " <listOfUnits>\n"
300  " <unit kind=\"dimensionless\" multiplier=\"0.001\" scale=\"3\" />\n"
301  " </listOfUnits>\n"
302  " </unitDefinition>\n"
303  " <unitDefinition id=\"time\">\n"
304  " <listOfUnits>\n"
305  " <unit kind=\"dimensionless\" multiplier=\"10\" scale=\"-1\" />\n"
306  " </listOfUnits>\n"
307  " </unitDefinition>\n"
308  " <unitDefinition id=\"substance\">\n"
309  " <listOfUnits>\n"
310  " <unit kind=\"dimensionless\" multiplier=\"0.01\" scale=\"2\" />\n"
311  " </listOfUnits>\n"
312  " </unitDefinition>\n"
313  " </listOfUnitDefinitions>\n"
314  " <listOfCompartments>\n"
315  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
316  " </listOfCompartments>\n"
317  " <listOfSpecies>\n"
318  " <species id=\"species_1\" name=\"S\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
319  " </listOfSpecies>\n"
320  " </model>\n"
321  "</sbml>\n";
322 
323 const char* test000077::MODEL_STRING3 =
324  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
325  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
326  " <model metaid=\"COPASI1\" id=\"Model_1\" name=\"test000077\">\n"
327  " <notes>\n"
328  " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
329  " <head>\n"
330  " <meta name=\"qrichtext\" content=\"1\"/>\n"
331  " </head>\n"
332  " <body style=\"font-size:13pt;font-family:Lucida Grande\">\n"
333  " <p>Model to test import of dimensionless units.</p>\n"
334  " </body>\n"
335  " </html>\n"
336  " </notes>\n"
337  " <listOfUnitDefinitions>\n"
338  " <unitDefinition id=\"volume\">\n"
339  " <listOfUnits>\n"
340  " <unit kind=\"dimensionless\" multiplier=\"0.04\" scale=\"-3\" />\n"
341  " </listOfUnits>\n"
342  " </unitDefinition>\n"
343  " <unitDefinition id=\"time\">\n"
344  " <listOfUnits>\n"
345  " <unit kind=\"dimensionless\" multiplier=\"10\" scale=\"-1\" />\n"
346  " </listOfUnits>\n"
347  " </unitDefinition>\n"
348  " <unitDefinition id=\"substance\">\n"
349  " <listOfUnits>\n"
350  " <unit kind=\"dimensionless\" multiplier=\"0.01\" scale=\"2\" />\n"
351  " </listOfUnits>\n"
352  " </unitDefinition>\n"
353  " </listOfUnitDefinitions>\n"
354  " <listOfCompartments>\n"
355  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
356  " </listOfCompartments>\n"
357  " <listOfSpecies>\n"
358  " <species id=\"species_1\" name=\"S\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
359  " </listOfSpecies>\n"
360  " </model>\n"
361  "</sbml>\n";
362 
363 const char* test000077::MODEL_STRING4 =
364  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
365  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
366  " <model metaid=\"COPASI1\" id=\"Model_1\" name=\"test000077\">\n"
367  " <notes>\n"
368  " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
369  " <head>\n"
370  " <meta name=\"qrichtext\" content=\"1\"/>\n"
371  " </head>\n"
372  " <body style=\"font-size:13pt;font-family:Lucida Grande\">\n"
373  " <p>Model to test import of dimensionless units.</p>\n"
374  " </body>\n"
375  " </html>\n"
376  " </notes>\n"
377  " <listOfUnitDefinitions>\n"
378  " <unitDefinition id=\"volume\">\n"
379  " <listOfUnits>\n"
380  " <unit kind=\"dimensionless\" multiplier=\"0.001\" scale=\"3\" />\n"
381  " </listOfUnits>\n"
382  " </unitDefinition>\n"
383  " <unitDefinition id=\"time\">\n"
384  " <listOfUnits>\n"
385  " <unit kind=\"dimensionless\" multiplier=\"10\" scale=\"-2\" />\n"
386  " </listOfUnits>\n"
387  " </unitDefinition>\n"
388  " <unitDefinition id=\"substance\">\n"
389  " <listOfUnits>\n"
390  " <unit kind=\"dimensionless\" multiplier=\"0.01\" scale=\"2\" />\n"
391  " </listOfUnits>\n"
392  " </unitDefinition>\n"
393  " </listOfUnitDefinitions>\n"
394  " <listOfCompartments>\n"
395  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
396  " </listOfCompartments>\n"
397  " <listOfSpecies>\n"
398  " <species id=\"species_1\" name=\"S\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
399  " </listOfSpecies>\n"
400  " </model>\n"
401  "</sbml>\n";
402 
403 const char* test000077::MODEL_STRING5 =
404  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
405  "<sbml xmlns=\"http://www.sbml.org/sbml/level2/version3\" level=\"2\" version=\"3\">\n"
406  " <model metaid=\"COPASI1\" id=\"Model_1\" name=\"test000077\">\n"
407  " <notes>\n"
408  " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
409  " <head>\n"
410  " <meta name=\"qrichtext\" content=\"1\"/>\n"
411  " </head>\n"
412  " <body style=\"font-size:13pt;font-family:Lucida Grande\">\n"
413  " <p>Model to test import of dimensionless units.</p>\n"
414  " </body>\n"
415  " </html>\n"
416  " </notes>\n"
417  " <listOfUnitDefinitions>\n"
418  " <unitDefinition id=\"volume\">\n"
419  " <listOfUnits>\n"
420  " <unit kind=\"dimensionless\" multiplier=\"0.001\" scale=\"3\" />\n"
421  " </listOfUnits>\n"
422  " </unitDefinition>\n"
423  " <unitDefinition id=\"time\">\n"
424  " <listOfUnits>\n"
425  " <unit kind=\"dimensionless\" multiplier=\"10\" scale=\"-1\" />\n"
426  " </listOfUnits>\n"
427  " </unitDefinition>\n"
428  " <unitDefinition id=\"substance\">\n"
429  " <listOfUnits>\n"
430  " <unit kind=\"dimensionless\" multiplier=\"0.1\" scale=\"2\" />\n"
431  " </listOfUnits>\n"
432  " </unitDefinition>\n"
433  " </listOfUnitDefinitions>\n"
434  " <listOfCompartments>\n"
435  " <compartment id=\"compartment_1\" name=\"compartment\" size=\"1\"/>\n"
436  " </listOfCompartments>\n"
437  " <listOfSpecies>\n"
438  " <species id=\"species_1\" name=\"S\" compartment=\"compartment_1\" initialConcentration=\"1\"/>\n"
439  " </listOfSpecies>\n"
440  " </model>\n"
441  "</sbml>\n";
442 
443 const char* test000077::MODEL_STRING6 =
444  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
445  "<!-- generated with COPASI 4.5.30 (Debug) (http://www.copasi.org) at 2009-01-27 14:56:07 UTC -->\n"
446  "<COPASI xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.copasi.org/static/schema.xsd\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"30\">\n"
447  " <Model key=\"Model_0\" name=\"test000077\" timeUnit=\"dimensionless\" volumeUnit=\"dimensionless\" quantityUnit=\"dimensionless\" type=\"deterministic\">\n"
448  " <Comment>\n"
449  " <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:13pt;font-family:Lucida Grande\">\n"
450  "<p>Model to test export of dimensionless units.</p>\n"
451  "</body></html>\n"
452  " </Comment>\n"
453  " <ListOfCompartments>\n"
454  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"fixed\">\n"
455  " </Compartment>\n"
456  " </ListOfCompartments>\n"
457  " <ListOfMetabolites>\n"
458  " <Metabolite key=\"Metabolite_0\" name=\"S\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
459  " </Metabolite>\n"
460  " </ListOfMetabolites>\n"
461  " <StateTemplate>\n"
462  " <StateTemplateVariable objectReference=\"Model_0\"/>\n"
463  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
464  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
465  " </StateTemplate>\n"
466  " <InitialState type=\"initialState\">\n"
467  " 0 1 1\n"
468  " </InitialState>\n"
469  " </Model>\n"
470  "</COPASI>\n";
void test_import_dimensionless_1()
Definition: test000077.cpp:50
SBMLDocument * getCurrentSBMLDocument()
static const char * MODEL_STRING3
Definition: test000077.h:53
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
CModel::QuantityUnit getQuantityUnitEnum() const
Definition: CModel.cpp:2331
void test_import_dimensionless_3()
Definition: test000077.cpp:90
const std::string & getText() const
const size_t & getNumber() const
static const char * MODEL_STRING6
Definition: test000077.h:56
void test_export_dimensionless()
Definition: test000077.cpp:189
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
#define MCSBML
void test_import_dimensionless_5()
Definition: test000077.cpp:156
void test_import_dimensionless_4()
Definition: test000077.cpp:123
static size_t size()
static const char * MODEL_STRING1
Definition: test000077.h:51
static const char * MODEL_STRING5
Definition: test000077.h:55
void test_import_dimensionless_2()
Definition: test000077.cpp:70
static CCopasiDataModel * addDatamodel()
static const char * MODEL_STRING4
Definition: test000077.h:54
CModel::TimeUnit getTimeUnitEnum() const
Definition: CModel.cpp:2243
static CCopasiMessage getLastMessage()
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
void setUp()
Definition: test000077.cpp:37
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000077.h:50
static void init(int argc, char *argv[], const bool &withGui=false)
CModel::VolumeUnit getVolumeUnitEnum() const
Definition: CModel.cpp:2175
void tearDown()
Definition: test000077.cpp:45
static const char * MODEL_STRING2
Definition: test000077.h:52