[Test] public void Test_Parse_7() { JID j = new JID("boo@foo/bar/baz"); Assert.AreEqual("boo", j.User); Assert.AreEqual("foo", j.Server); Assert.AreEqual("bar/baz", j.Resource); }
[Test] public void Test_Parse_9() { JID j = new JID("boo/foo@bar"); Assert.AreEqual(null, j.User); Assert.AreEqual("boo", j.Server); Assert.AreEqual("foo@bar", j.Resource); }
public void TestUserHost() { PresenceManager pp = new PresenceManager(); Presence pres = new Presence(doc); JID f = new JID("foo", "bar", null); pres.From = f; pp.AddPresence(pres); Assert.AreEqual("foo@bar", pp[f.Bare].From.ToString()); }
public void Setup() { mocks = new MockRepository(); stream = mocks.DynamicMock<XmppStream>(); tracker = mocks.DynamicMock<IIQTracker>(); doc = new XmlDocument(); jid = new JID("test.example.com"); }
[Test] public void Test_Create() { JID j = new JID("foo", "kixeye.jabber.com", "there"); Assert.AreEqual("[email protected]/there", j.ToString()); j = new JID(null, "kixeye.jabber.com", null); Assert.AreEqual("kixeye.jabber.com", j.ToString()); j = new JID("foo", "kixeye.jabber.com", null); Assert.AreEqual("*****@*****.**", j.ToString()); j = new JID(null, "kixeye.jabber.com", "there"); Assert.AreEqual("kixeye.jabber.com/there", j.ToString()); }
public void TestAdd() { PresenceManager pp = new PresenceManager(); Presence pres = new Presence(doc); JID f = new JID("foo", "bar", "baz"); pres.From = f; pp.AddPresence(pres); Assert.AreEqual("foo@bar/baz", pp[f].From.ToString()); f.Resource = null; Assert.AreEqual("foo@bar/baz", pp[f].From.ToString()); pres = new Presence(doc); pres.Status = "wandering"; pres.From = new JID("foo", "bar", "baz"); pp.AddPresence(pres); Assert.AreEqual("wandering", pp[f].Status); }
public void TestRetrieve() { PresenceManager pp = new PresenceManager(); Presence pres = new Presence(doc); JID f = new JID("foo", "bar", "baz"); pres.From = f; pres.Priority = "0"; pp.AddPresence(pres); Assert.AreEqual("foo@bar/baz", pp[f.Bare].From.ToString()); pres = new Presence(doc); f = new JID("foo", "bar", "bay"); pres.From = f; pres.Priority = "1"; pp.AddPresence(pres); Assert.AreEqual("foo@bar/bay", pp[f.Bare].From.ToString()); pres = new Presence(doc); pres.From = f; pres.Type = PresenceType.unavailable; pp.AddPresence(pres); Assert.AreEqual("foo@bar/baz", pp[f.Bare].From.ToString()); }
[Test] public void Test_Config() { JID j = new JID("config@-internal"); Assert.AreEqual("config", j.User); Assert.AreEqual("-internal", j.Server); Assert.AreEqual(null, j.Resource); }
public void TestNumeric() { PresenceManager pp = new PresenceManager(); Presence pres = new Presence(doc); JID f = new JID("support", "conference.192.168.32.109", "bob"); pres.From = f; pres.Status = "Working"; pp.AddPresence(pres); Assert.AreEqual("[email protected]/bob", pp[f].From.ToString()); f.Resource = null; Assert.AreEqual("[email protected]/bob", pp[f].From.ToString()); }
public void TestRemove() { PresenceManager pp = new PresenceManager(); Presence pres = new Presence(doc); JID f = new JID("foo", "bar", "baz"); pres.From = f; pres.Status = "Working"; pres.Priority = "1"; pp.AddPresence(pres); Assert.AreEqual("foo@bar/baz", pp[f].From.ToString()); f.Resource = null; Assert.AreEqual("foo@bar/baz", pp[f].From.ToString()); pres = new Presence(doc); pres.Status = "wandering"; pres.From = new JID("foo", "bar", "boo"); pp.AddPresence(pres); Assert.AreEqual("Working", pp[f].Status); pres.Priority = "2"; pp.AddPresence(pres); Assert.AreEqual("wandering", pp[f].Status); pres.Type = PresenceType.unavailable; pp.AddPresence(pres); Assert.AreEqual("Working", pp[f].Status); }
[Test] public void Test_EmptyResourceUser() { try { JID j = new JID("boo@foo/"); string u = j.User; Assert.IsTrue(false); } catch (JIDFormatException) { Assert.IsTrue(true); } catch (Exception) { Assert.IsTrue(false); } }
private void m_pres_OnPrimarySessionChange(object sender, JID bare) { Presence pres = m_pres[bare]; LinkedList nodelist = (LinkedList) m_items[bare.ToString()]; if (nodelist == null) return; foreach (ItemNode n in nodelist) { n.ChangePresence(pres); } }
public void Test_Unescape() { string u = new JID(@"d\[email protected]/elder").Unescape(); Assert.AreEqual("d'artagnan", u); u = new JID(@"space\[email protected]").Unescape(); Assert.AreEqual("space cadet", u); u = new JID(@"call\20me\20\22ishmael\[email protected]").Unescape(); Assert.AreEqual("call me \"ishmael\"", u); u = new JID(@"at\26t\[email protected]").Unescape(); Assert.AreEqual("at&t guy", u); u = new JID(@"\[email protected]").Unescape(); Assert.AreEqual("/.fanboy", u); u = new JID(@"\3a\3afoo\3a\[email protected]").Unescape(); Assert.AreEqual("::foo::", u); u = new JID(@"\3cfoo\[email protected]").Unescape(); Assert.AreEqual("<foo>", u); u = new JID(@"user\[email protected]").Unescape(); Assert.AreEqual("user@host", u); u = new JID(@"c\3a\[email protected]").Unescape(); Assert.AreEqual(@"c:\net", u); u = new JID(@"c\3a\5c\[email protected]").Unescape(); Assert.AreEqual(@"c:\\net", u); u = new JID(@"c\3a\5ccool\[email protected]").Unescape(); Assert.AreEqual(@"c:\cool stuff", u); u = new JID(@"c\3a\[email protected]").Unescape(); Assert.AreEqual(@"c:\5commas", u); u = new JID(@"\[email protected]").Unescape(); Assert.AreEqual(@"\c0", u); u = new JID(@"\[email protected]").Unescape(); Assert.AreEqual(@"\30", u); }
[Test] public void Test_Insensitive() { JID j = new JID("foo@boo/bar"); Assert.AreEqual(0, j.CompareTo(new JID("foo@BOO/bar"))); Assert.AreEqual(0, j.CompareTo(new JID("FOO@boo/bar"))); Assert.AreEqual(0, j.CompareTo(new JID("FOO@BOO/bar"))); Assert.AreEqual(-1, j.CompareTo(new JID("FOO@BOO/BAR"))); }
public void TestHostResource() { PresenceManager pp = new PresenceManager(); Presence pres = new Presence(doc); JID f = new JID(null, "bar", "baz"); pres.From = f; pp.AddPresence(pres); Assert.AreEqual("bar/baz", pp[f.Bare].From.ToString()); }
[Test] public void Test_BadCompare() { try { JID j = new JID("foo@boo/bar"); j.CompareTo("foo@boo/bar"); Assert.IsTrue(false); } catch (ArgumentException) { Assert.IsTrue(true); } catch (Exception) { Assert.IsTrue(false); } }
[Test] public void Test_Compare_Greater() { JID j = new JID("foo@bar/baz"); Assert.AreEqual(1, j.CompareTo(new JID("foo@bap/baz"))); Assert.AreEqual(1, j.CompareTo(new JID("fon@bar/baz"))); Assert.AreEqual(1, j.CompareTo(new JID("foo@bar/bay"))); Assert.AreEqual(1, j.CompareTo(new JID("foo@bar"))); Assert.AreEqual(1, j.CompareTo(new JID("bar"))); Assert.AreEqual(1, j.CompareTo(new JID("bar/baz"))); j = new JID("foo@bar"); Assert.AreEqual(1, j.CompareTo(new JID("foo@bap/baz"))); Assert.AreEqual(1, j.CompareTo(new JID("fon@bar/baz"))); Assert.AreEqual(1, j.CompareTo(new JID("bar"))); Assert.AreEqual(1, j.CompareTo(new JID("bar/baz"))); Assert.AreEqual(true, j > new JID("foo@bap/baz")); Assert.AreEqual(true, j >= new JID("foo@bap/baz")); // /me runs out of interest. }
[Test] public void Test_Compare_Less() { JID j = new JID("foo@bar/baz"); Assert.AreEqual(-1, j.CompareTo(new JID("foo@bas/baz"))); Assert.AreEqual(-1, j.CompareTo(new JID("fop@bar/baz"))); Assert.AreEqual(-1, j.CompareTo(new JID("foo@bar/bazz"))); j = new JID("foo@bar"); Assert.AreEqual(-1, j.CompareTo(new JID("foo@bas/baz"))); Assert.AreEqual(-1, j.CompareTo(new JID("foo@bas"))); Assert.AreEqual(-1, j.CompareTo(new JID("fop@bar/baz"))); Assert.AreEqual(-1, j.CompareTo(new JID("fop@bar"))); Assert.AreEqual(-1, j.CompareTo(new JID("foo@bar/baz"))); j = new JID("bar"); Assert.AreEqual(-1, j.CompareTo(new JID("foo@bar/baz"))); Assert.AreEqual(-1, j.CompareTo(new JID("foo@bar"))); Assert.AreEqual(-1, j.CompareTo(new JID("bas"))); Assert.AreEqual(-1, j.CompareTo(new JID("bas/baz"))); Assert.AreEqual(-1, j.CompareTo(new JID("bar/baz"))); Assert.AreEqual(true, j < new JID("foo@bar/baz")); Assert.AreEqual(true, j <= new JID("foo@bar/baz")); }
[Test] public void Test_Compare_Equal() { JID j = new JID("foo@bar/baz"); Assert.AreEqual(0, j.CompareTo(j)); Assert.AreEqual(0, j.CompareTo(new JID("foo@bar/baz"))); j = new JID("foo@bar"); Assert.AreEqual(0, j.CompareTo(j)); Assert.AreEqual(0, j.CompareTo(new JID("foo@bar"))); Assert.IsTrue(j == new JID("foo@bar")); Assert.IsTrue(j == new JID("foo@BAR")); Assert.IsTrue(j == new JID("FOO@BAR")); Assert.IsTrue(j == new JID("FOO@bar")); Assert.AreEqual(new JID("FOO@bar").GetHashCode(), j.GetHashCode()); j = new JID("bar"); Assert.AreEqual(0, j.CompareTo(j)); Assert.AreEqual(0, j.CompareTo(new JID("bar"))); j = new JID("foo/bar"); Assert.AreEqual(0, j.CompareTo(j)); Assert.AreEqual(0, j.CompareTo(new JID("foo/bar"))); Assert.AreEqual(true, j >= new JID("foo/bar")); Assert.AreEqual(true, j <= new JID("foo/bar")); }
[Test] public void Test_TwoAt() { try { JID j = new JID("boo@foo@bar"); string u = j.User; Assert.IsTrue(false); } catch (JIDFormatException) { Assert.IsTrue(true); } catch (Exception) { Assert.IsTrue(false); } }
[Test] public void Test_Numeric() { JID j = new JID("support", "conference.192.168.32.109", "bob"); Assert.AreEqual("conference.192.168.32.109", j.Server); }
public Class1(string[] args) { JabberClient jc = new JabberClient(); jc.OnReadText += new Kixeye.Bedrock.TextHandler(jc_OnReadText); jc.OnWriteText += new Kixeye.Bedrock.TextHandler(jc_OnWriteText); jc.OnError +=new Kixeye.Bedrock.ExceptionHandler(jc_OnError); jc.OnStreamError += new Kixeye.Jabber.Protocol.ProtocolHandler(jc_OnStreamError); jc.AutoReconnect = 3f; GetOpt go = new GetOpt(this); try { go.Process(args); } catch (ArgumentException) { go.UsageExit(); } if (untrustedOK) jc.OnInvalidCertificate += new System.Net.Security.RemoteCertificateValidationCallback(jc_OnInvalidCertificate); JID j = new JID(jid); jc.User = j.User; jc.Server = j.Server; jc.NetworkHost = networkHost; jc.Port = port; jc.Resource = "Jabber.Net Console Client"; jc.Password = pass; jc.AutoStartTLS = TLS; jc.AutoPresence = initialPresence; if (certificateFile != null) { jc.SetCertificateFile(certificateFile, certificatePass); Console.WriteLine(jc.LocalCertificate.ToString(true)); } if (boshURL != null) { jc[Options.POLL_URL] = boshURL; jc[Options.CONNECTION_TYPE] = ConnectionType.HTTP_Binding; } if (register) { jc.AutoLogin = false; jc.OnLoginRequired += new Kixeye.Bedrock.ObjectHandler(jc_OnLoginRequired); jc.OnRegisterInfo += new RegisterInfoHandler(this.jc_OnRegisterInfo); jc.OnRegistered += new IQHandler(jc_OnRegistered); } CapsManager cm = new CapsManager(); cm.Stream = jc; cm.Node = "http://cursive.net/clients/ConsoleClient"; Console.WriteLine("Connecting"); jc.Connect(); Console.WriteLine("Connected"); string line; while ((line = Console.ReadLine()) != null) { if (line == "/clear") { // Hm.... I wonder if this works on windows. Console.Write("\x1b[H\x1b[2J"); continue; } if ((line == "/q") || (line == "/quit")) { jc.Close(); break; } if (line.Trim() == "") { continue; } try { if (line == "</stream:stream>") { jc.Write(line); } else { // TODO: deal with stanzas that span lines... keep // parsing until we have a full "doc". XmlDocument doc = new XmlDocument(); doc.LoadXml(line); XmlElement elem = doc.DocumentElement; if (elem != null) jc.Write(elem); } } catch (XmlException ex) { Console.WriteLine("Invalid XML: " + ex.Message); } } }