2009-11-23 04:16:27 +00:00
|
|
|
package xmlx
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2009-11-25 01:50:06 +00:00
|
|
|
func TestLoadLocal(t *testing.T) {
|
2009-11-23 04:16:27 +00:00
|
|
|
doc := New();
|
|
|
|
err := doc.LoadFile("test.xml");
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(doc.Root.Children) == 0 {
|
2009-11-23 04:49:44 +00:00
|
|
|
t.Errorf("Root node has no children.");
|
2009-11-23 04:16:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-25 01:50:06 +00:00
|
|
|
func TestLoadRemote(t *testing.T) {
|
|
|
|
doc := New();
|
|
|
|
err := doc.LoadUri("http://tldp.org/authors/template/Sample-HOWTO.xml");
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(doc.Root.Children) == 0 {
|
|
|
|
t.Errorf("Root node has no children.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-23 04:16:27 +00:00
|
|
|
func TestSave(t *testing.T) {
|
|
|
|
doc := New();
|
|
|
|
err := doc.LoadFile("test.xml");
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("LoadFile(): %s", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = doc.SaveFile("test1.xml");
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("SaveFile(): %s", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeSearch(t *testing.T) {
|
|
|
|
doc := New();
|
|
|
|
err := doc.LoadFile("test.xml");
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("LoadFile(): %s", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node := doc.SelectNode("", "item");
|
|
|
|
if node == nil {
|
|
|
|
t.Errorf("SelectNode(): No node found.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes := doc.SelectNodes("", "item");
|
|
|
|
if len(nodes) == 0 {
|
|
|
|
t.Errorf("SelectNodes(): no nodes found.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|