xmpp/structs_test.go
author Chris Jones <chris@cjones.org>
Sat, 09 Nov 2013 12:22:01 -0700
changeset 179 4477c9f31f43
parent 178 ccfebbd9f49b
permissions -rw-r--r--
Added a JID.Bare() function, to product the bare JID as defined in the RFC.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
     1
package xmpp
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
     2
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
     3
import (
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
     4
	"bytes"
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
     5
	"encoding/xml"
114
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
     6
	"fmt"
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
     7
	"os"
115
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
     8
	"reflect"
114
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
     9
	"runtime"
115
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
    10
	"strings"
2
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    11
	"testing"
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    12
)
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    13
3
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    14
func assertEquals(t *testing.T, expected, observed string) {
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    15
	if expected != observed {
114
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    16
		file := "unknown"
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    17
		line := 0
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    18
		_, file, line, _ = runtime.Caller(1)
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    19
		fmt.Fprintf(os.Stderr, "%s:%d: Expected:\n%s\nObserved:\n%s\n",
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    20
			file, line, expected, observed)
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    21
		t.Fail()
3
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    22
	}
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    23
}
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    24
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    25
func TestJid(t *testing.T) {
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    26
	jid := JID("user@domain/res")
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    27
	assertEquals(t, "user", jid.Node())
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    28
	assertEquals(t, "domain", jid.Domain())
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    29
	assertEquals(t, "res", jid.Resource())
3
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    30
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    31
	jid = "domain.tld"
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    32
	if jid.Node() != "" {
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    33
		t.Errorf("Node: %v\n", jid.Node())
3
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    34
	}
178
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    35
	assertEquals(t, "domain.tld", jid.Domain())
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    36
	if jid.Resource() != "" {
ccfebbd9f49b Changed the JID type to be an alias of string, rather than a struct. This allows it to be used as a key in a map, among other benefits.
Chris Jones <chris@cjones.org>
parents: 172
diff changeset
    37
		t.Errorf("Resource: %v\n", jid.Resource())
3
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    38
	}
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    39
}
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    40
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    41
func assertMarshal(t *testing.T, expected string, marshal interface{}) {
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    42
	var buf bytes.Buffer
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    43
	enc := xml.NewEncoder(&buf)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    44
	err := enc.Encode(marshal)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    45
	if err != nil {
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    46
		t.Errorf("Marshal error for %s: %s", marshal, err)
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    47
	}
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    48
	observed := buf.String()
114
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    49
	if expected != observed {
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    50
		file := "unknown"
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    51
		line := 0
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    52
		_, file, line, _ = runtime.Caller(1)
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    53
		fmt.Fprintf(os.Stderr, "%s:%d: Expected:\n%s\nObserved:\n%s\n",
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    54
			file, line, expected, observed)
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    55
		t.Fail()
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    56
	}
3
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    57
}
6121aa2f21b1 Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents: 2
diff changeset
    58
2
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    59
func TestStreamMarshal(t *testing.T) {
22
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
    60
	s := &stream{To: "bob"}
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    61
	exp := `<stream:stream xmlns="` + NsClient +
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    62
		`" xmlns:stream="` + NsStream + `" to="bob">`
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    63
	assertEquals(t, exp, s.String())
2
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    64
22
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
    65
	s = &stream{To: "bob", From: "alice", Id: "#3", Version: "5.3"}
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    66
	exp = `<stream:stream xmlns="` + NsClient +
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    67
		`" xmlns:stream="` + NsStream + `" to="bob" from="alice"` +
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 3
diff changeset
    68
		` id="#3" version="5.3">`
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    69
	assertEquals(t, exp, s.String())
2
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    70
22
d6b7b4cbf50d Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents: 21
diff changeset
    71
	s = &stream{Lang: "en_US"}
98
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    72
	exp = `<stream:stream xmlns="` + NsClient +
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    73
		`" xmlns:stream="` + NsStream + `" xml:lang="en_US">`
c9cc4eda6dce Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents: 72
diff changeset
    74
	assertEquals(t, exp, s.String())
2
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    75
}
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    76
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    77
func TestStreamErrorMarshal(t *testing.T) {
34
7b1f924c75e2 Made the namespace constants public.
Chris Jones <chris@cjones.org>
parents: 31
diff changeset
    78
	name := xml.Name{Space: NsStreams, Local: "ack"}
31
1dc47df5c99f Made streamError non-public, and made a first attempt at a stream
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
    79
	e := &streamError{Any: Generic{XMLName: name}}
114
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    80
	exp := `<error xmlns="` + NsStream + `"><ack xmlns="` + NsStreams +
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    81
		`"></ack></error>`
2
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    82
	assertMarshal(t, exp, e)
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    83
6
8e425e340ca1 Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents: 3
diff changeset
    84
	txt := errText{Lang: "pt", Text: "things happen"}
31
1dc47df5c99f Made streamError non-public, and made a first attempt at a stream
Chris Jones <chris@cjones.org>
parents: 26
diff changeset
    85
	e = &streamError{Any: Generic{XMLName: name}, Text: &txt}
114
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    86
	exp = `<error xmlns="` + NsStream + `"><ack xmlns="` + NsStreams +
34
7b1f924c75e2 Made the namespace constants public.
Chris Jones <chris@cjones.org>
parents: 31
diff changeset
    87
		`"></ack><text xmlns="` + NsStreams +
114
a058e33c1666 Updated for the latest revision of the encoding/xml fixes: The context object owned by Encoder and Decoder isn't directly accessible.
Chris Jones <christian.jones@sri.com>
parents: 111
diff changeset
    88
		`" xml:lang="pt">things happen</text></error>`
2
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    89
	assertMarshal(t, exp, e)
4dabfef08c8c Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff changeset
    90
}
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    91
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    92
func TestIqMarshal(t *testing.T) {
111
36287f2cf06e Step 1 of moving to interface Stanza and embedded struct Header.
Chris Jones <chris@cjones.org>
parents: 110
diff changeset
    93
	iq := &Iq{Header: Header{Type: "set", Id: "3",
110
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 98
diff changeset
    94
		Nested: []interface{}{Generic{XMLName: xml.Name{Space: NsBind,
7696e6a01709 Instead of making Stanza an interface that Iq, Message, and Presence implement, change it to an embedded struct.
Chris Jones <chris@cjones.org>
parents: 98
diff changeset
    95
			Local: "bind"}}}}}
34
7b1f924c75e2 Made the namespace constants public.
Chris Jones <chris@cjones.org>
parents: 31
diff changeset
    96
	exp := `<iq id="3" type="set"><bind xmlns="` + NsBind +
12
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    97
		`"></bind></iq>`
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    98
	assertMarshal(t, exp, iq)
122ab6208c3c Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents: 7
diff changeset
    99
}
26
4d0a369079ce Removed the TextOut channel.
Chris Jones <chris@cjones.org>
parents: 25
diff changeset
   100
71
578c2a83dc18 Added a quick test of XML escaping.
Chris Jones <chris@cjones.org>
parents: 61
diff changeset
   101
func TestMarshalEscaping(t *testing.T) {
172
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
   102
	msg := &Message{Body: []Text{Text{XMLName: xml.Name{Local: "body"},
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
   103
		Chardata: `&<!-- "`}}}
115
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   104
	exp := `<message xmlns="jabber:client"><body>&amp;&lt;!-- &#34;</body></message>`
71
578c2a83dc18 Added a quick test of XML escaping.
Chris Jones <chris@cjones.org>
parents: 61
diff changeset
   105
	assertMarshal(t, exp, msg)
578c2a83dc18 Added a quick test of XML escaping.
Chris Jones <chris@cjones.org>
parents: 61
diff changeset
   106
}
115
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   107
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   108
func TestUnmarshalMessage(t *testing.T) {
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   109
	str := `<message to="a@b.c"><body>foo!</body></message>`
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   110
	r := strings.NewReader(str)
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   111
	ch := make(chan interface{})
163
3f891f7fe817 Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents: 147
diff changeset
   112
	cl := &Client{}
3f891f7fe817 Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents: 147
diff changeset
   113
	go cl.recvXml(r, ch, make(map[xml.Name]reflect.Type))
115
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   114
	obs := <-ch
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   115
	exp := &Message{XMLName: xml.Name{Local: "message", Space: "jabber:client"},
116
Chris Jones <christian.jones@sri.com>
parents: 115
diff changeset
   116
		Header: Header{To: "a@b.c", Innerxml: "<body>foo!</body>"},
172
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
   117
		Body: []Text{Text{XMLName: xml.Name{Local: "body", Space: "jabber:client"},
36a42bc073f0 Removed uses of Generic from the Stanza types.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
   118
			Chardata: "foo!"}}}
115
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   119
	if !reflect.DeepEqual(obs, exp) {
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   120
		t.Errorf("read %s\ngot:  %#v\nwant: %#v\n", str, obs, exp)
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   121
	}
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   122
	obsMsg, ok := obs.(*Message)
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   123
	if !ok {
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   124
		t.Fatalf("Not a Message: %T", obs)
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   125
	}
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   126
	obsBody := obsMsg.Body
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   127
	expBody := exp.Body
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   128
	if !reflect.DeepEqual(obsBody, expBody) {
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   129
		t.Errorf("body\ngot:  %#v\nwant: %#v\n", obsBody, expBody)
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   130
	}
7c45fc3f524a Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents: 114
diff changeset
   131
}