author | Chris Jones <chris@cjones.org> |
Sat, 31 Dec 2011 11:39:23 -0700 | |
changeset 38 | 2839fece923e |
parent 36 | 9fe022261dcc |
child 39 | 4a06f7ccfa84 |
permissions | -rw-r--r-- |
36
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
1 |
// Copyright 2011 The Go Authors. All rights reserved. |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
2 |
// Use of this source code is governed by a BSD-style |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
3 |
// license that can be found in the LICENSE file. |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
4 |
|
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
5 |
package xmpp |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
6 |
|
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
7 |
import ( |
38 | 8 |
"reflect" |
9 |
"strings" |
|
36
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
10 |
"testing" |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
11 |
"xml" |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
12 |
) |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
13 |
|
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
14 |
// This is mostly just tests of the roster data structures. |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
15 |
|
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
16 |
func TestRosterIqMarshal(t *testing.T) { |
38 | 17 |
iq := &Iq{From: "from", Lang: "en", Nested: |
36
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
18 |
RosterQuery{XMLName: xml.Name{Space: NsRoster, Local: |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
19 |
"query"}, Item: []RosterItem{}}} |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
20 |
exp := `<iq from="from" xml:lang="en"><query xmlns="` + |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
21 |
NsRoster + `"></query></iq>` |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
22 |
assertMarshal(t, exp, iq) |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
23 |
} |
38 | 24 |
|
25 |
func TestRosterIqUnmarshal(t *testing.T) { |
|
26 |
str := `<iq from="from" xml:lang="en"><query xmlns="` + |
|
27 |
NsRoster + `"><item jid="a@b.c"/></query></iq>` |
|
28 |
r := strings.NewReader(str) |
|
29 |
var st Stanza = &Iq{} |
|
30 |
xml.Unmarshal(r, st) |
|
31 |
err := parseExtended(st, newRosterQuery) |
|
32 |
if err != nil { |
|
33 |
t.Fatalf("parseExtended: %v", err) |
|
34 |
} |
|
35 |
assertEquals(t, "iq", st.XName()) |
|
36 |
assertEquals(t, "from", st.XFrom()) |
|
37 |
assertEquals(t, "en", st.XLang()) |
|
38 |
nested := st.XNested() |
|
39 |
if nested == nil { |
|
40 |
t.Fatalf("nested nil") |
|
41 |
} |
|
42 |
rq, ok := nested.(*RosterQuery) |
|
43 |
if !ok { |
|
44 |
t.Fatalf("nested not RosterQuery: %v", |
|
45 |
reflect.TypeOf(nested)) |
|
46 |
} |
|
47 |
if len(rq.Item) != 1 { |
|
48 |
t.Fatalf("Wrong # items: %v", rq.Item) |
|
49 |
} |
|
50 |
item := rq.Item[0] |
|
51 |
assertEquals(t, "a@b.c", item.Jid) |
|
52 |
} |