Forums

F.A.Q. F.A.Q.    Register Register    Login Login    Home Home
Search Search
SBML Discussions » libsbml-development » Fixed appendNotes(), setAnnotation(), and setNotes() in the trunk
Show: Today's Posts  :: Message Navigator
| Subscribe to topic 
Return to the default flat view Create a new topic Submit Reply
AuthorTopic
ajouraku


Posts: 57
Registered:
May 2008
Fixed appendNotes(), setAnnotation(), and setNotes() in the trunk 23 Feb '09 11:01


Hi guys,

I committed the fix for SBase::appendNotes(), SBase::setAnnotation(), and
SBase::setNotes() functions in the trunk today.
I also updated test files (TestSBase.cpp and corresponding converted test
files for language bindings).

Could you try the fix and let me know if you have any problems?

I'll commit the same fix for libsbml-4 branch ASAP.

Thanks,

Akiya

ajouraku@users.sourceforge.net wrote
> Revision: 9112
> http://sbml.svn.sourceforge.net/sbml/?rev=9112&view=rev
> Author: ajouraku
> Date: 2009-02-23 13:24:48 +0000 (Mon, 23 Feb 2009)
>
> Log Message:
> -----------
> 1. Fixed SBase::setNotes(const XMLNode*) and SBase::setAnnotation(const XMLNode*)
> functions to remove a dummy root XMLNode (*) in the given XMLNode tree.
>
> --------------------------------------------------------------------------------
> (*) An empty XMLNode which is neither start, end, nor text. This node is created
> as a dummy root XMLNode in "XMLNode* XMLNode::convertStringtoXMLNode(const string&)
> function if the given XMLNode string contains two or more top level elements
> such as "<p>...</p></br>".
> --------------------------------------------------------------------------------
>
> Although the dummy XMLNode never affects the validity of the SBase object
> (outputted notes/annotation string is never affected by the dummy XMLNode),
> the dummy node may be intuitively unexpected when manipulating the XMLNode tree.
>
> 2. Fixed the following problems in SBase::appendNotes(const XMLNode*) function.
>
> 1) memory leaks
>
> 2) existing mNotes (a data member of XMLNode* for <notes> in the SBase class)
> can be deleted by appendNotes(..), which may cause an unexpected junk pointer.
>
> In SBase::appendNotes(..), mNotes was updated by internally invoking setNotes(..).
> Since mNotes is deleted and then regenerated by new operator in setNotes(..)
> function, previously stored note's XMLNode (e.g. by getNotes() ) could be a
> junk pointer when appendNotes(..) invoked after setNotes(..) or appendNotes(..),
> and this seems to be an unexpected behavior.
>
> The following example code shows the problem:
>
> --------------------------------------------------------------------------------
> string nstr1 = '<notes><p xmlns="http://www.w3.org/1999/xhtml">FOO</p></notes>';
> string nstr2 = '<notes><p xmlns="http://www.w3.org/1999/xhtml">BAR</p></notes>';
>
> Model m;
> m.setNotes(nstr1);
> XMLNode* notesNode = m.getNotes();
> ...
> m.appendNotes(nstr2); // <-------- notesNode may be a junk pointer after this.
>
> cout << notesNode->getNotesString() << endl; // <----- segv may happen
> --------------------------------------------------------------------------------
>
>
> 3) The given notes node could be wrongly appended to the existing mNotes if
>
> (1) the given notes enclosed with <notes>...</notes> tags,
>
> or
>
> (2) the given notes node consists of two or more top level elements which
> are permitted in the body element such as "<p>A</p><br/>".
>
>
> 3. Updated test files for setNotes(), setAnnotation() and appendNotes() functions.
>
> Modified Paths:
> --------------
> trunk/libsbml/src/bindings/csharp/test/sbml/TestSBase.cs
> trunk/libsbml/src/bindings/java/test/org/sbml/libsbml/test/sbml/TestSBase.java
> trunk/libsbml/src/bindings/python/test/sbml/TestSBase.py
> trunk/libsbml/src/bindings/ruby/test/sbml/TestSBase.rb
> trunk/libsbml/src/sbml/SBase.cpp
> trunk/libsbml/src/sbml/test/TestSBase.cpp
>
> Modified: trunk/libsbml/src/bindings/csharp/test/sbml/TestSBase.cs
> ===================================================================
> --- trunk/libsbml/src/bindings/csharp/test/sbml/TestSBase.cs 2009-02-21 19:00:24 UTC (rev 9111)
> +++ trunk/libsbml/src/bindings/csharp/test/sbml/TestSBase.cs 2009-02-23 13:24:48 UTC (rev 9112)
> @@ -5,8 +5,8 @@
> /// @author Akiya Jouraku (Csharp conversion)
> /// @author Ben Bornstein
> ///
> -/// $Id:$
> -/// $HeadURL:$
> +/// $Id$
> +/// $HeadURL$
> ///
> /// This test file was converted from src/sbml/test/TestSBase.cpp
> /// with the help of conversion sciprt (ctest_converter.pl).
> @@ -791,53 +791,104 @@
> string taggednewnotes = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> "</notes>";
> - string newnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";;
> + string taggednewnotes2 = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>";
> + string newnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + string newnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>" +
> + "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>";
> + string newnotes3 = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" + "</notes>";;
> + string newnotes4 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>";
> S.setNotes(notes);
> assertTrue( S.isSetNotes() == true );
> S.appendNotes(newnotes);
> string notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(( notes1 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(newnotes2);
> + string notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes2 == taggednewnotes2 ));
> + S.setNotes(notes);
> + S.appendNotes(newnotes3);
> + string notes3 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes3 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(newnotes4);
> + string notes4 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes4 == taggednewnotes2 ));
> }
>
> public void test_SBase_appendNotesString1()
> {
> - string notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + string notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>";
> string taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>";
> - string addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + string addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>";
> + string addnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> string notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(( notes1 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + string notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes2 == taggednewnotes ));
> }
>
> public void test_SBase_appendNotesString2()
> {
> - string notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + string notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>";
> string taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> @@ -845,35 +896,85 @@
> " </html>\n" +
> "</notes>";
> string addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>\n";;
> + string addnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> string notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(( notes1 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + string notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes2 == taggednewnotes ));
> }
>
> public void test_SBase_appendNotesString3()
> {
> - string notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + string notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>";
> string taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>";
> - string addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";;
> + string taggednewnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>";
> + string addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n";
> + string addnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>";
> + string addnotes3 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> + "</notes>";
> + string addnotes4 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> string notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(( notes1 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + string notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes2 == taggednewnotes2 ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes3);
> + string notes3 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes3 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes4);
> + string notes4 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes4 == taggednewnotes2 ));
> }
>
> public void test_SBase_appendNotesString4()
> @@ -881,23 +982,42 @@
> string notes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is a test note </p>\n" + "</body>";;
> string taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>";
> - string addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + string addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>";
> + string addnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> string notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(( notes1 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + string notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes2 == taggednewnotes ));
> }
>
> public void test_SBase_appendNotesString5()
> @@ -905,23 +1025,42 @@
> string notes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>";;
> string taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>";
> - string addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + string addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>";
> + string addnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> string notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(( notes1 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + string notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes2 == taggednewnotes ));
> }
>
> public void test_SBase_appendNotesString6()
> @@ -934,11 +1073,21 @@
> " </body>\n" +
> "</notes>";
> string addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>";;
> + string addnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> string notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(( notes1 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + string notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes2 == taggednewnotes ));
> }
>
> public void test_SBase_appendNotesString7()
> @@ -951,11 +1100,21 @@
> " </body>\n" +
> "</notes>";
> string addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>";;
> + string addnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> string notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(( notes1 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + string notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes2 == taggednewnotes ));
> }
>
> public void test_SBase_appendNotesString8()
> @@ -967,12 +1126,43 @@
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> " </body>\n" +
> "</notes>";
> - string addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";;
> + string taggednewnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + " </body>\n" +
> + "</notes>";
> + string addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + string addnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>";
> + string addnotes3 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> + "</notes>";
> + string addnotes4 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> string notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(( notes1 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + string notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes2 == taggednewnotes2 ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes3);
> + string notes3 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes3 == taggednewnotes ));
> + S.setNotes(notes);
> + S.appendNotes(addnotes4);
> + string notes4 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(( notes4 == taggednewnotes2 ));
> }
>
> public void test_SBase_getQualifiersFromResources()
> @@ -1030,8 +1220,7 @@
> }
> XMLNode t1 = S.getAnnotation();
> assertTrue( t1.getNumChildren() == 1 );
> - XMLNode t2 = t1.getChild(0);
> - assertTrue(( "This is a test note" == t2.getChild(0).getCharacters() ));
> + assertTrue(( "This is a test note" == t1.getChild(0).getCharacters() ));
> S.setAnnotation(S.getAnnotationString());
> t1 = S.getAnnotation();
> assertTrue( t1.getNumChildren() == 1 );
> @@ -1049,7 +1238,7 @@
> }
> t1 = S.getAnnotation();
> assertTrue( t1.getNumChildren() == 1 );
> - t2 = t1.getChild(0);
> + XMLNode t2 = t1.getChild(0);
> assertTrue(( "This is a test note" == t2.getCharacters() ));
> }
>
> @@ -1111,8 +1300,7 @@
> }
> XMLNode t1 = S.getNotes();
> assertTrue( t1.getNumChildren() == 1 );
> - XMLNode t2 = t1.getChild(0);
> - assertTrue(( "This is a test note" == t2.getChild(0).getCharacters() ));
> + assertTrue(( "This is a test note" == t1.getChild(0).getCharacters() ));
> S.setNotes(S.getNotesString());
> t1 = S.getNotes();
> assertTrue( t1.getNumChildren() == 1 );
> @@ -1130,7 +1318,7 @@
> }
> t1 = S.getNotes();
> assertTrue( t1.getNumChildren() == 1 );
> - t2 = t1.getChild(0);
> + XMLNode t2 = t1.getChild(0);
> assertTrue(( "This is a test note" == t2.getCharacters() ));
> }
>
>
> Modified: trunk/libsbml/src/bindings/java/test/org/sbml/libsbml/test/sbml/TestSBase.java
> ===================================================================
> --- trunk/libsbml/src/bindings/java/test/org/sbml/libsbml/test/sbml/TestSBase.java 2009-02-21 19:00:24 UTC (rev 9111)
> +++ trunk/libsbml/src/bindings/java/test/org/sbml/libsbml/test/sbml/TestSBase.java 2009-02-23 13:24:48 UTC (rev 9112)
> @@ -6,8 +6,8 @@
> * @author Akiya Jouraku (Java conversion)
> * @author Ben Bornstein
> *
> - * $Id:$
> - * $HeadURL:$
> + * $Id$
> + * $HeadURL$
> *
> * This test file was converted from src/sbml/test/TestSBase.cpp
> * with the help of conversion sciprt (ctest_converter.pl).
> @@ -16,7 +16,7 @@
> * This file is part of libSBML. Please visit http://sbml.org for more
> * information about SBML, and the latest version of libSBML.
> *
> - * Copyright 2005-2008 California Institute of Technology.
> + * Copyright 2005-2009 California Institute of Technology.
> * Copyright 2002-2005 California Institute of Technology and
> * Japan Science and Technology Corporation.
> *
> @@ -245,7 +245,7 @@
> XMLNode p_node1 = new XMLNode(p_token);
> XMLNode text_node1 = new XMLNode(text_token1);
> XMLNode notes;
> - XMLNode child, child1;
> + XMLNode child,child1;
> p_node.addChild(text_node);
> body_node.addChild(p_node);
> html_node.addChild(head_node);
> @@ -326,7 +326,7 @@
> XMLNode p_node1 = new XMLNode(p_token);
> XMLNode text_node1 = new XMLNode(text_token1);
> XMLNode notes;
> - XMLNode child, child1;
> + XMLNode child,child1;
> p_node.addChild(text_node);
> body_node.addChild(p_node);
> html_node.addChild(head_node);
> @@ -403,7 +403,7 @@
> XMLNode p_node1 = new XMLNode(p_token1);
> XMLNode text_node1 = new XMLNode(text_token1);
> XMLNode notes;
> - XMLNode child, child1;
> + XMLNode child,child1;
> p_node.addChild(text_node);
> body_node.addChild(p_node);
> html_node.addChild(head_node);
> @@ -479,7 +479,7 @@
> XMLNode p_node1 = new XMLNode(p_token);
> XMLNode text_node1 = new XMLNode(text_token1);
> XMLNode notes;
> - XMLNode child, child1;
> + XMLNode child,child1;
> p_node.addChild(text_node);
> body_node.addChild(p_node);
> p_node1.addChild(text_node1);
> @@ -554,7 +554,7 @@
> XMLNode p_node1 = new XMLNode(p_token);
> XMLNode text_node1 = new XMLNode(text_token1);
> XMLNode notes;
> - XMLNode child, child1;
> + XMLNode child,child1;
> p_node.addChild(text_node);
> p_node1.addChild(text_node1);
> body_node1.addChild(p_node1);
> @@ -621,7 +621,7 @@
> XMLNode p_node1 = new XMLNode(p_token);
> XMLNode text_node1 = new XMLNode(text_token1);
> XMLNode notes;
> - XMLNode child, child1;
> + XMLNode child,child1;
> p_node.addChild(text_node);
> body_node.addChild(p_node);
> p_node1.addChild(text_node1);
> @@ -680,7 +680,7 @@
> XMLNode p_node1 = new XMLNode(p_token);
> XMLNode text_node1 = new XMLNode(text_token1);
> XMLNode notes;
> - XMLNode child, child1;
> + XMLNode child,child1;
> p_node.addChild(text_node);
> p_node1.addChild(text_node1);
> body_node1.addChild(p_node1);
> @@ -738,7 +738,7 @@
> XMLNode p_node1 = new XMLNode(p_token1);
> XMLNode text_node1 = new XMLNode(text_token1);
> XMLNode notes;
> - XMLNode child, child1;
> + XMLNode child,child1;
> p_node.addChild(text_node);
> body_node.addChild(p_node);
> p_node1.addChild(text_node1);
> @@ -784,53 +784,103 @@
> String taggednewnotes = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> "</notes>";
> - String newnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";;
> + String taggednewnotes2 = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>";
> + String newnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + String newnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>" +
> + "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>";
> + String newnotes3 = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" + "</notes>";
> + String newnotes4 = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>";
> S.setNotes(notes);
> assertTrue( S.isSetNotes() == true );
> S.appendNotes(newnotes);
> String notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(taggednewnotes.equals(notes1));
> + S.setNotes(notes);
> + S.appendNotes(newnotes2);
> + String notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes2.equals(notes2));
> + S.setNotes(notes);
> + S.appendNotes(newnotes3);
> + String notes3 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes.equals(notes3));
> + S.setNotes(notes);
> + S.appendNotes(newnotes4);
> + String notes4 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes2.equals(notes4));
> }
>
> public void test_SBase_appendNotesString1()
> {
> - String notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + String notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>";
> String taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>";
> - String addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + String addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>";
> + String addnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> String notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(taggednewnotes.equals(notes1));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + String notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes.equals(notes2));
> }
>
> public void test_SBase_appendNotesString2()
> {
> - String notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + String notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>";
> String taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> @@ -838,35 +888,85 @@
> " </html>\n" +
> "</notes>";
> String addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>\n";;
> + String addnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> String notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(taggednewnotes.equals(notes1));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + String notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes.equals(notes2));
> }
>
> public void test_SBase_appendNotesString3()
> {
> - String notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + String notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>";
> String taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>";
> - String addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";;
> + String taggednewnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>";
> + String addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n";
> + String addnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>";
> + String addnotes3 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> + "</notes>";
> + String addnotes4 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> String notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(taggednewnotes.equals(notes1));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + String notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes2.equals(notes2));
> + S.setNotes(notes);
> + S.appendNotes(addnotes3);
> + String notes3 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes.equals(notes3));
> + S.setNotes(notes);
> + S.appendNotes(addnotes4);
> + String notes4 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes2.equals(notes4));
> }
>
> public void test_SBase_appendNotesString4()
> @@ -874,23 +974,42 @@
> String notes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is a test note </p>\n" + "</body>";;
> String taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>";
> - String addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + String addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>";
> + String addnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> String notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(taggednewnotes.equals(notes1));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + String notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes.equals(notes2));
> }
>
> public void test_SBase_appendNotesString5()
> @@ -898,23 +1017,42 @@
> String notes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>";;
> String taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>";
> - String addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + String addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>";
> + String addnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> String notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(taggednewnotes.equals(notes1));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + String notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes.equals(notes2));
> }
>
> public void test_SBase_appendNotesString6()
> @@ -927,11 +1065,21 @@
> " </body>\n" +
> "</notes>";
> String addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>";;
> + String addnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> String notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(taggednewnotes.equals(notes1));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + String notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes.equals(notes2));
> }
>
> public void test_SBase_appendNotesString7()
> @@ -944,11 +1092,21 @@
> " </body>\n" +
> "</notes>";
> String addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>";;
> + String addnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> String notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(taggednewnotes.equals(notes1));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + String notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes.equals(notes2));
> }
>
> public void test_SBase_appendNotesString8()
> @@ -960,12 +1118,43 @@
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> " </body>\n" +
> "</notes>";
> - String addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";;
> + String taggednewnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + " </body>\n" +
> + "</notes>";
> + String addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + String addnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>";
> + String addnotes3 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> + "</notes>";
> + String addnotes4 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>";
> S.setNotes(notes);
> S.appendNotes(addnotes);
> String notes1 = S.getNotesString();
> assertTrue( S.isSetNotes() == true );
> assertTrue(taggednewnotes.equals(notes1));
> + S.setNotes(notes);
> + S.appendNotes(addnotes2);
> + String notes2 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes2.equals(notes2));
> + S.setNotes(notes);
> + S.appendNotes(addnotes3);
> + String notes3 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes.equals(notes3));
> + S.setNotes(notes);
> + S.appendNotes(addnotes4);
> + String notes4 = S.getNotesString();
> + assertTrue( S.isSetNotes() == true );
> + assertTrue(taggednewnotes2.equals(notes4));
> }
>
> public void test_SBase_getQualifiersFromResources()
> @@ -1023,8 +1212,7 @@
> }
> XMLNode t1 = S.getAnnotation();
> assertTrue( t1.getNumChildren() == 1 );
> - XMLNode t2 = t1.getChild(0);
> - assertTrue(t2.getChild(0).getCharacters().equals( "This is a test note"));
> + assertTrue(t1.getChild(0).getCharacters().equals( "This is a test note"));
> S.setAnnotation(S.getAnnotationString());
> t1 = S.getAnnotation();
> assertTrue( t1.getNumChildren() == 1 );
> @@ -1042,7 +1230,7 @@
> }
> t1 = S.getAnnotation();
> assertTrue( t1.getNumChildren() == 1 );
> - t2 = t1.getChild(0);
> + XMLNode t2 = t1.getChild(0);
> assertTrue(t2.getCharacters().equals( "This is a test note"));
> }
>
> @@ -1104,8 +1292,7 @@
> }
> XMLNode t1 = S.getNotes();
> assertTrue( t1.getNumChildren() == 1 );
> - XMLNode t2 = t1.getChild(0);
> - assertTrue(t2.getChild(0).getCharacters().equals( "This is a test note"));
> + assertTrue(t1.getChild(0).getCharacters().equals( "This is a test note"));
> S.setNotes(S.getNotesString());
> t1 = S.getNotes();
> assertTrue( t1.getNumChildren() == 1 );
> @@ -1123,7 +1310,7 @@
> }
> t1 = S.getNotes();
> assertTrue( t1.getNumChildren() == 1 );
> - t2 = t1.getChild(0);
> + XMLNode t2 = t1.getChild(0);
> assertTrue(t2.getCharacters().equals( "This is a test note"));
> }
>
>
> Modified: trunk/libsbml/src/bindings/python/test/sbml/TestSBase.py
> ===================================================================
> --- trunk/libsbml/src/bindings/python/test/sbml/TestSBase.py 2009-02-21 19:00:24 UTC (rev 9111)
> +++ trunk/libsbml/src/bindings/python/test/sbml/TestSBase.py 2009-02-23 13:24:48 UTC (rev 9112)
> @@ -677,51 +677,100 @@
> taggednewnotes = wrapString("<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> "</notes>")
> + taggednewnotes2 = wrapString("<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>")
> newnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + newnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>""<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>"
> + newnotes3 = wrapString("<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" + "</notes>")
> + newnotes4 = wrapString("<notes>\n" " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>")
> self.S.setNotes(notes)
> self.assert_( self.S.isSetNotes() == True )
> self.S.appendNotes(newnotes)
> notes1 = self.S.getNotesString()
> self.assert_( self.S.isSetNotes() == True )
> self.assert_(( notes1 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(newnotes2)
> + notes2 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes2 == taggednewnotes2 ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(newnotes3)
> + notes3 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes3 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(newnotes4)
> + notes4 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes4 == taggednewnotes2 ))
> pass
>
> def test_SBase_appendNotesString1(self):
> - notes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + notes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>")
> taggednewnotes = wrapString("<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>")
> - addnotes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + addnotes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>")
> + addnotes2 = wrapString("<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>")
> self.S.setNotes(notes)
> self.S.appendNotes(addnotes)
> notes1 = self.S.getNotesString()
> self.assert_( self.S.isSetNotes() == True )
> self.assert_(( notes1 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes2)
> + notes2 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes2 == taggednewnotes ))
> pass
>
> def test_SBase_appendNotesString2(self):
> - notes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + notes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>")
> taggednewnotes = wrapString("<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> @@ -729,80 +778,165 @@
> " </html>\n" +
> "</notes>")
> addnotes = wrapString("<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>\n")
> + addnotes2 = wrapString("<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>")
> self.S.setNotes(notes)
> self.S.appendNotes(addnotes)
> notes1 = self.S.getNotesString()
> self.assert_( self.S.isSetNotes() == True )
> self.assert_(( notes1 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes2)
> + notes2 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes2 == taggednewnotes ))
> pass
>
> def test_SBase_appendNotesString3(self):
> - notes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + notes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>")
> taggednewnotes = wrapString("<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>")
> - addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + taggednewnotes2 = wrapString("<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>")
> + addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n";
> + addnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n""<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>"
> + addnotes3 = wrapString("<notes>\n" " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> + "</notes>")
> + addnotes4 = wrapString("<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>")
> self.S.setNotes(notes)
> self.S.appendNotes(addnotes)
> notes1 = self.S.getNotesString()
> self.assert_( self.S.isSetNotes() == True )
> self.assert_(( notes1 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes2)
> + notes2 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes2 == taggednewnotes2 ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes3)
> + notes3 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes3 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes4)
> + notes4 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes4 == taggednewnotes2 ))
> pass
>
> def test_SBase_appendNotesString4(self):
> notes = wrapString("<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is a test note </p>\n" + "</body>")
> taggednewnotes = wrapString("<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>")
> - addnotes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + addnotes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>")
> + addnotes2 = wrapString("<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>")
> self.S.setNotes(notes)
> self.S.appendNotes(addnotes)
> notes1 = self.S.getNotesString()
> self.assert_( self.S.isSetNotes() == True )
> self.assert_(( notes1 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes2)
> + notes2 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes2 == taggednewnotes ))
> pass
>
> def test_SBase_appendNotesString5(self):
> notes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>";
> taggednewnotes = wrapString("<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>")
> - addnotes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + addnotes = wrapString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>")
> + addnotes2 = wrapString("<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>")
> self.S.setNotes(notes)
> self.S.appendNotes(addnotes)
> notes1 = self.S.getNotesString()
> self.assert_( self.S.isSetNotes() == True )
> self.assert_(( notes1 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes2)
> + notes2 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes2 == taggednewnotes ))
> pass
>
> def test_SBase_appendNotesString6(self):
> @@ -814,11 +948,21 @@
> " </body>\n" +
> "</notes>")
> addnotes = wrapString("<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>")
> + addnotes2 = wrapString("<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>")
> self.S.setNotes(notes)
> self.S.appendNotes(addnotes)
> notes1 = self.S.getNotesString()
> self.assert_( self.S.isSetNotes() == True )
> self.assert_(( notes1 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes2)
> + notes2 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes2 == taggednewnotes ))
> pass
>
> def test_SBase_appendNotesString7(self):
> @@ -830,11 +974,21 @@
> " </body>\n" +
> "</notes>")
> addnotes = wrapString("<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>")
> + addnotes2 = wrapString("<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>")
> self.S.setNotes(notes)
> self.S.appendNotes(addnotes)
> notes1 = self.S.getNotesString()
> self.assert_( self.S.isSetNotes() == True )
> self.assert_(( notes1 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes2)
> + notes2 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes2 == taggednewnotes ))
> pass
>
> def test_SBase_appendNotesString8(self):
> @@ -845,12 +999,42 @@
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> " </body>\n" +
> "</notes>")
> + taggednewnotes2 = wrapString("<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + " </body>\n" +
> + "</notes>")
> addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + addnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n""<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>"
> + addnotes3 = wrapString("<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> + "</notes>")
> + addnotes4 = wrapString("<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>")
> self.S.setNotes(notes)
> self.S.appendNotes(addnotes)
> notes1 = self.S.getNotesString()
> self.assert_( self.S.isSetNotes() == True )
> self.assert_(( notes1 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes2)
> + notes2 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes2 == taggednewnotes2 ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes3)
> + notes3 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes3 == taggednewnotes ))
> + self.S.setNotes(notes)
> + self.S.appendNotes(addnotes4)
> + notes4 = self.S.getNotesString()
> + self.assert_( self.S.isSetNotes() == True )
> + self.assert_(( notes4 == taggednewnotes2 ))
> pass
>
> def test_SBase_getQualifiersFromResources(self):
> @@ -900,8 +1084,7 @@
> pass
> t1 = self.S.getAnnotation()
> self.assert_( t1.getNumChildren() == 1 )
> - t2 = t1.getChild(0)
> - self.assert_(( "This is a test note" == t2.getChild(0).getCharacters() ))
> + self.assert_(( "This is a test note" == t1.getChild(0).getCharacters() ))
> self.S.setAnnotation(self.S.getAnnotationString())
> t1 = self.S.getAnnotation()
> self.assert_( t1.getNumChildren() == 1 )
> @@ -969,8 +1152,7 @@
> pass
> t1 = self.S.getNotes()
> self.assert_( t1.getNumChildren() == 1 )
> - t2 = t1.getChild(0)
> - self.assert_(( "This is a test note" == t2.getChild(0).getCharacters() ))
> + self.assert_(( "This is a test note" == t1.getChild(0).getCharacters() ))
> self.S.setNotes(self.S.getNotesString())
> t1 = self.S.getNotes()
> self.assert_( t1.getNumChildren() == 1 )
>
> Modified: trunk/libsbml/src/bindings/ruby/test/sbml/TestSBase.rb
> ===================================================================
> --- trunk/libsbml/src/bindings/ruby/test/sbml/TestSBase.rb 2009-02-21 19:00:24 UTC (rev 9111)
> +++ trunk/libsbml/src/bindings/ruby/test/sbml/TestSBase.rb 2009-02-23 13:24:48 UTC (rev 9112)
> @@ -670,51 +670,100 @@
> taggednewnotes = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> "</notes>"
> + taggednewnotes2 = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>"
> newnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + newnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>""<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>"
> + newnotes3 = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" + "</notes>";
> + newnotes4 = "<notes>\n" " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>"
> @@s.setNotes(notes)
> assert( @@s.isSetNotes() == true )
> @@s.appendNotes(newnotes)
> notes1 = @@s.getNotesString()
> assert( @@s.isSetNotes() == true )
> assert (( notes1 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(newnotes2)
> + notes2 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes2 == taggednewnotes2 ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(newnotes3)
> + notes3 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes3 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(newnotes4)
> + notes4 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes4 == taggednewnotes2 ))
> end
>
> def test_SBase_appendNotesString1
> - notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>"
> taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>"
> - addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>"
> + addnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>"
> @@s.setNotes(notes)
> @@s.appendNotes(addnotes)
> notes1 = @@s.getNotesString()
> assert( @@s.isSetNotes() == true )
> assert (( notes1 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes2)
> + notes2 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes2 == taggednewnotes ))
> end
>
> def test_SBase_appendNotesString2
> - notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>"
> taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> @@ -722,80 +771,165 @@
> " </html>\n" +
> "</notes>"
> addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>\n";
> + addnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>"
> @@s.setNotes(notes)
> @@s.appendNotes(addnotes)
> notes1 = @@s.getNotesString()
> assert( @@s.isSetNotes() == true )
> assert (( notes1 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes2)
> + notes2 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes2 == taggednewnotes ))
> end
>
> def test_SBase_appendNotesString3
> - notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " </body>\n" +
> "</html>"
> taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>"
> - addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + taggednewnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>"
> + addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n";
> + addnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n""<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>"
> + addnotes3 = "<notes>\n" " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> + "</notes>"
> + addnotes4 = "<notes>\n" + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>"
> @@s.setNotes(notes)
> @@s.appendNotes(addnotes)
> notes1 = @@s.getNotesString()
> assert( @@s.isSetNotes() == true )
> assert (( notes1 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes2)
> + notes2 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes2 == taggednewnotes2 ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes3)
> + notes3 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes3 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes4)
> + notes4 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes4 == taggednewnotes2 ))
> end
>
> def test_SBase_appendNotesString4
> notes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is a test note </p>\n" + "</body>";
> taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>"
> - addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>"
> + addnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>"
> @@s.setNotes(notes)
> @@s.appendNotes(addnotes)
> notes1 = @@s.getNotesString()
> assert( @@s.isSetNotes() == true )
> assert (( notes1 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes2)
> + notes2 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes2 == taggednewnotes ))
> end
>
> def test_SBase_appendNotesString5
> notes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>";
> taggednewnotes = "<notes>\n" +
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> - " <head/>\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> " </html>\n" +
> "</notes>"
> - addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head/>\n" +
> + addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> " <body>\n" +
> " <p>This is more test notes </p>\n" +
> " </body>\n" +
> "</html>"
> + addnotes2 = "<notes>\n" +
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <head>\n" +
> + " <title/>\n" +
> + " </head>\n" +
> + " <body>\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + " </html>\n" +
> + "</notes>"
> @@s.setNotes(notes)
> @@s.appendNotes(addnotes)
> notes1 = @@s.getNotesString()
> assert( @@s.isSetNotes() == true )
> assert (( notes1 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes2)
> + notes2 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes2 == taggednewnotes ))
> end
>
> def test_SBase_appendNotesString6
> @@ -807,11 +941,21 @@
> " </body>\n" +
> "</notes>"
> addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>";
> + addnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>"
> @@s.setNotes(notes)
> @@s.appendNotes(addnotes)
> notes1 = @@s.getNotesString()
> assert( @@s.isSetNotes() == true )
> assert (( notes1 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes2)
> + notes2 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes2 == taggednewnotes ))
> end
>
> def test_SBase_appendNotesString7
> @@ -823,11 +967,21 @@
> " </body>\n" +
> "</notes>"
> addnotes = "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <p>This is more test notes </p>\n" + "</body>";
> + addnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is more test notes </p>\n" +
> + " </body>\n" +
> + "</notes>"
> @@s.setNotes(notes)
> @@s.appendNotes(addnotes)
> notes1 = @@s.getNotesString()
> assert( @@s.isSetNotes() == true )
> assert (( notes1 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes2)
> + notes2 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes2 == taggednewnotes ))
> end
>
> def test_SBase_appendNotesString8
> @@ -838,12 +992,42 @@
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> " </body>\n" +
> "</notes>"
> + taggednewnotes2 = "<notes>\n" +
> + " <body xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
> + " <p>This is a test note </p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + " </body>\n" +
> + "</notes>"
> addnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + addnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n""<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>"
> + addnotes3 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n" +
> + "</notes>"
> + addnotes4 = "<notes>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n" +
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n" +
> + "</notes>"
> @@s.setNotes(notes)
> @@s.appendNotes(addnotes)
> notes1 = @@s.getNotesString()
> assert( @@s.isSetNotes() == true )
> assert (( notes1 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes2)
> + notes2 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes2 == taggednewnotes2 ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes3)
> + notes3 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes3 == taggednewnotes ))
> + @@s.setNotes(notes)
> + @@s.appendNotes(addnotes4)
> + notes4 = @@s.getNotesString()
> + assert( @@s.isSetNotes() == true )
> + assert (( notes4 == taggednewnotes2 ))
> end
>
> def test_SBase_getQualifiersFromResources
> @@ -893,8 +1077,7 @@
> end
> t1 = @@s.getAnnotation()
> assert( t1.getNumChildren() == 1 )
> - t2 = t1.getChild(0)
> - assert (( "This is a test note" == t2.getChild(0).getCharacters() ))
> + assert (( "This is a test note" == t1.getChild(0).getCharacters() ))
> @@s.setAnnotation(@@s.getAnnotationString())
> t1 = @@s.getAnnotation()
> assert( t1.getNumChildren() == 1 )
> @@ -962,8 +1145,7 @@
> end
> t1 = @@s.getNotes()
> assert( t1.getNumChildren() == 1 )
> - t2 = t1.getChild(0)
> - assert (( "This is a test note" == t2.getChild(0).getCharacters() ))
> + assert (( "This is a test note" == t1.getChild(0).getCharacters() ))
> @@s.setNotes(@@s.getNotesString())
> t1 = @@s.getNotes()
> assert( t1.getNumChildren() == 1 )
>
> Modified: trunk/libsbml/src/sbml/SBase.cpp
> ===================================================================
> --- trunk/libsbml/src/sbml/SBase.cpp 2009-02-21 19:00:24 UTC (rev 9111)
> +++ trunk/libsbml/src/sbml/SBase.cpp 2009-02-23 13:24:48 UTC (rev 9112)
> @@ -630,7 +630,23 @@
> {
> XMLToken ann_t = XMLToken(XMLTriple("annotation", "", ""), XMLAttributes());
> mAnnotation = new XMLNode(ann_t);
> - mAnnotation->addChild(*annotation);
> +
> + // The root node of the given XMLNode tree can be an empty XMLNode
> + // (i.e. neither start, end, nor text XMLNode) if the given annotation was
> + // converted from an XML string whose top level elements are neither
> + // "html" nor "body" and not enclosed with <annotation>..</annotation> tags
> + // (e.g. <foo xmlns:foo="...">..</foo><bar xmlns:bar="...">..</bar> )
> + if (!annotation->isStart() && !annotation->isEnd() && !annotation->isText())
> + {
> + for (unsigned int i=0; i < annotation->getNumChildren(); i++)
> + {
> + mAnnotation->addChild(annotation->getChild(i));
> + }
> + }
> + else
> + {
> + mAnnotation->addChild(*annotation);
> + }
> }
> else
> {
> @@ -800,7 +816,23 @@
> XMLToken notes_t = XMLToken(XMLTriple("notes", "", ""),
> XMLAttributes());
> mNotes = new XMLNode(notes_t);
> - mNotes->addChild(*notes);
> +
> + // The root node of the given XMLNode tree can be an empty XMLNode
> + // (i.e. neither start, end, nor text XMLNode) if the given notes was
> + // converted from an XML string whose top level elements are neither
> + // "html" nor "body" and not enclosed with <notes>..</notes> tag
> + // (e.g. <p ...>..</p><br/>).
> + if (!notes->isStart() && !notes->isEnd() && !notes->isText() )
> + {
> + for (unsigned int i=0; i < notes->getNumChildren(); i++)
> + {
> + mNotes->addChild(notes->getChild(i));
> + }
> + }
> + else
> + {
> + mNotes->addChild(*notes);
> + }
> }
> }
> else
> @@ -845,18 +877,76 @@
> {
> if(!notes) return;
>
> - const string& name = notes->getName();
> + if (mNotes && mNotes->getNumChildren() > 0)
> + {
> + // The content of notes in SBML can consist only of the following
> + // possibilities:
> + //
> + // 1. A complete XHTML document (minus the XML and DOCTYPE
> + // declarations), that is, XHTML content beginning with the
> + // html tag.
> + // (_NotesType is _ANotesHTML.)
> + //
> + // 2. The body element from an XHTML document.
> + // (_NotesType is _ANotesBody.)
> + //
> + // 3. Any XHTML content that would be permitted within a body
> + // element, each one must declare the XML namespace separately.
> + // (_NotesType is _ANotesAny.)
>
> - if (mNotes != 0)
> - {
> - XMLNode *newNotes = new XMLNode();
> - /* check for notes tags on the added notes and strip if present*/
> + typedef enum { _ANotesHTML, _ANotesBody, _ANotesAny } _NotesType;
> +
> + _NotesType curNotesType = _ANotesAny;
> + _NotesType addedNotesType = _ANotesAny;
> +
> + XMLNode& curNotes = *mNotes;
> + XMLNode addedNotes;
> +
> + //------------------------------------------------------------
> + //
> + // STEP1 : identifies the type of the given notes
> + //
> + //------------------------------------------------------------
> +
> + const string& name = notes->getName();
> +
> if (name == "notes")
> {
> - int num_children = notes->getNumChildren();
> - for(int i=0; i < num_children; i++)
> + /* check for notes tags on the added notes and strip if present and
> + the notes tag has "html" or "body" element */
> +
> + if (notes->getNumChildren() > 0)
> + {
> + // notes->getChild(0) must be "html", "body", or any XHTML
> + // element that would be permitted within a "body" element
> + // (e.g. <p>..</p>, <br>..</br> and so forth).
> +
> + const string& cname = notes->getChild(0).getName();
> +
> + if (cname == "html")
> + {
> + addedNotes = notes->getChild(0);
> + addedNotesType = _ANotesHTML;
> + }
> + else if (cname == "body")
> + {
> + addedNotes = notes->getChild(0);
> + addedNotesType = _ANotesBody;
> + }
> + else
> + {
> + // the notes tag must NOT be stripped if notes->getChild(0) node
> + // is neither "html" nor "body" element because the children of
> + // the addedNotes will be added to the curNotes later if the node
> + // is neither "html" nor "body".
> + addedNotes = *notes;
> + addedNotesType = _ANotesAny;
> + }
> + }
> + else
> {
> - newNotes->addChild(notes->getChild(i));
> + // the given notes is empty
> + return;
> }
> }
> else
> @@ -864,237 +954,218 @@
> // if the XMLNode argument notes has been created from a string and
> // it is a set of subelements there may be a single empty node
> // as parent - leaving this in doesnt affect the writing out of notes
> - //but messes up the check for correct syntax
> - if (notes->getNumChildren() == 1 &&
> - notes->isEOF() &&
> - notes->isAttributesEmpty() &&
> - notes->isNamespacesEmpty() &&
> - name == "")
> + // but messes up the check for correct syntax
> + if (!notes->isStart() && !notes->isEnd() && !notes->isText() )
> {
> - newNotes = notes->getChild(0).clone();
> + if (notes->getNumChildren() > 0)
> + {
> + addedNotes = *notes;
> + addedNotesType = _ANotesAny;
> + }
> + else
> + {
> + // the given notes is empty
> + return;
> + }
> }
> else
> {
> - newNotes = notes->clone();
> + if (name == "html")
> + {
> + addedNotes = *notes;
> + addedNotesType = _ANotesHTML;
> + }
> + else if (name == "body")
> + {
> + addedNotes = *notes;
> + addedNotesType = _ANotesBody;
> + }
> + else
> + {
> + // The given notes node needs to be added to a parent node
> + // if the node is neither "html" nor "body" element because the
> + // children of addedNotes will be added to the curNotes later if the
> + // node is neither "html" nor "body" (i.e. any XHTML element that
> + // would be permitted within a "body" element)
> + addedNotes.addChild(*notes);
> + addedNotesType = _ANotesAny;
> + }
> }
> }
>
> + //
> + // checks the addedNotes of "html" if the html tag contains "head" and
> + // "body" tags which must be located in this order, otherwise nothing will
> + // be done.
> + //
> + if (addedNotesType == _ANotesHTML)
> + {
> + if ((addedNotes.getNumChildren() != 2) ||
> + ( (addedNotes.getChild(0).getName() != "head") ||
> + (addedNotes.getChild(1).getName() != "body")
> + )
> + )
> + {
> + return;
> + }
> + }
>
> + //------------------------------------------------------------
> + //
> + // STEP2: identifies the type of the existing notes
> + //
> + //------------------------------------------------------------
> +
> + // curNotes.getChild(0) must be "html", "body", or any XHTML
> + // element that would be permitted within a "body" element .
> +
> + const string& cname = curNotes.getChild(0).getName();
> +
> + if (cname == "html")
> + {
> + XMLNode& curHTML = curNotes.getChild(0);
> + //
> + // checks the curHTML if the html tag contains "head" and "body" tags
> + // which must be located in this order, otherwise nothing will be done.
> + //
> + if ((curHTML.getNumChildren() != 2) ||
> + ( (curHTML.getChild(0).getName() != "head") ||
> + (curHTML.getChild(1).getName() != "body")
> + )
> + )
> + {
> + return;
> + }
> + curNotesType = _ANotesHTML;
> + }
> + else if (cname == "body")
> + {
> + curNotesType = _ANotesBody;
> + }
> + else
> + {
> + curNotesType = _ANotesAny;
> + }
> +
> /*
> * BUT we also have the issue of the rules relating to notes
> * contents and where to add them ie we cannot add a second body element
> * etc...
> */
> - XMLToken notesToken = XMLToken(XMLTriple("notes", "", ""), XMLAttributes());
>
> - XMLNode* newHeadTag=NULL;
> - XMLNode* newBodyTag=NULL;
> + //------------------------------------------------------------
> + //
> + // STEP3: appends the given notes to the current notes
> + //
> + //------------------------------------------------------------
> +
> unsigned int i;
>
> - if (mNotes->getNumChildren() == 1
> - && mNotes->getChild(0).getName() == "html")
> + if (curNotesType == _ANotesHTML)
> {
> - XMLNode* NotesTag = new XMLNode(notesToken);
> - XMLNode* HTMLTag = new XMLNode(mNotes->getChild(0));
> - HTMLTag->removeChildren();
> - XMLNode* BodyTag = new XMLNode(mNotes->getChild(0).getChild(1));
> - XMLNode* HeadTag = new XMLNode(mNotes->getChild(0).getChild(0));
> + XMLNode& curHTML = curNotes.getChild(0);
> + XMLNode& curBody = curHTML.getChild(1);
>
> - if (newNotes->getNumChildren() == 2
> - && newNotes->getName() == "html")
> + if (addedNotesType == _ANotesHTML)
> {
> - // add head and body from new notes to existing head and body
> - newHeadTag = new XMLNode(newNotes->getChild(0));
> - newBodyTag = new XMLNode(newNotes->getChild(1));
> + // adds the given html tag to the current html tag
>
> - for(i = 0; i < newHeadTag->getNumChildren(); i++)
> + XMLNode& addedBody = addedNotes.getChild(1);
> +
> + for (i=0; i < addedBody.getNumChildren(); i++)
> {
> - HeadTag->addChild(*newHeadTag->getChild(i).clone());
> + curBody.addChild(addedBody.getChild(i));
> }
> - for(i = 0; i < newBodyTag->getNumChildren(); i++)
> - {
> - BodyTag->addChild(*newBodyTag->getChild(i).clone());
> - }
> -
> - HTMLTag->addChild(*HeadTag);
> - HTMLTag->addChild(*BodyTag);
> - NotesTag->addChild(*HTMLTag);
> - delete newHeadTag;
> - delete newBodyTag;
> - setNotes(NotesTag);
> }
> - else if (newNotes->getName() == "body")
> + else if ((addedNotesType == _ANotesBody) || (addedNotesType == _ANotesAny))
> {
> - // add contents of new body to existing body
> - newBodyTag = new XMLNode(*newNotes);
> - for(i = 0; i < newBodyTag->getNumChildren(); i++)
> - {
> - BodyTag->addChild(*newBodyTag->getChild(i).clone());
> - }
> -
> - HTMLTag->addChild(*HeadTag);
> - HTMLTag->addChild(*BodyTag);
> - NotesTag->addChild(*HTMLTag);
> - delete newBodyTag;
> - setNotes(NotesTag);
> - }
> - else
> - {
> - // add new notes to body of existing
> + // adds the given body or other tag (permitted in the body) to the current
> + // html tag
>
> - for(i = 0; i < newNotes->getNumChildren(); i++)
> + for (i=0; i < addedNotes.getNumChildren(); i++)
> {
> - BodyTag->addChild(*newNotes->clone());
> + curBody.addChild(addedNotes.getChild(i));
> }
> -
> - HTMLTag->addChild(*HeadTag);
> - HTMLTag->addChild(*BodyTag);
> - NotesTag->addChild(*HTMLTag);
> - setNotes(NotesTag);
> }
> -
> - delete HTMLTag;
> - delete BodyTag;
> - delete HeadTag;
> -
> }
> -
> - else if (mNotes->getNumChildren() == 1
> - && mNotes->getChild(0).getName() == "body")
> + else if (curNotesType == _ANotesBody)
> {
> - XMLNode* NotesTag = new XMLNode(notesToken);
> -
> - if (newNotes->getNumChildren() == 2
> - && newNotes->getName() == "html")
> + if (addedNotesType == _ANotesHTML)
> {
> - /* in this case the original doesnt have a html tag
> - * so we need to add one
> - */
> - XMLNode* HTMLTag = new XMLNode(*newNotes);
> - HTMLTag->removeChildren();
> - XMLNode* BodyTag = new XMLNode(newNotes->getChild(1));
> - XMLNode* HeadTag = new XMLNode(newNotes->getChild(0));
> -
> - // add body from existing notes to newly created body
> - newBodyTag = new XMLNode(mNotes->getChild(0));
> + // adds the given html tag to the current body tag
>
> - for(i = newBodyTag->getNumChildren(); i > 0; i--)
> + XMLNode addedHTML(addedNotes);
> + XMLNode& addedBody = addedHTML.getChild(1);
> + XMLNode& curBody = curNotes.getChild(0);
> +
> + for (i=0; i < curBody.getNumChildren(); i++)
> {
> - BodyTag->insertChild(0, *newBodyTag->getChild(i-1).clone());
> + addedBody.insertChild(i,curBody.getChild(i));
> }
>
> - HTMLTag->addChild(*HeadTag);
> - HTMLTag->addChild(*BodyTag);
> - NotesTag->addChild(*HTMLTag);
> - delete HTMLTag;
> - delete BodyTag;
> - delete HeadTag;
> - delete newBodyTag;
> - setNotes(NotesTag);
> + curNotes.removeChildren();
> + curNotes.addChild(addedHTML);
> }
> - else if (newNotes->getName() == "body")
> + else if ((addedNotesType == _ANotesBody) || (addedNotesType == _ANotesAny))
> {
> - XMLNode* BodyTag = new XMLNode(mNotes->getChild(0));
> - // add contents of new body to existing body
> - newBodyTag = new XMLNode(*newNotes);
> - for(i = 0; i < newBodyTag->getNumChildren(); i++)
> + // adds the given body or other tag (permitted in the body) to the current
> + // body tag
> +
> + XMLNode& curBody = curNotes.getChild(0);
> +
> + for (i=0; i < addedNotes.getNumChildren(); i++)
> {
> - BodyTag->addChild(*newBodyTag->getChild(i).clone());
> + curBody.addChild(addedNotes.getChild(i));
> }
> -
> - NotesTag->addChild(*BodyTag);
> - delete BodyTag;
> - delete newBodyTag;
> - setNotes(NotesTag);
> }
> - else
> - {
> - // add new notes to body of existing
> - XMLNode* BodyTag = new XMLNode(mNotes->getChild(0));
> -
> - for(i = 0; i < newNotes->getNumChildren(); i++)
> - {
> - BodyTag->addChild(*newNotes->clone());
> - }
> - NotesTag->addChild(*BodyTag);
> - delete BodyTag;
> - setNotes(NotesTag);
> - }
> }
> -
> - else
> + else if (curNotesType == _ANotesAny)
> {
> + if (addedNotesType == _ANotesHTML)
> + {
> + // adds the given html tag to the current any tag permitted in the body.
>
> - if (newNotes->getNumChildren() == 2
> - && newNotes->getName() == "html")
> - {
> - /* in this case the original doesnt have a html tag
> - * so we need to add one
> - */
> - XMLNode* NotesTag = new XMLNode(notesToken);
> - XMLNode* HTMLTag = new XMLNode(*newNotes);
> - HTMLTag->removeChildren();
> - XMLNode* BodyTag = new XMLNode(newNotes->getChild(1));
> - XMLNode* HeadTag = new XMLNode(newNotes->getChild(0));
> -
> - for(i = mNotes->getNumChildren(); i > 0; i--)
> + XMLNode addedHTML(addedNotes);
> + XMLNode& addedBody = addedHTML.getChild(1);
> +
> + for (i=0; i < curNotes.getNumChildren(); i++)
> {
> - BodyTag->insertChild(0, *mNotes->getChild(i-1).clone());
> + addedBody.insertChild(i,curNotes.getChild(i));
> }
> -
> - HTMLTag->addChild(*HeadTag);
> - HTMLTag->addChild(*BodyTag);
> - NotesTag->addChild(*HTMLTag);
> - delete HTMLTag;
> - delete BodyTag;
> - delete HeadTag;
> - setNotes(NotesTag);
> +
> + curNotes.removeChildren();
> + curNotes.addChild(addedHTML);
> }
> - else if (newNotes->getName() == "body")
> + else if (addedNotesType == _ANotesBody)
> {
> - /* in this case the original doesnt have a body tag
> - * so we need to add one
> - */
> - XMLNode* NotesTag = new XMLNode(notesToken);
> - XMLNode* BodyTag = new XMLNode(*newNotes);
> - for(i = mNotes->getNumChildren(); i > 0; i--)
> + // adds the given body tag to the current any tag permitted in the body.
> +
> + XMLNode addedBody(addedNotes);
> +
> + for (i=0; i < curNotes.getNumChildren(); i++)
> {
> - BodyTag->insertChild(0, *mNotes->getChild(i-1).clone());
> + addedBody.insertChild(i,curNotes.getChild(i));
> }
> -
> - NotesTag->addChild(*BodyTag);
> - delete BodyTag;
> - setNotes(NotesTag);
> +
> + curNotes.removeChildren();
> + curNotes.addChild(addedBody);
> }
> - else
> + else if (addedNotesType == _ANotesAny)
> {
> - XMLNode* NotesTag = new XMLNode(*mNotes);
> + // adds the given any tag permitted in the boy to that of the current
> + // any tag.
>
> - for(i = 0; i < newNotes->getNumChildren(); i++)
> + for (i=0; i < addedNotes.getNumChildren(); i++)
> {
> - NotesTag->addChild(*newNotes->clone());
> + curNotes.addChild(addedNotes.getChild(i));
> }
> - setNotes(NotesTag);
> }
> }
> -
> - delete newNotes;
> }
> - else
> + else // if (mNotes == NULL)
> {
> - /* check for notes tags and add if necessary */
> -
> - if (name == "notes")
> - {
> - setNotes(notes);
> - }
> - else
> - {
> - XMLToken ann_t = XMLToken(XMLTriple("notes", "", ""), XMLAttributes());
> - XMLNode * ann = new XMLNode(ann_t);
> - ann->addChild(*notes);
> - setNotes(ann);
> - }
> + // setNotes accepts XMLNode with/without top level notes tags.
> + setNotes(notes);
> }
>
> }
>
> Modified: trunk/libsbml/src/sbml/test/TestSBase.cpp
> ===================================================================
> --- trunk/libsbml/src/sbml/test/TestSBase.cpp 2009-02-21 19:00:24 UTC (rev 9111)
> +++ trunk/libsbml/src/sbml/test/TestSBase.cpp 2009-02-23 13:24:48 UTC (rev 9112)
> @@ -223,8 +223,7 @@
> XMLNode_t *t1 = SBase_getNotes(S);
> fail_unless(XMLNode_getNumChildren(t1) == 1);
>
> - const XMLNode_t *t2 = XMLNode_getChild(t1,0);
> - fail_unless(!strcmp(XMLNode_getCharacters(XMLNode_getChild(t2,0)), "This is a test note"));
> + fail_unless(!strcmp(XMLNode_getCharacters(XMLNode_getChild(t1,0)), "This is a test note"));
>
>
> /* Reflexive case (pathological) */
> @@ -253,7 +252,7 @@
> t1 = SBase_getNotes(S);
> fail_unless(XMLNode_getNumChildren(t1) == 1);
>
> - t2 = XMLNode_getChild(t1,0);
> + const XMLNode_t *t2 = XMLNode_getChild(t1,0);
> fail_unless(!strcmp(XMLNode_getCharacters(t2), "This is a test note"));
>
> }
> @@ -276,8 +275,7 @@
> XMLNode_t *t1 = SBase_getAnnotation(S);
> fail_unless(XMLNode_getNumChildren(t1) == 1);
>
> - const XMLNode_t *t2 = XMLNode_getChild(t1,0);
> - fail_unless(!strcmp(XMLNode_getCharacters(XMLNode_getChild(t2,0)), "This is a test note"));
> + fail_unless(!strcmp(XMLNode_getCharacters(XMLNode_getChild(t1,0)), "This is a test note"));
>
>
> /* Reflexive case (pathological) */
> @@ -306,7 +304,7 @@
> t1 = SBase_getAnnotation(S);
> fail_unless(XMLNode_getNumChildren(t1) == 1);
>
> - t2 = XMLNode_getChild(t1,0);
> + const XMLNode_t *t2 = XMLNode_getChild(t1,0);
> fail_unless(!strcmp(XMLNode_getCharacters(t2), "This is a test note"));
> }
> END_TEST
> @@ -1102,17 +1100,35 @@
>
> START_TEST (test_SBase_appendNotesString)
> {
> + // add p to p
> char * notes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>";
> char * taggednewnotes = "<notes>\n"
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n"
> " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n"
> "</notes>";
> + char * taggednewnotes2 = "<notes>\n"
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is a test note </p>\n"
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n"
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n"
> + "</notes>";
> char * newnotes = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>";
> + char * newnotes2 = "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>"
> + "<p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>";
> + char * newnotes3= "<notes>\n"
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes </p>\n"
> + "</notes>";
> + char * newnotes4 = "<notes>\n"
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 1</p>\n"
> + " <p xmlns=\"http://www.w3.org/1999/xhtml\">This is more test notes 2</p>\n"
> + "</notes>";
>
> SBase_setNotesString(S, notes);
>
> fail_unless(SBase_isSetNotes(S) == 1);
>
> + //
> + // add one p tag
> + //
> SBase_appendNotesString(S, newnotes);
>
> const char * notes1 = SBase_getNotesString(S);
> @@ -1120,6 +1136,38 @@
> fail_unless(SBase_isSetNotes(S) == 1);
> fail_unless(!strcmp(taggednewnotes, notes1));
>
> + //
> + // add two p tags
> + //
> + SBase_setNotesString(S, notes);
> + SBase_appendNotesString(S, newnotes2);
> +
> + const char * notes2 = SBase_getNotesString(S);
> +
> + fail_unless(SBase_isSetNotes(S) == 1);
> + fail_unless(!strcmp(taggednewnotes2, notes2));
> +
> + //
> + // add one p tag with notes tag
> + //
> + SBase_setNotesString(S, notes);
> + SBase_appendNotesString(S, newnotes3);
> +
> + const char * notes3 = SBase_getNotesString(S);
> +
> + fail_unless(SBase_isSetNotes(S) == 1);
> + fail_unless(!strcmp(taggednewnotes, notes3));
> +
> + //
> + // add two p tags with notes tag
> + //
> + SBase_setNotesString(S, notes);
> + SBase_appendNotesString(S, newnotes4);
> +
> + const char * notes4 = SBase_getNotesString(S);
> +
> + fail_unless(SBase_isSetNotes(S) == 1);
> + fail_unless(!strcmp(taggednewnotes2, notes4));
> }
> END_TEST
>
> @@ -1127,7 +1175,9 @@
> START_TEST (test_SBase_appendNotesString1)
> { // add html to html
> char * notes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
> - " <head/>\n"
> + " <head>\n"
> + " <title/>\n"
> + " </head>\n"
> " <body>\n"
> " <p>This is a test note </p>\n"
> " </body>\n"
> @@ -1135,7 +1185,9 @@
> char * taggednewnotes =
> "<notes>\n"
> " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
> - " <head/>\n"
> + " <head>\n"
> + " <title/>\n"
> + " </head>\n"
> " <body>\n"
> " <p>This is a test note </p>\n"
> " <p>This is more test notes </p>\n"
> @@ -1143,12 +1195,27 @@
> " </html>\n"
> "</notes>";
> char * addnotes = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
> - " <head/>\n"
> + " <head>\n"
> + " <title/>\n"
> + " </head>\n"
> " <body>\n"
> " <p>This is more test notes </p>\n"
> " </body>\n"
> "</html>";
> + char * addnotes2 =
> + "<notes>\n"
> + " <html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
> + " <head>\n"
> + " <title/>\n"
> + " </head>\n"
> + " <body>\n"
> + " <p>This is more test not
____________________________________________________________
To manage your libsbml-development list subscription, visit
https://utils.its.caltech.edu/mailman/listinfo/libsbml-development

For a web interface to the libsbml-development mailing list, visit
http://sbml.org/Forums/

For questions or feedback about the libsbml-development list,
contact sbml-team@caltech.edu

      

SubjectPosterDate
Read Message   Fixed appendNotes(), setAnnotation(), and setNotes...  ajouraku23 Feb '09 11:01
Previous Topic:Release of libSBML-3.3.2
Next Topic:libSBML development plans - Feb 2009
Go to forum:
-=] Back to Top [=-

Powered by FUDforum. (Copyright Advanced Internet Designs Inc.)

Please use our issue tracking system for any questions or suggestions about this website.