public void Test_Large_Partial() { count = 0; AsynchElementStream es = new AsynchElementStream(); es.OnElement += new ProtocolHandler(es_OnElement); es.Push(ENC.GetBytes("<stream>")); string test = "<presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='[email protected]/Home' to='[email protected]/Test'><priority>1</priority><c xmlns='http://jabber.org/protocol/caps' node='http://pidgin.im/caps' ver='2.3.1' ext='moodn nickn tunen avatar'/><x xmlns='vcard-temp:x:update'><photo>d206b82e4c1478ab033dacc55eacb1cfda7706c8</photo></x></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cancel'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence><presence from='*****@*****.**' to='[email protected]/Test' type='error'><error code='404' type='cance"; es.Push(ENC.GetBytes(test)); test = "l'><remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></presence>"; es.Push(ENC.GetBytes(test)); Assert.AreEqual(count, 20); }
public void Test_Large() { AsynchElementStream es = new AsynchElementStream(); // es.OnElement += new ProtocolHandler(jabOnElement); es.Push(ENC.GetBytes("<stream>")); byte[] buf = ENC.GetBytes("<test/>"); MemoryStream ms = new MemoryStream(); for (int i = 0; i < 1024; i++) { ms.Write(buf, 0, buf.Length); } es.Push(ms.ToArray()); }
bool ISocketEventListener.OnRead(BaseSocket sock, byte[] buf, int offset, int length) { Debug.Assert(m_listener != null); Debug.Assert(m_elements != null); m_listener.BytesRead(buf, offset, length); m_elements.Push(buf, offset, length); return(true); }
[Test] public void Test_Parse() { AsynchElementStream es = new AsynchElementStream(); es.AddFactory(new global::jabber.protocol.x.Factory()); es.OnElement += new ProtocolHandler(es_OnElement); es.Push(System.Text.Encoding.UTF8.GetBytes(tstring)); Assert.IsTrue(gotElement); }
bool ISocketEventListener.OnRead(BaseSocket sock, byte[] buf, int offset, int length) { int tim = (int)m_listener[Options.KEEP_ALIVE]; if (tim > 0) { m_timer.Change(tim, tim); } m_listener.BytesRead(buf, offset, length); try { m_elements.Push(buf, offset, length); } catch (Exception e) { ((ISocketEventListener)this).OnError(sock, e); sock.Close(); return(false); } return(true); }
/* * Try several ways to generate PartialTokenException. */ [Test] public void Test_Partial() { fail = false; AsynchElementStream es = new AsynchElementStream(); es.OnDocumentEnd += new ObjectHandler(jabOnEnd); es.Push(ENC.GetBytes("<stream>")); es.OnElement += new ProtocolHandler(jabOnElement); es.Push(ENC.GetBytes("<te")); are.WaitOne(100, true); Assert.IsTrue(!fail); es.Push(ENC.GetBytes("st/>")); es.Push(ENC.GetBytes("<test>")); es.Push(ENC.GetBytes("</")); es.Push(ENC.GetBytes("test>")); es.Push(ENC.GetBytes("<test>")); es.Push(ENC.GetBytes("16;est</test>")); es.Push(ENC.GetBytes("<test>")); es.Push(new byte[] { 0xC5 }); es.Push(new byte[] { 0x81 }); es.Push(ENC.GetBytes("</test>")); es.Push(ENC.GetBytes("<test f")); es.Push(ENC.GetBytes("oo='bar'/>")); es.Push(ENC.GetBytes("<test foo=")); es.Push(ENC.GetBytes("'bar'/>")); es.Push(ENC.GetBytes("<test foo='")); es.Push(ENC.GetBytes("bar'/>")); es.Push(new byte[] {}); }
bool ISocketEventListener.OnRead(BaseSocket sock, byte[] buf, int offset, int length) { m_listener.BytesRead(buf, offset, length); m_elements?.Push(buf, offset, length); return(true); }