COPASI API  4.16.103
test000071.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000071.cpp,v $
3 // $Revision: 1.5 $
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 "test000071.h"
20 
21 #include <sstream>
22 #include "utilities.hpp"
24 #include "copasi/model/CModel.h"
25 #include "copasi/model/CMetab.h"
27 #include "copasi/model/CReaction.h"
30 
31 #include "sbml/SBMLDocument.h"
32 #include "sbml/Model.h"
33 #include "sbml/FunctionDefinition.h"
34 #include "sbml/math/ASTNode.h"
35 
37 
38 /**
39  * This test checks if the workaround for bug 1085 works.
40  * Or once libSBML has been fixed, it checks that the bug no longer occurs.
41  */
42 CCopasiDataModel* test000071::pCOPASIDATAMODEL = NULL;
43 
45 {
46  // Create the root container.
47  CCopasiRootContainer::init(0, NULL, false);
48  // Create the global data model.
50 }
51 
53 {
55 }
56 
58 {
59  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
60  std::istringstream iss(test000071::MODEL_STRING1);
61  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
62  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
63  const SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
64  CPPUNIT_ASSERT(pDocument == NULL);
65  CModel* pModel = pDataModel->getModel();
66  CPPUNIT_ASSERT(pModel != NULL);
67  std::string sbmlString = pDataModel->exportSBMLToString(NULL, 2, 1);
68  CPPUNIT_ASSERT(!sbmlString.empty());
69  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(sbmlString));
70  pDocument = pDataModel->getCurrentSBMLDocument();
71  CPPUNIT_ASSERT(pDocument != NULL);
72  const Model* pSBMLModel = pDocument->getModel();
73  CPPUNIT_ASSERT(pSBMLModel != NULL);
74  // check if there is one function defintition
75  CPPUNIT_ASSERT(pSBMLModel->getListOfFunctionDefinitions()->size() == 1);
76  const FunctionDefinition* pFunDef = pSBMLModel->getFunctionDefinition(0);
77  CPPUNIT_ASSERT(pFunDef != NULL);
78  CPPUNIT_ASSERT(pFunDef->getName() == "sqrt_call");
79  const ASTNode* pMath = pFunDef->getMath();
80  CPPUNIT_ASSERT(pMath != NULL);
81  // the last child should be the actual function expression
82  pMath = pMath->getChild(pMath->getNumChildren() - 1);
83  CPPUNIT_ASSERT(pMath != NULL);
84  // check that the root node is a root function call
85  CPPUNIT_ASSERT(pMath->getType() == AST_FUNCTION_ROOT);
86  // the root function can have either one or two arguments
87  // if there are two arguments the first one is the degree and needs to be 2
88  // since we have a sqrt call
89  CPPUNIT_ASSERT(pMath->getNumChildren() == 1 || pMath->getNumChildren() == 2);
90 
91  if (pMath->getNumChildren() == 2)
92  {
93  CPPUNIT_ASSERT(pMath->getChild(0) != NULL);
94  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_INTEGER);
95  CPPUNIT_ASSERT(pMath->getChild(0)->getInteger() == 2);
96  pMath = pMath->getChild(1);
97  CPPUNIT_ASSERT(pMath != NULL);
98  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
99  CPPUNIT_ASSERT(pMath->getName() == std::string("k"));
100  }
101  else if (pMath->getNumChildren() == 1)
102  {
103  pMath = pMath->getChild(0);
104  CPPUNIT_ASSERT(pMath != NULL);
105  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
106  CPPUNIT_ASSERT(pMath->getName() == std::string("k"));
107  }
108 }
109 
110 const char* test000071::MODEL_STRING1 =
111  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
112  "<!-- generated with COPASI 4.4.27 (Debug) (http://www.copasi.org) at 2008-09-27 14:44:36 UTC -->\n"
113  "<COPASI xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.copasi.org/static/schema.xsd\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"27\">\n"
114  " <ListOfFunctions>\n"
115  " <Function key=\"Function_47\" name=\"sqrt_call\" type=\"UserDefined\" reversible=\"unspecified\">\n"
116  " <Expression>\n"
117  " sqrt(k)\n"
118  " </Expression>\n"
119  " <ListOfParameterDescriptions>\n"
120  " <ParameterDescription key=\"FunctionParameter_243\" name=\"k\" order=\"0\" role=\"constant\"/>\n"
121  " </ListOfParameterDescriptions>\n"
122  " </Function>\n"
123  " </ListOfFunctions>\n"
124  " <Model key=\"Model_0\" name=\"New Model\" timeUnit=\"s\" volumeUnit=\"ml\" quantityUnit=\"mmol\" type=\"deterministic\">\n"
125  " <Comment>\n"
126  " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
127  " \n"
128  " </body>\n"
129  " </Comment>\n"
130  " <ListOfModelValues>\n"
131  " <ModelValue key=\"ModelValue_0\" name=\"P\" simulationType=\"assignment\">\n"
132  " <Expression>\n"
133  " sqrt_call(4)\n"
134  " </Expression>\n"
135  " </ModelValue>\n"
136  " </ListOfModelValues>\n"
137  " <StateTemplate>\n"
138  " <StateTemplateVariable objectReference=\"Model_0\"/>\n"
139  " <StateTemplateVariable objectReference=\"ModelValue_0\"/>\n"
140  " </StateTemplate>\n"
141  " <InitialState type=\"initialState\">\n"
142  " 0 0\n"
143  " </InitialState>\n"
144  " </Model>\n"
145  "</COPASI>\n"
146  ;
SBMLDocument * getCurrentSBMLDocument()
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
void tearDown()
Definition: test000071.cpp:52
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
void setUp()
Definition: test000071.cpp:44
static const char * MODEL_STRING1
Definition: test000071.h:33
static CCopasiDataModel * addDatamodel()
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
static void init(int argc, char *argv[], const bool &withGui=false)
Definition: CModel.h:50
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000071.h:34
void test_bug1085()
Definition: test000071.cpp:57