1 ///  @file    TestGetMultipleObjects.cs
2 ///  @brief   GetMultipleObjects unit tests
3 ///  @author  Frank Bergmann (Csharp conversion)
4 ///  @author  Akiya Jouraku (Csharp conversion)
5 ///  @author  Sarah Keating
6 
7 ///
8 ///  ====== WARNING ===== WARNING ===== WARNING ===== WARNING ===== WARNING ======
9 ///
10 ///  DO NOT EDIT THIS FILE.
11 ///
12 ///  This file was generated automatically by converting the file located at
13 ///  src/sbml/test/TestGetMultipleObjects.cpp
14 ///  using the conversion program dev/utilities/translateTests/translateTests.pl.
15 ///  Any changes made here will be lost the next time the file is regenerated.
16 ///
17 ///  -----------------------------------------------------------------------------
18 ///  This file is part of libSBML.  Please visit http://sbml.org for more
19 ///  information about SBML, and the latest version of libSBML.
20 ///
21 ///  Copyright 2005-2010 California Institute of Technology.
22 ///  Copyright 2002-2005 California Institute of Technology and
23 ///                      Japan Science and Technology Corporation.
24 ///
25 ///  This library is free software; you can redistribute it and/or modify it
26 ///  under the terms of the GNU Lesser General Public License as published by
27 ///  the Free Software Foundation.  A copy of the license agreement is provided
28 ///  in the file named "LICENSE.txt" included with this software distribution
29 ///  and also available online as http://sbml.org/software/libsbml/license.html
30 ///  -----------------------------------------------------------------------------
31 
32 
33 namespace LibSBMLCSTest.sbml {
34 
35   using libsbmlcs;
36 
37   using System;
38 
39   using System.IO;
40 
41   public class TestGetMultipleObjects {
42     public class AssertionError : System.Exception
43     {
AssertionError()44       public AssertionError() : base()
45       {
46 
47       }
48     }
49 
50 
assertTrue(bool condition)51     static void assertTrue(bool condition)
52     {
53       if (condition == true)
54       {
55         return;
56       }
57       throw new AssertionError();
58     }
59 
assertEquals(object a, object b)60     static void assertEquals(object a, object b)
61     {
62       if ( (a == null) && (b == null) )
63       {
64         return;
65       }
66       else if ( (a == null) || (b == null) )
67       {
68         throw new AssertionError();
69       }
70       else if (a.Equals(b))
71       {
72         return;
73       }
74 
75       throw new AssertionError();
76     }
77 
assertNotEquals(object a, object b)78     static void assertNotEquals(object a, object b)
79     {
80       if ( (a == null) && (b == null) )
81       {
82         throw new AssertionError();
83       }
84       else if ( (a == null) || (b == null) )
85       {
86         return;
87       }
88       else if (a.Equals(b))
89       {
90         throw new AssertionError();
91       }
92     }
93 
assertEquals(bool a, bool b)94     static void assertEquals(bool a, bool b)
95     {
96       if ( a == b )
97       {
98         return;
99       }
100       throw new AssertionError();
101     }
102 
assertNotEquals(bool a, bool b)103     static void assertNotEquals(bool a, bool b)
104     {
105       if ( a != b )
106       {
107         return;
108       }
109       throw new AssertionError();
110     }
111 
assertEquals(int a, int b)112     static void assertEquals(int a, int b)
113     {
114       if ( a == b )
115       {
116         return;
117       }
118       throw new AssertionError();
119     }
120 
assertNotEquals(int a, int b)121     static void assertNotEquals(int a, int b)
122     {
123       if ( a != b )
124       {
125         return;
126       }
127       throw new AssertionError();
128     }
129 
130 
test_GetMultipleObjects_allElements()131     public void test_GetMultipleObjects_allElements()
132     {
133       SBMLReader reader = new SBMLReader();
134       SBMLDocument d;
135       string filename =  "../../sbml/test/test-data/";
136       filename += "multiple-ids.xml";
137       d = reader.readSBML(filename);
138       if (d == null);
139       {
140       }
141       SBaseList list = d.getListOfAllElements();
142       assertTrue( list.getSize() == 37 );
143       d = null;
144     }
145 
test_GetMultipleObjects_getId()146     public void test_GetMultipleObjects_getId()
147     {
148       SBMLReader reader = new SBMLReader();
149       SBMLDocument d;
150       string filename =  "../../sbml/test/test-data/";
151       filename += "multiple-ids.xml";
152       d = reader.readSBML(filename);
153       if (d == null);
154       {
155       }
156       SBase obj = d.getElementBySId("no_id");
157       assertTrue( obj == null );
158       obj = d.getElementBySId("");
159       assertTrue( obj == null );
160       obj = d.getElementBySId("find_id");
161       assertTrue( obj != null );
162       assertTrue( obj.getTypeCode() == libsbml.SBML_MODEL );
163       obj = d.getElementBySId("func1");
164       assertTrue( obj != null );
165       assertTrue( obj.getTypeCode() == libsbml.SBML_FUNCTION_DEFINITION );
166       obj = d.getElementBySId("comp");
167       assertTrue( obj != null );
168       assertTrue( obj.getTypeCode() == libsbml.SBML_COMPARTMENT );
169       obj = d.getElementBySId("b");
170       assertTrue( obj != null );
171       assertTrue( obj.getTypeCode() == libsbml.SBML_SPECIES );
172       obj = d.getElementBySId("x");
173       assertTrue( obj != null );
174       assertTrue( obj.getTypeCode() == libsbml.SBML_PARAMETER );
175       obj = d.getElementBySId("J0");
176       assertTrue( obj != null );
177       assertTrue( obj.getTypeCode() == libsbml.SBML_REACTION );
178       obj = d.getElementBySId("E0");
179       assertTrue( obj != null );
180       assertTrue( obj.getTypeCode() == libsbml.SBML_EVENT );
181       d = null;
182     }
183 
test_GetMultipleObjects_getMetaId()184     public void test_GetMultipleObjects_getMetaId()
185     {
186       SBMLReader reader = new SBMLReader();
187       SBMLDocument d;
188       string filename =  "../../sbml/test/test-data/";
189       filename += "multiple-ids.xml";
190       d = reader.readSBML(filename);
191       if (d == null);
192       {
193       }
194       SBase obj = d.getElementByMetaId("no_id");
195       assertTrue( obj == null );
196       obj = d.getElementByMetaId("");
197       assertTrue( obj == null );
198       obj = d.getElementByMetaId("meta1");
199       assertTrue( obj != null );
200       assertTrue( obj.getTypeCode() == libsbml.SBML_DOCUMENT );
201       obj = d.getElementByMetaId("meta2");
202       assertTrue( obj != null );
203       assertTrue( obj.getTypeCode() == libsbml.SBML_MODEL );
204       obj = d.getElementByMetaId("meta3");
205       assertTrue( obj != null );
206       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
207       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_COMPARTMENT );
208       obj = d.getElementByMetaId("meta4");
209       assertTrue( obj != null );
210       assertTrue( obj.getTypeCode() == libsbml.SBML_COMPARTMENT );
211       obj = d.getElementByMetaId("meta5");
212       assertTrue( obj != null );
213       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
214       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_SPECIES );
215       obj = d.getElementByMetaId("meta6");
216       assertTrue( obj != null );
217       assertTrue( obj.getTypeCode() == libsbml.SBML_SPECIES );
218       obj = d.getElementByMetaId("meta7");
219       assertTrue( obj != null );
220       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
221       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_REACTION );
222       obj = d.getElementByMetaId("meta8");
223       assertTrue( obj != null );
224       assertTrue( obj.getTypeCode() == libsbml.SBML_REACTION );
225       obj = d.getElementByMetaId("meta9");
226       assertTrue( obj != null );
227       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
228       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_SPECIES_REFERENCE );
229       obj = d.getElementByMetaId("meta10");
230       assertTrue( obj != null );
231       assertTrue( obj.getTypeCode() == libsbml.SBML_SPECIES_REFERENCE );
232       obj = d.getElementByMetaId("meta11");
233       assertTrue( obj != null );
234       assertTrue( obj.getTypeCode() == libsbml.SBML_KINETIC_LAW );
235       obj = d.getElementByMetaId("meta12");
236       assertTrue( obj != null );
237       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
238       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_EVENT );
239       obj = d.getElementByMetaId("meta13");
240       assertTrue( obj != null );
241       assertTrue( obj.getTypeCode() == libsbml.SBML_EVENT );
242       obj = d.getElementByMetaId("meta14");
243       assertTrue( obj != null );
244       assertTrue( obj.getTypeCode() == libsbml.SBML_TRIGGER );
245       obj = d.getElementByMetaId("meta15");
246       assertTrue( obj != null );
247       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
248       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_EVENT_ASSIGNMENT );
249       obj = d.getElementByMetaId("meta16");
250       assertTrue( obj != null );
251       assertTrue( obj.getTypeCode() == libsbml.SBML_EVENT_ASSIGNMENT );
252       obj = d.getElementByMetaId("meta17");
253       assertTrue( obj != null );
254       assertTrue( obj.getTypeCode() == libsbml.SBML_DELAY );
255       obj = d.getElementByMetaId("meta18");
256       assertTrue( obj != null );
257       assertTrue( obj.getTypeCode() == libsbml.SBML_PARAMETER );
258       obj = d.getElementByMetaId("meta19");
259       assertTrue( obj != null );
260       assertTrue( obj.getTypeCode() == libsbml.SBML_PRIORITY );
261       obj = d.getElementByMetaId("meta20");
262       assertTrue( obj != null );
263       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
264       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_FUNCTION_DEFINITION );
265       obj = d.getElementByMetaId("meta21");
266       assertTrue( obj != null );
267       assertTrue( obj.getTypeCode() == libsbml.SBML_FUNCTION_DEFINITION );
268       obj = d.getElementByMetaId("meta22");
269       assertTrue( obj != null );
270       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
271       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_INITIAL_ASSIGNMENT );
272       obj = d.getElementByMetaId("meta23");
273       assertTrue( obj != null );
274       assertTrue( obj.getTypeCode() == libsbml.SBML_INITIAL_ASSIGNMENT );
275       obj = d.getElementByMetaId("meta24");
276       assertTrue( obj != null );
277       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
278       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_RULE );
279       obj = d.getElementByMetaId("meta25");
280       assertTrue( obj != null );
281       assertTrue( obj.getTypeCode() == libsbml.SBML_RATE_RULE );
282       obj = d.getElementByMetaId("meta26");
283       assertTrue( obj != null );
284       assertTrue( obj.getTypeCode() == libsbml.SBML_ASSIGNMENT_RULE );
285       obj = d.getElementByMetaId("meta27");
286       assertTrue( obj != null );
287       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
288       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_LOCAL_PARAMETER );
289       obj = d.getElementByMetaId("meta28");
290       assertTrue( obj != null );
291       assertTrue( obj.getTypeCode() == libsbml.SBML_LOCAL_PARAMETER );
292       obj = d.getElementByMetaId("meta29");
293       assertTrue( obj != null );
294       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
295       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_UNIT_DEFINITION );
296       obj = d.getElementByMetaId("meta30");
297       assertTrue( obj != null );
298       assertTrue( obj.getTypeCode() == libsbml.SBML_UNIT_DEFINITION );
299       obj = d.getElementByMetaId("meta31");
300       assertTrue( obj != null );
301       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
302       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_UNIT );
303       obj = d.getElementByMetaId("meta32");
304       assertTrue( obj != null );
305       assertTrue( obj.getTypeCode() == libsbml.SBML_UNIT );
306       obj = d.getElementByMetaId("meta33");
307       assertTrue( obj != null );
308       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
309       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_PARAMETER );
310       obj = d.getElementByMetaId("meta34");
311       assertTrue( obj != null );
312       assertTrue( obj.getTypeCode() == libsbml.SBML_LIST_OF );
313       assertTrue( ((ListOf) obj).getItemTypeCode() == libsbml.SBML_MODIFIER_SPECIES_REFERENCE );
314       obj = d.getElementByMetaId("meta35");
315       assertTrue( obj != null );
316       assertTrue( obj.getTypeCode() == libsbml.SBML_MODIFIER_SPECIES_REFERENCE );
317       d = null;
318     }
319 
test_GetMultipleObjects_noAssignments()320     public void test_GetMultipleObjects_noAssignments()
321     {
322       SBMLReader reader = new SBMLReader();
323       SBMLDocument d;
324       string filename =  "../../sbml/test/test-data/";
325       filename += "assignments-invalid.xml";
326       d = reader.readSBML(filename);
327       if (d.getModel() == null);
328       {
329       }
330       SBase obj = d.getElementBySId("ia");
331       assertTrue( obj == null );
332       obj = d.getElementByMetaId("ia_meta");
333       assertTrue( obj != null );
334       assertTrue( obj.getTypeCode() == libsbml.SBML_INITIAL_ASSIGNMENT );
335       obj = d.getElementBySId("ar");
336       assertTrue( obj == null );
337       obj = d.getElementByMetaId("ar_meta");
338       assertTrue( obj != null );
339       assertTrue( obj.getTypeCode() == libsbml.SBML_ASSIGNMENT_RULE );
340       obj = d.getElementBySId("rr");
341       assertTrue( obj == null );
342       obj = d.getElementByMetaId("rr_meta");
343       assertTrue( obj != null );
344       assertTrue( obj.getTypeCode() == libsbml.SBML_RATE_RULE );
345       obj = d.getElementBySId("ea");
346       assertTrue( obj == null );
347       obj = d.getElementByMetaId("ea_meta");
348       assertTrue( obj != null );
349       assertTrue( obj.getTypeCode() == libsbml.SBML_EVENT_ASSIGNMENT );
350       d = null;
351     }
352 
test_GetMultipleObjects_noLocalParameters()353     public void test_GetMultipleObjects_noLocalParameters()
354     {
355       SBMLReader reader = new SBMLReader();
356       SBMLDocument d;
357       string filename =  "../../sbml/test/test-data/";
358       filename += "multiple-ids.xml";
359       d = reader.readSBML(filename);
360       if (d == null);
361       {
362       }
363       SBase rxn = d.getElementBySId("J0");
364       assertTrue( rxn != null );
365       SBase obj = rxn.getElementBySId("x");
366       assertTrue( obj == null );
367       obj = rxn.getElementByMetaId("meta28");
368       assertTrue( obj != null );
369       assertTrue( obj.getTypeCode() == libsbml.SBML_LOCAL_PARAMETER );
370       d = null;
371     }
372 
test_GetMultipleObjects_noUnits()373     public void test_GetMultipleObjects_noUnits()
374     {
375       SBMLReader reader = new SBMLReader();
376       SBMLDocument d;
377       string filename =  "../../sbml/test/test-data/";
378       filename += "multiple-ids.xml";
379       d = reader.readSBML(filename);
380       if (d == null);
381       {
382       }
383       SBase obj = d.getElementBySId("volume");
384       assertTrue( obj == null );
385       obj = d.getElementByMetaId("meta30");
386       assertTrue( obj != null );
387       assertTrue( obj.getTypeCode() == libsbml.SBML_UNIT_DEFINITION );
388       d = null;
389     }
390 
391   }
392 }
393