1 /**
2  * \file    TestXMLToken_newSetters.c
3  * \brief   XMLToken_newSetters unit tests
4  * \author  Sarah Keating
5  *
6  * <!--------------------------------------------------------------------------
7  * This file is part of libSBML.  Please visit http://sbml.org for more
8  * information about SBML, and the latest version of libSBML.
9  *
10  * Copyright (C) 2020 jointly by the following organizations:
11  *     1. California Institute of Technology, Pasadena, CA, USA
12  *     2. University of Heidelberg, Heidelberg, Germany
13  *     3. University College London, London, UK
14  *
15  * Copyright (C) 2019 jointly by the following organizations:
16  *     1. California Institute of Technology, Pasadena, CA, USA
17  *     2. University of Heidelberg, Heidelberg, Germany
18  *
19  * Copyright (C) 2013-2018 jointly by the following organizations:
20  *     1. California Institute of Technology, Pasadena, CA, USA
21  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
22  *     3. University of Heidelberg, Heidelberg, Germany
23  *
24  * Copyright (C) 2009-2013 jointly by the following organizations:
25  *     1. California Institute of Technology, Pasadena, CA, USA
26  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
27  *
28  * Copyright (C) 2006-2008 by the California Institute of Technology,
29  *     Pasadena, CA, USA
30  *
31  * Copyright (C) 2002-2005 jointly by the following organizations:
32  *     1. California Institute of Technology, Pasadena, CA, USA
33  *     2. Japan Science and Technology Agency, Japan
34  *
35  * This library is free software; you can redistribute it and/or modify it
36  * under the terms of the GNU Lesser General Public License as published by
37  * the Free Software Foundation.  A copy of the license agreement is provided
38  * in the file named "LICENSE.txt" included with this software distribution
39  * and also available online as http://sbml.org/software/libsbml/license.html
40  * ---------------------------------------------------------------------- -->*/
41 
42 #if defined(__cplusplus)
43 #include <iostream>
44 #endif
45 
46 
47 #include <check.h>
48 
49 #include <sbml/common/common.h>
50 #include <sbml/xml/XMLToken.h>
51 #include <sbml/xml/XMLTriple.h>
52 
53 
54 #include <sbml/common/extern.h>
55 
56 #if defined(__cplusplus)
57 LIBSBML_CPP_NAMESPACE_USE
58 CK_CPPSTART
59 #endif
60 
START_TEST(test_XMLToken_newSetters_setAttributes1)61 START_TEST(test_XMLToken_newSetters_setAttributes1)
62 {
63   /*-- setup --*/
64 
65   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
66   XMLAttributes_t* attr   = XMLAttributes_create();
67   XMLToken_t*      token  = XMLToken_createWithTripleAttr(triple, attr);
68   XMLAttributes_t* nattr  = XMLAttributes_create();
69 
70   XMLTriple_t* xt1    = XMLTriple_createWith("name1", "http://name1.org/", "p1");
71 
72   XMLAttributes_addWithTriple(nattr, xt1, "val1");
73 
74   /*-- test of setting attributes -- */
75 
76   int i = XMLToken_setAttributes(token, nattr);
77 
78   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
79   fail_unless(XMLToken_isAttributesEmpty(token)   == 0 );
80 
81   /*-- teardown --*/
82 
83   XMLAttributes_free(nattr);
84   XMLAttributes_free(attr);
85   XMLTriple_free(triple);
86   XMLToken_free(token);
87   XMLTriple_free(xt1);
88 }
89 END_TEST
90 
91 
START_TEST(test_XMLToken_newSetters_setAttributes2)92 START_TEST(test_XMLToken_newSetters_setAttributes2)
93 {
94   int i ;
95   /*-- setup --*/
96 
97   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
98   XMLToken_t*      token  = XMLToken_createWithTriple(triple);
99   XMLAttributes_t* nattr  = XMLAttributes_create();
100 
101   XMLTriple_t* xt1    = XMLTriple_createWith("name1", "http://name1.org/", "p1");
102 
103   XMLAttributes_addWithTriple(nattr, xt1, "val1");
104 
105   /*-- test of setting attributes with NULL value -- */
106   i = XMLToken_setAttributes(token, NULL);
107 
108   fail_unless ( i == LIBSBML_INVALID_OBJECT);
109 
110   /*-- test of setting attributes -- */
111 
112   i = XMLToken_setAttributes(token, nattr);
113 
114   fail_unless ( i == LIBSBML_INVALID_XML_OPERATION);
115   fail_unless(XMLToken_isAttributesEmpty(token)   == 1 );
116 
117 
118   /*-- teardown --*/
119 
120   XMLAttributes_free(nattr);
121   XMLTriple_free(triple);
122   XMLToken_free(token);
123   XMLTriple_free(xt1);
124 }
125 END_TEST
126 
127 
START_TEST(test_XMLToken_newSetters_clearAttributes1)128 START_TEST(test_XMLToken_newSetters_clearAttributes1)
129 {
130   /*-- setup --*/
131 
132   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
133   XMLAttributes_t* attr   = XMLAttributes_create();
134   XMLToken_t*      token  = XMLToken_createWithTripleAttr(triple, attr);
135   XMLAttributes_t* nattr  = XMLAttributes_create();
136 
137   XMLTriple_t* xt1    = XMLTriple_createWith("name1", "http://name1.org/", "p1");
138 
139   XMLAttributes_addWithTriple(nattr, xt1, "val1");
140 
141   /*-- test of setting attributes -- */
142 
143   int i = XMLToken_setAttributes(token, nattr);
144 
145   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
146   fail_unless(XMLToken_isAttributesEmpty(token)   == 0 );
147 
148   i = XMLToken_clearAttributes(token);
149 
150   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
151   fail_unless(XMLToken_isAttributesEmpty(token)   == 1 );
152   /*-- teardown --*/
153 
154   XMLAttributes_free(nattr);
155   XMLAttributes_free(attr);
156   XMLTriple_free(triple);
157   XMLToken_free(token);
158   XMLTriple_free(xt1);
159 }
160 END_TEST
161 
162 
START_TEST(test_XMLToken_newSetters_addAttributes1)163 START_TEST(test_XMLToken_newSetters_addAttributes1)
164 {
165   const char * test;
166   /*-- setup --*/
167 
168   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
169   XMLAttributes_t* attr   = XMLAttributes_create();
170   XMLToken_t*      token  = XMLToken_createWithTripleAttr(triple, attr);
171 
172   XMLTriple_t* xt2    = XMLTriple_createWith("name3",
173                                              "http://name3.org/", "p3");
174   /*-- test of adding attributes --*/
175 
176   int i = XMLToken_addAttr(token, "name1", "val1");
177 
178   fail_unless( i == LIBSBML_OPERATION_SUCCESS );
179   fail_unless( XMLToken_getAttributesLength(token) == 1 );
180   fail_unless( XMLToken_isAttributesEmpty(token)   == 0 );
181 
182   test = XMLToken_getAttrName  (token, 0);
183   fail_unless( strcmp(test, "name1") == 0 );
184   safe_free((void*)(test));
185 
186   test = XMLToken_getAttrValue (token, 0);
187   fail_unless( strcmp(test, "val1" ) == 0 );
188   safe_free((void*)(test));
189 
190 
191   i = XMLToken_addAttrWithNS(token, "name2", "val2",
192                                              "http://name1.org/", "p1");
193 
194   fail_unless( i == LIBSBML_OPERATION_SUCCESS );
195   fail_unless( XMLToken_getAttributesLength(token) == 2 );
196   fail_unless( XMLToken_isAttributesEmpty(token)   == 0 );
197 
198   test = XMLToken_getAttrName  (token, 1);
199   fail_unless( strcmp(test, "name2") == 0 );
200   safe_free((void*)(test));
201 
202   test = XMLToken_getAttrValue (token, 1);
203   fail_unless( strcmp(test, "val2" ) == 0 );
204   safe_free((void*)(test));
205 
206   test = XMLToken_getAttrURI   (token, 1);
207   fail_unless( strcmp(test, "http://name1.org/") == 0 );
208   safe_free((void*)(test));
209 
210   test = XMLToken_getAttrPrefix(token, 1);
211   fail_unless( strcmp(test, "p1"   ) == 0 );
212   safe_free((void*)(test));
213 
214 
215   i = XMLToken_addAttrWithTriple(token, xt2, "val2");
216 
217   fail_unless( i == LIBSBML_OPERATION_SUCCESS );
218   fail_unless( XMLToken_getAttributesLength(token) == 3 );
219   fail_unless( XMLToken_isAttributesEmpty(token)   == 0 );
220 
221   test = XMLToken_getAttrName  (token, 2);
222   fail_unless( strcmp(test, "name3") == 0 );
223   safe_free((void*)(test));
224 
225   test = XMLToken_getAttrValue (token, 2);
226   fail_unless( strcmp(test, "val2" ) == 0 );
227   safe_free((void*)(test));
228 
229   test = XMLToken_getAttrURI   (token, 2);
230   fail_unless( strcmp(test, "http://name3.org/") == 0 );
231   safe_free((void*)(test));
232 
233   test = XMLToken_getAttrPrefix(token, 2);
234   fail_unless( strcmp(test, "p3"   ) == 0 );
235   safe_free((void*)(test));
236 
237 
238   /*-- teardown --*/
239 
240   XMLTriple_free(xt2);
241   XMLTriple_free(triple);
242   XMLAttributes_free(attr);
243   XMLToken_free(token);
244 }
245 END_TEST
246 
247 
START_TEST(test_XMLToken_newSetters_addAttributes2)248 START_TEST(test_XMLToken_newSetters_addAttributes2)
249 {
250   /*-- setup --*/
251 
252   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
253   XMLToken_t*      token  = XMLToken_createWithTriple(triple);
254 
255   XMLTriple_t* xt2    = XMLTriple_createWith("name3",
256                                              "http://name3.org/", "p3");
257   /*-- test of adding attributes --*/
258 
259   int i = XMLToken_addAttr(token, "name1", "val1");
260 
261   fail_unless( i == LIBSBML_INVALID_XML_OPERATION );
262   fail_unless( XMLToken_getAttributesLength(token) == 0 );
263   fail_unless( XMLToken_isAttributesEmpty(token)   == 1 );
264 
265   i = XMLToken_addAttrWithNS(token, "name2", "val2",
266                                              "http://name1.org/", "p1");
267 
268   fail_unless( i == LIBSBML_INVALID_XML_OPERATION );
269   fail_unless( XMLToken_getAttributesLength(token) == 0 );
270   fail_unless( XMLToken_isAttributesEmpty(token)   == 1 );
271 
272   i = XMLToken_addAttrWithTriple(token, xt2, "val2");
273 
274   fail_unless( i == LIBSBML_INVALID_XML_OPERATION );
275   fail_unless( XMLToken_getAttributesLength(token) == 0 );
276   fail_unless( XMLToken_isAttributesEmpty(token)   == 1 );
277 
278   /*-- teardown --*/
279 
280   XMLTriple_free(xt2);
281   XMLTriple_free(triple);
282   XMLToken_free(token);
283 }
284 END_TEST
285 
286 
START_TEST(test_XMLToken_newSetters_setNamespaces1)287 START_TEST(test_XMLToken_newSetters_setNamespaces1)
288 {
289   /*-- setup --*/
290 
291   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
292   XMLAttributes_t* attr   = XMLAttributes_create();
293   XMLToken_t*      token  = XMLToken_createWithTripleAttr(triple, attr);
294   XMLNamespaces_t* ns = XMLNamespaces_create();
295 
296   fail_unless( XMLToken_getNamespacesLength(token) == 0 );
297   fail_unless( XMLToken_isNamespacesEmpty(token)   == 1 );
298 
299   /*-- test of setting namespaces -- */
300   XMLNamespaces_add(ns, "http://test1.org/", "test1");
301 
302   int i =   XMLToken_setNamespaces(token, ns);
303 
304   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
305   fail_unless( XMLToken_getNamespacesLength(token) == 1 );
306   fail_unless( XMLToken_isNamespacesEmpty(token)   == 0 );
307 
308   /*-- teardown --*/
309 
310   XMLAttributes_free(attr);
311   XMLTriple_free(triple);
312   XMLToken_free(token);
313   XMLNamespaces_free(ns);
314 }
315 END_TEST
316 
317 
START_TEST(test_XMLToken_newSetters_setNamespaces2)318 START_TEST(test_XMLToken_newSetters_setNamespaces2)
319 {
320   int i;
321   /*-- setup --*/
322 
323   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
324   XMLToken_t*      token  = XMLToken_createWithTriple(triple);
325   XMLNamespaces_t* ns = XMLNamespaces_create();
326 
327   fail_unless( XMLToken_getNamespacesLength(token) == 0 );
328   fail_unless( XMLToken_isNamespacesEmpty(token)   == 1 );
329 
330   /*-- test of setting namespaces -- */
331   XMLNamespaces_add(ns, "http://test1.org/", "test1");
332 
333 
334   /*-- test of setting namespaces with NULL value -- */
335   i = XMLToken_setNamespaces(token, NULL);
336 
337   fail_unless ( i == LIBSBML_INVALID_OBJECT);
338 
339 
340   /*-- test of setting namespaces -- */
341   i =   XMLToken_setNamespaces(token, ns);
342 
343   fail_unless ( i == LIBSBML_INVALID_XML_OPERATION);
344   fail_unless( XMLToken_getNamespacesLength(token) == 0 );
345   fail_unless( XMLToken_isNamespacesEmpty(token)   == 1 );
346 
347   /*-- teardown --*/
348 
349   XMLTriple_free(triple);
350   XMLToken_free(token);
351   XMLNamespaces_free(ns);
352 }
353 END_TEST
354 
355 
START_TEST(test_XMLToken_newSetters_clearNamespaces1)356 START_TEST(test_XMLToken_newSetters_clearNamespaces1)
357 {
358   /*-- setup --*/
359 
360   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
361   XMLAttributes_t* attr   = XMLAttributes_create();
362   XMLToken_t*      token  = XMLToken_createWithTripleAttr(triple, attr);
363   XMLNamespaces_t* ns = XMLNamespaces_create();
364 
365   fail_unless( XMLToken_getNamespacesLength(token) == 0 );
366   fail_unless( XMLToken_isNamespacesEmpty(token)   == 1 );
367 
368   /*-- test of setting namespaces -- */
369   XMLNamespaces_add(ns, "http://test1.org/", "test1");
370 
371   int i =   XMLToken_setNamespaces(token, ns);
372 
373   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
374   fail_unless( XMLToken_getNamespacesLength(token) == 1 );
375   fail_unless( XMLToken_isNamespacesEmpty(token)   == 0 );
376 
377   i = XMLToken_clearNamespaces(token);
378 
379   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
380   fail_unless( XMLToken_getNamespacesLength(token) == 0 );
381   fail_unless( XMLToken_isNamespacesEmpty(token)   == 1 );
382 
383   /*-- teardown --*/
384 
385   XMLAttributes_free(attr);
386   XMLTriple_free(triple);
387   XMLToken_free(token);
388   XMLNamespaces_free(ns);
389 }
390 END_TEST
391 
392 
START_TEST(test_XMLToken_newSetters_addNamespaces1)393 START_TEST(test_XMLToken_newSetters_addNamespaces1)
394 {
395   /*-- setup --*/
396 
397   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
398   XMLAttributes_t* attr   = XMLAttributes_create();
399   XMLToken_t*      token  = XMLToken_createWithTripleAttr(triple, attr);
400 
401   fail_unless( XMLToken_getNamespacesLength(token) == 0 );
402   fail_unless( XMLToken_isNamespacesEmpty(token)   == 1 );
403 
404   /*-- test of setting namespaces -- */
405   int i =  XMLToken_addNamespace(token, "http://test1.org/", "test1");
406 
407   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
408   fail_unless( XMLToken_getNamespacesLength(token) == 1 );
409   fail_unless( XMLToken_isNamespacesEmpty(token)   == 0 );
410 
411   /*-- teardown --*/
412 
413   XMLAttributes_free(attr);
414   XMLTriple_free(triple);
415   XMLToken_free(token);
416 }
417 END_TEST
418 
419 
START_TEST(test_XMLToken_newSetters_addNamespaces2)420 START_TEST(test_XMLToken_newSetters_addNamespaces2)
421 {
422   /*-- setup --*/
423 
424   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
425   XMLToken_t*      token  = XMLToken_createWithTriple(triple);
426 
427   fail_unless( XMLToken_getNamespacesLength(token) == 0 );
428   fail_unless( XMLToken_isNamespacesEmpty(token)   == 1 );
429 
430   /*-- test of setting namespaces -- */
431   int i =   XMLToken_addNamespace(token, "http://test1.org/", "test1");
432 
433   fail_unless ( i == LIBSBML_INVALID_XML_OPERATION);
434   fail_unless( XMLToken_getNamespacesLength(token) == 0 );
435   fail_unless( XMLToken_isNamespacesEmpty(token)   == 1 );
436 
437   /*-- teardown --*/
438 
439   XMLTriple_free(triple);
440   XMLToken_free(token);
441 }
442 END_TEST
443 
444 
START_TEST(test_XMLToken_newSetters_setTriple1)445 START_TEST(test_XMLToken_newSetters_setTriple1)
446 {
447   /*-- setup --*/
448 
449   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
450   XMLToken_t*      token  = XMLToken_create();
451 
452   /*-- test of setting triple -- */
453   int i =   XMLToken_setTriple(token, triple);
454 
455   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
456   fail_unless( !strcmp(XMLToken_getName(token), "test") );
457 
458   /*-- teardown --*/
459 
460   XMLTriple_free(triple);
461   XMLToken_free(token);
462 }
463 END_TEST
464 
465 
START_TEST(test_XMLToken_newSetters_setTriple2)466 START_TEST(test_XMLToken_newSetters_setTriple2)
467 {
468   int i;
469   /*-- setup --*/
470 
471   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
472   XMLToken_t *token = XMLToken_createWithText("This is text");
473 
474 
475   /*-- test of setting triple with NULL value -- */
476   i = XMLToken_setTriple(token, NULL);
477 
478   fail_unless ( i == LIBSBML_INVALID_OBJECT);
479 
480 
481   /*-- test of setting triple -- */
482   i =   XMLToken_setTriple(token, triple);
483 
484   fail_unless ( i == LIBSBML_INVALID_XML_OPERATION);
485 
486   /*-- teardown --*/
487 
488   XMLTriple_free(triple);
489   XMLToken_free(token);
490 }
491 END_TEST
492 
493 
START_TEST(test_XMLToken_newSetters_setEnd)494 START_TEST(test_XMLToken_newSetters_setEnd)
495 {
496   /*-- setup --*/
497 
498   XMLToken_t*      token  = XMLToken_create();
499   fail_unless( XMLToken_isEnd(token) == 0 );
500 
501   /*-- test of setting end -- */
502   int i =   XMLToken_setEnd(token);
503 
504   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
505   fail_unless( XMLToken_isEnd(token) == 1 );
506 
507   i =   XMLToken_unsetEnd(token);
508 
509   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
510   fail_unless( XMLToken_isEnd(token) == 0 );
511   /*-- teardown --*/
512 
513   XMLToken_free(token);
514 }
515 END_TEST
516 
517 
START_TEST(test_XMLToken_newSetters_setEOF)518 START_TEST(test_XMLToken_newSetters_setEOF)
519 {
520   /*-- setup --*/
521 
522   XMLToken_t*      token  = XMLToken_create();
523   fail_unless( XMLToken_isEnd(token) == 0 );
524 
525   /*-- test of setting eof -- */
526   int i =   XMLToken_setEOF(token);
527 
528   fail_unless ( i == LIBSBML_OPERATION_SUCCESS);
529   fail_unless( XMLToken_isEnd(token) == 0 );
530   fail_unless( XMLToken_isStart(token) == 0 );
531   fail_unless( XMLToken_isText(token) == 0 );
532 
533   /*-- teardown --*/
534 
535   XMLToken_free(token);
536 }
537 END_TEST
538 
539 
START_TEST(test_XMLToken_newSetters_removeAttributes1)540 START_TEST(test_XMLToken_newSetters_removeAttributes1)
541 {
542   /*-- setup --*/
543 
544   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
545   XMLAttributes_t* attr   = XMLAttributes_create();
546   XMLToken_t*      token  = XMLToken_createWithTripleAttr(triple, attr);
547 
548   XMLTriple_t* xt2    = XMLTriple_createWith("name3",
549                                              "http://name3.org/", "p3");
550   XMLTriple_t* xt1    = XMLTriple_createWith("name5",
551                                              "http://name5.org/", "p5");
552   int i = XMLToken_addAttr(token, "name1", "val1");
553   i = XMLToken_addAttrWithNS(token, "name2", "val2",
554                                              "http://name1.org/", "p1");
555   i = XMLToken_addAttrWithTriple(token, xt2, "val2");
556   i = XMLToken_addAttr(token, "name4", "val4");
557 
558   fail_unless (XMLAttributes_getLength(XMLToken_getAttributes(token)) == 4);
559 
560   i = XMLToken_removeAttr(token, 7);
561 
562   fail_unless ( i == LIBSBML_INDEX_EXCEEDS_SIZE );
563 
564   i = XMLToken_removeAttrByName(token, "name7");
565 
566   fail_unless ( i == LIBSBML_INDEX_EXCEEDS_SIZE );
567 
568   i = XMLToken_removeAttrByNS(token, "name7", "namespaces7");
569 
570   fail_unless ( i == LIBSBML_INDEX_EXCEEDS_SIZE );
571 
572   i = XMLToken_removeAttrByTriple(token, xt1);
573 
574   fail_unless ( i == LIBSBML_INDEX_EXCEEDS_SIZE );
575   fail_unless (XMLAttributes_getLength(XMLToken_getAttributes(token)) == 4);
576 
577   i = XMLToken_removeAttr(token, 3);
578 
579   fail_unless ( i == LIBSBML_OPERATION_SUCCESS );
580   fail_unless (XMLAttributes_getLength(XMLToken_getAttributes(token)) == 3);
581 
582   i = XMLToken_removeAttrByName(token, "name1");
583 
584   fail_unless ( i == LIBSBML_OPERATION_SUCCESS );
585   fail_unless (XMLAttributes_getLength(XMLToken_getAttributes(token)) == 2);
586 
587   i = XMLToken_removeAttrByNS(token, "name2", "http://name1.org/");
588 
589   fail_unless ( i == LIBSBML_OPERATION_SUCCESS );
590   fail_unless (XMLAttributes_getLength(XMLToken_getAttributes(token)) == 1);
591 
592   i = XMLToken_removeAttrByTriple(token, xt2);
593 
594   fail_unless ( i == LIBSBML_OPERATION_SUCCESS );
595   fail_unless (XMLAttributes_getLength(XMLToken_getAttributes(token)) == 0);
596 
597   /*-- teardown --*/
598 
599   XMLTriple_free(xt1);
600   XMLTriple_free(xt2);
601   XMLTriple_free(triple);
602   XMLAttributes_free(attr);
603   XMLToken_free(token);
604 }
605 END_TEST
606 
607 
START_TEST(test_XMLToken_newSetters_removeNamespaces)608 START_TEST (test_XMLToken_newSetters_removeNamespaces)
609 {
610   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
611   XMLAttributes_t* attr   = XMLAttributes_create();
612   XMLToken_t*      token  = XMLToken_createWithTripleAttr(triple, attr);
613 
614   XMLToken_addNamespace(token, "http://test1.org/", "test1");
615 
616   fail_unless( XMLToken_getNamespacesLength(token) == 1 );
617 
618   int i = XMLToken_removeNamespace(token, 4);
619 
620   fail_unless( i == LIBSBML_INDEX_EXCEEDS_SIZE);
621   fail_unless( XMLToken_getNamespacesLength(token) == 1 );
622 
623   i = XMLToken_removeNamespace(token, 0);
624 
625   fail_unless( i == LIBSBML_OPERATION_SUCCESS);
626   fail_unless( XMLToken_getNamespacesLength(token) == 0 );
627 
628   XMLToken_free(token);
629   XMLTriple_free(triple);
630   XMLAttributes_free(attr);
631 }
632 END_TEST
633 
634 
START_TEST(test_XMLToken_newSetters_removeNamespaces1)635 START_TEST (test_XMLToken_newSetters_removeNamespaces1)
636 {
637   XMLTriple_t*     triple = XMLTriple_createWith("test","","");
638   XMLAttributes_t* attr   = XMLAttributes_create();
639   XMLToken_t*      token  = XMLToken_createWithTripleAttr(triple, attr);
640 
641   XMLToken_addNamespace(token, "http://test1.org/", "test1");
642 
643   fail_unless( XMLToken_getNamespacesLength(token) == 1 );
644 
645   int i = XMLToken_removeNamespaceByPrefix(token, "test2");
646 
647   fail_unless( i == LIBSBML_INDEX_EXCEEDS_SIZE);
648   fail_unless( XMLToken_getNamespacesLength(token) == 1 );
649 
650   i = XMLToken_removeNamespaceByPrefix(token, "test1");
651 
652   fail_unless( i == LIBSBML_OPERATION_SUCCESS);
653   fail_unless( XMLToken_getNamespacesLength(token) == 0 );
654 
655   XMLToken_free(token);
656   XMLTriple_free(triple);
657   XMLAttributes_free(attr);
658 }
659 END_TEST
660 
661 
662 Suite *
create_suite_XMLToken_newSetters(void)663 create_suite_XMLToken_newSetters (void)
664 {
665   Suite *suite = suite_create("XMLToken_newSetters");
666   TCase *tcase = tcase_create("XMLToken_newSetters");
667 
668   tcase_add_test( tcase, test_XMLToken_newSetters_setAttributes1);
669   tcase_add_test( tcase, test_XMLToken_newSetters_setAttributes2);
670   tcase_add_test( tcase, test_XMLToken_newSetters_clearAttributes1);
671   tcase_add_test( tcase, test_XMLToken_newSetters_addAttributes1);
672   tcase_add_test( tcase, test_XMLToken_newSetters_addAttributes2);
673   tcase_add_test( tcase, test_XMLToken_newSetters_setNamespaces1);
674   tcase_add_test( tcase, test_XMLToken_newSetters_setNamespaces2);
675   tcase_add_test( tcase, test_XMLToken_newSetters_clearNamespaces1);
676   tcase_add_test( tcase, test_XMLToken_newSetters_addNamespaces1);
677   tcase_add_test( tcase, test_XMLToken_newSetters_addNamespaces2);
678   tcase_add_test( tcase, test_XMLToken_newSetters_setTriple1);
679   tcase_add_test( tcase, test_XMLToken_newSetters_setTriple2);
680   tcase_add_test( tcase, test_XMLToken_newSetters_setEnd);
681   tcase_add_test( tcase, test_XMLToken_newSetters_setEOF);
682   tcase_add_test( tcase, test_XMLToken_newSetters_removeAttributes1);
683   tcase_add_test( tcase, test_XMLToken_newSetters_removeNamespaces);
684   tcase_add_test( tcase, test_XMLToken_newSetters_removeNamespaces1);
685 
686   suite_add_tcase(suite, tcase);
687 
688   return suite;
689 }
690 
691 #if defined(__cplusplus)
692 CK_CPPEND
693 #endif
694 
695