COPASI API  4.16.103
test000089.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000089.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 #include "test000089.h"
15 
16 #include "utilities.hpp"
20 
21 #include <sbml/SBMLDocument.h>
22 #include <sbml/Model.h>
23 #include <sbml/Species.h>
24 #include <sbml/Parameter.h>
25 #include <sbml/Rule.h>
26 #include <sbml/math/ASTNode.h>
27 
28 // test for bug1412
29 
30 CCopasiDataModel* test000089::pCOPASIDATAMODEL = NULL;
31 
33 {
34  // Create the root container.
35  CCopasiRootContainer::init(0, NULL, false);
36  // Create the global data model.
38 }
39 
41 {
43 }
44 
46 {
47  try
48  {
49  std::istringstream iss(test000089::MODEL_STRING1);
50  bool result = load_cps_model_from_stream(iss, *pCOPASIDATAMODEL);
51  CPPUNIT_ASSERT(result == true);
52  CPPUNIT_ASSERT(pCOPASIDATAMODEL->getModel() != NULL);
53  }
54  catch (...)
55  {
56  // there should be no exception
57  CPPUNIT_ASSERT(false);
58  }
59 
60  try
61  {
62  CPPUNIT_ASSERT(pCOPASIDATAMODEL->exportSBMLToString(NULL, 2, 3).empty() == false);
63  }
64  catch (...)
65  {
66  // there should be no exception
67  CPPUNIT_ASSERT(false);
68  }
69 
70  CPPUNIT_ASSERT(CCopasiMessage::size() == 0);
71  const SBMLDocument* pDocument = pCOPASIDATAMODEL->getCurrentSBMLDocument();
72  CPPUNIT_ASSERT(pDocument != NULL);
73  CPPUNIT_ASSERT(pDocument->getLevel() == 2);
74  CPPUNIT_ASSERT(pDocument->getVersion() == 3);
75  const Model* pModel = pDocument->getModel();
76  CPPUNIT_ASSERT(pModel != NULL);
77  CPPUNIT_ASSERT(pModel->getListOfFunctionDefinitions()->size() == 0);
78  CPPUNIT_ASSERT(pModel->getListOfCompartments()->size() == 1);
79  CPPUNIT_ASSERT(pModel->getListOfSpecies()->size() == 1);
80  CPPUNIT_ASSERT(pModel->getListOfParameters()->size() == 1);
81  CPPUNIT_ASSERT(pModel->getListOfReactions()->size() == 0);
82  CPPUNIT_ASSERT(pModel->getListOfRules()->size() == 1);
83  const Rule* pRule = pModel->getRule(0);
84  CPPUNIT_ASSERT(pRule != NULL);
85  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
86  const AssignmentRule* pAssignmentRule = dynamic_cast<const AssignmentRule*>(pRule);
87  CPPUNIT_ASSERT(pAssignmentRule != NULL);
88  const Species* pSpecies = pModel->getSpecies(0);
89  CPPUNIT_ASSERT(pSpecies != NULL);
90  CPPUNIT_ASSERT(pSpecies->getName() == "M");
91  const Parameter* pParameter = pModel->getParameter(pAssignmentRule->getVariable());
92  CPPUNIT_ASSERT(pParameter != NULL);
93  CPPUNIT_ASSERT(pParameter->getName() == "MV");
94  const ASTNode* pMath = pAssignmentRule->getMath();
95  CPPUNIT_ASSERT(pMath != NULL);
96  CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE);
97  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
98  const ASTNode* pChild = pMath->getChild(0);
99  CPPUNIT_ASSERT(pChild != NULL);
100  CPPUNIT_ASSERT(pChild->getType() == AST_REAL);
101  CPPUNIT_ASSERT(fabs(pChild->getReal() - 1.0) < 1e-6);
102  pChild = pMath->getChild(1);
103  CPPUNIT_ASSERT(pChild != NULL);
104  CPPUNIT_ASSERT(pChild->getType() == AST_NAME);
105  CPPUNIT_ASSERT(pChild->getName() == pSpecies->getId());
106 }
107 
108 const char* test000089::MODEL_STRING1 =
109  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
110  "<!-- generated with COPASI 4.5.31 (development) (http://www.copasi.org) at 2010-03-01 08:59:11 UTC -->\n"
111  "<?oxygen RNGSchema=\"http://www.copasi.org/static/schema/CopasiML.rng\" type=\"xml\"?>\n"
112  "<COPASI xmlns=\"http://www.copasi.org/static/schema\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"31\">\n"
113  " <Model key=\"Model_1\" name=\"Model\" simulationType=\"time\" timeUnit=\"s\" volumeUnit=\"l\" areaUnit=\"µm²\" lengthUnit=\"m\" quantityUnit=\"#\" type=\"deterministic\">\n"
114  " <ListOfCompartments>\n"
115  " <Compartment key=\"Compartment_1\" name=\"C\" simulationType=\"fixed\" dimensionality=\"3\" />\n"
116  " </ListOfCompartments> \n"
117  " <ListOfMetabolites>\n"
118  " <Metabolite key=\"Metabolite_1\" name=\"M\" simulationType=\"fixed\" compartment=\"Compartment_1\" />\n"
119  " </ListOfMetabolites>\n"
120  " <ListOfModelValues>\n"
121  " <ModelValue key=\"ModelValue_1\" name=\"MV\" simulationType=\"assignment\">\n"
122  " <Expression>\n"
123  " 1/&lt;CN=Root,Model=Model,Vector=Compartments[C],Vector=Metabolites[M],Reference=Concentration&gt;\n"
124  " </Expression>\n"
125  " </ModelValue>\n"
126  " </ListOfModelValues>\n"
127  " <StateTemplate>\n"
128  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
129  " <StateTemplateVariable objectReference=\"ModelValue_1\"/>\n"
130  " <StateTemplateVariable objectReference=\"Compartment_1\"/>\n"
131  " <StateTemplateVariable objectReference=\"Metabolite_1\"/>\n"
132  " </StateTemplate>\n"
133  " <InitialState type=\"initialState\">\n"
134  " 0 1 2 3 \n"
135  " </InitialState>\n"
136  " </Model>\n"
137  "</COPASI>\n";
SBMLDocument * getCurrentSBMLDocument()
void test_bug1412()
Definition: test000089.cpp:45
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static size_t size()
void setUp()
Definition: test000089.cpp:32
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000089.h:35
static CCopasiDataModel * addDatamodel()
void tearDown()
Definition: test000089.cpp:40
static void init(int argc, char *argv[], const bool &withGui=false)
static const char * MODEL_STRING1
Definition: test000089.h:36