21 #include "sbml/xml/XMLNode.h"
22 #include "sbml/xml/XMLAttributes.h"
23 #include "sbml/xml/XMLInputStream.h"
50 XMLInputStream inputstream(s.c_str(),
false);
51 XMLNode node(inputstream);
52 CPPUNIT_ASSERT(node.getName() ==
"sbml");
53 unsigned int i, iMax = node.getNumChildren();
54 CPPUNIT_ASSERT(iMax > 0);
55 const XMLNode* pModelNode = NULL;
56 const XMLNode* pUnitDefinitionsNode = NULL;
57 const XMLNode* pLengthNode = NULL;
58 const XMLNode* pAreaNode = NULL;
59 const XMLNode* pVolumeNode = NULL;
60 const XMLNode* pTimeNode = NULL;
61 const XMLNode* pSubstanceNode = NULL;
62 const XMLNode* pListOfUnitsNode = NULL;
63 const XMLNode* pUnitNode = NULL;
64 const XMLNode* pChild = NULL;
65 const XMLAttributes* pAttr = NULL;
69 for (
unsigned int i = 0; i < iMax; ++i)
71 pChild = &node.getChild(i);
73 if (pChild->getName() ==
"model")
81 assert(pModelNode != NULL);
82 pAttr = &pModelNode->getAttributes();
83 int index = pAttr->getIndex(
"lengthUnits");
84 CPPUNIT_ASSERT(index != -1);
85 std::string v = pAttr->getValue(index);
86 CPPUNIT_ASSERT(v ==
"length");
88 index = pAttr->getIndex(
"areaUnits");
89 CPPUNIT_ASSERT(index != -1);
90 v = pAttr->getValue(index);
91 CPPUNIT_ASSERT(v ==
"area");
93 index = pAttr->getIndex(
"volumeUnits");
94 CPPUNIT_ASSERT(index != -1);
95 v = pAttr->getValue(index);
96 CPPUNIT_ASSERT(v ==
"volume");
98 index = pAttr->getIndex(
"timeUnits");
99 CPPUNIT_ASSERT(index != -1);
100 v = pAttr->getValue(index);
101 CPPUNIT_ASSERT(v ==
"time");
103 index = pAttr->getIndex(
"substanceUnits");
104 CPPUNIT_ASSERT(index != -1);
105 v = pAttr->getValue(index);
106 CPPUNIT_ASSERT(v ==
"substance");
108 index = pAttr->getIndex(
"extentUnits");
109 CPPUNIT_ASSERT(index != -1);
110 v = pAttr->getValue(index);
111 CPPUNIT_ASSERT(v ==
"substance");
115 iMax = pModelNode->getNumChildren();
116 CPPUNIT_ASSERT(iMax > 0);
118 for (i = 0; i < iMax; ++i)
120 pChild = &pModelNode->getChild(i);
122 if (pChild->getName() ==
"listOfUnitDefinitions")
124 pUnitDefinitionsNode = pChild;
130 CPPUNIT_ASSERT(pUnitDefinitionsNode != NULL);
132 iMax = pUnitDefinitionsNode->getNumChildren();
134 CPPUNIT_ASSERT(iMax > 4);
141 for (i = 0; i < iMax; ++i)
143 pChild = &pUnitDefinitionsNode->getChild(i);
145 if (pChild->getName() ==
"unitDefinition")
147 pAttr = &pChild->getAttributes();
148 index = pAttr->getIndex(
"id");
149 CPPUNIT_ASSERT(index != -1);
150 v = pAttr->getValue(index);
157 else if (v ==
"length")
159 pLengthNode = pChild;
162 else if (v ==
"volume")
164 pVolumeNode = pChild;
167 else if (v ==
"time")
172 else if (v ==
"substance")
174 pSubstanceNode = pChild;
180 unsigned int numUnitChildren = 0;
181 CPPUNIT_ASSERT(pAreaNode != NULL);
182 iMax = pAreaNode->getNumChildren();
183 CPPUNIT_ASSERT(iMax > 0);
185 for (i = 0; i < iMax; ++i)
187 pChild = &pAreaNode->getChild(i);
189 if (pChild->getName() ==
"listOfUnits")
191 pListOfUnitsNode = pChild;
196 CPPUNIT_ASSERT(pListOfUnitsNode != NULL);
197 iMax = pListOfUnitsNode->getNumChildren();
198 CPPUNIT_ASSERT(iMax > 0);
200 for (i = 0; i < iMax; ++i)
202 pChild = &pListOfUnitsNode->getChild(i);
204 if (pChild->getName() ==
"unit")
215 CPPUNIT_ASSERT(numUnitChildren == 1);
216 CPPUNIT_ASSERT(pUnitNode != NULL);
217 pAttr = &pUnitNode->getAttributes();
219 index = pAttr->getIndex(
"kind");
220 CPPUNIT_ASSERT(index != -1);
221 v = pAttr->getValue(index);
222 CPPUNIT_ASSERT(v ==
"metre");
224 index = pAttr->getIndex(
"multiplier");
225 CPPUNIT_ASSERT(index != -1);
226 v = pAttr->getValue(index);
227 CPPUNIT_ASSERT(v ==
"1");
229 index = pAttr->getIndex(
"scale");
230 CPPUNIT_ASSERT(index != -1);
231 v = pAttr->getValue(index);
232 CPPUNIT_ASSERT(v ==
"-3");
234 index = pAttr->getIndex(
"exponent");
235 CPPUNIT_ASSERT(index != -1);
236 v = pAttr->getValue(index);
237 CPPUNIT_ASSERT(v ==
"2");
240 CPPUNIT_ASSERT(pLengthNode != NULL);
241 iMax = pLengthNode->getNumChildren();
243 CPPUNIT_ASSERT(iMax > 0);
244 pListOfUnitsNode = NULL;
246 for (i = 0; i < iMax; ++i)
248 pChild = &pLengthNode->getChild(i);
250 if (pChild->getName() ==
"listOfUnits")
252 pListOfUnitsNode = pChild;
257 CPPUNIT_ASSERT(pListOfUnitsNode != NULL);
258 iMax = pListOfUnitsNode->getNumChildren();
259 CPPUNIT_ASSERT(iMax > 0);
261 for (i = 0; i < iMax; ++i)
263 pChild = &pListOfUnitsNode->getChild(i);
265 if (pChild->getName() ==
"unit")
273 CPPUNIT_ASSERT(numUnitChildren == 1);
274 CPPUNIT_ASSERT(pUnitNode != NULL);
275 pAttr = &pUnitNode->getAttributes();
277 index = pAttr->getIndex(
"kind");
278 CPPUNIT_ASSERT(index != -1);
279 v = pAttr->getValue(index);
280 CPPUNIT_ASSERT(v ==
"metre");
282 index = pAttr->getIndex(
"multiplier");
283 CPPUNIT_ASSERT(index != -1);
284 v = pAttr->getValue(index);
285 CPPUNIT_ASSERT(v ==
"1");
287 index = pAttr->getIndex(
"scale");
288 CPPUNIT_ASSERT(index != -1);
289 v = pAttr->getValue(index);
290 CPPUNIT_ASSERT(v ==
"0");
292 index = pAttr->getIndex(
"exponent");
293 CPPUNIT_ASSERT(index != -1);
294 v = pAttr->getValue(index);
295 CPPUNIT_ASSERT(v ==
"1");
297 CPPUNIT_ASSERT(pVolumeNode != NULL);
298 iMax = pVolumeNode->getNumChildren();
300 CPPUNIT_ASSERT(iMax > 0);
301 pListOfUnitsNode = NULL;
303 for (i = 0; i < iMax; ++i)
305 pChild = &pVolumeNode->getChild(i);
307 if (pChild->getName() ==
"listOfUnits")
309 pListOfUnitsNode = pChild;
314 CPPUNIT_ASSERT(pListOfUnitsNode != NULL);
315 iMax = pListOfUnitsNode->getNumChildren();
316 CPPUNIT_ASSERT(iMax > 0);
318 for (i = 0; i < iMax; ++i)
320 pChild = &pListOfUnitsNode->getChild(i);
322 if (pChild->getName() ==
"unit")
330 CPPUNIT_ASSERT(numUnitChildren == 1);
331 CPPUNIT_ASSERT(pUnitNode != NULL);
332 pAttr = &pUnitNode->getAttributes();
334 index = pAttr->getIndex(
"kind");
335 CPPUNIT_ASSERT(index != -1);
336 v = pAttr->getValue(index);
337 CPPUNIT_ASSERT(v ==
"litre");
339 index = pAttr->getIndex(
"multiplier");
340 CPPUNIT_ASSERT(index != -1);
341 v = pAttr->getValue(index);
342 CPPUNIT_ASSERT(v ==
"1");
344 index = pAttr->getIndex(
"scale");
345 CPPUNIT_ASSERT(index != -1);
346 v = pAttr->getValue(index);
347 CPPUNIT_ASSERT(v ==
"0");
349 index = pAttr->getIndex(
"exponent");
350 CPPUNIT_ASSERT(index != -1);
351 v = pAttr->getValue(index);
352 CPPUNIT_ASSERT(v ==
"1");
354 CPPUNIT_ASSERT(pTimeNode != NULL);
355 iMax = pTimeNode->getNumChildren();
357 CPPUNIT_ASSERT(iMax > 0);
358 pListOfUnitsNode = NULL;
360 for (i = 0; i < iMax; ++i)
362 pChild = &pTimeNode->getChild(i);
364 if (pChild->getName() ==
"listOfUnits")
366 pListOfUnitsNode = pChild;
371 CPPUNIT_ASSERT(pListOfUnitsNode != NULL);
372 iMax = pListOfUnitsNode->getNumChildren();
373 CPPUNIT_ASSERT(iMax > 0);
375 for (i = 0; i < iMax; ++i)
377 pChild = &pListOfUnitsNode->getChild(i);
379 if (pChild->getName() ==
"unit")
387 CPPUNIT_ASSERT(numUnitChildren == 1);
388 CPPUNIT_ASSERT(pUnitNode != NULL);
389 pAttr = &pUnitNode->getAttributes();
391 index = pAttr->getIndex(
"kind");
392 CPPUNIT_ASSERT(index != -1);
393 v = pAttr->getValue(index);
394 CPPUNIT_ASSERT(v ==
"second");
396 index = pAttr->getIndex(
"multiplier");
397 CPPUNIT_ASSERT(index != -1);
398 v = pAttr->getValue(index);
399 CPPUNIT_ASSERT(v ==
"1");
401 index = pAttr->getIndex(
"scale");
402 CPPUNIT_ASSERT(index != -1);
403 v = pAttr->getValue(index);
404 CPPUNIT_ASSERT(v ==
"0");
406 index = pAttr->getIndex(
"exponent");
407 CPPUNIT_ASSERT(index != -1);
408 v = pAttr->getValue(index);
409 CPPUNIT_ASSERT(v ==
"1");
412 CPPUNIT_ASSERT(pSubstanceNode != NULL);
413 iMax = pSubstanceNode->getNumChildren();
415 CPPUNIT_ASSERT(iMax > 0);
416 pListOfUnitsNode = NULL;
418 for (i = 0; i < iMax; ++i)
420 pChild = &pSubstanceNode->getChild(i);
422 if (pChild->getName() ==
"listOfUnits")
424 pListOfUnitsNode = pChild;
429 CPPUNIT_ASSERT(pListOfUnitsNode != NULL);
430 iMax = pListOfUnitsNode->getNumChildren();
431 CPPUNIT_ASSERT(iMax > 0);
433 for (i = 0; i < iMax; ++i)
435 pChild = &pListOfUnitsNode->getChild(i);
437 if (pChild->getName() ==
"unit")
445 CPPUNIT_ASSERT(numUnitChildren == 1);
446 CPPUNIT_ASSERT(pUnitNode != NULL);
447 pAttr = &pUnitNode->getAttributes();
449 index = pAttr->getIndex(
"kind");
450 CPPUNIT_ASSERT(index != -1);
451 v = pAttr->getValue(index);
452 CPPUNIT_ASSERT(v ==
"mole");
454 index = pAttr->getIndex(
"multiplier");
455 CPPUNIT_ASSERT(index != -1);
456 v = pAttr->getValue(index);
457 CPPUNIT_ASSERT(v ==
"1");
459 index = pAttr->getIndex(
"scale");
460 CPPUNIT_ASSERT(index != -1);
461 v = pAttr->getValue(index);
462 CPPUNIT_ASSERT(v ==
"0");
464 index = pAttr->getIndex(
"exponent");
465 CPPUNIT_ASSERT(index != -1);
466 v = pAttr->getValue(index);
467 CPPUNIT_ASSERT(v ==
"1");
473 "<sbml xmlns=\"http://www.sbml.org/sbml/level3/version1/core\" xmlns:comp=\"http://www.sbml.org/sbml/level3/version1/comp/version1\" level=\"3\" version=\"1\" > \n"
474 "<model id=\"Module_1_1\" name=\"Module_1\" areaUnits=\"area\" substanceUnits=\"mole\" >\n"
475 " <listOfUnitDefinitions>\n"
476 " <unitDefinition id=\"area\" name=\"area\">\n"
478 " <unit exponent=\"2\" kind=\"metre\" multiplier=\"1.0\" scale=\"-3\"/>\n"
480 " </unitDefinition>\n"
481 " </listOfUnitDefinitions>\n"
482 " <listOfCompartments>\n"
483 " <compartment id=\"cell_1\" name=\"cell\" size=\"1.0\" constant=\"false\" spatialDimensions=\"2.0\" />\n"
484 " </listOfCompartments>\n"
486 " <species id=\"CycB_1\" name=\"CycB\" compartment=\"cell_1\" initialConcentration=\"1.0\" hasOnlySubstanceUnits=\"false\" boundaryCondition=\"false\" constant=\"false\" />\n"
487 " </listOfSpecies> \n"
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
CCopasiDataModel * pDataModel
static const char * SBML_STRING
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)