1 /**
2  * \file    TestSBase.cpp
3  * \brief   SBase unit tests
4  * \author  Ben Bornstein
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 #include <sbml/common/common.h>
43 #include <sbml/common/extern.h>
44 
45 #include <sbml/SBase.h>
46 #include <sbml/Model.h>
47 #include <sbml/SBMLDocument.h>
48 #include <sbml/SBMLWriter.h>
49 #include <sbml/annotation/CVTerm.h>
50 #include <sbml/annotation/ModelHistory.h>
51 #include <sbml/annotation/ModelCreator.h>
52 #include <sbml/annotation/Date.h>
53 
54 #include <check.h>
55 
56 LIBSBML_CPP_NAMESPACE_USE
57 
58 
59 /*
60  * We create a lot of strings in this file, for testing, and we don't
61  * do what this warning tries to help with, so we shut it up just
62  * for this file.
63  */
64 #ifdef __GNUC__
65 #pragma GCC diagnostic ignored "-Wwrite-strings"
66 #endif
67 
68 BEGIN_C_DECLS
69 
70 static SBase *S;
71 
72 
73 void
SBaseTest_setup(void)74 SBaseTest_setup (void)
75 {
76   S = new(std::nothrow) Model(2, 4);
77 
78   if (S == NULL)
79   {
80     fail("'new(std::nothrow) SBase;' returned a NULL pointer.");
81   }
82 
83 }
84 
85 
86 void
SBaseTest_teardown(void)87 SBaseTest_teardown (void)
88 {
89   delete S;
90 }
91 
92 
START_TEST(test_SBase_setMetaId)93 START_TEST (test_SBase_setMetaId)
94 {
95   const char *metaid = "x12345";
96 
97 
98   SBase_setMetaId(S, metaid);
99 
100   fail_unless( !strcmp(SBase_getMetaId(S), metaid), NULL );
101   fail_unless( SBase_isSetMetaId(S)      , NULL );
102 
103   if (SBase_getMetaId(S) == metaid)
104   {
105     fail("SBase_setMetaId(...) did not make a copy of string.");
106   }
107 
108   /* Reflexive case (pathological) */
109   SBase_setMetaId(S, SBase_getMetaId(S));
110   fail_unless( !strcmp(SBase_getMetaId(S), metaid), NULL );
111 
112   SBase_setMetaId(S, NULL);
113   fail_unless( !SBase_isSetMetaId(S), NULL );
114 
115   if (SBase_getMetaId(S) != NULL)
116   {
117     fail("SBase_setMetaId(S, NULL) did not clear string.");
118   }
119 }
120 END_TEST
121 
122 
START_TEST(test_SBase_setNotes)123 START_TEST (test_SBase_setNotes)
124 {
125   Model_t *c = new(std::nothrow) Model(1, 2);
126   XMLToken* token = XMLToken_createWithText("This is a test note");
127   XMLNode* node = XMLNode_createFromToken(token);
128 
129 
130   SBase_setNotes(c, node);
131 
132   fail_unless(SBase_isSetNotes(c) == 1);
133 
134   if (SBase_getNotes(c) == node)
135   {
136     fail("SBase_setNotes(...) did not make a copy of node.");
137   }
138   XMLNode_t *t1 = SBase_getNotes(c);
139 
140   fail_unless(XMLNode_getNumChildren(t1) == 1);
141   fail_unless(!strcmp(XMLNode_getCharacters(XMLNode_getChild(t1,0)), "This is a test note"));
142 
143 
144   /* Reflexive case (pathological)  */
145   SBase_setNotes(c, SBase_getNotes(c));
146   t1 = SBase_getNotes(c);
147   fail_unless(XMLNode_getNumChildren(t1) == 1);
148   const char * chars = XMLNode_getCharacters(XMLNode_getChild(t1,0));
149   fail_unless(!strcmp(chars, "This is a test note"));
150 
151   SBase_setNotes(c, NULL);
152   fail_unless(SBase_isSetNotes(c) == 0 );
153 
154   if (SBase_getNotes(c) != NULL)
155   {
156     fail("SBase_setNotes(c, NULL) did not clear string.");
157   }
158 
159   SBase_setNotes(c, node);
160 
161   fail_unless(SBase_isSetNotes(c) == 1);
162 
163   /* test notes with character reference */
164 
165   XMLToken_free(token);
166   XMLNode_free(node);
167   token = XMLToken_createWithText("(CR) &#0168; &#x00a8; &#x00A8; (NOT CR) &#; &#x; &#00a8; &#0168 &#x00a8");
168   node  = XMLNode_createFromToken(token);
169 
170   SBase_setNotes(c, node);
171   t1 = SBase_getNotes(c);
172 
173   fail_unless(XMLNode_getNumChildren(t1) == 1);
174 
175   char * s = XMLNode_toXMLString(XMLNode_getChild(t1,0));
176   const char * expected = "(CR) &#0168; &#x00a8; &#x00A8; (NOT CR) &amp;#; &amp;#x; &amp;#00a8; &amp;#0168 &amp;#x00a8";
177 
178   fail_unless(!strcmp(s,expected));
179   safe_free(s);
180 
181   /* test notes with predefined entity */
182 
183   XMLToken_free(token);
184   XMLNode_free(node);
185   token = XMLToken_createWithText("& ' > < \" &amp; &apos; &gt; &lt; &quot;");
186   node  = XMLNode_createFromToken(token);
187 
188   SBase_setNotes(c, node);
189   t1 = SBase_getNotes(c);
190 
191   fail_unless(XMLNode_getNumChildren(t1) == 1);
192 
193   char * s2 = XMLNode_toXMLString(XMLNode_getChild(t1,0));
194   const char * expected2 = "&amp; &apos; &gt; &lt; &quot; &amp; &apos; &gt; &lt; &quot;";
195 
196   fail_unless(!strcmp(s2,expected2));
197   safe_free(s2);
198 
199   Model_free(c);
200   XMLToken_free(token);
201   XMLNode_free(node);
202 }
203 END_TEST
204 
205 
START_TEST(test_SBase_setAnnotation)206 START_TEST (test_SBase_setAnnotation)
207 {
208   XMLToken* token = XMLToken_createWithText("This is a test note");
209   XMLNode* node = XMLNode_createFromToken(token);
210 
211   SBase_setAnnotation(S, node);
212 
213   fail_unless(SBase_isSetAnnotation(S) == 1);
214 
215   XMLNode_t *t1 = SBase_getAnnotation(S);
216 
217   fail_unless(XMLNode_getNumChildren(t1) == 1);
218   fail_unless(!strcmp(XMLNode_getCharacters(XMLNode_getChild(t1,0)), "This is a test note"));
219 
220   if (SBase_getAnnotation(S) == node)
221   {
222     fail("SBase_setAnnotation(...) did not make a copy of node.");
223   }
224 
225   /* Reflexive case (pathological) */
226   SBase_setAnnotation(S, SBase_getAnnotation(S));
227   fail_unless(!strcmp(XMLNode_getCharacters(XMLNode_getChild(SBase_getAnnotation(S),0)), "This is a test note"));
228 
229   SBase_setAnnotation(S, NULL);
230   fail_unless(SBase_isSetAnnotation(S) == 0 );
231 
232   if (SBase_getAnnotation(S) != NULL)
233   {
234     fail("SBase_setAnnotation(S, NULL) did not clear string.");
235   }
236 
237   SBase_setAnnotation(S, node);
238 
239   fail_unless(SBase_isSetAnnotation(S) == 1);
240 
241   SBase_unsetAnnotation(S);
242 
243   fail_unless(SBase_isSetAnnotation(S) == 0);
244 
245   /* test annotations with character reference */
246 
247   XMLToken_free(token);
248   XMLNode_free(node);
249   token = XMLToken_createWithText("(CR) &#0168; &#x00a8; &#x00A8; (NOT CR) &#; &#x; &#00a8; &#0168 &#x00a8");
250   node  = XMLNode_createFromToken(token);
251 
252   SBase_setAnnotation(S, node);
253   t1 = SBase_getAnnotation(S);
254 
255   fail_unless(XMLNode_getNumChildren(t1) == 1);
256 
257   char * s = XMLNode_toXMLString(XMLNode_getChild(t1,0));
258   const char * expected = "(CR) &#0168; &#x00a8; &#x00A8; (NOT CR) &amp;#; &amp;#x; &amp;#00a8; &amp;#0168 &amp;#x00a8";
259 
260   fail_unless(!strcmp(s,expected));
261   safe_free(s);
262 
263   /* test notes with predefined entity */
264 
265   XMLToken_free(token);
266   XMLNode_free(node);
267   token = XMLToken_createWithText("& ' > < \" &amp; &apos; &gt; &lt; &quot;");
268   node  = XMLNode_createFromToken(token);
269 
270   SBase_setAnnotation(S, node);
271   t1 = SBase_getAnnotation(S);
272 
273   fail_unless(XMLNode_getNumChildren(t1) == 1);
274 
275   char * s2 = XMLNode_toXMLString(XMLNode_getChild(t1,0));
276   const char * expected2 = "&amp; &apos; &gt; &lt; &quot; &amp; &apos; &gt; &lt; &quot;";
277 
278   fail_unless(!strcmp(s2,expected2));
279 
280   XMLToken_free(token);
281   XMLNode_free(node);
282   safe_free(s2);
283 }
284 END_TEST
285 
286 
START_TEST(test_SBase_unsetAnnotationWithCVTerms)287 START_TEST (test_SBase_unsetAnnotationWithCVTerms)
288 {
289   CVTerm_t   *cv;
290 
291   const char *annt =
292         "<annotation>\n"
293         "  <test:test xmlns:test=\"http://test.org/test\">this is a test node</test:test>\n"
294         "</annotation>";
295 
296   const char *annt_with_cvterm =
297         "<annotation>\n"
298         "  <test:test xmlns:test=\"http://test.org/test\">this is a test node</test:test>\n"
299         "  <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
300 				"xmlns:dc=\"http://purl.org/dc/elements/1.1/\" "
301         "xmlns:dcterms=\"http://purl.org/dc/terms/\" "
302 				"xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\" "
303         "xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" "
304 				"xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\">\n"
305         "    <rdf:Description rdf:about=\"#_000001\">\n"
306         "      <bqbiol:is>\n"
307         "        <rdf:Bag>\n"
308         "          <rdf:li rdf:resource=\"http://www.geneontology.org/#GO:0005895\"/>\n"
309         "        </rdf:Bag>\n"
310         "      </bqbiol:is>\n"
311         "    </rdf:Description>\n"
312         "  </rdf:RDF>\n"
313         "</annotation>";
314 
315   SBase_setAnnotationString(S, (char*)annt);
316   fail_unless(SBase_isSetAnnotation(S) == 1);
317   char* str = SBase_getAnnotationString(S);
318   fail_unless(!strcmp(str, annt));
319   safe_free(str);
320 
321   SBase_unsetAnnotation(S);
322   fail_unless(SBase_isSetAnnotation(S) == 0);
323   fail_unless(SBase_getAnnotation(S) == NULL);
324 
325   SBase_setAnnotationString(S, (char*)annt);
326   SBase_setMetaId(S, "_000001");
327   cv = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
328   CVTerm_setBiologicalQualifierType(cv, BQB_IS);
329   CVTerm_addResource(cv, "http://www.geneontology.org/#GO:0005895");
330   SBase_addCVTerm(S, cv);
331 
332   str = SBase_getAnnotationString(S);
333   fail_unless(SBase_isSetAnnotation(S) == 1);
334   fail_unless(!strcmp(str, annt_with_cvterm));
335   safe_free(str);
336 
337   SBase_unsetAnnotation(S);
338   fail_unless(SBase_isSetAnnotation(S) == 0);
339   fail_unless(SBase_getAnnotation(S) == NULL);
340 
341   CVTerm_free(cv);
342 }
343 END_TEST
344 
START_TEST(test_SBase_unsetAnnotationWithModelHistory)345 START_TEST (test_SBase_unsetAnnotationWithModelHistory)
346 {
347   ModelHistory_t *h = ModelHistory_create();
348   ModelCreator_t *c = ModelCreator_create();
349   Date_t *dc;
350   Date_t *dm;
351 
352   const char *annt =
353         "<annotation>\n"
354         "  <test:test xmlns:test=\"http://test.org/test\">this is a test node</test:test>\n"
355         "</annotation>";
356 
357   const char *annt_with_modelhistory =
358        "<annotation>\n"
359        "  <test:test xmlns:test=\"http://test.org/test\">this is a test node</test:test>\n"
360        "  <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
361 			 "xmlns:dc=\"http://purl.org/dc/elements/1.1/\" "
362 			 "xmlns:dcterms=\"http://purl.org/dc/terms/\" "
363 			 "xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\" "
364 			 "xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" "
365 			 "xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\">\n"
366        "    <rdf:Description rdf:about=\"#_000001\">\n"
367        "      <dc:creator>\n"
368        "        <rdf:Bag>\n"
369        "          <rdf:li rdf:parseType=\"Resource\">\n"
370        "            <vCard:N rdf:parseType=\"Resource\">\n"
371        "              <vCard:Family>Keating</vCard:Family>\n"
372        "              <vCard:Given>Sarah</vCard:Given>\n"
373        "            </vCard:N>\n"
374        "            <vCard:EMAIL>sbml-team@caltech.edu</vCard:EMAIL>\n"
375        "          </rdf:li>\n"
376        "        </rdf:Bag>\n"
377        "      </dc:creator>\n"
378        "      <dcterms:created rdf:parseType=\"Resource\">\n"
379        "        <dcterms:W3CDTF>2005-12-29T12:15:45+02:00</dcterms:W3CDTF>\n"
380        "      </dcterms:created>\n"
381        "      <dcterms:modified rdf:parseType=\"Resource\">\n"
382        "        <dcterms:W3CDTF>2005-12-30T12:15:45+02:00</dcterms:W3CDTF>\n"
383        "      </dcterms:modified>\n"
384        "    </rdf:Description>\n"
385        "  </rdf:RDF>\n"
386        "</annotation>";
387 
388   SBase_setAnnotationString(S, (char*)annt);
389   fail_unless(SBase_isSetAnnotation(S) == 1);
390   char* str = SBase_getAnnotationString(S);
391   fail_unless(!strcmp(str, annt));
392   safe_free(str);
393 
394   SBase_unsetAnnotation(S);
395   fail_unless(SBase_isSetAnnotation(S) == 0);
396   fail_unless(SBase_getAnnotation(S) == NULL);
397 
398   SBase_setAnnotationString(S, (char*)annt);
399   SBase_setMetaId(S, "_000001");
400 
401   ModelCreator_setFamilyName(c, (char *) "Keating");
402   ModelCreator_setGivenName(c, (char *) "Sarah");
403   ModelCreator_setEmail(c, (char *) "sbml-team@caltech.edu");
404 
405   ModelHistory_addCreator(h, c);
406   dc =  Date_createFromValues(2005, 12, 29, 12, 15, 45, 1, 2, 0);
407   ModelHistory_setCreatedDate(h, dc);
408   dm =  Date_createFromValues(2005, 12, 30, 12, 15, 45, 1, 2, 0);
409   ModelHistory_setModifiedDate(h, dm);
410   Model_setModelHistory((Model_t*)S, h);
411 
412   fail_unless(SBase_isSetAnnotation(S) == 1);
413   str = SBase_getAnnotationString(S);
414   fail_unless(!strcmp(str, annt_with_modelhistory));
415   safe_free(str);
416 
417   SBase_unsetAnnotation(S);
418   fail_unless(SBase_isSetAnnotation(S) == 0);
419   fail_unless(SBase_getAnnotation(S) == NULL);
420 
421   Date_free(dc);
422   Date_free(dm);
423   ModelCreator_free(c);
424   ModelHistory_free(h);
425 }
426 END_TEST
427 
428 
START_TEST(test_SBase_setNotesString)429 START_TEST (test_SBase_setNotesString)
430 {
431   Model_t *c = new(std::nothrow) Model(1,2);
432   char * notes = "This is a test note";
433   char * taggednotes = "<notes>This is a test note</notes>";
434 
435   SBase_setNotesString(c, notes);
436 
437   fail_unless(SBase_isSetNotes(c) == 1);
438 
439   char* str = SBase_getNotesString(c);
440   if (strcmp(str, taggednotes))
441   {
442     fail("SBase_setNotesString(...) did not make a copy of node.");
443   }
444   safe_free(str);
445   XMLNode_t *t1 = SBase_getNotes(c);
446   fail_unless(XMLNode_getNumChildren(t1) == 1);
447 
448   const XMLNode_t *t2 = XMLNode_getChild(t1,0);
449   fail_unless(!strcmp(XMLNode_getCharacters(t2), "This is a test note"));
450 
451 
452   /* Reflexive case (pathological)  */
453   str = SBase_getNotesString(c);
454   SBase_setNotesString(c, str);
455   safe_free(str);
456   t1 = SBase_getNotes(c);
457   fail_unless(XMLNode_getNumChildren(t1) == 1);
458   char * chars = SBase_getNotesString(c);
459   fail_unless(!strcmp(chars, taggednotes));
460   safe_free(chars);
461 
462   SBase_setNotesString(c, (char *)"");
463   fail_unless(SBase_isSetNotes(c) == 0 );
464 
465   if (SBase_getNotesString(c) != NULL)
466   {
467     fail("SBase_getNotesString(c, "") did not clear string.");
468   }
469 
470   SBase_setNotesString(c, taggednotes);
471 
472   fail_unless(SBase_isSetNotes(c) == 1);
473 
474   str = SBase_getNotesString(c);
475   if (strcmp(str, taggednotes))
476   {
477     fail("SBase_setNotesString(...) did not make a copy of node.");
478   }
479   t1 = SBase_getNotes(c);
480   safe_free(str);
481   fail_unless(XMLNode_getNumChildren(t1) == 1);
482 
483   t2 = XMLNode_getChild(t1,0);
484   fail_unless(!strcmp(XMLNode_getCharacters(t2), "This is a test note"));
485   Model_free(c);
486 }
487 END_TEST
488 
489 
START_TEST(test_SBase_setNotesString_l3)490 START_TEST (test_SBase_setNotesString_l3)
491 {
492   Model_t *c = new(std::nothrow) Model(3, 1);
493   const char * notes = "This is a test note";
494   //const char * taggednotes = "<notes>\n  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note</p>\n</notes>";
495 
496   // this should not set the notes since they are invalid xhtml
497   SBase_setNotesString(c, notes);
498 
499   fail_unless(SBase_isSetNotes(c) == 0);
500   Model_free(c);
501 }
502 END_TEST
503 
504 
START_TEST(test_SBase_setNotesString_l3_addMarkup)505 START_TEST (test_SBase_setNotesString_l3_addMarkup)
506 {
507   Model_t *c = new(std::nothrow) Model(3, 1);
508   char * notes = "This is a test note";
509   char * taggednotes = "<notes>\n  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note</p>\n</notes>";
510 
511   SBase_setNotesStringAddMarkup(c, notes);
512 
513   fail_unless(SBase_isSetNotes(c) == 1);
514 
515   char* str = SBase_getNotesString(c);
516   if (strcmp(str, taggednotes))
517   {
518     fail("SBase_setNotesString(...) did not make a copy of node.");
519   }
520   safe_free(str);
521   XMLNode_t *t1 = SBase_getNotes(c);
522   fail_unless(XMLNode_getNumChildren(t1) == 1);
523 
524   const XMLNode_t *t2 = XMLNode_getChild(t1,0);
525   fail_unless(XMLNode_getNumChildren(t2) == 1);
526 
527   const XMLNode_t *t3 = XMLNode_getChild(t2,0);
528   fail_unless(!strcmp(XMLNode_getCharacters(t3), "This is a test note"));
529 
530 
531   SBase_setNotesStringAddMarkup(c, taggednotes);
532 
533   fail_unless(SBase_isSetNotes(c) == 1);
534 
535   str = SBase_getNotesString(c);
536   if (strcmp(str, taggednotes))
537   {
538     fail("SBase_setNotesString(...) did not make a copy of node.");
539   }
540   safe_free(str);
541   t1 = SBase_getNotes(c);
542   fail_unless(XMLNode_getNumChildren(t1) == 1);
543 
544   t2 = XMLNode_getChild(t1,0);
545   fail_unless(XMLNode_getNumChildren(t2) == 1);
546 
547   t3 = XMLNode_getChild(t2,0);
548   fail_unless(!strcmp(XMLNode_getCharacters(t3), "This is a test note"));
549 
550   Model_free(c);
551 }
552 END_TEST
553 
554 
START_TEST(test_SBase_setAnnotationString)555 START_TEST (test_SBase_setAnnotationString)
556 {
557   char * annotation = "This is a test note";
558   char * taggedannotation = "<annotation>This is a test note</annotation>";
559 
560   SBase_setAnnotationString(S, annotation);
561 
562   fail_unless(SBase_isSetAnnotation(S) == 1);
563 
564   char* str = SBase_getAnnotationString(S);
565   if (strcmp(str, taggedannotation))
566   {
567     fail("SBase_setAnnotationString(...) did not make a copy of node.");
568   }
569   safe_free(str);
570   XMLNode_t *t1 = SBase_getAnnotation(S);
571   fail_unless(XMLNode_getNumChildren(t1) == 1);
572 
573   fail_unless(!strcmp(XMLNode_getCharacters(XMLNode_getChild(t1,0)), "This is a test note"));
574 
575 
576   /* Reflexive case (pathological)  */
577   str = SBase_getAnnotationString(S);
578   SBase_setAnnotationString(S, str);
579   safe_free(str);
580   t1 = SBase_getAnnotation(S);
581   fail_unless(XMLNode_getNumChildren(t1) == 1);
582   char * chars = SBase_getAnnotationString(S);
583   fail_unless(!strcmp(chars, taggedannotation));
584   safe_free(chars);
585 
586   SBase_setAnnotationString(S, "");
587   fail_unless(SBase_isSetAnnotation(S) == 0 );
588 
589   if (SBase_getAnnotationString(S) != NULL)
590   {
591     fail("SBase_getAnnotationString(S, "") did not clear string.");
592   }
593 
594   SBase_setAnnotationString(S, taggedannotation);
595 
596   fail_unless(SBase_isSetAnnotation(S) == 1);
597 
598   str = SBase_getAnnotationString(S);
599   if (strcmp(str, taggedannotation))
600   {
601     fail("SBase_setAnnotationString(...) did not make a copy of node.");
602   }
603   safe_free(str);
604   t1 = SBase_getAnnotation(S);
605   fail_unless(XMLNode_getNumChildren(t1) == 1);
606 
607   const XMLNode_t *t2 = XMLNode_getChild(t1,0);
608   fail_unless(!strcmp(XMLNode_getCharacters(t2), "This is a test note"));
609 }
610 END_TEST
611 
612 
START_TEST(test_SBase_appendNotes)613 START_TEST (test_SBase_appendNotes)
614 { // add a p tag to a p tag
615   XMLTriple_t *triple = XMLTriple_createWith("p", "", "");
616   XMLAttributes_t * att = XMLAttributes_create ();
617   XMLNamespaces_t *ns = XMLNamespaces_create();
618   XMLNamespaces_add(ns, "http://www.w3.org/1999/xhtml", "");
619   XMLToken_t *token4 = XMLToken_createWithText("This is my text");
620   XMLNode_t *node4 = XMLNode_createFromToken(token4);
621   XMLToken_t *token5 = XMLToken_createWithText("This is additional text");
622   XMLNode_t *node5 = XMLNode_createFromToken(token5);
623 
624   XMLToken* token = XMLToken_createWithTripleAttrNS(triple, att, ns);
625   XMLNode* node = XMLNode_createFromToken(token);
626   XMLNode_addChild(node, node4);
627 
628   SBase_setNotes(S, node);
629 
630   fail_unless(SBase_isSetNotes(S) == 1);
631 
632   XMLToken* token1 = XMLToken_createWithTripleAttrNS(triple, att, ns);
633   XMLNode* node1 = XMLNode_createFromToken(token1);
634   XMLNode_addChild(node1, node5);
635 
636   SBase_appendNotes(S, node1);
637 
638   fail_unless(SBase_isSetNotes(S) == 1);
639 
640   XMLNode* node2 = SBase_getNotes(S);
641 
642   fail_unless(XMLNode_getNumChildren(node2) == 2);
643   fail_unless(!strcmp(XMLNode_getName(XMLNode_getChild(node2, 0)), "p"));
644   fail_unless(XMLNode_getNumChildren(XMLNode_getChild(node2, 0)) == 1);
645   fail_unless(!strcmp(XMLNode_getName(XMLNode_getChild(node2, 1)), "p"));
646   fail_unless(XMLNode_getNumChildren(XMLNode_getChild(node2, 1)) == 1);
647 
648   const char * chars1 = XMLNode_getCharacters(XMLNode_getChild(
649     XMLNode_getChild(node2, 0), 0));
650   const char * chars2 = XMLNode_getCharacters(XMLNode_getChild(
651     XMLNode_getChild(node2, 1), 0));
652 
653   fail_unless(!strcmp(chars1, "This is my text"));
654   fail_unless(!strcmp(chars2, "This is additional text"));
655 
656   XMLNode_free(node);
657   XMLNode_free(node1);
658   XMLTriple_free(triple);
659   XMLAttributes_free(att);
660   XMLNamespaces_free(ns);
661   XMLToken_free(token4);
662   XMLNode_free(node4);
663   XMLToken_free(token5);
664   XMLNode_free(node5);
665   XMLToken_free(token);
666   XMLToken_free(token1);
667 }
668 END_TEST
669 
670 
START_TEST(test_SBase_appendNotes1)671 START_TEST (test_SBase_appendNotes1)
672 {
673   // add a html tag to an html tag
674   XMLAttributes_t * att = XMLAttributes_create ();
675   XMLNamespaces_t *ns = XMLNamespaces_create();
676   XMLNamespaces_add(ns, "http://www.w3.org/1999/xhtml", "");
677   XMLTriple_t *html_triple = XMLTriple_createWith("html", "", "");
678   XMLTriple_t *head_triple = XMLTriple_createWith("head", "", "");
679   XMLTriple_t *title_triple = XMLTriple_createWith("title", "", "");
680   XMLTriple_t *body_triple = XMLTriple_createWith("body", "", "");
681   XMLTriple_t *p_triple = XMLTriple_createWith("p", "", "");
682   XMLToken_t *html_token = XMLToken_createWithTripleAttrNS(html_triple, att, ns);
683   XMLToken_t *head_token = XMLToken_createWithTripleAttr(head_triple, att);
684   XMLToken_t *title_token = XMLToken_createWithTripleAttr(title_triple, att);
685   XMLToken_t *body_token = XMLToken_createWithTripleAttr(body_triple, att);
686   XMLToken_t *p_token = XMLToken_createWithTripleAttr(p_triple, att);
687   XMLToken_t *text_token = XMLToken_createWithText("This is my text");
688   XMLNode_t *html_node = XMLNode_createFromToken(html_token);
689   XMLNode_t *head_node = XMLNode_createFromToken(head_token);
690   XMLNode_t *title_node = XMLNode_createFromToken(title_token);
691   XMLNode_t *body_node = XMLNode_createFromToken(body_token);
692   XMLNode_t *p_node = XMLNode_createFromToken(p_token);
693   XMLNode_t *text_node = XMLNode_createFromToken(text_token);
694 
695   XMLToken_t *text_token1 = XMLToken_createWithText("This is more text");
696   XMLNode_t *html_node1 = XMLNode_createFromToken(html_token);
697   XMLNode_t *head_node1 = XMLNode_createFromToken(head_token);
698   XMLNode_t *title_node1 = XMLNode_createFromToken(title_token);
699   XMLNode_t *body_node1 = XMLNode_createFromToken(body_token);
700   XMLNode_t *p_node1 = XMLNode_createFromToken(p_token);
701   XMLNode_t *text_node1 = XMLNode_createFromToken(text_token1);
702 
703   XMLNode_t * notes;
704   const XMLNode_t *child, *child1;
705 
706   XMLNode_addChild(p_node, text_node);
707   XMLNode_addChild(body_node, p_node);
708   XMLNode_addChild(head_node, title_node);
709   XMLNode_addChild(html_node, head_node);
710   XMLNode_addChild(html_node, body_node);
711 
712   XMLNode_addChild(p_node1, text_node1);
713   XMLNode_addChild(body_node1, p_node1);
714   XMLNode_addChild(head_node1, title_node1);
715   XMLNode_addChild(html_node1, head_node1);
716   XMLNode_addChild(html_node1, body_node1);
717 
718   SBase_setNotes(S, html_node);
719   SBase_appendNotes(S, html_node1);
720 
721   notes = SBase_getNotes(S);
722 
723   fail_unless(!strcmp(XMLNode_getName(notes), "notes"));
724   fail_unless(XMLNode_getNumChildren(notes) == 1);
725 
726   child = XMLNode_getChild(notes, 0);
727 
728   fail_unless(!strcmp(XMLNode_getName(child), "html"));
729   fail_unless(XMLNode_getNumChildren(child) == 2);
730 
731   child = XMLNode_getChild(child, 1);
732 
733   fail_unless(!strcmp(XMLNode_getName(child), "body"));
734   fail_unless(XMLNode_getNumChildren(child) == 2);
735 
736   child1 = XMLNode_getChild(child, 0);
737 
738   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
739   fail_unless(XMLNode_getNumChildren(child1) == 1);
740 
741   child1 = XMLNode_getChild(child1, 0);
742 
743   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is my text"));
744   fail_unless(XMLNode_getNumChildren(child1) == 0);
745 
746   child1 = XMLNode_getChild(child, 1);
747 
748   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
749   fail_unless(XMLNode_getNumChildren(child1) == 1);
750 
751   child1 = XMLNode_getChild(child1, 0);
752 
753   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is more text"));
754   fail_unless(XMLNode_getNumChildren(child1) == 0);
755 
756   XMLAttributes_free(att);
757   XMLNamespaces_free(ns);
758   XMLTriple_free(html_triple);
759   XMLTriple_free(head_triple);
760   XMLTriple_free(title_triple);
761   XMLTriple_free(body_triple);
762   XMLTriple_free(p_triple);
763   XMLToken_free(html_token);
764   XMLToken_free(head_token);
765   XMLToken_free(title_token);
766   XMLToken_free(body_token);
767   XMLToken_free(p_token);
768   XMLToken_free(text_token);
769   XMLToken_free(text_token1);
770   XMLNode_free(html_node);
771   XMLNode_free(head_node);
772   XMLNode_free(title_node);
773   XMLNode_free(body_node);
774   XMLNode_free(p_node);
775   XMLNode_free(text_node);
776   XMLNode_free(html_node1);
777   XMLNode_free(head_node1);
778   XMLNode_free(title_node1);
779   XMLNode_free(body_node1);
780   XMLNode_free(p_node1);
781   XMLNode_free(text_node1);
782 }
783 END_TEST
784 
785 
START_TEST(test_SBase_appendNotes2)786 START_TEST (test_SBase_appendNotes2)
787 {// add a body tag to an html tag
788   XMLAttributes_t * att = XMLAttributes_create ();
789   XMLNamespaces_t *ns = XMLNamespaces_create();
790   XMLNamespaces_add(ns, "http://www.w3.org/1999/xhtml", "");
791   XMLTriple_t *html_triple = XMLTriple_createWith("html", "", "");
792   XMLTriple_t *head_triple = XMLTriple_createWith("head", "", "");
793   XMLTriple_t *title_triple = XMLTriple_createWith("title", "", "");
794   XMLTriple_t *body_triple = XMLTriple_createWith("body", "", "");
795   XMLTriple_t *p_triple = XMLTriple_createWith("p", "", "");
796   XMLToken_t *html_token = XMLToken_createWithTripleAttrNS(html_triple, att, ns);
797   XMLToken_t *head_token = XMLToken_createWithTripleAttr(head_triple, att);
798   XMLToken_t *title_token = XMLToken_createWithTripleAttr(title_triple, att);
799   XMLToken_t *body_token = XMLToken_createWithTripleAttr(body_triple, att);
800   XMLToken_t *p_token = XMLToken_createWithTripleAttr(p_triple, att);
801   XMLToken_t *text_token = XMLToken_createWithText("This is my text");
802   XMLNode_t *html_node = XMLNode_createFromToken(html_token);
803   XMLNode_t *head_node = XMLNode_createFromToken(head_token);
804   XMLNode_t *title_node = XMLNode_createFromToken(title_token);
805   XMLNode_t *body_node = XMLNode_createFromToken(body_token);
806   XMLNode_t *p_node = XMLNode_createFromToken(p_token);
807   XMLNode_t *text_node = XMLNode_createFromToken(text_token);
808 
809   XMLToken_t *body_token1 = XMLToken_createWithTripleAttrNS(body_triple, att, ns);
810   XMLToken_t *text_token1 = XMLToken_createWithText("This is more text");
811   XMLNode_t *body_node1 = XMLNode_createFromToken(body_token1);
812   XMLNode_t *p_node1 = XMLNode_createFromToken(p_token);
813   XMLNode_t *text_node1 = XMLNode_createFromToken(text_token1);
814 
815   XMLNode_t * notes;
816   const XMLNode_t *child, *child1;
817 
818   XMLNode_addChild(p_node, text_node);
819   XMLNode_addChild(body_node, p_node);
820   XMLNode_addChild(head_node, title_node);
821   XMLNode_addChild(html_node, head_node);
822   XMLNode_addChild(html_node, body_node);
823 
824   XMLNode_addChild(p_node1, text_node1);
825   XMLNode_addChild(body_node1, p_node1);
826 
827   SBase_setNotes(S, html_node);
828   SBase_appendNotes(S, body_node1);
829 
830   notes = SBase_getNotes(S);
831 
832   fail_unless(!strcmp(XMLNode_getName(notes), "notes"));
833   fail_unless(XMLNode_getNumChildren(notes) == 1);
834 
835   child = XMLNode_getChild(notes, 0);
836 
837   fail_unless(!strcmp(XMLNode_getName(child), "html"));
838   fail_unless(XMLNode_getNumChildren(child) == 2);
839 
840   child = XMLNode_getChild(child, 1);
841 
842   fail_unless(!strcmp(XMLNode_getName(child), "body"));
843   fail_unless(XMLNode_getNumChildren(child) == 2);
844 
845   child1 = XMLNode_getChild(child, 0);
846 
847   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
848   fail_unless(XMLNode_getNumChildren(child1) == 1);
849 
850   child1 = XMLNode_getChild(child1, 0);
851 
852   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is my text"));
853   fail_unless(XMLNode_getNumChildren(child1) == 0);
854 
855   child1 = XMLNode_getChild(child, 1);
856 
857   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
858   fail_unless(XMLNode_getNumChildren(child1) == 1);
859 
860   child1 = XMLNode_getChild(child1, 0);
861 
862   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is more text"));
863   fail_unless(XMLNode_getNumChildren(child1) == 0);
864 
865   XMLAttributes_free(att);
866   XMLNamespaces_free(ns);
867   XMLTriple_free(html_triple);
868   XMLTriple_free(head_triple);
869   XMLTriple_free(title_triple);
870   XMLTriple_free(body_triple);
871   XMLTriple_free(p_triple);
872   XMLToken_free(html_token);
873   XMLToken_free(head_token);
874   XMLToken_free(title_token);
875   XMLToken_free(body_token);
876   XMLToken_free(p_token);
877   XMLToken_free(text_token);
878   XMLToken_free(text_token1);
879   XMLToken_free(body_token1);
880   XMLNode_free(html_node);
881   XMLNode_free(head_node);
882   XMLNode_free(title_node);
883   XMLNode_free(body_node);
884   XMLNode_free(p_node);
885   XMLNode_free(text_node);
886   XMLNode_free(body_node1);
887   XMLNode_free(p_node1);
888   XMLNode_free(text_node1);
889 }
890 END_TEST
891 
892 
START_TEST(test_SBase_appendNotes3)893 START_TEST (test_SBase_appendNotes3)
894 {
895   // add a p tag to an html tag
896   XMLAttributes_t * att = XMLAttributes_create ();
897   XMLNamespaces_t *ns = XMLNamespaces_create();
898   XMLNamespaces_add(ns, "http://www.w3.org/1999/xhtml", "");
899   XMLTriple_t *html_triple = XMLTriple_createWith("html", "", "");
900   XMLTriple_t *head_triple = XMLTriple_createWith("head", "", "");
901   XMLTriple_t *title_triple = XMLTriple_createWith("title", "", "");
902   XMLTriple_t *body_triple = XMLTriple_createWith("body", "", "");
903   XMLTriple_t *p_triple = XMLTriple_createWith("p", "", "");
904   XMLToken_t *html_token = XMLToken_createWithTripleAttrNS(html_triple, att, ns);
905   XMLToken_t *head_token = XMLToken_createWithTripleAttr(head_triple, att);
906   XMLToken_t *title_token = XMLToken_createWithTripleAttr(title_triple, att);
907   XMLToken_t *body_token = XMLToken_createWithTripleAttr(body_triple, att);
908   XMLToken_t *p_token = XMLToken_createWithTripleAttr(p_triple, att);
909   XMLToken_t *text_token = XMLToken_createWithText("This is my text");
910   XMLNode_t *html_node = XMLNode_createFromToken(html_token);
911   XMLNode_t *head_node = XMLNode_createFromToken(head_token);
912   XMLNode_t *title_node = XMLNode_createFromToken(title_token);
913   XMLNode_t *body_node = XMLNode_createFromToken(body_token);
914   XMLNode_t *p_node = XMLNode_createFromToken(p_token);
915   XMLNode_t *text_node = XMLNode_createFromToken(text_token);
916 
917   XMLToken_t *p_token1 = XMLToken_createWithTripleAttrNS(p_triple, att, ns);
918   XMLToken_t *text_token1 = XMLToken_createWithText("This is more text");
919   XMLNode_t *p_node1 = XMLNode_createFromToken(p_token1);
920   XMLNode_t *text_node1 = XMLNode_createFromToken(text_token1);
921 
922   XMLNode_t * notes;
923   const XMLNode_t *child, *child1;
924 
925   XMLNode_addChild(p_node, text_node);
926   XMLNode_addChild(body_node, p_node);
927   XMLNode_addChild(head_node, title_node);
928   XMLNode_addChild(html_node, head_node);
929   XMLNode_addChild(html_node, body_node);
930 
931   XMLNode_addChild(p_node1, text_node1);
932 
933   SBase_setNotes(S, html_node);
934   SBase_appendNotes(S, p_node1);
935 
936   notes = SBase_getNotes(S);
937 
938   fail_unless(!strcmp(XMLNode_getName(notes), "notes"));
939   fail_unless(XMLNode_getNumChildren(notes) == 1);
940 
941   child = XMLNode_getChild(notes, 0);
942 
943   fail_unless(!strcmp(XMLNode_getName(child), "html"));
944   fail_unless(XMLNode_getNumChildren(child) == 2);
945 
946   child = XMLNode_getChild(child, 1);
947 
948   fail_unless(!strcmp(XMLNode_getName(child), "body"));
949   fail_unless(XMLNode_getNumChildren(child) == 2);
950 
951   child1 = XMLNode_getChild(child, 0);
952 
953   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
954   fail_unless(XMLNode_getNumChildren(child1) == 1);
955 
956   child1 = XMLNode_getChild(child1, 0);
957 
958   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is my text"));
959   fail_unless(XMLNode_getNumChildren(child1) == 0);
960 
961   child1 = XMLNode_getChild(child, 1);
962 
963   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
964   fail_unless(XMLNode_getNumChildren(child1) == 1);
965 
966   child1 = XMLNode_getChild(child1, 0);
967 
968   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is more text"));
969   fail_unless(XMLNode_getNumChildren(child1) == 0);
970 
971   XMLAttributes_free(att);
972   XMLNamespaces_free(ns);
973   XMLTriple_free(html_triple);
974   XMLTriple_free(head_triple);
975   XMLTriple_free(title_triple);
976   XMLTriple_free(body_triple);
977   XMLTriple_free(p_triple);
978   XMLToken_free(html_token);
979   XMLToken_free(head_token);
980   XMLToken_free(title_token);
981   XMLToken_free(body_token);
982   XMLToken_free(p_token);
983   XMLToken_free(text_token);
984   XMLToken_free(text_token1);
985   XMLToken_free(p_token1);
986   XMLNode_free(html_node);
987   XMLNode_free(head_node);
988   XMLNode_free(title_node);
989   XMLNode_free(body_node);
990   XMLNode_free(p_node);
991   XMLNode_free(text_node);
992   XMLNode_free(p_node1);
993   XMLNode_free(text_node1);
994 }
995 END_TEST
996 
997 
START_TEST(test_SBase_appendNotes4)998 START_TEST (test_SBase_appendNotes4)
999 {
1000   // add a html tag to a body tag
1001   XMLAttributes_t * att = XMLAttributes_create ();
1002   XMLNamespaces_t *ns = XMLNamespaces_create();
1003   XMLNamespaces_add(ns, "http://www.w3.org/1999/xhtml", "");
1004   XMLTriple_t *html_triple = XMLTriple_createWith("html", "", "");
1005   XMLTriple_t *head_triple = XMLTriple_createWith("head", "", "");
1006   XMLTriple_t *title_triple = XMLTriple_createWith("title", "", "");
1007   XMLTriple_t *body_triple = XMLTriple_createWith("body", "", "");
1008   XMLTriple_t *p_triple = XMLTriple_createWith("p", "", "");
1009   XMLToken_t *html_token = XMLToken_createWithTripleAttrNS(html_triple, att, ns);
1010   XMLToken_t *head_token = XMLToken_createWithTripleAttr(head_triple, att);
1011   XMLToken_t *title_token = XMLToken_createWithTripleAttr(title_triple, att);
1012   XMLToken_t *body_token = XMLToken_createWithTripleAttr(body_triple, att);
1013   XMLToken_t *p_token = XMLToken_createWithTripleAttr(p_triple, att);
1014   XMLToken_t *body_token1 = XMLToken_createWithTripleAttrNS(body_triple, att, ns);
1015   XMLToken_t *text_token = XMLToken_createWithText("This is my text");
1016   XMLNode_t *body_node = XMLNode_createFromToken(body_token1);
1017   XMLNode_t *p_node = XMLNode_createFromToken(p_token);
1018   XMLNode_t *text_node = XMLNode_createFromToken(text_token);
1019 
1020   XMLToken_t *text_token1 = XMLToken_createWithText("This is more text");
1021   XMLNode_t *html_node1 = XMLNode_createFromToken(html_token);
1022   XMLNode_t *head_node1 = XMLNode_createFromToken(head_token);
1023   XMLNode_t *title_node1 = XMLNode_createFromToken(title_token);
1024   XMLNode_t *body_node1 = XMLNode_createFromToken(body_token);
1025   XMLNode_t *p_node1 = XMLNode_createFromToken(p_token);
1026   XMLNode_t *text_node1 = XMLNode_createFromToken(text_token1);
1027 
1028   XMLNode_t * notes;
1029   const XMLNode_t *child, *child1;
1030 
1031   XMLNode_addChild(p_node, text_node);
1032   XMLNode_addChild(body_node, p_node);
1033 
1034   XMLNode_addChild(p_node1, text_node1);
1035   XMLNode_addChild(body_node1, p_node1);
1036   XMLNode_addChild(head_node1, title_node1);
1037   XMLNode_addChild(html_node1, head_node1);
1038   XMLNode_addChild(html_node1, body_node1);
1039 
1040   SBase_setNotes(S, body_node);
1041   SBase_appendNotes(S, html_node1);
1042 
1043   notes = SBase_getNotes(S);
1044 
1045   fail_unless(!strcmp(XMLNode_getName(notes), "notes"));
1046   fail_unless(XMLNode_getNumChildren(notes) == 1);
1047 
1048   child = XMLNode_getChild(notes, 0);
1049 
1050   fail_unless(!strcmp(XMLNode_getName(child), "html"));
1051   fail_unless(XMLNode_getNumChildren(child) == 2);
1052 
1053   child = XMLNode_getChild(child, 1);
1054 
1055   fail_unless(!strcmp(XMLNode_getName(child), "body"));
1056   fail_unless(XMLNode_getNumChildren(child) == 2);
1057 
1058   child1 = XMLNode_getChild(child, 0);
1059 
1060   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
1061   fail_unless(XMLNode_getNumChildren(child1) == 1);
1062 
1063   child1 = XMLNode_getChild(child1, 0);
1064 
1065   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is my text"));
1066   fail_unless(XMLNode_getNumChildren(child1) == 0);
1067 
1068   child1 = XMLNode_getChild(child, 1);
1069 
1070   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
1071   fail_unless(XMLNode_getNumChildren(child1) == 1);
1072 
1073   child1 = XMLNode_getChild(child1, 0);
1074 
1075   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is more text"));
1076   fail_unless(XMLNode_getNumChildren(child1) == 0);
1077 
1078   XMLAttributes_free(att);
1079   XMLNamespaces_free(ns);
1080   XMLTriple_free(html_triple);
1081   XMLTriple_free(head_triple);
1082   XMLTriple_free(title_triple);
1083   XMLTriple_free(body_triple);
1084   XMLTriple_free(p_triple);
1085   XMLToken_free(html_token);
1086   XMLToken_free(head_token);
1087   XMLToken_free(title_token);
1088   XMLToken_free(body_token);
1089   XMLToken_free(p_token);
1090   XMLToken_free(text_token);
1091   XMLToken_free(text_token1);
1092   XMLToken_free(body_token1);
1093   XMLNode_free(body_node);
1094   XMLNode_free(p_node);
1095   XMLNode_free(text_node);
1096   XMLNode_free(html_node1);
1097   XMLNode_free(head_node1);
1098   XMLNode_free(title_node1);
1099   XMLNode_free(body_node1);
1100   XMLNode_free(p_node1);
1101   XMLNode_free(text_node1);
1102 }
1103 END_TEST
1104 
1105 
START_TEST(test_SBase_appendNotes5)1106 START_TEST (test_SBase_appendNotes5)
1107 {
1108   // add a html tag to a p tag
1109   XMLAttributes_t * att = XMLAttributes_create ();
1110   XMLNamespaces_t *ns = XMLNamespaces_create();
1111   XMLNamespaces_add(ns, "http://www.w3.org/1999/xhtml", "");
1112   XMLTriple_t *html_triple = XMLTriple_createWith("html", "", "");
1113   XMLTriple_t *head_triple = XMLTriple_createWith("head", "", "");
1114   XMLTriple_t *title_triple = XMLTriple_createWith("title", "", "");
1115   XMLTriple_t *body_triple = XMLTriple_createWith("body", "", "");
1116   XMLTriple_t *p_triple = XMLTriple_createWith("p", "", "");
1117   XMLToken_t *html_token = XMLToken_createWithTripleAttrNS(html_triple, att, ns);
1118   XMLToken_t *head_token = XMLToken_createWithTripleAttr(head_triple, att);
1119   XMLToken_t *title_token = XMLToken_createWithTripleAttr(title_triple, att);
1120   XMLToken_t *body_token = XMLToken_createWithTripleAttr(body_triple, att);
1121   XMLToken_t *p_token = XMLToken_createWithTripleAttr(p_triple, att);
1122   XMLToken_t *p_token1 = XMLToken_createWithTripleAttrNS(p_triple, att, ns);
1123   XMLToken_t *text_token = XMLToken_createWithText("This is my text");
1124   XMLNode_t *p_node = XMLNode_createFromToken(p_token1);
1125   XMLNode_t *text_node = XMLNode_createFromToken(text_token);
1126 
1127   XMLToken_t *text_token1 = XMLToken_createWithText("This is more text");
1128   XMLNode_t *html_node1 = XMLNode_createFromToken(html_token);
1129   XMLNode_t *head_node1 = XMLNode_createFromToken(head_token);
1130   XMLNode_t *title_node1 = XMLNode_createFromToken(title_token);
1131   XMLNode_t *body_node1 = XMLNode_createFromToken(body_token);
1132   XMLNode_t *p_node1 = XMLNode_createFromToken(p_token);
1133   XMLNode_t *text_node1 = XMLNode_createFromToken(text_token1);
1134 
1135   XMLNode_t * notes;
1136   const XMLNode_t *child, *child1;
1137 
1138   XMLNode_addChild(p_node, text_node);
1139 
1140   XMLNode_addChild(p_node1, text_node1);
1141   XMLNode_addChild(body_node1, p_node1);
1142   XMLNode_addChild(head_node1, title_node1);
1143   XMLNode_addChild(html_node1, head_node1);
1144   XMLNode_addChild(html_node1, body_node1);
1145 
1146   SBase_setNotes(S, p_node);
1147   SBase_appendNotes(S, html_node1);
1148 
1149   notes = SBase_getNotes(S);
1150 
1151   fail_unless(!strcmp(XMLNode_getName(notes), "notes"));
1152   fail_unless(XMLNode_getNumChildren(notes) == 1);
1153 
1154   child = XMLNode_getChild(notes, 0);
1155 
1156   fail_unless(!strcmp(XMLNode_getName(child), "html"));
1157   fail_unless(XMLNode_getNumChildren(child) == 2);
1158 
1159   child = XMLNode_getChild(child, 1);
1160 
1161   fail_unless(!strcmp(XMLNode_getName(child), "body"));
1162   fail_unless(XMLNode_getNumChildren(child) == 2);
1163 
1164   child1 = XMLNode_getChild(child, 0);
1165 
1166   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
1167   fail_unless(XMLNode_getNumChildren(child1) == 1);
1168 
1169   child1 = XMLNode_getChild(child1, 0);
1170 
1171   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is my text"));
1172   fail_unless(XMLNode_getNumChildren(child1) == 0);
1173 
1174   child1 = XMLNode_getChild(child, 1);
1175 
1176   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
1177   fail_unless(XMLNode_getNumChildren(child1) == 1);
1178 
1179   child1 = XMLNode_getChild(child1, 0);
1180 
1181   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is more text"));
1182   fail_unless(XMLNode_getNumChildren(child1) == 0);
1183 
1184   XMLAttributes_free(att);
1185   XMLNamespaces_free(ns);
1186   XMLTriple_free(html_triple);
1187   XMLTriple_free(head_triple);
1188   XMLTriple_free(title_triple);
1189   XMLTriple_free(body_triple);
1190   XMLTriple_free(p_triple);
1191   XMLToken_free(html_token);
1192   XMLToken_free(head_token);
1193   XMLToken_free(title_token);
1194   XMLToken_free(body_token);
1195   XMLToken_free(p_token);
1196   XMLToken_free(p_token1);
1197   XMLToken_free(text_token);
1198   XMLToken_free(text_token1);
1199   XMLNode_free(p_node);
1200   XMLNode_free(text_node);
1201   XMLNode_free(html_node1);
1202   XMLNode_free(head_node1);
1203   XMLNode_free(title_node1);
1204   XMLNode_free(body_node1);
1205   XMLNode_free(p_node1);
1206   XMLNode_free(text_node1);
1207 }
1208 END_TEST
1209 
1210 
START_TEST(test_SBase_appendNotes6)1211 START_TEST (test_SBase_appendNotes6)
1212 {// add a body tag to an body tag
1213   XMLAttributes_t * att = XMLAttributes_create ();
1214   XMLNamespaces_t *ns = XMLNamespaces_create();
1215   XMLNamespaces_add(ns, "http://www.w3.org/1999/xhtml", "");
1216   XMLTriple_t *body_triple = XMLTriple_createWith("body", "", "");
1217   XMLTriple_t *p_triple = XMLTriple_createWith("p", "", "");
1218   XMLToken_t *body_token = XMLToken_createWithTripleAttrNS(body_triple, att, ns);
1219   XMLToken_t *p_token = XMLToken_createWithTripleAttr(p_triple, att);
1220   XMLToken_t *text_token = XMLToken_createWithText("This is my text");
1221   XMLNode_t *body_node = XMLNode_createFromToken(body_token);
1222   XMLNode_t *p_node = XMLNode_createFromToken(p_token);
1223   XMLNode_t *text_node = XMLNode_createFromToken(text_token);
1224 
1225   XMLToken_t *text_token1 = XMLToken_createWithText("This is more text");
1226   XMLNode_t *body_node1 = XMLNode_createFromToken(body_token);
1227   XMLNode_t *p_node1 = XMLNode_createFromToken(p_token);
1228   XMLNode_t *text_node1 = XMLNode_createFromToken(text_token1);
1229 
1230   XMLNode_t * notes;
1231   const XMLNode_t *child, *child1;
1232 
1233   XMLNode_addChild(p_node, text_node);
1234   XMLNode_addChild(body_node, p_node);
1235 
1236   XMLNode_addChild(p_node1, text_node1);
1237   XMLNode_addChild(body_node1, p_node1);
1238 
1239   SBase_setNotes(S, body_node);
1240   SBase_appendNotes(S, body_node1);
1241 
1242   notes = SBase_getNotes(S);
1243 
1244   fail_unless(!strcmp(XMLNode_getName(notes), "notes"));
1245   fail_unless(XMLNode_getNumChildren(notes) == 1);
1246 
1247   child = XMLNode_getChild(notes, 0);
1248 
1249   fail_unless(!strcmp(XMLNode_getName(child), "body"));
1250   fail_unless(XMLNode_getNumChildren(child) == 2);
1251 
1252   child1 = XMLNode_getChild(child, 0);
1253 
1254   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
1255   fail_unless(XMLNode_getNumChildren(child1) == 1);
1256 
1257   child1 = XMLNode_getChild(child1, 0);
1258 
1259   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is my text"));
1260   fail_unless(XMLNode_getNumChildren(child1) == 0);
1261 
1262   child1 = XMLNode_getChild(child, 1);
1263 
1264   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
1265   fail_unless(XMLNode_getNumChildren(child1) == 1);
1266 
1267   child1 = XMLNode_getChild(child1, 0);
1268 
1269   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is more text"));
1270   fail_unless(XMLNode_getNumChildren(child1) == 0);
1271 
1272   XMLAttributes_free(att);
1273   XMLNamespaces_free(ns);
1274   XMLTriple_free(body_triple);
1275   XMLTriple_free(p_triple);
1276   XMLToken_free(body_token);
1277   XMLToken_free(p_token);
1278   XMLToken_free(text_token);
1279   XMLToken_free(text_token1);
1280   XMLNode_free(body_node);
1281   XMLNode_free(p_node);
1282   XMLNode_free(text_node);
1283   XMLNode_free(body_node1);
1284   XMLNode_free(p_node1);
1285   XMLNode_free(text_node1);
1286 }
1287 END_TEST
1288 
1289 
START_TEST(test_SBase_appendNotes7)1290 START_TEST (test_SBase_appendNotes7)
1291 {// add a body tag to an p tag
1292   XMLAttributes_t * att = XMLAttributes_create ();
1293   XMLNamespaces_t *ns = XMLNamespaces_create();
1294   XMLNamespaces_add(ns, "http://www.w3.org/1999/xhtml", "");
1295   XMLTriple_t *body_triple = XMLTriple_createWith("body", "", "");
1296   XMLTriple_t *p_triple = XMLTriple_createWith("p", "", "");
1297   XMLToken_t *body_token = XMLToken_createWithTripleAttrNS(body_triple, att, ns);
1298   XMLToken_t *p_token1 = XMLToken_createWithTripleAttrNS(p_triple, att, ns);
1299   XMLToken_t *text_token = XMLToken_createWithText("This is my text");
1300   XMLToken_t *p_token = XMLToken_createWithTripleAttr(p_triple, att);
1301   XMLNode_t *p_node = XMLNode_createFromToken(p_token1);
1302   XMLNode_t *text_node = XMLNode_createFromToken(text_token);
1303 
1304   XMLToken_t *text_token1 = XMLToken_createWithText("This is more text");
1305   XMLNode_t *body_node1 = XMLNode_createFromToken(body_token);
1306   XMLNode_t *p_node1 = XMLNode_createFromToken(p_token);
1307   XMLNode_t *text_node1 = XMLNode_createFromToken(text_token1);
1308 
1309   XMLNode_t * notes;
1310   const XMLNode_t *child, *child1;
1311 
1312   XMLNode_addChild(p_node, text_node);
1313 
1314   XMLNode_addChild(p_node1, text_node1);
1315   XMLNode_addChild(body_node1, p_node1);
1316 
1317   SBase_setNotes(S, p_node);
1318   SBase_appendNotes(S, body_node1);
1319 
1320   notes = SBase_getNotes(S);
1321 
1322   fail_unless(!strcmp(XMLNode_getName(notes), "notes"));
1323   fail_unless(XMLNode_getNumChildren(notes) == 1);
1324 
1325   child = XMLNode_getChild(notes, 0);
1326 
1327   fail_unless(!strcmp(XMLNode_getName(child), "body"));
1328   fail_unless(XMLNode_getNumChildren(child) == 2);
1329 
1330   child1 = XMLNode_getChild(child, 0);
1331 
1332   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
1333   fail_unless(XMLNode_getNumChildren(child1) == 1);
1334 
1335   child1 = XMLNode_getChild(child1, 0);
1336 
1337   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is my text"));
1338   fail_unless(XMLNode_getNumChildren(child1) == 0);
1339 
1340   child1 = XMLNode_getChild(child, 1);
1341 
1342   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
1343   fail_unless(XMLNode_getNumChildren(child1) == 1);
1344 
1345   child1 = XMLNode_getChild(child1, 0);
1346 
1347   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is more text"));
1348   fail_unless(XMLNode_getNumChildren(child1) == 0);
1349 
1350   XMLAttributes_free(att);
1351   XMLNamespaces_free(ns);
1352   XMLTriple_free(body_triple);
1353   XMLTriple_free(p_triple);
1354   XMLToken_free(body_token);
1355   XMLToken_free(p_token);
1356   XMLToken_free(p_token1);
1357   XMLToken_free(text_token);
1358   XMLToken_free(text_token1);
1359   XMLNode_free(p_node);
1360   XMLNode_free(text_node);
1361   XMLNode_free(body_node1);
1362   XMLNode_free(p_node1);
1363   XMLNode_free(text_node1);
1364 }
1365 END_TEST
1366 
1367 
START_TEST(test_SBase_appendNotes8)1368 START_TEST (test_SBase_appendNotes8)
1369 {
1370   // add a p tag to an body tag
1371   XMLAttributes_t * att = XMLAttributes_create ();
1372   XMLNamespaces_t *ns = XMLNamespaces_create();
1373   XMLNamespaces_add(ns, "http://www.w3.org/1999/xhtml", "");
1374   XMLTriple_t *body_triple = XMLTriple_createWith("body", "", "");
1375   XMLTriple_t *p_triple = XMLTriple_createWith("p", "", "");
1376   XMLToken_t *body_token = XMLToken_createWithTripleAttrNS(body_triple, att, ns);
1377   XMLToken_t *p_token = XMLToken_createWithTripleAttr(p_triple, att);
1378   XMLToken_t *text_token = XMLToken_createWithText("This is my text");
1379   XMLNode_t *body_node = XMLNode_createFromToken(body_token);
1380   XMLNode_t *p_node = XMLNode_createFromToken(p_token);
1381   XMLNode_t *text_node = XMLNode_createFromToken(text_token);
1382 
1383   XMLToken_t *p_token1 = XMLToken_createWithTripleAttrNS(p_triple, att, ns);
1384   XMLToken_t *text_token1 = XMLToken_createWithText("This is more text");
1385   XMLNode_t *p_node1 = XMLNode_createFromToken(p_token1);
1386   XMLNode_t *text_node1 = XMLNode_createFromToken(text_token1);
1387 
1388   XMLNode_t * notes;
1389   const XMLNode_t *child, *child1;
1390 
1391   XMLNode_addChild(p_node, text_node);
1392   XMLNode_addChild(body_node, p_node);
1393 
1394   XMLNode_addChild(p_node1, text_node1);
1395 
1396   SBase_setNotes(S, body_node);
1397   SBase_appendNotes(S, p_node1);
1398 
1399   notes = SBase_getNotes(S);
1400 
1401   fail_unless(!strcmp(XMLNode_getName(notes), "notes"));
1402   fail_unless(XMLNode_getNumChildren(notes) == 1);
1403 
1404   child = XMLNode_getChild(notes, 0);
1405 
1406   fail_unless(!strcmp(XMLNode_getName(child), "body"));
1407   fail_unless(XMLNode_getNumChildren(child) == 2);
1408 
1409   child1 = XMLNode_getChild(child, 0);
1410 
1411   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
1412   fail_unless(XMLNode_getNumChildren(child1) == 1);
1413 
1414   child1 = XMLNode_getChild(child1, 0);
1415 
1416   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is my text"));
1417   fail_unless(XMLNode_getNumChildren(child1) == 0);
1418 
1419   child1 = XMLNode_getChild(child, 1);
1420 
1421   fail_unless(!strcmp(XMLNode_getName(child1), "p"));
1422   fail_unless(XMLNode_getNumChildren(child1) == 1);
1423 
1424   child1 = XMLNode_getChild(child1, 0);
1425 
1426   fail_unless(!strcmp(XMLNode_getCharacters(child1), "This is more text"));
1427   fail_unless(XMLNode_getNumChildren(child1) == 0);
1428 
1429   XMLAttributes_free(att);
1430   XMLNamespaces_free(ns);
1431   XMLTriple_free(body_triple);
1432   XMLTriple_free(p_triple);
1433   XMLToken_free(body_token);
1434   XMLToken_free(p_token);
1435   XMLToken_free(text_token);
1436   XMLToken_free(text_token1);
1437   XMLToken_free(p_token1);
1438   XMLNode_free(body_node);
1439   XMLNode_free(p_node);
1440   XMLNode_free(text_node);
1441   XMLNode_free(p_node1);
1442   XMLNode_free(text_node1);
1443 }
1444 END_TEST
1445 
1446 
START_TEST(test_SBase_appendNotesString)1447 START_TEST (test_SBase_appendNotesString)
1448 {
1449   // add p to p
1450   char * notes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>";
1451   char * taggednewnotes = "<notes>\n"
1452                        "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n"
1453                        "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n"
1454                        "</notes>";
1455   char * taggednewnotes2 = "<notes>\n"
1456                        "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n"
1457                        "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n"
1458                        "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n"
1459                        "</notes>";
1460   char * newnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
1461   char * newnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>"
1462                      "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>";
1463   char * newnotes3= "<notes>\n"
1464                     "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n"
1465                     "</notes>";
1466   char * newnotes4 = "<notes>\n"
1467                      "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n"
1468                      "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n"
1469                      "</notes>";
1470 
1471   SBase_setNotesString(S, notes);
1472 
1473   fail_unless(SBase_isSetNotes(S) == 1);
1474 
1475   //
1476   // add one p tag
1477   //
1478   SBase_appendNotesString(S, newnotes);
1479 
1480   char * notes1 = SBase_getNotesString(S);
1481 
1482   fail_unless(SBase_isSetNotes(S) == 1);
1483   fail_unless(!strcmp(taggednewnotes, notes1));
1484 
1485   //
1486   // add two p tags
1487   //
1488   SBase_setNotesString(S, notes);
1489   SBase_appendNotesString(S, newnotes2);
1490 
1491   char * notes2 = SBase_getNotesString(S);
1492 
1493   fail_unless(SBase_isSetNotes(S) == 1);
1494   fail_unless(!strcmp(taggednewnotes2, notes2));
1495 
1496   //
1497   // add one p tag with notes tag
1498   //
1499   SBase_setNotesString(S, notes);
1500   SBase_appendNotesString(S, newnotes3);
1501 
1502   char * notes3 = SBase_getNotesString(S);
1503 
1504   fail_unless(SBase_isSetNotes(S) == 1);
1505   fail_unless(!strcmp(taggednewnotes, notes3));
1506 
1507   //
1508   // add two p tags with notes tag
1509   //
1510   SBase_setNotesString(S, notes);
1511   SBase_appendNotesString(S, newnotes4);
1512 
1513   char * notes4 = SBase_getNotesString(S);
1514 
1515   fail_unless(SBase_isSetNotes(S) == 1);
1516   fail_unless(!strcmp(taggednewnotes2, notes4));
1517 
1518   safe_free(notes1);
1519   safe_free(notes2);
1520   safe_free(notes3);
1521   safe_free(notes4);
1522 }
1523 END_TEST
1524 
1525 
START_TEST(test_SBase_appendNotesString1)1526 START_TEST (test_SBase_appendNotesString1)
1527 { // add html to html
1528   char * notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1529                  "  <head>\n"
1530                  "    <title/>\n"
1531                  "  </head>\n"
1532                  "  <body>\n"
1533                  "    <p>This is a test note </p>\n"
1534                  "  </body>\n"
1535                  "</html>";
1536   char * taggednewnotes =
1537                  "<notes>\n"
1538                  "  <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1539                  "    <head>\n"
1540                  "      <title/>\n"
1541                  "    </head>\n"
1542                  "    <body>\n"
1543                  "      <p>This is a test note </p>\n"
1544                  "      <p>This is more test notes </p>\n"
1545                  "    </body>\n"
1546                  "  </html>\n"
1547                  "</notes>";
1548   char * addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1549                  "  <head>\n"
1550                  "    <title/>\n"
1551                  "  </head>\n"
1552                  "  <body>\n"
1553                  "    <p>This is more test notes </p>\n"
1554                  "  </body>\n"
1555                  "</html>";
1556   char * addnotes2 =
1557                  "<notes>\n"
1558                  "  <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1559                  "    <head>\n"
1560                  "      <title/>\n"
1561                  "    </head>\n"
1562                  "    <body>\n"
1563                  "      <p>This is more test notes </p>\n"
1564                  "    </body>\n"
1565                  "  </html>\n"
1566                  "</notes>";
1567 
1568   // add html tag
1569 
1570   SBase_setNotesString(S, notes);
1571   SBase_appendNotesString(S, addnotes);
1572 
1573   char *notes1 = SBase_getNotesString(S);
1574 
1575   fail_unless(SBase_isSetNotes(S) == 1);
1576   fail_unless(!strcmp(taggednewnotes, notes1));
1577 
1578   // add html tag with notes tag
1579 
1580   SBase_setNotesString(S, notes);
1581   SBase_appendNotesString(S, addnotes2);
1582 
1583   char *notes2 = SBase_getNotesString(S);
1584 
1585   fail_unless(SBase_isSetNotes(S) == 1);
1586   fail_unless(!strcmp(taggednewnotes, notes2));
1587 
1588   safe_free(notes1);
1589   safe_free(notes2);
1590 }
1591 END_TEST
1592 
1593 
START_TEST(test_SBase_appendNotesString2)1594 START_TEST (test_SBase_appendNotesString2)
1595 { // add body to html
1596   char * notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1597                  "  <head>\n"
1598                  "    <title/>\n"
1599                  "  </head>\n"
1600                  "  <body>\n"
1601                  "    <p>This is a test note </p>\n"
1602                  "  </body>\n"
1603                  "</html>";
1604   char * taggednewnotes =
1605                  "<notes>\n"
1606                  "  <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1607                  "    <head>\n"
1608                  "      <title/>\n"
1609                  "    </head>\n"
1610                  "    <body>\n"
1611                  "      <p>This is a test note </p>\n"
1612                  "      <p>This is more test notes </p>\n"
1613                  "    </body>\n"
1614                  "  </html>\n"
1615                  "</notes>";
1616   char * addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1617                     "  <p>This is more test notes </p>\n"
1618                     "</body>\n";
1619   char * addnotes2 =
1620                     "<notes>\n"
1621                     "  <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1622                     "    <p>This is more test notes </p>\n"
1623                     "  </body>\n"
1624                     "</notes>";
1625 
1626   // add body tag
1627 
1628   SBase_setNotesString(S, notes);
1629   SBase_appendNotesString(S, addnotes);
1630 
1631   char *notes1 = SBase_getNotesString(S);
1632 
1633   fail_unless(SBase_isSetNotes(S) == 1);
1634   fail_unless(!strcmp(taggednewnotes, notes1));
1635 
1636   // add body tag with notes tag
1637 
1638   SBase_setNotesString(S, notes);
1639   SBase_appendNotesString(S, addnotes2);
1640 
1641   char *notes2 = SBase_getNotesString(S);
1642 
1643   fail_unless(SBase_isSetNotes(S) == 1);
1644   fail_unless(!strcmp(taggednewnotes, notes2));
1645 
1646   safe_free(notes1);
1647   safe_free(notes2);
1648 }
1649 END_TEST
1650 
1651 
START_TEST(test_SBase_appendNotesString3)1652 START_TEST (test_SBase_appendNotesString3)
1653 { // add p to html
1654   char * notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1655                  "  <head>\n"
1656                  "    <title/>\n"
1657                  "  </head>\n"
1658                  "  <body>\n"
1659                  "    <p>This is a test note </p>\n"
1660                  "  </body>\n"
1661                  "</html>";
1662   char * taggednewnotes =
1663                  "<notes>\n"
1664                  "  <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1665                  "    <head>\n"
1666                  "      <title/>\n"
1667                  "    </head>\n"
1668                  "    <body>\n"
1669                  "      <p>This is a test note </p>\n"
1670                  "      <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n"
1671                  "    </body>\n"
1672                  "  </html>\n"
1673                  "</notes>";
1674   char * taggednewnotes2 =
1675                  "<notes>\n"
1676                  "  <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1677                  "    <head>\n"
1678                  "      <title/>\n"
1679                  "    </head>\n"
1680                  "    <body>\n"
1681                  "      <p>This is a test note </p>\n"
1682                  "      <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n"
1683                  "      <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n"
1684                  "    </body>\n"
1685                  "  </html>\n"
1686                  "</notes>";
1687   char * addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n";
1688   char * addnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n"
1689                      "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>";
1690   char * addnotes3 = "<notes>\n"
1691                      "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n"
1692                      "</notes>";
1693   char * addnotes4 = "<notes>\n"
1694                      "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n"
1695                      "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n"
1696                      "</notes>";
1697 
1698   // add one p tag
1699 
1700   SBase_setNotesString(S, notes);
1701   SBase_appendNotesString(S, addnotes);
1702 
1703   char *notes1 = SBase_getNotesString(S);
1704 
1705   fail_unless(SBase_isSetNotes(S) == 1);
1706   fail_unless(!strcmp(taggednewnotes, notes1));
1707 
1708   // add two p tags
1709 
1710   SBase_setNotesString(S, notes);
1711   SBase_appendNotesString(S, addnotes2);
1712 
1713   char *notes2 = SBase_getNotesString(S);
1714 
1715   fail_unless(SBase_isSetNotes(S) == 1);
1716   fail_unless(!strcmp(taggednewnotes2, notes2));
1717 
1718   // add one p tag with notes tag
1719 
1720   SBase_setNotesString(S, notes);
1721   SBase_appendNotesString(S, addnotes3);
1722 
1723   char *notes3 = SBase_getNotesString(S);
1724 
1725   fail_unless(SBase_isSetNotes(S) == 1);
1726   fail_unless(!strcmp(taggednewnotes, notes3));
1727 
1728   // add two p tags with notes tags
1729 
1730   SBase_setNotesString(S, notes);
1731   SBase_appendNotesString(S, addnotes4);
1732 
1733   char *notes4 = SBase_getNotesString(S);
1734 
1735   fail_unless(SBase_isSetNotes(S) == 1);
1736   fail_unless(!strcmp(taggednewnotes2, notes4));
1737 
1738   safe_free(notes1);
1739   safe_free(notes2);
1740   safe_free(notes3);
1741   safe_free(notes4);
1742 }
1743 END_TEST
1744 
1745 
START_TEST(test_SBase_appendNotesString4)1746 START_TEST (test_SBase_appendNotesString4)
1747 { // add html to body
1748   char * notes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1749                  "  <p>This is a test note </p>\n"
1750                  "</body>";
1751   char * taggednewnotes =
1752                  "<notes>\n"
1753                  "  <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1754                  "    <head>\n"
1755                  "      <title/>\n"
1756                  "    </head>\n"
1757                  "    <body>\n"
1758                  "      <p>This is a test note </p>\n"
1759                  "      <p>This is more test notes </p>\n"
1760                  "    </body>\n"
1761                  "  </html>\n"
1762                  "</notes>";
1763   char * addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1764                  "  <head>\n"
1765                  "    <title/>\n"
1766                  "  </head>\n"
1767                  "  <body>\n"
1768                  "    <p>This is more test notes </p>\n"
1769                  "  </body>\n"
1770                  "</html>";
1771   char * addnotes2 =
1772                  "<notes>\n"
1773                  "  <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1774                  "    <head>\n"
1775                  "      <title/>\n"
1776                  "    </head>\n"
1777                  "    <body>\n"
1778                  "      <p>This is more test notes </p>\n"
1779                  "    </body>\n"
1780                  "  </html>\n"
1781                  "</notes>";
1782 
1783   // add html tag
1784 
1785   SBase_setNotesString(S, notes);
1786   SBase_appendNotesString(S, addnotes);
1787 
1788   char *notes1 = SBase_getNotesString(S);
1789 
1790   fail_unless(SBase_isSetNotes(S) == 1);
1791   fail_unless(!strcmp(taggednewnotes, notes1));
1792 
1793   // add html tag with notes tag
1794 
1795   SBase_setNotesString(S, notes);
1796   SBase_appendNotesString(S, addnotes2);
1797 
1798   char *notes2 = SBase_getNotesString(S);
1799 
1800   fail_unless(SBase_isSetNotes(S) == 1);
1801   fail_unless(!strcmp(taggednewnotes, notes2));
1802 
1803   safe_free(notes1);
1804   safe_free(notes2);
1805 }
1806 END_TEST
1807 
1808 
START_TEST(test_SBase_appendNotesString5)1809 START_TEST (test_SBase_appendNotesString5)
1810 { // add html to p
1811   char * notes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>";
1812   char * taggednewnotes =
1813                  "<notes>\n"
1814                  "  <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1815                  "    <head>\n"
1816                  "      <title/>\n"
1817                  "    </head>\n"
1818                  "    <body>\n"
1819                  "      <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n"
1820                  "      <p>This is more test notes </p>\n"
1821                  "    </body>\n"
1822                  "  </html>\n"
1823                  "</notes>";
1824   char * addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1825                  "  <head>\n"
1826                  "    <title/>\n"
1827                  "  </head>\n"
1828                  "  <body>\n"
1829                  "    <p>This is more test notes </p>\n"
1830                  "  </body>\n"
1831                  "</html>";
1832   char * addnotes2 =
1833                  "<notes>\n"
1834                  "  <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1835                  "    <head>\n"
1836                  "      <title/>\n"
1837                  "    </head>\n"
1838                  "    <body>\n"
1839                  "      <p>This is more test notes </p>\n"
1840                  "    </body>\n"
1841                  "  </html>\n"
1842                  "</notes>";
1843 
1844   // add html tag
1845 
1846   SBase_setNotesString(S, notes);
1847   SBase_appendNotesString(S, addnotes);
1848 
1849   char *notes1 = SBase_getNotesString(S);
1850 
1851   fail_unless(SBase_isSetNotes(S) == 1);
1852   fail_unless(!strcmp(taggednewnotes, notes1));
1853 
1854   // add html tag with notes tag
1855 
1856   SBase_setNotesString(S, notes);
1857   SBase_appendNotesString(S, addnotes2);
1858 
1859   char *notes2 = SBase_getNotesString(S);
1860 
1861   fail_unless(SBase_isSetNotes(S) == 1);
1862   fail_unless(!strcmp(taggednewnotes, notes2));
1863 
1864   safe_free(notes1);
1865   safe_free(notes2);
1866 }
1867 END_TEST
1868 
1869 
START_TEST(test_SBase_appendNotesString6)1870 START_TEST (test_SBase_appendNotesString6)
1871 { // add body to body
1872   char * notes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1873                  "  <p>This is a test note </p>\n"
1874                  "</body>";
1875   char * taggednewnotes =
1876                  "<notes>\n"
1877                  "  <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1878                  "    <p>This is a test note </p>\n"
1879                  "    <p>This is more test notes </p>\n"
1880                  "  </body>\n"
1881                  "</notes>";
1882   char * addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1883                  "  <p>This is more test notes </p>\n"
1884                  "</body>";
1885   char * addnotes2 =
1886                  "<notes>\n"
1887                  "  <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1888                  "    <p>This is more test notes </p>\n"
1889                  "  </body>\n"
1890                  "</notes>";
1891 
1892   // add body tag
1893 
1894   SBase_setNotesString(S, notes);
1895   SBase_appendNotesString(S, addnotes);
1896 
1897   char *notes1 = SBase_getNotesString(S);
1898 
1899   fail_unless(SBase_isSetNotes(S) == 1);
1900   fail_unless(!strcmp(taggednewnotes, notes1));
1901 
1902   // add body tag with notes tag
1903 
1904   SBase_setNotesString(S, notes);
1905   SBase_appendNotesString(S, addnotes2);
1906 
1907   char *notes2 = SBase_getNotesString(S);
1908 
1909   fail_unless(SBase_isSetNotes(S) == 1);
1910   fail_unless(!strcmp(taggednewnotes, notes2));
1911 
1912   safe_free(notes1);
1913   safe_free(notes2);
1914 }
1915 END_TEST
1916 
1917 
START_TEST(test_SBase_appendNotesString7)1918 START_TEST (test_SBase_appendNotesString7)
1919 { // add body to p
1920   char * notes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>";
1921   char * taggednewnotes =
1922                  "<notes>\n"
1923                  "  <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1924                  "    <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n"
1925                  "    <p>This is more test notes </p>\n"
1926                  "  </body>\n"
1927                  "</notes>";
1928   char * addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1929                  "  <p>This is more test notes </p>\n"
1930                  "</body>";
1931   char * addnotes2 =
1932                  "<notes>\n"
1933                  "  <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1934                  "    <p>This is more test notes </p>\n"
1935                  "  </body>\n"
1936                  "</notes>";
1937 
1938   // add body tag
1939 
1940   SBase_setNotesString(S, notes);
1941   SBase_appendNotesString(S, addnotes);
1942 
1943   char *notes1 = SBase_getNotesString(S);
1944 
1945   fail_unless(SBase_isSetNotes(S) == 1);
1946   fail_unless(!strcmp(taggednewnotes, notes1));
1947 
1948   // add body tag with notes tag
1949 
1950   SBase_setNotesString(S, notes);
1951   SBase_appendNotesString(S, addnotes2);
1952 
1953   char *notes2 = SBase_getNotesString(S);
1954 
1955   fail_unless(SBase_isSetNotes(S) == 1);
1956   fail_unless(!strcmp(taggednewnotes, notes2));
1957 
1958   safe_free(notes1);
1959   safe_free(notes2);
1960 }
1961 END_TEST
1962 
1963 
START_TEST(test_SBase_appendNotesString8)1964 START_TEST (test_SBase_appendNotesString8)
1965 { // add p to body
1966   char * notes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1967                  "  <p>This is a test note </p>\n"
1968                  "</body>";
1969   char * taggednewnotes =
1970                  "<notes>\n"
1971                  "  <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1972                  "    <p>This is a test note </p>\n"
1973                  "    <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n"
1974                  "  </body>\n"
1975                  "</notes>";
1976   char * taggednewnotes2 =
1977                  "<notes>\n"
1978                  "  <body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
1979                  "    <p>This is a test note </p>\n"
1980                  "    <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n"
1981                  "    <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n"
1982                  "  </body>\n"
1983                  "</notes>";
1984   char * addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
1985   char * addnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n"
1986                      "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>";
1987   char * addnotes3 =
1988                  "<notes>\n"
1989                  "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n"
1990                  "</notes>";
1991   char * addnotes4 =
1992                  "<notes>\n"
1993                  "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n"
1994                  "  <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n"
1995                  "</notes>";
1996 
1997   // add one p tag
1998 
1999   SBase_setNotesString(S, notes);
2000   SBase_appendNotesString(S, addnotes);
2001 
2002   char *notes1 = SBase_getNotesString(S);
2003 
2004   fail_unless(SBase_isSetNotes(S) == 1);
2005   fail_unless(!strcmp(taggednewnotes, notes1));
2006 
2007   // add two p tags
2008 
2009   SBase_setNotesString(S, notes);
2010   SBase_appendNotesString(S, addnotes2);
2011 
2012   char *notes2 = SBase_getNotesString(S);
2013 
2014   fail_unless(SBase_isSetNotes(S) == 1);
2015   fail_unless(!strcmp(taggednewnotes2, notes2));
2016 
2017   // add one p tag with notes tag
2018 
2019   SBase_setNotesString(S, notes);
2020   SBase_appendNotesString(S, addnotes3);
2021 
2022   char *notes3 = SBase_getNotesString(S);
2023 
2024   fail_unless(SBase_isSetNotes(S) == 1);
2025   fail_unless(!strcmp(taggednewnotes, notes3));
2026 
2027   // add two p tags with notes tags
2028 
2029   SBase_setNotesString(S, notes);
2030   SBase_appendNotesString(S, addnotes4);
2031 
2032   char *notes4 = SBase_getNotesString(S);
2033 
2034   fail_unless(SBase_isSetNotes(S) == 1);
2035   fail_unless(!strcmp(taggednewnotes2, notes4));
2036 
2037   safe_free(notes1);
2038   safe_free(notes2);
2039   safe_free(notes3);
2040   safe_free(notes4);
2041 }
2042 END_TEST
2043 
2044 
START_TEST(test_SBase_CVTerms)2045 START_TEST(test_SBase_CVTerms)
2046 {
2047   CVTerm_t * cv = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2048   CVTerm_setBiologicalQualifierType(cv, BQB_IS);
2049   CVTerm_addResource(cv, "foo");
2050 
2051   fail_unless(SBase_getNumCVTerms(S) == 0);
2052   fail_unless(SBase_getCVTerms(S) == NULL);
2053 
2054   SBase_setMetaId(S, "_id");
2055   SBase_addCVTerm(S, cv);
2056   fail_unless(SBase_getNumCVTerms(S) == 1);
2057   fail_unless(SBase_getCVTerms(S) != NULL);
2058 
2059   fail_unless(SBase_getCVTerm(S, 0) != cv);
2060 
2061   CVTerm_free(cv);
2062 }
2063 END_TEST
2064 
2065 
START_TEST(test_SBase_addCVTerms)2066 START_TEST(test_SBase_addCVTerms)
2067 {
2068   CVTerm_t * cv = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2069   CVTerm_setBiologicalQualifierType(cv, BQB_ENCODES);
2070   CVTerm_addResource(cv, "foo");
2071   SBase_setMetaId(S, "sbase1");
2072 
2073   SBase_addCVTerm(S, cv);
2074 
2075   fail_unless(SBase_getNumCVTerms(S) == 1);
2076   fail_unless(SBase_getCVTerms(S) != NULL);
2077 
2078   XMLAttributes_t *res = CVTerm_getResources(SBase_getCVTerm(S, 0));
2079   fail_unless(!strcmp(res->getValue(0).c_str(), "foo"));
2080 
2081   CVTerm_t * cv1 = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2082   CVTerm_setBiologicalQualifierType(cv1, BQB_IS);
2083   CVTerm_addResource(cv1, "bar");
2084 
2085   SBase_addCVTerm(S, cv1);
2086 
2087   fail_unless(SBase_getNumCVTerms(S) == 2);
2088 
2089   /* same qualifier so should just add to resources of existing term */
2090   CVTerm_t * cv2 = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2091   CVTerm_setBiologicalQualifierType(cv2, BQB_IS);
2092   CVTerm_addResource(cv2, "bar1");
2093 
2094   SBase_addCVTerm(S, cv2);
2095 
2096   fail_unless(SBase_getNumCVTerms(S) == 2);
2097 
2098   res = CVTerm_getResources(SBase_getCVTerm(S, 1));
2099 
2100   fail_unless(XMLAttributes_getLength(res) == 2);
2101   fail_unless(!strcmp(res->getValue(0).c_str(), "bar"));
2102   fail_unless(!strcmp(res->getValue(1).c_str(), "bar1"));
2103 
2104 
2105   /* existing term shouldnt get added*/
2106   CVTerm_t * cv4 = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2107   CVTerm_setBiologicalQualifierType(cv4, BQB_IS);
2108   CVTerm_addResource(cv4, "bar1");
2109 
2110   SBase_addCVTerm(S, cv4);
2111 
2112   fail_unless(SBase_getNumCVTerms(S) == 2);
2113 
2114   res = CVTerm_getResources(SBase_getCVTerm(S, 1));
2115 
2116   fail_unless(XMLAttributes_getLength(res) == 2);
2117   fail_unless(!strcmp(res->getValue(0).c_str(), "bar"));
2118   fail_unless(!strcmp(res->getValue(1).c_str(), "bar1"));
2119 
2120   /* existing term with different qualifier shouldnt get added*/
2121   CVTerm_t * cv5 = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2122   CVTerm_setBiologicalQualifierType(cv5, BQB_HAS_PART);
2123   CVTerm_addResource(cv5, "bar1");
2124 
2125   SBase_addCVTerm(S, cv5);
2126 
2127   fail_unless(SBase_getNumCVTerms(S) == 2);
2128 
2129   res = CVTerm_getResources(SBase_getCVTerm(S, 1));
2130 
2131   fail_unless(XMLAttributes_getLength(res) == 2);
2132   fail_unless(!strcmp(res->getValue(0).c_str(), "bar"));
2133   fail_unless(!strcmp(res->getValue(1).c_str(), "bar1"));
2134 
2135   CVTerm_free(cv);
2136   CVTerm_free(cv2);
2137   CVTerm_free(cv1);
2138   CVTerm_free(cv4);
2139   CVTerm_free(cv5);
2140 }
2141 END_TEST
2142 
2143 
START_TEST(test_SBase_unsetCVTerms)2144 START_TEST(test_SBase_unsetCVTerms)
2145 {
2146   CVTerm_t * cv = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2147   CVTerm_setBiologicalQualifierType(cv, BQB_ENCODES);
2148   CVTerm_addResource(cv, "foo");
2149 
2150   SBase_setMetaId(S, "sbase1");
2151   SBase_addCVTerm(S, cv);
2152   CVTerm_t * cv1 = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2153   CVTerm_setBiologicalQualifierType(cv1, BQB_IS);
2154   CVTerm_addResource(cv1, "bar");
2155 
2156   SBase_addCVTerm(S, cv1);
2157   CVTerm_t * cv2 = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2158   CVTerm_setBiologicalQualifierType(cv2, BQB_IS);
2159   CVTerm_addResource(cv2, "bar1");
2160 
2161   SBase_addCVTerm(S, cv2);
2162   CVTerm_t * cv4 = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2163   CVTerm_setBiologicalQualifierType(cv4, BQB_IS);
2164   CVTerm_addResource(cv4, "bar1");
2165 
2166   SBase_addCVTerm(S, cv4);
2167 
2168   fail_unless(SBase_getNumCVTerms(S) == 2);
2169 
2170   SBase_unsetCVTerms(S);
2171 
2172   fail_unless(SBase_getNumCVTerms(S) == 0);
2173   fail_unless(SBase_getCVTerms(S) == NULL);
2174 
2175   CVTerm_free(cv);
2176   CVTerm_free(cv2);
2177   CVTerm_free(cv1);
2178   CVTerm_free(cv4);
2179 }
2180 END_TEST
2181 
2182 
START_TEST(test_SBase_getQualifiersFromResources)2183 START_TEST(test_SBase_getQualifiersFromResources)
2184 {
2185   CVTerm_t * cv = CVTerm_createWithQualifierType(BIOLOGICAL_QUALIFIER);
2186   CVTerm_setBiologicalQualifierType(cv, BQB_ENCODES);
2187   CVTerm_addResource(cv, "foo");
2188 
2189   SBase_setMetaId(S, "sbase1");
2190   SBase_addCVTerm(S, cv);
2191 
2192   fail_unless(SBase_getResourceBiologicalQualifier(S, "foo") == BQB_ENCODES);
2193 
2194   CVTerm_t * cv1 = CVTerm_createWithQualifierType(MODEL_QUALIFIER);
2195   CVTerm_setModelQualifierType(cv1, BQM_IS);
2196   CVTerm_addResource(cv1, "bar");
2197 
2198   SBase_addCVTerm(S, cv1);
2199 
2200   fail_unless(SBase_getResourceModelQualifier(S, "bar") == BQM_IS);
2201 
2202   CVTerm_free(cv);
2203   CVTerm_free(cv1);
2204 
2205 
2206 }
2207 END_TEST
2208 
setOrAppendNotes(SBase * base,std::string note)2209 void setOrAppendNotes(SBase* base, std::string note)
2210 {
2211 	if ( base->isSetNotes() )
2212 	{
2213 			base->appendNotes(note);
2214 	}
2215 	else
2216 	{
2217 		base->setNotes(note);
2218 	}
2219 }
2220 
START_TEST(test_SBase_appendNotesWithGlobalNamespace)2221 START_TEST(test_SBase_appendNotesWithGlobalNamespace)
2222 {
2223 
2224   char * notes =
2225 		"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
2226 		"<sbml xmlns=\"http://www.sbml.org/sbml/level2/version4\" xmlns:html=\"http://www.w3.org/1999/xhtml\" level=\"2\" version=\"4\">\n"
2227 		"  <model id=\"test\" name=\"name\">\n"
2228 		"    <notes>\n"
2229 		"      <html:p>DATE: 2010/12/08 13:00:00</html:p>\n"
2230 		"      <html:p>VERSION: 0.99</html:p>\n"
2231 		"      <html:p>TAXONOMY: 9606</html:p>\n"
2232 		"    </notes>\n"
2233 		"  </model>\n"
2234 		"</sbml>\n";
2235 
2236 	SBMLDocument sbmlDoc (2, 4);
2237     sbmlDoc.getNamespaces()->add("http://www.w3.org/1999/xhtml", "html");
2238     Model *sbmlModel  = sbmlDoc.createModel();
2239     sbmlModel->setId("test");
2240     sbmlModel->setName("name");
2241     setOrAppendNotes(sbmlModel, "<html:p>DATE: 2010/12/08 13:00:00</html:p>");
2242     setOrAppendNotes(sbmlModel, "<html:p>VERSION: 0.99</html:p>");
2243     setOrAppendNotes(sbmlModel, "<html:p>TAXONOMY: 9606</html:p>");
2244 
2245 	SBMLWriter ttt;
2246 	char* documentString = ttt.writeToString(&sbmlDoc);
2247 	fail_unless(!strcmp(documentString, notes));
2248     safe_free(documentString);
2249 }
2250 END_TEST
2251 
START_TEST(test_SBase_hasValidLevelVersionNamespaceCombination)2252 START_TEST(test_SBase_hasValidLevelVersionNamespaceCombination)
2253 {
2254 
2255 	Species *species = new Species(3, 1);
2256 	// should be valid from start
2257 	fail_unless(species->hasValidLevelVersionNamespaceCombination() == true);
2258 	delete species;
2259 
2260 	XMLNamespaces invalidNamespaces;
2261 	species = new Species(3, 1);
2262 	species->setNamespaces( &invalidNamespaces );
2263 
2264 	// libsbml actually allows an undeclared SBML namespace
2265 	//// sbml namespace missing
2266     //fail_unless(species->hasValidLevelVersionNamespaceCombination() == false);
2267 
2268 
2269 	// hasValidLevelVersionNamespaceCombination actually would allow for the two
2270 	// namespaces defined if they had an empty prefix!
2271 
2272 	// wrong level / version combination
2273 	invalidNamespaces.add(SBMLNamespaces::getSBMLNamespaceURI(2, 3), "sbml23");
2274     species->setNamespaces( &invalidNamespaces);
2275 	fail_unless(species->hasValidLevelVersionNamespaceCombination() == false);
2276 
2277 	// multiple SBML namespaces
2278 	invalidNamespaces.add(SBMLNamespaces::getSBMLNamespaceURI(3, 1), "sbml31");
2279 	species->setNamespaces( &invalidNamespaces );
2280 	fail_unless(species->hasValidLevelVersionNamespaceCombination() == false);
2281 
2282 	// now all should be well
2283 	invalidNamespaces.clear();
2284 	invalidNamespaces.add(SBMLNamespaces::getSBMLNamespaceURI(3, 1), "sbml31");
2285 	species->setNamespaces( &invalidNamespaces );
2286 	fail_unless(species->hasValidLevelVersionNamespaceCombination() == true);
2287 	delete species;
2288 }
2289 END_TEST
2290 
START_TEST(test_SBase_addCVTerms_num_check)2291 START_TEST(test_SBase_addCVTerms_num_check)
2292 {
2293   // test model  qualifiers
2294 	for (int i = (int)BQM_IS; i<(int)BQM_UNKNOWN; i++)
2295 	{
2296     CVTerm *term1 = new CVTerm();
2297     term1->setQualifierType(MODEL_QUALIFIER);
2298     term1->setModelQualifierType((ModelQualifierType_t)i);
2299     term1->addResource("http://myresource1");
2300 
2301     CVTerm *term2 = new CVTerm();
2302     term2->setQualifierType(MODEL_QUALIFIER);
2303     term2->setModelQualifierType((ModelQualifierType_t)i);
2304     term2->addResource("http://myresource2");
2305 
2306     Species *species = new Species(3, 1);
2307     species->setMetaId("meta1");
2308 
2309     fail_unless (species->addCVTerm(term1, false) == LIBSBML_OPERATION_SUCCESS);
2310     fail_unless (species->getNumCVTerms() == 1);
2311 
2312     // add term 2 (should be merged with term 1)
2313     fail_unless (species->addCVTerm(term2, false) == LIBSBML_OPERATION_SUCCESS);
2314     fail_unless (species->getNumCVTerms() == 1);
2315 
2316     species->getCVTerm(0)->removeResource(term2->getResourceURI(0));
2317 
2318     // add term 2 (added as separate bag)
2319     fail_unless (species->addCVTerm(term2, true) == LIBSBML_OPERATION_SUCCESS);
2320     fail_unless (species->getNumCVTerms() == 2);
2321 
2322     delete term1;
2323     delete term2;
2324     delete species;
2325 
2326 	}
2327 
2328   // test biol qualifiers
2329 
2330   for (int i = (int)BQB_IS; i<(int)BQB_UNKNOWN; i++)
2331 	{
2332     CVTerm *term1 = new CVTerm();
2333     term1->setQualifierType(BIOLOGICAL_QUALIFIER);
2334     term1->setBiologicalQualifierType((BiolQualifierType_t)i);
2335     term1->addResource("http://myresource1");
2336 
2337     CVTerm *term2 = new CVTerm();
2338     term2->setQualifierType(BIOLOGICAL_QUALIFIER);
2339     term2->setBiologicalQualifierType((BiolQualifierType_t)i);
2340     term2->addResource("http://myresource2");
2341 
2342     Species *species = new Species(3, 1);
2343     species->setMetaId("meta1");
2344 
2345     fail_unless (species->addCVTerm(term1, false) == LIBSBML_OPERATION_SUCCESS);
2346     fail_unless (species->getNumCVTerms() == 1);
2347 
2348     // add term 2 (should be merged with term 1)
2349     fail_unless (species->addCVTerm(term2, false) == LIBSBML_OPERATION_SUCCESS);
2350     fail_unless (species->getNumCVTerms() == 1);
2351 
2352     species->getCVTerm(0)->removeResource(term2->getResourceURI(0));
2353 
2354     // add term 2 (added as separate bag)
2355     fail_unless (species->addCVTerm(term2, true) == LIBSBML_OPERATION_SUCCESS);
2356     fail_unless (species->getNumCVTerms() == 2);
2357 
2358     delete term1;
2359     delete term2;
2360     delete species;
2361 
2362 	}
2363 
2364 
2365 }
2366 END_TEST
2367 
START_TEST(test_SBase_matchesSBMLNamespaces)2368 START_TEST(test_SBase_matchesSBMLNamespaces)
2369 {
2370   SBMLNamespaces sbmlns1(3,1);
2371   SBMLNamespaces sbmlns2(2,4);
2372 
2373   Species s(&sbmlns1);
2374   Parameter p(&sbmlns1);
2375 
2376   fail_unless(s.matchesSBMLNamespaces(&(p)) == true);
2377   fail_unless(p.matchesSBMLNamespaces(&(s)) == true);
2378 
2379   p = &sbmlns2;
2380 
2381   fail_unless(s.matchesSBMLNamespaces(&(p)) == false);
2382   fail_unless(p.matchesSBMLNamespaces(&(s)) == false);
2383 
2384   sbmlns1.addNamespace("http:foo", "bar");
2385 
2386   Compartment c(&sbmlns1);
2387 
2388   fail_unless(s.matchesSBMLNamespaces(&(c)) == false);
2389   fail_unless(c.matchesSBMLNamespaces(&(s)) == false);
2390   fail_unless(p.matchesSBMLNamespaces(&(c)) == false);
2391   fail_unless(c.matchesSBMLNamespaces(&(p)) == false);
2392 
2393   s = &sbmlns1;
2394 
2395   fail_unless(s.matchesSBMLNamespaces(&(c)) == true);
2396   fail_unless(c.matchesSBMLNamespaces(&(s)) == true);
2397 
2398   SBMLNamespaces sbmlns3(3,1);
2399   c = &sbmlns3;
2400 
2401   fail_unless(s.matchesSBMLNamespaces(&(c)) == false);
2402   fail_unless(c.matchesSBMLNamespaces(&(s)) == false);
2403 
2404   sbmlns3.addNamespace("http:foo1", "bar1");
2405   c = &sbmlns3;
2406 
2407   fail_unless(s.matchesSBMLNamespaces(&(c)) == false);
2408   fail_unless(c.matchesSBMLNamespaces(&(s)) == false);
2409 
2410   sbmlns3.addNamespace("http:foo", "bar");
2411   sbmlns1.addNamespace("http:foo1", "bar1");
2412   s = &sbmlns1;
2413   c = &sbmlns3;
2414 
2415   fail_unless(s.matchesSBMLNamespaces(&(c)) == true);
2416   fail_unless(c.matchesSBMLNamespaces(&(s)) == true);
2417 }
2418 END_TEST
2419 
START_TEST(test_SBase_matchesRequiredSBMLNamespacesForAddition)2420 START_TEST(test_SBase_matchesRequiredSBMLNamespacesForAddition)
2421 {
2422   SBMLNamespaces sbmlns1(3,1);
2423   SBMLNamespaces sbmlns2(2,4);
2424 
2425   Species s(&sbmlns1);
2426   Parameter p(&sbmlns1);
2427 
2428   fail_unless(s.matchesRequiredSBMLNamespacesForAddition(&(p)) == true);
2429   fail_unless(p.matchesRequiredSBMLNamespacesForAddition(&(s)) == true);
2430 
2431   p = &sbmlns2;
2432 
2433   fail_unless(s.matchesRequiredSBMLNamespacesForAddition(&(p)) == false);
2434   fail_unless(p.matchesRequiredSBMLNamespacesForAddition(&(s)) == false);
2435 
2436   sbmlns1.addNamespace("http:foo", "bar");
2437 
2438   Compartment c(&sbmlns1);
2439 
2440   fail_unless(s.matchesRequiredSBMLNamespacesForAddition(&(c)) == true);
2441   fail_unless(c.matchesRequiredSBMLNamespacesForAddition(&(s)) == true);
2442   fail_unless(p.matchesRequiredSBMLNamespacesForAddition(&(c)) == false);
2443   fail_unless(c.matchesRequiredSBMLNamespacesForAddition(&(p)) == false);
2444 
2445   sbmlns1.addNamespace("http://www.sbml.org/sbml/level3/version1/qual/version1", "bar1");
2446   s = &sbmlns1;
2447 
2448   fail_unless(s.matchesRequiredSBMLNamespacesForAddition(&(c)) == true);
2449   fail_unless(c.matchesRequiredSBMLNamespacesForAddition(&(s)) == false);
2450 
2451   SBMLNamespaces sbmlns3(3,1);
2452   sbmlns3.addNamespace("http://www.sbml.org/sbml/level3/version1/qual/version1", "bar1");
2453   c = &sbmlns3;
2454 
2455   fail_unless(s.matchesRequiredSBMLNamespacesForAddition(&(c)) == true);
2456   fail_unless(c.matchesRequiredSBMLNamespacesForAddition(&(s)) == true);
2457 
2458   SBMLNamespaces sbmlns4(3,1);
2459   p = &sbmlns4;
2460 
2461   fail_unless(p.matchesRequiredSBMLNamespacesForAddition(&(c)) == false);
2462   fail_unless(c.matchesRequiredSBMLNamespacesForAddition(&(p)) == true);
2463 
2464   sbmlns4.addNamespace("http://www.sbml.org/sbml/level3/version1/qual/version2", "bar2");
2465   p = &sbmlns4;
2466 
2467   fail_unless(p.matchesRequiredSBMLNamespacesForAddition(&(c)) == false);
2468   fail_unless(c.matchesRequiredSBMLNamespacesForAddition(&(p)) == false);
2469 
2470   SBMLNamespaces sbmlns5(3,1);
2471   sbmlns5.addNamespace("http://www.sbml.org/sbml/level3/version1/qual/version1", "bar1");
2472   sbmlns5.removeNamespace(SBMLNamespaces::getSBMLNamespaceURI(3,1));
2473   p = &sbmlns5;
2474 
2475   fail_unless(p.matchesRequiredSBMLNamespacesForAddition(&(c)) == false);
2476   fail_unless(c.matchesRequiredSBMLNamespacesForAddition(&(p)) == false);
2477 
2478   SBMLNamespaces sbmlns6(3,1);
2479   sbmlns6.addNamespace("http://www.sbml.org/sbml/level3/version1/qual/version1", "bar1");
2480   sbmlns6.addNamespace("http://www.sbml.org/sbml/level3/version1/comp/version1", "comp");
2481   p = &sbmlns6;
2482 
2483   fail_unless(p.matchesRequiredSBMLNamespacesForAddition(&(c)) == true);
2484   fail_unless(c.matchesRequiredSBMLNamespacesForAddition(&(p)) == false);
2485 }
2486 END_TEST
2487 
START_TEST(test_SBase_prefixMetaIdSBO)2488 START_TEST(test_SBase_prefixMetaIdSBO)
2489 {
2490   Species species(3,1);
2491   species.setMetaId("meta1");
2492   species.setSBOTerm(245);
2493 
2494   char* noPrefixch = species.toSBML();
2495   std::string noPrefix(noPrefixch);
2496   safe_free(noPrefixch);
2497   fail_unless (noPrefix.find(" metaid=") != std::string::npos);
2498   fail_unless (noPrefix.find(" sboTerm=") != std::string::npos);
2499 
2500   species.getNamespaces()->remove("");
2501   species.getNamespaces()->add(SBMLNamespaces::getSBMLNamespaceURI(3, 1), "l3v1");
2502 
2503   char* prefixch = species.toSBML();
2504   std::string prefix(prefixch);
2505   safe_free(prefixch);
2506   fail_unless (prefix.find(" l3v1:metaid=") != std::string::npos);
2507   fail_unless (prefix.find(" l3v1:sboTerm=") != std::string::npos);
2508 
2509   fail_unless (noPrefix != prefix);
2510 }
2511 END_TEST
2512 
START_TEST(test_SBase_userData)2513 START_TEST(test_SBase_userData)
2514 {
2515   Species s1(3, 1);
2516   int myValue = 10;
2517   fail_unless(s1.getUserData() == NULL);
2518   fail_unless(s1.isSetUserData() == false);
2519   fail_unless(s1.setUserData(&myValue) == LIBSBML_OPERATION_SUCCESS);
2520   fail_unless((*(int*)s1.getUserData()) == 10);
2521   fail_unless(s1.isSetUserData() == true);
2522 
2523   // make sure that cloning also clones the pointer to the data
2524   Species *s2 = s1.clone();
2525   fail_unless((*(int*)s2->getUserData()) == 10);
2526   fail_unless(s1.isSetUserData() == true);
2527   delete s2;
2528 
2529   fail_unless(s1.setUserData(NULL) == LIBSBML_OPERATION_SUCCESS);
2530   fail_unless(s1.getUserData() == NULL);
2531   fail_unless(s1.isSetUserData() == false);
2532 
2533   // test that when accessed with NULL arguments nothing bad happens
2534 
2535   fail_unless(SBase_getUserData(NULL) == NULL);
2536   fail_unless(SBase_setUserData(NULL, NULL) == LIBSBML_INVALID_OBJECT);
2537 
2538 
2539 }
2540 END_TEST
2541 
START_TEST(test_SBase_userData1)2542 START_TEST(test_SBase_userData1)
2543 {
2544   Species s1(3, 1);
2545   int myValue = 10;
2546   fail_unless(s1.getUserData() == NULL);
2547   fail_unless(s1.isSetUserData() == false);
2548   fail_unless(s1.setUserData(&myValue) == LIBSBML_OPERATION_SUCCESS);
2549   fail_unless((*(int*)s1.getUserData()) == 10);
2550   fail_unless(s1.isSetUserData() == true);
2551 
2552   // test the unset function
2553   fail_unless(s1.unsetUserData() == LIBSBML_OPERATION_SUCCESS);
2554   fail_unless(s1.getUserData() == NULL);
2555   fail_unless(s1.isSetUserData() == false);
2556 }
2557 END_TEST
2558 
2559 Suite *
create_suite_SBase(void)2560 create_suite_SBase (void)
2561 {
2562   Suite *suite = suite_create("SBase");
2563   TCase *tcase = tcase_create("SBase");
2564 
2565 
2566   tcase_add_checked_fixture(tcase, SBaseTest_setup, SBaseTest_teardown);
2567 
2568   tcase_add_test(tcase, test_SBase_setMetaId     );
2569  // tcase_add_test(tcase, test_SBase_setNotes      );
2570   tcase_add_test(tcase, test_SBase_setAnnotation );
2571   tcase_add_test(tcase, test_SBase_setNotes);
2572   tcase_add_test(tcase, test_SBase_setNotesString);
2573   tcase_add_test(tcase, test_SBase_setNotesString_l3);
2574   tcase_add_test(tcase, test_SBase_setNotesString_l3_addMarkup);
2575   tcase_add_test(tcase, test_SBase_setAnnotationString);
2576   tcase_add_test(tcase, test_SBase_unsetAnnotationWithCVTerms );
2577   tcase_add_test(tcase, test_SBase_unsetAnnotationWithModelHistory );
2578 
2579   tcase_add_test(tcase, test_SBase_appendNotes );
2580   tcase_add_test(tcase, test_SBase_appendNotes1 );
2581   tcase_add_test(tcase, test_SBase_appendNotes2 );
2582   tcase_add_test(tcase, test_SBase_appendNotes3 );
2583   tcase_add_test(tcase, test_SBase_appendNotes4 );
2584   tcase_add_test(tcase, test_SBase_appendNotes5 );
2585   tcase_add_test(tcase, test_SBase_appendNotes6 );
2586   tcase_add_test(tcase, test_SBase_appendNotes7 );
2587   tcase_add_test(tcase, test_SBase_appendNotes8 );
2588   tcase_add_test(tcase, test_SBase_appendNotesString );
2589   tcase_add_test(tcase, test_SBase_appendNotesString1);
2590   tcase_add_test(tcase, test_SBase_appendNotesString2);
2591   tcase_add_test(tcase, test_SBase_appendNotesString3);
2592   tcase_add_test(tcase, test_SBase_appendNotesString4);
2593   tcase_add_test(tcase, test_SBase_appendNotesString5);
2594   tcase_add_test(tcase, test_SBase_appendNotesString6);
2595   tcase_add_test(tcase, test_SBase_appendNotesString7);
2596   tcase_add_test(tcase, test_SBase_appendNotesString8);
2597   tcase_add_test(tcase, test_SBase_appendNotesWithGlobalNamespace );
2598 
2599   tcase_add_test(tcase, test_SBase_CVTerms );
2600   tcase_add_test(tcase, test_SBase_addCVTerms );
2601   tcase_add_test(tcase, test_SBase_addCVTerms_num_check );
2602   tcase_add_test(tcase, test_SBase_unsetCVTerms );
2603   tcase_add_test(tcase, test_SBase_getQualifiersFromResources );
2604   tcase_add_test(tcase, test_SBase_hasValidLevelVersionNamespaceCombination);
2605   tcase_add_test(tcase, test_SBase_matchesSBMLNamespaces);
2606   tcase_add_test(tcase, test_SBase_matchesRequiredSBMLNamespacesForAddition);
2607   tcase_add_test(tcase, test_SBase_userData);
2608   tcase_add_test(tcase, test_SBase_userData1);
2609 
2610   tcase_add_test(tcase, test_SBase_prefixMetaIdSBO);
2611 
2612   suite_add_tcase(suite, tcase);
2613 
2614   return suite;
2615 }
2616 
2617 
2618 END_C_DECLS
2619