81 `" xml:lang="pt">things happen</text></stream:error>` |
81 `" xml:lang="pt">things happen</text></stream:error>` |
82 assertMarshal(t, exp, e) |
82 assertMarshal(t, exp, e) |
83 } |
83 } |
84 |
84 |
85 func TestIqMarshal(t *testing.T) { |
85 func TestIqMarshal(t *testing.T) { |
86 iq := &Iq{Type: "set", Id: "3", Any: &Generic{XMLName: |
86 iq := &Iq{Type: "set", Id: "3", Nested: |
87 xml.Name{Space: NsBind, Local: "bind"}}} |
87 []interface{}{Generic{XMLName: xml.Name{Space: NsBind, |
|
88 Local: "bind"}}}} |
88 exp := `<iq id="3" type="set"><bind xmlns="` + NsBind + |
89 exp := `<iq id="3" type="set"><bind xmlns="` + NsBind + |
89 `"></bind></iq>` |
90 `"></bind></iq>` |
90 assertMarshal(t, exp, iq) |
91 assertMarshal(t, exp, iq) |
91 } |
92 } |
92 |
93 |
104 assertEquals(t, "A", st.GetType()) |
105 assertEquals(t, "A", st.GetType()) |
105 assertEquals(t, "en", st.GetLang()) |
106 assertEquals(t, "en", st.GetLang()) |
106 if st.GetError() != nil { |
107 if st.GetError() != nil { |
107 t.Errorf("iq: error %v", st.GetError()) |
108 t.Errorf("iq: error %v", st.GetError()) |
108 } |
109 } |
109 if st.generic() == nil { |
110 if st.innerxml() == "" { |
110 t.Errorf("iq: nil child") |
111 t.Errorf("iq: empty child") |
111 } |
112 } |
112 assertEquals(t, "foo", st.generic().XMLName.Local) |
113 assertEquals(t, "<foo>text</foo>", st.innerxml()) |
113 assertEquals(t, "text", st.generic().Chardata) |
|
114 |
114 |
115 str = `<message to="alice" from="bob"/>` |
115 str = `<message to="alice" from="bob"/>` |
116 st, err = ParseStanza(str) |
116 st, err = ParseStanza(str) |
117 if err != nil { |
117 if err != nil { |
118 t.Fatalf("message: %v", err) |
118 t.Fatalf("message: %v", err) |
123 assertEquals(t, "", st.GetId()) |
123 assertEquals(t, "", st.GetId()) |
124 assertEquals(t, "", st.GetLang()) |
124 assertEquals(t, "", st.GetLang()) |
125 if st.GetError() != nil { |
125 if st.GetError() != nil { |
126 t.Errorf("message: error %v", st.GetError()) |
126 t.Errorf("message: error %v", st.GetError()) |
127 } |
127 } |
128 if st.generic() != nil { |
128 if st.innerxml() != "" { |
129 t.Errorf("message: child %v", st.generic()) |
129 t.Errorf("message: child %v", st.innerxml()) |
130 } |
130 } |
131 |
131 |
132 str = `<presence/>` |
132 str = `<presence/>` |
133 st, err = ParseStanza(str) |
133 st, err = ParseStanza(str) |
134 if err != nil { |
134 if err != nil { |