author | Chris Jones <christian.jones@sri.com> |
Sun, 15 Sep 2013 16:41:02 -0600 | |
changeset 150 | fa7f6ff10c67 |
parent 147 | d7679d991b17 |
child 163 | 3f891f7fe817 |
permissions | -rw-r--r-- |
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) { |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
26 |
str := "user@domain/res" |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
27 |
jid := &JID{} |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
28 |
if err := jid.Set(str); err != nil { |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
29 |
t.Errorf("Set(%s) failed: %s", str, err) |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
30 |
} |
25
7437d6eed227
Made JID.Node a string rather than *string. This is more appropriate
Chris Jones <chris@cjones.org>
parents:
24
diff
changeset
|
31 |
assertEquals(t, "user", jid.Node) |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
32 |
assertEquals(t, "domain", jid.Domain) |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
33 |
assertEquals(t, "res", jid.Resource) |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
34 |
assertEquals(t, str, jid.String()) |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
35 |
|
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
36 |
str = "domain.tld" |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
37 |
if err := jid.Set(str); err != nil { |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
38 |
t.Errorf("Set(%s) failed: %s", str, err) |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
39 |
} |
25
7437d6eed227
Made JID.Node a string rather than *string. This is more appropriate
Chris Jones <chris@cjones.org>
parents:
24
diff
changeset
|
40 |
if jid.Node != "" { |
7437d6eed227
Made JID.Node a string rather than *string. This is more appropriate
Chris Jones <chris@cjones.org>
parents:
24
diff
changeset
|
41 |
t.Errorf("Node: %v\n", jid.Node) |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
42 |
} |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
43 |
assertEquals(t, "domain.tld", jid.Domain) |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
44 |
if jid.Resource != "" { |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
45 |
t.Errorf("Resource: %v\n", jid.Resource) |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
46 |
} |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
47 |
assertEquals(t, str, jid.String()) |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
48 |
} |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
49 |
|
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
50 |
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
|
51 |
var buf bytes.Buffer |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
52 |
enc := xml.NewEncoder(&buf) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
53 |
err := enc.Encode(marshal) |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
54 |
if err != nil { |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
55 |
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
|
56 |
} |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
_, 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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
} |
3
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
66 |
} |
6121aa2f21b1
Made JID implement flag.Value.
Chris Jones <chris@cjones.org>
parents:
2
diff
changeset
|
67 |
|
2
4dabfef08c8c
Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
68 |
func TestStreamMarshal(t *testing.T) { |
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
69 |
s := &stream{To: "bob"} |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
70 |
exp := `<stream:stream xmlns="` + NsClient + |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
71 |
`" xmlns:stream="` + NsStream + `" to="bob">` |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
72 |
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
|
73 |
|
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
74 |
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
|
75 |
exp = `<stream:stream xmlns="` + NsClient + |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
76 |
`" 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
|
77 |
` id="#3" version="5.3">` |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
78 |
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
|
79 |
|
22
d6b7b4cbf50d
Made the stream type non-public.
Chris Jones <chris@cjones.org>
parents:
21
diff
changeset
|
80 |
s = &stream{Lang: "en_US"} |
98
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
81 |
exp = `<stream:stream xmlns="` + NsClient + |
c9cc4eda6dce
Updated for Go 1.0 + upcoming XML fixes.
Chris Jones <chris@cjones.org>
parents:
72
diff
changeset
|
82 |
`" 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
|
83 |
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
|
84 |
} |
4dabfef08c8c
Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
85 |
|
4dabfef08c8c
Forgot to add the new xmpp.go from my last commit. Also added some
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
86 |
func TestStreamErrorMarshal(t *testing.T) { |
34
7b1f924c75e2
Made the namespace constants public.
Chris Jones <chris@cjones.org>
parents:
31
diff
changeset
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
`"></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
|
91 |
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
|
92 |
|
6
8e425e340ca1
Implemented writing to the remote. Now we have bidirectional communication.
Chris Jones <christian.jones@sri.com>
parents:
3
diff
changeset
|
93 |
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
|
94 |
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
|
95 |
exp = `<error xmlns="` + NsStream + `"><ack xmlns="` + NsStreams + |
34
7b1f924c75e2
Made the namespace constants public.
Chris Jones <chris@cjones.org>
parents:
31
diff
changeset
|
96 |
`"></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
|
97 |
`" 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
|
98 |
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
|
99 |
} |
12
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
100 |
|
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
Local: "bind"}}}}} |
34
7b1f924c75e2
Made the namespace constants public.
Chris Jones <chris@cjones.org>
parents:
31
diff
changeset
|
105 |
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
|
106 |
`"></bind></iq>` |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
107 |
assertMarshal(t, exp, iq) |
122ab6208c3c
Added resource binding and structures for <iq>, <message>, and <presence>.
Chris Jones <chris@cjones.org>
parents:
7
diff
changeset
|
108 |
} |
26 | 109 |
|
71
578c2a83dc18
Added a quick test of XML escaping.
Chris Jones <chris@cjones.org>
parents:
61
diff
changeset
|
110 |
func TestMarshalEscaping(t *testing.T) { |
578c2a83dc18
Added a quick test of XML escaping.
Chris Jones <chris@cjones.org>
parents:
61
diff
changeset
|
111 |
msg := &Message{Body: &Generic{XMLName: xml.Name{Local: "body"}, |
578c2a83dc18
Added a quick test of XML escaping.
Chris Jones <chris@cjones.org>
parents:
61
diff
changeset
|
112 |
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
|
113 |
exp := `<message xmlns="jabber:client"><body>&<!-- "</body></message>` |
71
578c2a83dc18
Added a quick test of XML escaping.
Chris Jones <chris@cjones.org>
parents:
61
diff
changeset
|
114 |
assertMarshal(t, exp, msg) |
578c2a83dc18
Added a quick test of XML escaping.
Chris Jones <chris@cjones.org>
parents:
61
diff
changeset
|
115 |
} |
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
|
116 |
|
7c45fc3f524a
Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents:
114
diff
changeset
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
ch := make(chan interface{}) |
147
d7679d991b17
Function renames and improved doc.
Chris Jones <christian.jones@sri.com>
parents:
142
diff
changeset
|
121 |
go 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
|
122 |
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
|
123 |
exp := &Message{XMLName: xml.Name{Local: "message", Space: "jabber:client"}, |
116 | 124 |
Header: Header{To: "a@b.c", Innerxml: "<body>foo!</body>"}, |
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
|
125 |
Body: &Generic{XMLName: xml.Name{Local: "body", Space: "jabber:client"}, |
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 |
Chardata: "foo!"}} |
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 |
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
|
128 |
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
|
129 |
} |
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 |
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
|
131 |
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
|
132 |
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
|
133 |
} |
7c45fc3f524a
Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents:
114
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
} |
7c45fc3f524a
Put the sub-elements of Message and Presence into the jabber:client namespace.
Chris Jones <christian.jones@sri.com>
parents:
114
diff
changeset
|
139 |
} |