49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
-
+
-
+
-
+
-
+
|
XMPPPresence *pres = [XMPPPresence presence];
[pres addShow: @"chat"];
[pres addStatus: @"Bored"];
[pres addPriority: 20];
[pres setTo: [XMPPJID JIDWithString: @"alice@example.com"]];
[pres setFrom: [XMPPJID JIDWithString: @"bob@example.org"]];
assert([[pres stringValue] isEqual: @"<presence to='alice@example.com' "
assert([[pres XMLString] isEqual: @"<presence to='alice@example.com' "
@"from='bob@example.org'><show>chat</show>"
@"<status>Bored</status><priority>20</priority>"
@"</presence>"]);
XMPPMessage *msg = [XMPPMessage messageWithType: @"chat"];
[msg addBody: @"Hello everyone"];
[msg setTo: [XMPPJID JIDWithString: @"jdev@conference.jabber.org"]];
[msg setFrom: [XMPPJID JIDWithString: @"alice@example.com"]];
assert([[msg stringValue] isEqual: @"<message type='chat' "
assert([[msg XMLString] isEqual: @"<message type='chat' "
@"to='jdev@conference.jabber.org' "
@"from='alice@example.com'><body>Hello everyone</body>"
@"</message>"]);
XMPPIQ *iq = [XMPPIQ IQWithType: @"set" ID: @"128"];
[iq setTo: [XMPPJID JIDWithString: @"juliet@capulet.lit"]];
[iq setFrom: [XMPPJID JIDWithString: @"romeo@montague.lit"]];
assert([[iq stringValue] isEqual: @"<iq type='set' id='128' "
assert([[iq XMLString] isEqual: @"<iq type='set' id='128' "
@"to='juliet@capulet.lit' "
@"from='romeo@montague.lit'/>"]);
OFXMLElement *elem = [OFXMLElement elementWithName: @"iq"];
[elem addAttributeWithName: @"from"
stringValue: @"bob@localhost"];
[elem addAttributeWithName: @"to"
stringValue: @"alice@localhost"];
[elem addAttributeWithName: @"type"
stringValue: @"get"];
[elem addAttributeWithName: @"id"
stringValue: @"42"];
XMPPStanza *stanza = [XMPPStanza stanzaWithElement: elem];
assert([[elem stringValue] isEqual: [stanza stringValue]]);
assert([[elem XMLString] isEqual: [stanza XMLString]]);
assert(([[OFString stringWithFormat: @"%@, %@, %@, %@",
[[stanza from] fullJID], [[stanza to] fullJID], [stanza type],
[stanza ID]] isEqual: @"bob@localhost, alice@localhost, get, 42"]));
conn = [[XMPPConnection alloc] init];
[conn setDelegate: self];
|