author | Chris Jones <christian.jones@sri.com> |
Thu, 19 Jan 2012 22:57:36 -0700 | |
changeset 84 | 25c4296a3524 |
parent 75 | 03a923eb5c01 |
child 93 | fbd51fa6b7ea |
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 ( |
74
e619e18dcec3
Ran gofix from weekly-2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
72
diff
changeset
|
8 |
"encoding/xml" |
38 | 9 |
"reflect" |
10 |
"strings" |
|
36
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
11 |
"testing" |
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) { |
72 | 17 |
iq := &Iq{From: "from", Lang: "en", Nested: []interface{}{RosterQuery{}}} |
36
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
18 |
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
|
19 |
NsRoster + `"></query></iq>` |
9fe022261dcc
Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff
changeset
|
20 |
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
|
21 |
} |
38 | 22 |
|
23 |
func TestRosterIqUnmarshal(t *testing.T) { |
|
24 |
str := `<iq from="from" xml:lang="en"><query xmlns="` + |
|
25 |
NsRoster + `"><item jid="a@b.c"/></query></iq>` |
|
26 |
r := strings.NewReader(str) |
|
27 |
var st Stanza = &Iq{} |
|
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
28 |
err := xml.Unmarshal(r, st) |
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
29 |
if err != nil { |
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
30 |
t.Fatalf("Unmarshal: %v", err) |
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
31 |
} |
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
32 |
assertEquals(t, "from", st.GetFrom()) |
72 | 33 |
m := map[string]func(*xml.Name) interface{}{NsRoster: newRosterQuery} |
75
03a923eb5c01
Updated for weekly.2012-01-15.
Chris Jones <christian.jones@sri.com>
parents:
74
diff
changeset
|
34 |
err = parseExtended(st, m) |
38 | 35 |
if err != nil { |
36 |
t.Fatalf("parseExtended: %v", err) |
|
37 |
} |
|
42
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
39
diff
changeset
|
38 |
assertEquals(t, "iq", st.GetName()) |
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
39
diff
changeset
|
39 |
assertEquals(t, "from", st.GetFrom()) |
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
39
diff
changeset
|
40 |
assertEquals(t, "en", st.GetLang()) |
f6bb47ca12f2
Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
Chris Jones <chris@cjones.org>
parents:
39
diff
changeset
|
41 |
nested := st.GetNested() |
38 | 42 |
if nested == nil { |
43 |
t.Fatalf("nested nil") |
|
44 |
} |
|
61
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
42
diff
changeset
|
45 |
if len(nested) != 1 { |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
42
diff
changeset
|
46 |
t.Fatalf("wrong size nested(%d): %v", len(nested), |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
42
diff
changeset
|
47 |
nested) |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
42
diff
changeset
|
48 |
} |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
42
diff
changeset
|
49 |
var rq *RosterQuery |
16513974d273
Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents:
42
diff
changeset
|
50 |
rq, ok := nested[0].(*RosterQuery) |
38 | 51 |
if !ok { |
52 |
t.Fatalf("nested not RosterQuery: %v", |
|
53 |
reflect.TypeOf(nested)) |
|
54 |
} |
|
55 |
if len(rq.Item) != 1 { |
|
56 |
t.Fatalf("Wrong # items: %v", rq.Item) |
|
57 |
} |
|
58 |
item := rq.Item[0] |
|
59 |
assertEquals(t, "a@b.c", item.Jid) |
|
60 |
} |