COPASI API  4.16.103
test000100.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000100.cpp,v $
3 // $Revision: 1.3 $
4 // $Name: $
5 // $Author: bergmann $
6 // $Date: 2012/04/19 15:00:10 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2011 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 #include "test000100.h"
15 
16 #include <string>
17 #include <sstream>
18 #include <stdexcept>
19 #include <iostream>
20 #ifndef WIN32
21 #include <signal.h>
22 #endif
23 #include "utilities.hpp"
24 
27 
28 // Since this bug leads to failed assertions in the debug version,
29 // we need to make sure that the call to abort made by assert does not end the program.
30 // For this we change the signal handler to one that throws an exception.
31 // The current version is specific to linux. If these tests are to be run under windows,
32 // the mechanism for setting the signal handler will probably have to be modified.
33 void abort_handler(int)
34 {
35  throw std::runtime_error("Received SIGABRT signal.");
36 }
37 
38 #ifndef WIN32
39 struct sigaction* pNewAct = NULL;
40 struct sigaction* pOldAct = NULL;
41 #endif
43 {
44 #ifndef WIN32
45  // set a new action handler for SIGABRT that throws an exception
46  // instead of terminating the program. This is needed to handle failed assertions
47  // in debug versions.
48  pNewAct = new struct sigaction();
49  pNewAct->sa_handler = &abort_handler;
50  pOldAct = new struct sigaction();
51  int x = sigaction(SIGABRT, pNewAct, pOldAct);
52 
53  if (x != 0)
54  {
55  std::cerr << "Setting the signal handler failed." << std::endl;
56  }
57 
58 #endif
59  // Create the root container.
60  CCopasiRootContainer::init(0, NULL, false);
62 }
63 
65 {
67 #ifndef WIN32
68  // restore the old action handler
69  int x = sigaction(SIGABRT, pOldAct, NULL);
70 
71  if (x != 0)
72  {
73  std::cerr << "Resetting the signal handler failed." << std::endl;
74  }
75 
76 #endif
77 }
78 
79 // test whether exporting an SBML Level 3 file after an SBML Level 2 file
80 // succeeds
82 {
83  CPPUNIT_ASSERT(pDataModel != NULL);
84  std::istringstream iss(test000100::CPS_STRING);
85  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
86  std::string s;
87 
88  try
89  {
90  s = pDataModel->exportSBMLToString(NULL, 2, 1);
91  }
92  catch (...)
93  {
94  CPPUNIT_ASSERT_MESSAGE("The first export to Level 2 Version 1 failed.", false);
95  }
96 
97  try
98  {
99  s = pDataModel->exportSBMLToString(NULL, 3, 1);
100  }
101  catch (...)
102  {
103  CPPUNIT_ASSERT_MESSAGE("The second export to Level 3 Version 1 failed.", false);
104  }
105 }
106 
107 // test whether exporting an SBML Level 3 file before an SBML Level 2 file
108 // succeeds
110 {
111  CPPUNIT_ASSERT(pDataModel != NULL);
112  std::istringstream iss(test000100::CPS_STRING);
113  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
114  std::string s;
115 
116  try
117  {
118  s = pDataModel->exportSBMLToString(NULL, 3, 1);
119  }
120  catch (...)
121  {
122  CPPUNIT_ASSERT_MESSAGE("The first export to Level 3 Version 1 failed.", false);
123  }
124 
125  try
126  {
127  s = pDataModel->exportSBMLToString(NULL, 2, 1);
128  }
129  catch (...)
130  {
131  CPPUNIT_ASSERT_MESSAGE("The second export to Level 2 Version 1 failed.", false);
132  }
133 }
134 
135 
136 
137 const char* test000100::CPS_STRING =
138  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
139  "<!-- generated with COPASI 4.7.34 (Debug) (http://www.copasi.org) at 2011-09-08 08:14:18 UTC -->\n"
140  "<?oxygen RNGSchema=\"http://www.copasi.org/static/schema/CopasiML.rng\" type=\"xml\"?>\n"
141  "<COPASI xmlns=\"http://www.copasi.org/static/schema\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"34\">\n"
142  " <ListOfFunctions>\n"
143  " <Function key=\"Function_6\" name=\"Constant flux (irreversible)\" type=\"PreDefined\" reversible=\"false\">\n"
144  " <Expression>\n"
145  " v\n"
146  " </Expression>\n"
147  " <ListOfParameterDescriptions>\n"
148  " <ParameterDescription key=\"FunctionParameter_49\" name=\"v\" order=\"0\" role=\"constant\"/>\n"
149  " </ListOfParameterDescriptions>\n"
150  " </Function>\n"
151  " <Function key=\"Function_13\" name=\"Mass action (irreversible)\" type=\"MassAction\" reversible=\"false\">\n"
152  " <Expression>\n"
153  " k1*PRODUCT&lt;substrate_i&gt;\n"
154  " </Expression>\n"
155  " <ListOfParameterDescriptions>\n"
156  " <ParameterDescription key=\"FunctionParameter_81\" name=\"k1\" order=\"0\" role=\"constant\"/>\n"
157  " <ParameterDescription key=\"FunctionParameter_79\" name=\"substrate\" order=\"1\" role=\"substrate\"/>\n"
158  " </ListOfParameterDescriptions>\n"
159  " </Function>\n"
160  " </ListOfFunctions>\n"
161  " <Model key=\"Model_0\" name=\"New Model\" simulationType=\"time\" timeUnit=\"s\" volumeUnit=\"µl\" areaUnit=\"m²\" lengthUnit=\"m\" quantityUnit=\"nmol\" type=\"deterministic\" avogadroConstant=\"6.02214179e+23\">\n"
162  " <ListOfCompartments>\n"
163  " <Compartment key=\"Compartment_0\" name=\"cell\" simulationType=\"fixed\" dimensionality=\"3\">\n"
164  " </Compartment>\n"
165  " </ListOfCompartments>\n"
166  " <ListOfMetabolites>\n"
167  " <Metabolite key=\"Metabolite_0\" name=\"glucose\" simulationType=\"fixed\" compartment=\"Compartment_0\">\n"
168  " </Metabolite>\n"
169  " <Metabolite key=\"Metabolite_1\" name=\"glucose-6-phosphate\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
170  " </Metabolite>\n"
171  " <Metabolite key=\"Metabolite_2\" name=\"ATP\" simulationType=\"fixed\" compartment=\"Compartment_0\">\n"
172  " </Metabolite>\n"
173  " <Metabolite key=\"Metabolite_3\" name=\"ADP\" simulationType=\"reactions\" compartment=\"Compartment_0\">\n"
174  " </Metabolite>\n"
175  " </ListOfMetabolites>\n"
176  " <ListOfModelValues>\n"
177  " <ModelValue key=\"ModelValue_0\" name=\"rateConstant\" simulationType=\"assignment\">\n"
178  " <Expression>\n"
179  " 1.0/4.0+2.0\n"
180  " </Expression>\n"
181  " </ModelValue>\n"
182  " </ListOfModelValues>\n"
183  " <ListOfReactions>\n"
184  " <Reaction key=\"Reaction_0\" name=\"hexokinase\" reversible=\"false\">\n"
185  " <ListOfSubstrates>\n"
186  " <Substrate metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
187  " <Substrate metabolite=\"Metabolite_2\" stoichiometry=\"1\"/>\n"
188  " </ListOfSubstrates>\n"
189  " <ListOfProducts>\n"
190  " <Product metabolite=\"Metabolite_1\" stoichiometry=\"1\"/>\n"
191  " <Product metabolite=\"Metabolite_3\" stoichiometry=\"1\"/>\n"
192  " </ListOfProducts>\n"
193  " <ListOfConstants>\n"
194  " <Constant key=\"Parameter_93\" name=\"v\" value=\"0.5\"/>\n"
195  " </ListOfConstants>\n"
196  " <KineticLaw function=\"Function_6\">\n"
197  " <ListOfCallParameters>\n"
198  " <CallParameter functionParameter=\"FunctionParameter_49\">\n"
199  " <SourceParameter reference=\"Parameter_93\"/>\n"
200  " </CallParameter>\n"
201  " </ListOfCallParameters>\n"
202  " </KineticLaw>\n"
203  " </Reaction>\n"
204  " <Reaction key=\"Reaction_1\" name=\"hexokinase-backwards\" reversible=\"false\">\n"
205  " <ListOfSubstrates>\n"
206  " <Substrate metabolite=\"Metabolite_1\" stoichiometry=\"1\"/>\n"
207  " <Substrate metabolite=\"Metabolite_3\" stoichiometry=\"1\"/>\n"
208  " </ListOfSubstrates>\n"
209  " <ListOfProducts>\n"
210  " <Product metabolite=\"Metabolite_0\" stoichiometry=\"1\"/>\n"
211  " <Product metabolite=\"Metabolite_2\" stoichiometry=\"1\"/>\n"
212  " </ListOfProducts>\n"
213  " <ListOfConstants>\n"
214  " <Constant key=\"Parameter_94\" name=\"k1\" value=\"1\"/>\n"
215  " </ListOfConstants>\n"
216  " <KineticLaw function=\"Function_13\">\n"
217  " <ListOfCallParameters>\n"
218  " <CallParameter functionParameter=\"FunctionParameter_81\">\n"
219  " <SourceParameter reference=\"ModelValue_0\"/>\n"
220  " </CallParameter>\n"
221  " <CallParameter functionParameter=\"FunctionParameter_79\">\n"
222  " <SourceParameter reference=\"Metabolite_1\"/>\n"
223  " <SourceParameter reference=\"Metabolite_3\"/>\n"
224  " </CallParameter>\n"
225  " </ListOfCallParameters>\n"
226  " </KineticLaw>\n"
227  " </Reaction>\n"
228  " </ListOfReactions>\n"
229  " <StateTemplate>\n"
230  " <StateTemplateVariable objectReference=\"Model_0\"/>\n"
231  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
232  " <StateTemplateVariable objectReference=\"Metabolite_3\"/>\n"
233  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
234  " <StateTemplateVariable objectReference=\"Metabolite_0\"/>\n"
235  " <StateTemplateVariable objectReference=\"Metabolite_2\"/>\n"
236  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
237  " </StateTemplate>\n"
238  " <InitialState type=\"initialState\">\n"
239  " 0 0 0 2.25 3.011070895e+16 3.011070895e+16 5 \n"
240  " </InitialState>\n"
241  " </Model>\n"
242  "</COPASI>\n";
243 
static const char * CPS_STRING
Definition: test000100.h:40
void tearDown()
Definition: test000100.cpp:64
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
void test_bug1692_1()
Definition: test000100.cpp:81
struct sigaction * pNewAct
Definition: test000100.cpp:39
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static CCopasiDataModel * addDatamodel()
void setUp()
Definition: test000100.cpp:42
void test_bug1692_2()
Definition: test000100.cpp:109
CCopasiDataModel * pDataModel
Definition: test000100.h:42
static void init(int argc, char *argv[], const bool &withGui=false)
struct sigaction * pOldAct
Definition: test000100.cpp:40
void abort_handler(int)
Definition: test000100.cpp:33