1 /** 2 * @file TestReadDynExtension.cpp 3 * @brief Unit tests of reading DynExtension 4 * @author Sarah Keating 5 */ 6 7 #include <limits> 8 9 #include <iostream> 10 #include <check.h> 11 #include <sbml/SBMLTypes.h> 12 #include <sbml/extension/SBMLExtensionRegistry.h> 13 #include <sbml/conversion/ConversionProperties.h> 14 #include <sbml/packages/dyn/extension/DynExtension.h> 15 #include <sbml/packages/dyn/common/DynExtensionTypes.h> 16 #include <sbml/packages/dyn/validator/DynSBMLError.h> 17 #include <string> 18 19 /** @cond doxygenIgnored */ 20 21 using namespace std; 22 LIBSBML_CPP_NAMESPACE_USE 23 24 /** @endcond doxygenIgnored */ 25 26 27 CK_CPPSTART 28 29 extern char *TestDataDirectory; 30 START_TEST(test_DynExtension_read_L3V1V1)31START_TEST (test_DynExtension_read_L3V1V1) 32 { 33 string filename = string(TestDataDirectory) + "dyn_example1.xml"; 34 SBMLDocument *document = readSBMLFromFile(filename.c_str()); 35 36 fail_unless(document->getPackageName() == "core"); 37 38 Model *model = document->getModel(); 39 40 fail_unless(model != NULL); 41 fail_unless(model->getPackageName() == "core"); 42 fail_unless(document->getNumErrors() == 0); 43 44 // get the first event 45 Event * e = model->getEvent(0); 46 fail_unless(e != NULL); 47 fail_unless(e->getPackageName() == "core"); 48 49 // get dyn plugin 50 DynEventPlugin* eplugin = static_cast<DynEventPlugin*>(e->getPlugin("dyn")); 51 fail_unless(eplugin != NULL); 52 53 fail_unless(eplugin->isSetCboTerm() == true); 54 fail_unless(eplugin->getCboTerm() == "http://cbo.biocomplexity.indiana.edu/svn/cbo/trunk/CBO_1_0.owl#CellDeath"); 55 56 fail_unless(eplugin->isSetApplyToAll() == true); 57 fail_unless(eplugin->getApplyToAll() == true); 58 59 60 // get the second event 61 e = model->getEvent(1); 62 fail_unless(e != NULL); 63 fail_unless(e->getPackageName() == "core"); 64 65 // get dyn plugin 66 eplugin = static_cast<DynEventPlugin*>(e->getPlugin("dyn")); 67 fail_unless(eplugin != NULL); 68 69 fail_unless(eplugin->isSetCboTerm() == true); 70 fail_unless(eplugin->getCboTerm() == "http://cbo.biocomplexity.indiana.edu/svn/cbo/trunk/CBO_1_0.owl#CellDevision"); 71 72 fail_unless(eplugin->isSetApplyToAll() == true); 73 fail_unless(eplugin->getApplyToAll() == true); 74 75 delete document; 76 } 77 END_TEST 78 79 START_TEST(test_DynExtension_read_L3V1V1_2)80START_TEST (test_DynExtension_read_L3V1V1_2) 81 { 82 string filename = string(TestDataDirectory) + "dyn_example2.xml"; 83 SBMLDocument *document = readSBMLFromFile(filename.c_str()); 84 85 fail_unless(document->getPackageName() == "core"); 86 87 Model *model = document->getModel(); 88 89 fail_unless(model != NULL); 90 fail_unless(model->getPackageName() == "core"); 91 fail_unless(document->getNumErrors() == 0); 92 93 // get the first compartment 94 Compartment * c = model->getCompartment(0); 95 fail_unless(c != NULL); 96 fail_unless(c->getPackageName() == "core"); 97 98 // get dyn plugin 99 DynCompartmentPlugin* eplugin = static_cast<DynCompartmentPlugin*>(c->getPlugin("dyn")); 100 fail_unless(eplugin != NULL); 101 102 fail_unless(eplugin->isSetCboTerm() == false); 103 104 fail_unless(eplugin->getNumSpatialComponents() == 2); 105 106 SpatialComponent * sc = eplugin->getSpatialComponent(0); 107 108 fail_unless(sc != NULL); 109 110 fail_unless(sc->getSpatialIndex() == DYN_SPATIALKIND_CARTESIANX); 111 fail_unless(sc->getVariable() == "q1_X"); 112 113 sc = eplugin->getSpatialComponent(1); 114 115 fail_unless(sc != NULL); 116 117 fail_unless(sc->getSpatialIndex() == DYN_SPATIALKIND_CARTESIANY); 118 fail_unless(sc->getVariable() == "q1_Y"); 119 120 delete document; 121 } 122 END_TEST 123 124 START_TEST(test_DynExtension_read_L3V1V1_defaultNS)125START_TEST (test_DynExtension_read_L3V1V1_defaultNS) 126 { 127 string filename = string(TestDataDirectory) + "dyn_example2_defaultNS.xml"; 128 SBMLDocument *document = readSBMLFromFile(filename.c_str()); 129 130 fail_unless(document->getPackageName() == "core"); 131 132 Model *model = document->getModel(); 133 134 fail_unless(model != NULL); 135 fail_unless(model->getPackageName() == "core"); 136 fail_unless(document->getNumErrors() == 0); 137 138 // get the first compartment 139 Compartment * c = model->getCompartment(0); 140 fail_unless(c != NULL); 141 fail_unless(c->getPackageName() == "core"); 142 143 // get dyn plugin 144 DynCompartmentPlugin* eplugin = static_cast<DynCompartmentPlugin*>(c->getPlugin("dyn")); 145 fail_unless(eplugin != NULL); 146 147 fail_unless(eplugin->isSetCboTerm() == false); 148 149 fail_unless(eplugin->getNumSpatialComponents() == 2); 150 151 SpatialComponent * sc = eplugin->getSpatialComponent(0); 152 153 fail_unless(sc != NULL); 154 155 fail_unless(sc->getSpatialIndex() == DYN_SPATIALKIND_CARTESIANX); 156 fail_unless(sc->getVariable() == "q1_X"); 157 158 sc = eplugin->getSpatialComponent(1); 159 160 fail_unless(sc != NULL); 161 162 fail_unless(sc->getSpatialIndex() == DYN_SPATIALKIND_CARTESIANY); 163 fail_unless(sc->getVariable() == "q1_Y"); 164 165 delete document; 166 } 167 END_TEST 168 169 START_TEST(test_DynExtension_read_L3V1V1_unknown_elements)170START_TEST (test_DynExtension_read_L3V1V1_unknown_elements) 171 { 172 const char* s1 = 173 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 174 "<sbml xmlns=\"http://www.sbml.org/sbml/level3/version1/core\" xmlns:dyn=\"http://www.sbml.org/sbml/level3/version1/dyn/version1\" level=\"3\" version=\"1\" dyn:required=\"true\">\n" 175 " <model>\n" 176 " <listOfCompartments>\n" 177 " <compartment id=\"cytosol\" constant=\"true\">\n" 178 " <listOfSpatialComponents xmlns=\"http://www.sbml.org/sbml/level3/version1/dyn/version1\">\n" 179 " <spatialComponent spatialIndex=\"cartesianX\" variable=\"q1_X\" unknown=\"ss\"/>\n" 180 " </listOfSpatialComponents>\n" 181 " </compartment>\n" 182 " </listOfCompartments>\n" 183 " </model>\n" 184 "</sbml>\n" 185 ; 186 187 SBMLDocument *document = readSBMLFromString(s1); 188 Model *model = document->getModel(); 189 190 fail_unless(model != NULL); 191 fail_unless(document->getNumErrors() == 1); 192 193 delete document; 194 } 195 END_TEST 196 197 Suite * create_suite_ReadDynExtension(void)198create_suite_ReadDynExtension (void) 199 { 200 Suite *suite = suite_create("ReadDynExtension"); 201 TCase *tcase = tcase_create("ReadDynExtension"); 202 203 tcase_add_test( tcase, test_DynExtension_read_L3V1V1); 204 tcase_add_test( tcase, test_DynExtension_read_L3V1V1_2); 205 tcase_add_test( tcase, test_DynExtension_read_L3V1V1_defaultNS); 206 tcase_add_test( tcase, test_DynExtension_read_L3V1V1_unknown_elements); 207 suite_add_tcase(suite, tcase); 208 209 return suite; 210 } 211 212 213 CK_CPPEND 214