forked from jshiffer/go-xmpp
Resync with Master
Support NullableInt on MUC presence history element
This commit is contained in:
+40
-3
@@ -46,15 +46,52 @@ func TestMucHistory(t *testing.T) {
|
||||
|
||||
var parsedPresence stanza.Presence
|
||||
if err := xml.Unmarshal([]byte(str), &parsedPresence); err != nil {
|
||||
t.Errorf("Unmarshal(%s) returned error", str)
|
||||
t.Errorf("Unmarshal(%s) returned error: %s", str, err)
|
||||
return
|
||||
}
|
||||
|
||||
var muc stanza.MucPresence
|
||||
if ok := parsedPresence.Get(&muc); !ok {
|
||||
t.Error("muc presence extension was not found")
|
||||
return
|
||||
}
|
||||
|
||||
if muc.History.MaxStanzas != 20 {
|
||||
t.Errorf("incorrect max stanza: '%d'", muc.History.MaxStanzas)
|
||||
if v, ok := muc.History.MaxStanzas.Get(); !ok || v != 20 {
|
||||
t.Errorf("incorrect MaxStanzas: '%#v'", muc.History.MaxStanzas)
|
||||
}
|
||||
}
|
||||
|
||||
// https://xmpp.org/extensions/xep-0045.html#example-37
|
||||
func TestMucNoHistory(t *testing.T) {
|
||||
str := "<presence" +
|
||||
" id=\"n13mt3l\"" +
|
||||
" from=\"hag66@shakespeare.lit/pda\"" +
|
||||
" to=\"coven@chat.shakespeare.lit/thirdwitch\">" +
|
||||
"<x xmlns=\"http://jabber.org/protocol/muc\">" +
|
||||
"<history maxstanzas=\"0\"></history>" +
|
||||
"</x>" +
|
||||
"</presence>"
|
||||
|
||||
maxstanzas := 0
|
||||
|
||||
pres := stanza.Presence{Attrs: stanza.Attrs{
|
||||
From: "hag66@shakespeare.lit/pda",
|
||||
Id: "n13mt3l",
|
||||
To: "coven@chat.shakespeare.lit/thirdwitch",
|
||||
},
|
||||
Extensions: []stanza.PresExtension{
|
||||
stanza.MucPresence{
|
||||
History: stanza.History{MaxStanzas: stanza.NewNullableInt(maxstanzas)},
|
||||
},
|
||||
},
|
||||
}
|
||||
data, err := xml.Marshal(&pres)
|
||||
if err != nil {
|
||||
t.Error("error on encode:", err)
|
||||
return
|
||||
}
|
||||
|
||||
if string(data) != str {
|
||||
t.Errorf("incorrect stanza: \n%s\n%s", str, data)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user