COPASI API  4.16.103
test000081.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000081.cpp,v $
3 // $Revision: 1.2 $
4 // $Name: $
5 // $Author: gauges $
6 // $Date: 2010/03/11 11:55:16 $
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 "test000081.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* test000081::pCOPASIDATAMODEL = NULL;
32 
33 /**
34  * Test for bug 1205
35  */
37 {
38  // Create the root container.
39  CCopasiRootContainer::init(0, NULL, false);
40  // Create the global data model.
42 }
43 
45 {
47 }
48 
50 {
51  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
52  std::istringstream iss(test000081::MODEL_STRING1);
53  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
54  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
55  const SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
56  CPPUNIT_ASSERT(pDocument == NULL);
57  std::string sbmlString;
58 
59  try
60  {
61  sbmlString = pDataModel->exportSBMLToString(NULL, 2, 1);
62  }
63  catch (...)
64  {
65  // fail if an uncaught exception occurs during export
66  CPPUNIT_ASSERT(false);
67  }
68 
69  CPPUNIT_ASSERT(!sbmlString.empty());
70  // check if the exported SBML model has three compartments
71  pDocument = pDataModel->getCurrentSBMLDocument();
72  CPPUNIT_ASSERT(pDocument != NULL);
73  const Model* pModel = pDocument->getModel();
74  CPPUNIT_ASSERT(pModel != NULL);
75  unsigned int iMax = pModel->getListOfCompartments()->size();
76  CPPUNIT_ASSERT(iMax == 3);
77  // check that the compartment named compartment_2 has the id compartment_1
78  const Compartment* pCompartment = pModel->getCompartment("compartment_1");
79  CPPUNIT_ASSERT(pCompartment != NULL);
80  CPPUNIT_ASSERT(pCompartment->getName() == "compartment_2");
81 
82  // check if the exported SBML model has three species
83  iMax = pModel->getListOfSpecies()->size();
84  CPPUNIT_ASSERT(iMax == 3);
85  // check that the species named species_2 has the id species_1
86  const Species* pSpecies = pModel->getSpecies("species_1");
87  CPPUNIT_ASSERT(pSpecies != NULL);
88  CPPUNIT_ASSERT(pSpecies->getName() == "species_2");
89 
90  // check if the exported SBML model has three parameters
91  iMax = pModel->getListOfParameters()->size();
92  CPPUNIT_ASSERT(iMax == 3);
93  // check that the parameter named quantity_2 has the id parameter_1
94  const Parameter* pParameter = pModel->getParameter("parameter_1");
95  CPPUNIT_ASSERT(pParameter != NULL);
96  CPPUNIT_ASSERT(pParameter->getName() == "quantity_2");
97 
98  // check if the exported SBML model has three reactions
99  iMax = pModel->getListOfReactions()->size();
100  CPPUNIT_ASSERT(iMax == 3);
101  // check that the reaction named reaction_2 has the id reaction_1
102  const Reaction* pReaction = pModel->getReaction("reaction_1");
103  CPPUNIT_ASSERT(pReaction != NULL);
104  CPPUNIT_ASSERT(pReaction->getName() == "reaction_2");
105 }
106 
107 const char* test000081::MODEL_STRING1 =
108  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
109  "<!-- generated with COPASI 4.5.30 (Debug) (http://www.copasi.org) at 2009-05-07 08:59:15 UTC -->\n"
110  "<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"
111  " <ListOfFunctions>\n"
112  " <Function key=\"Function_13\" name=\"Mass action (irreversible)\" type=\"MassAction\" reversible=\"false\">\n"
113  " <Expression>\n"
114  " k1*PRODUCT&lt;substrate_i&gt;\n"
115  " </Expression>\n"
116  " <ListOfParameterDescriptions>\n"
117  " <ParameterDescription key=\"FunctionParameter_81\" name=\"k1\" order=\"0\" role=\"constant\"/>\n"
118  " <ParameterDescription key=\"FunctionParameter_79\" name=\"substrate\" order=\"1\" role=\"substrate\"/>\n"
119  " </ListOfParameterDescriptions>\n"
120  " </Function>\n"
121  " </ListOfFunctions>\n"
122  " <Model key=\"Model_1\" name=\"Model_1\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"mmol\" type=\"deterministic\">\n"
123  " <Comment>\n"
124  " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
125  " <head>\n"
126  " <meta name=\"qrichtext\" content=\"1\"/>\n"
127  " </head>\n"
128  " <body style=\"font-size:13pt;font-family:Lucida Grande\">\n"
129  " <p>This is a test model for Bug 1205</p>\n"
130  " </body>\n"
131  "</html>\n"
132  "\n"
133  " </Comment>\n"
134  " <ListOfCompartments>\n"
135  " <Compartment key=\"Compartment_0\" name=\"compartment\" simulationType=\"fixed\">\n"
136  " </Compartment>\n"
137  " <Compartment key=\"Compartment_1\" name=\"compartment_1\" simulationType=\"fixed\">\n"
138  " </Compartment>\n"
139  " <Compartment key=\"Compartment_2\" name=\"compartment_2\" simulationType=\"fixed\">\n"
140  " </Compartment>\n"
141  " </ListOfCompartments>\n"
142  " <ListOfMetabolites>\n"
143  " <Metabolite key=\"Metabolite_0\" name=\"species\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
144  " </Metabolite>\n"
145  " <Metabolite key=\"Metabolite_1\" name=\"species_1\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
146  " </Metabolite>\n"
147  " <Metabolite key=\"Metabolite_2\" name=\"species_2\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
148  " </Metabolite>\n"
149  " </ListOfMetabolites>\n"
150  " <ListOfModelValues>\n"
151  " <ModelValue key=\"ModelValue_0\" name=\"quantity\" simulationType=\"fixed\">\n"
152  " </ModelValue>\n"
153  " <ModelValue key=\"ModelValue_1\" name=\"quantity_1\" simulationType=\"fixed\">\n"
154  " </ModelValue>\n"
155  " <ModelValue key=\"ModelValue_2\" name=\"quantity_2\" simulationType=\"fixed\">\n"
156  " </ModelValue>\n"
157  " </ListOfModelValues>\n"
158  " <ListOfReactions>\n"
159  " <Reaction key=\"Reaction_1\" name=\"reaction\" reversible=\"false\">\n"
160  " <ListOfSubstrates>\n"
161  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
162  " </ListOfSubstrates>\n"
163  " <ListOfConstants>\n"
164  " <Constant key=\"Parameter_79\" name=\"k1\" value=\"0.1\"/>\n"
165  " </ListOfConstants>\n"
166  " <KineticLaw function=\"Function_13\">\n"
167  " <ListOfCallParameters>\n"
168  " <CallParameter functionParameter=\"FunctionParameter_81\">\n"
169  " <SourceParameter reference=\"Parameter_79\"/>\n"
170  " </CallParameter>\n"
171  " <CallParameter functionParameter=\"FunctionParameter_79\">\n"
172  " <SourceParameter reference=\"Metabolite_0\"/>\n"
173  " </CallParameter>\n"
174  " </ListOfCallParameters>\n"
175  " </KineticLaw>\n"
176  " </Reaction>\n"
177  " <Reaction key=\"Reaction_0\" name=\"reaction_1\" reversible=\"false\">\n"
178  " <ListOfSubstrates>\n"
179  " <Substrate metabolite=\"Metabolite_1\" stoichiometry=\"1\"/>\n"
180  " </ListOfSubstrates>\n"
181  " <ListOfConstants>\n"
182  " <Constant key=\"Parameter_80\" name=\"k1\" value=\"0.1\"/>\n"
183  " </ListOfConstants>\n"
184  " <KineticLaw function=\"Function_13\">\n"
185  " <ListOfCallParameters>\n"
186  " <CallParameter functionParameter=\"FunctionParameter_81\">\n"
187  " <SourceParameter reference=\"Parameter_80\"/>\n"
188  " </CallParameter>\n"
189  " <CallParameter functionParameter=\"FunctionParameter_79\">\n"
190  " <SourceParameter reference=\"Metabolite_1\"/>\n"
191  " </CallParameter>\n"
192  " </ListOfCallParameters>\n"
193  " </KineticLaw>\n"
194  " </Reaction>\n"
195  " <Reaction key=\"Reaction_2\" name=\"reaction_2\" reversible=\"false\">\n"
196  " <ListOfSubstrates>\n"
197  " <Substrate metabolite=\"Metabolite_2\" stoichiometry=\"1\"/>\n"
198  " </ListOfSubstrates>\n"
199  " <ListOfConstants>\n"
200  " <Constant key=\"Parameter_507\" name=\"k1\" value=\"0.1\"/>\n"
201  " </ListOfConstants>\n"
202  " <KineticLaw function=\"Function_13\">\n"
203  " <ListOfCallParameters>\n"
204  " <CallParameter functionParameter=\"FunctionParameter_81\">\n"
205  " <SourceParameter reference=\"Parameter_507\"/>\n"
206  " </CallParameter>\n"
207  " <CallParameter functionParameter=\"FunctionParameter_79\">\n"
208  " <SourceParameter reference=\"Metabolite_2\"/>\n"
209  " </CallParameter>\n"
210  " </ListOfCallParameters>\n"
211  " </KineticLaw>\n"
212  " </Reaction>\n"
213  " </ListOfReactions>\n"
214  " <StateTemplate>\n"
215  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
216  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
217  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
218  " <StateTemplateVariable objectReference=\"Metabolite_2\"/>\n"
219  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
220  " <StateTemplateVariable objectReference=\"ModelValue_1\"/>\n"
221  " <StateTemplateVariable objectReference=\"ModelValue_2\"/>\n"
222  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
223  " <StateTemplateVariable objectReference=\"Compartment_1\"/>\n"
224  " <StateTemplateVariable objectReference=\"Compartment_2\"/>\n"
225  " </StateTemplate>\n"
226  " <InitialState type=\"initialState\">\n"
227  " 0 6.022141500000001e+20 6.022141500000001e+20 6.022141500000001e+20 0 0 0 1 1 1\n"
228  " </InitialState>\n"
229  " </Model>\n"
230  " <GUI>\n"
231  " </GUI>\n"
232  " <SBMLReference file=\"bug1205.xml\">\n"
233  " <SBMLMap SBMLid=\"compartment_1\" COPASIkey=\"Compartment_2\"/>\n"
234  " <SBMLMap SBMLid=\"parameter_1\" COPASIkey=\"ModelValue_2\"/>\n"
235  " <SBMLMap SBMLid=\"reaction_1\" COPASIkey=\"Reaction_2\"/>\n"
236  " <SBMLMap SBMLid=\"species_1\" COPASIkey=\"Metabolite_2\"/>\n"
237  " </SBMLReference>\n"
238  "</COPASI>\n";
void setUp()
Definition: test000081.cpp:36
SBMLDocument * getCurrentSBMLDocument()
static const char * MODEL_STRING1
Definition: test000081.h:40
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000081.h:39
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
void test_bug1205()
Definition: test000081.cpp:49
void tearDown()
Definition: test000081.cpp:44
static CCopasiDataModel * addDatamodel()
static void init(int argc, char *argv[], const bool &withGui=false)