dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/tests/System.Xml TestXmlTextReader.c


From: adam ballai <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/tests/System.Xml TestXmlTextReader.cs,NONE,1.1 TestXml.cs,1.10,1.11
Date: Fri, 17 Jan 2003 16:55:20 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/tests/System.Xml
In directory subversions:/tmp/cvs-serv3285/tests/System.Xml

Modified Files:
        TestXml.cs 
Added Files:
        TestXmlTextReader.cs 
Log Message:


--- NEW FILE ---
/*
 * TestXmlTextReader.cs - Tests for the
 *              "System.Xml.TestXmlTextReader" class.
 *
 * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using CSUnit;
using System;
using System.IO;
using System.Text;
using System.Xml;

public class TestXmlTextReader : TestCase
{
        private XmlTextReader xmlReader;
        private StringReader stringReader;
        
        enum ReturnType : int
                        {
                                Name = 0,
                                Value = 1,
                                Innertext = 2,
                                InnerXml = 3,
                                OuterXml = 4,
                                LocalName = 5,
                                Prefix = 6
                        };
                
        private String[] xml = {"<soda 
caffeine=\"yes\">\n<size>medium</size>\n</soda>", 
                                        "<soda><size>medium</size></soda>"};

        
        // Constructor.
        public TestXmlTextReader(String name)
                        : base(name)
                        {
                                // Nothing to do here.
                        }

        // Set up for the tests.
        protected override void Setup()
                        {
                                stringReader = new StringReader(xml[0]);
                                xmlReader = new XmlTextReader(stringReader);
                        }

        // Clean up after the tests.
        protected override void Cleanup()
                        {
                                // Nothing to do here.
                        }

        // Check that the current contents of the output is a particular string.
        private void Check(String msg, String expected, ReturnType retType)
                        {
                                String actual;
                                switch (retType)
                                {
                                        case ReturnType.Name:
                                                actual = xmlReader.Name;
                                                break;
                                        case ReturnType.Value:
                                                actual = xmlReader.Value;
                                                break;
                                        case ReturnType.InnerXml:
                                                actual = 
xmlReader.ReadInnerXml();
                                                break;
                                        case ReturnType.OuterXml:
                                                actual = 
xmlReader.ReadOuterXml();
                                                break;
                                        case ReturnType.LocalName:
                                                actual = xmlReader.LocalName;
                                                break;
                                        case ReturnType.Prefix:
                                                actual = xmlReader.Prefix;
                                                break;
                                        default:
                                                // do nothing
                                                break;
                                }
                                
                                AssertEquals(msg, expected, actual);
                        }

        // Clear the current output.
        private void Clear()
                        {
                                xmlReader = null;
                        }

        // Reset the entire XML text reader.
        private void Reset()
                        {
                                xmlReader = new XmlTextReader(stringReader);
                        }

        // Test OuterXml.
        public void TestXmlTextReaderReadOuterXml()
                        {                                       
                                xmlReader.Read();
                                Check("ReadOuterXml (1)", xml[0], 
ReturnType.OuterXml);
                        
                                Reset();
                                stringReader = new StringReader(xml[1]);
                                xmlReader = new XmlTextReader(stringReader);
                                
                                xmlReader.Read();
                                Check("ReadOuterXml (2)", xml[1], 
ReturnType.OuterXml);

                                Clear();
                                        
                        }

        public void TestXmlTextReaderRead()
                        {
                                bool ret = xmlReader.Read();
                                AssertEquals("Read (1)", true, ret);
                                
                                Check("Read (2)", "soda", ReturnType.Name);
                                Check("Read (3)", "soda", ReturnType.LocalName);
                                
                                ret = xmlReader.Read();
                                AssertEquals("Read (4)", true, ret);
                        
                                ret = xmlReader.Read();
                                AssertEquals("Read (6)", true, ret);
                        
                                Check("Read (7)", "size", ReturnType.Name);
                                Check("Read (8)", "size", ReturnType.LocalName);

                                
                        }
                                

}; // class TestXmlTextWriter

Index: TestXml.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/tests/System.Xml/TestXml.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** TestXml.cs  13 Dec 2002 03:45:07 -0000      1.10
--- TestXml.cs  17 Jan 2003 21:55:18 -0000      1.11
***************
*** 42,45 ****
--- 42,49 ----
                                fullSuite.AddTest(suite);
  
+                               suite = new TestSuite("Reader Tests");
+                               suite.AddTests(typeof(TestXmlTextReader));
+                               fullSuite.AddTest(suite);
+ 
                        #if !ECMA_COMPAT
                                suite = new TestSuite("Node Tests");





reply via email to

[Prev in Thread] Current Thread [Next in Thread]