/// /// @file TestXMLOutputStream.cs /// @brief XMLOutputStream unit tests /// @author Frank Bergmann (Csharp conversion) /// @author Akiya Jouraku (Csharp conversion) /// @author Sarah Keating /// /// $Id: TestXMLOutputStream.cs 9830 2009-07-17 18:35:36Z ajouraku $ /// $HeadURL: https://sbml.svn.sourceforge.net/svnroot/sbml/trunk/libsbml/src/bindings/csharp/test/xml/TestXMLOutputStream.cs $ /// /// This test file was converted from src/sbml/test/TestXMLOutputStream.c /// with the help of conversion sciprt (ctest_converter.pl). /// /// */ namespace LibSBMLCSTest { using libsbml; using System.IO; public class TestXMLOutputStream { public class AssertionError : System.Exception { public AssertionError() : base() { } } static void assertTrue(bool condition) { if (condition == true) { return; } throw new AssertionError(); } static void assertEquals(object a, object b) { if ( (a == null) && (b == null) ) { return; } else if (a.Equals(b)) { return; } throw new AssertionError(); } static void assertNotEquals(object a, object b) { if ( (a == null) && (b == null) ) { throw new AssertionError(); } else if (a.Equals(b)) { throw new AssertionError(); } } static void assertEquals(bool a, bool b) { if ( a == b ) { return; } throw new AssertionError(); } static void assertNotEquals(bool a, bool b) { if ( a != b ) { return; } throw new AssertionError(); } static void assertEquals(int a, int b) { if ( a == b ) { return; } throw new AssertionError(); } static void assertNotEquals(int a, int b) { if ( a != b ) { return; } throw new AssertionError(); } public void test_XMLOutputStream_CharacterReference() { OStringStream oss = new OStringStream(); XMLOutputStream stream = new XMLOutputStream(oss,"",false); stream.startElement( "testcr"); stream.writeAttribute( "chars", "one" ); stream.writeAttribute( "amp", "&" ); stream.writeAttribute( "deccr", "¨" ); stream.writeAttribute( "hexcr", "¨"); stream.writeAttribute( "lhexcr", "¨"); stream.writeAttribute( "nodeccr1", "ژ" ); stream.writeAttribute( "nodeccr2", "&#;" ); stream.writeAttribute( "nodeccr3", "�a8;" ); stream.writeAttribute( "nodeccr4", "�A8;" ); stream.writeAttribute( "nohexcr1", "&#x;" ); stream.writeAttribute( "nohexcr2", "ꯍ" ); stream.endElement( "testcr"); string expected = ""; string s = oss.str(); assertTrue(( expected == s )); stream = null; } public void test_XMLOutputStream_Elements() { double d = 2.4; long l = 123456789; long ui = 5; long i = -3; OStringStream oss = new OStringStream(); XMLOutputStream stream = new XMLOutputStream(oss,"",false); stream.startElement( "fred"); stream.writeAttribute( "chars", "two"); stream.writeAttribute( "bool",true); stream.writeAttribute( "double",d); stream.writeAttribute( "long",l); stream.writeAttribute( "uint",ui); stream.writeAttribute( "int",i); stream.endElement( "fred"); string expected = "";; string s = oss.str(); assertTrue(( expected == s )); stream = null; } public void test_XMLOutputStream_PredefinedEntity() { OStringStream oss = new OStringStream(); XMLOutputStream stream = new XMLOutputStream(oss,"",false); stream.startElement( "testpde"); stream.writeAttribute( "amp", "&" ); stream.writeAttribute( "apos", "'" ); stream.writeAttribute( "gt", ">" ); stream.writeAttribute( "lt", "<" ); stream.writeAttribute( "quot", "\"" ); stream.writeAttribute( "pdeamp", "&" ); stream.writeAttribute( "pdeapos", "'"); stream.writeAttribute( "pdegt", ">" ); stream.writeAttribute( "pdelt", "<" ); stream.writeAttribute( "pdequot", """); stream.endElement( "testpde"); string expected = ""; string s = oss.str(); assertTrue(( expected == s )); stream = null; } public void test_XMLOutputStream_createStdout() { XMLOutputStream stream = new XMLOutputStream(libsbml.cout,"UTF-8",false); assertTrue( stream != null ); stream = null; } public void test_XMLOutputStream_createStdoutWithProgramInfo() { XMLOutputStream stream = new XMLOutputStream(libsbml.cout,"UTF-8",false, "foo", "bar"); assertTrue( stream != null ); stream = null; } public void test_XMLOutputStream_createString() { string expected = "\n";; OStringStream oss = new OStringStream(); XMLOutputStream stream = new XMLOutputStream(oss,"UTF-8",true); assertTrue( stream != null ); string str = oss.str(); assertTrue(( expected == str )); stream = null; } public void test_XMLOutputStream_createStringWithProgramInfo() { string expected = "\n";; OStringStream oss = new OStringStream(); XMLOutputStream stream = new XMLOutputStream(oss,"UTF-8",true, "", ""); assertTrue( stream != null ); string str = oss.str(); assertTrue(( expected == str )); stream = null; } public void test_XMLOutputStream_startEnd() { OStringStream oss = new OStringStream(); XMLOutputStream stream = new XMLOutputStream(oss,"",false); assertTrue( stream != null ); stream.startEndElement( "id"); string str = oss.str(); assertTrue(( "" == str )); stream = null; } } }