xmpp/structs_test.go
changeset 176 52c100897e9d
parent 172 36a42bc073f0
child 178 ccfebbd9f49b
equal deleted inserted replaced
175:fc8702a8572e 176:52c100897e9d
   106 		`"></bind></iq>`
   106 		`"></bind></iq>`
   107 	assertMarshal(t, exp, iq)
   107 	assertMarshal(t, exp, iq)
   108 }
   108 }
   109 
   109 
   110 func TestMarshalEscaping(t *testing.T) {
   110 func TestMarshalEscaping(t *testing.T) {
   111 	msg := &Message{Body: &Generic{XMLName: xml.Name{Local: "body"},
   111 	msg := &Message{Body: []Text{Text{XMLName: xml.Name{Local: "body"},
   112 		Chardata: `&<!-- "`}}
   112 		Chardata: `&<!-- "`}}}
   113 	exp := `<message xmlns="jabber:client"><body>&amp;&lt;!-- &#34;</body></message>`
   113 	exp := `<message xmlns="jabber:client"><body>&amp;&lt;!-- &#34;</body></message>`
   114 	assertMarshal(t, exp, msg)
   114 	assertMarshal(t, exp, msg)
   115 }
   115 }
   116 
   116 
   117 func TestUnmarshalMessage(t *testing.T) {
   117 func TestUnmarshalMessage(t *testing.T) {
   121 	cl := &Client{}
   121 	cl := &Client{}
   122 	go cl.recvXml(r, ch, make(map[xml.Name]reflect.Type))
   122 	go cl.recvXml(r, ch, make(map[xml.Name]reflect.Type))
   123 	obs := <-ch
   123 	obs := <-ch
   124 	exp := &Message{XMLName: xml.Name{Local: "message", Space: "jabber:client"},
   124 	exp := &Message{XMLName: xml.Name{Local: "message", Space: "jabber:client"},
   125 		Header: Header{To: "a@b.c", Innerxml: "<body>foo!</body>"},
   125 		Header: Header{To: "a@b.c", Innerxml: "<body>foo!</body>"},
   126 		Body: &Generic{XMLName: xml.Name{Local: "body", Space: "jabber:client"},
   126 		Body: []Text{Text{XMLName: xml.Name{Local: "body", Space: "jabber:client"},
   127 			Chardata: "foo!"}}
   127 			Chardata: "foo!"}}}
   128 	if !reflect.DeepEqual(obs, exp) {
   128 	if !reflect.DeepEqual(obs, exp) {
   129 		t.Errorf("read %s\ngot:  %#v\nwant: %#v\n", str, obs, exp)
   129 		t.Errorf("read %s\ngot:  %#v\nwant: %#v\n", str, obs, exp)
   130 	}
   130 	}
   131 	obsMsg, ok := obs.(*Message)
   131 	obsMsg, ok := obs.(*Message)
   132 	if !ok {
   132 	if !ok {