Пример #1
0
        public void CheckIfDisposed()
        {
            var newParser = new ExpatParser("ascii");

            var xml    = "<foo xmlns='urn:bar' />";
            var buffer = Encoding.UTF8.GetBytes(xml);

            newParser.Parse(buffer, buffer.Length);

            Assert.AreNotEqual(IntPtr.Zero, newParser.GetPointer());
            Assert.IsFalse(newParser.IsDisposed);
            Console.WriteLine("Pointer Before Dispose: " + newParser.GetPointer());
            newParser.Dispose();

            try
            {
                Assert.AreEqual(IntPtr.Zero, newParser.GetPointer());
                Assert.IsTrue(newParser.IsDisposed);
                Console.WriteLine("Pointer After Dispose: " + newParser.GetPointer());

                newParser.Parse(buffer, buffer.Length); // This MUST thrown exception.
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is ObjectDisposedException, $"Unknownu nhandled eception.\n{ex}");
            }
        }
Пример #2
0
        public void ParserXmlThenResetParser(string encoding)
        {
            var xml    = "<foo>";
            var buffer = Encoding.UTF8.GetBytes(xml);

            var objParser = new ExpatParser(encoding);

            objParser.Parse(buffer, buffer.Length, true);
            Assert.IsTrue(objParser.Reset());

            Console.WriteLine($"Byte Index: {parser.ByteIndex}");
            Console.WriteLine($"Byte Index: {parser.ByteCount}");

            Console.WriteLine("Lets reset the parser!");
            objParser.Parse(buffer, buffer.Length, true);

            Console.WriteLine($"Byte Index: {parser.ByteIndex}");
            Console.WriteLine($"Byte Index: {parser.ByteCount}");

            objParser.Dispose();
        }
Пример #3
0
 public void Configure()
 {
     parser = new ExpatParser("utf-8");
     parser.SetElementHandler(OnStartElement, OnEndElement);
 }