PageRenderTime 30ms CodeModel.GetById 25ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/test-document.vala

http://libgdom3.googlecode.com/
Vala | 69 lines | 59 code | 10 blank | 0 comment | 8 complexity | 5bc56386f13c0297ee6e3a1630b73f0b MD5 | raw file
 1using DOM;
 2
 3class DocumentTest:TestMan {
 4	Document doc;
 5
 6	Element e1_ref;
 7	Element e2_ref;
 8	Element e1;
 9	Element e2;
10	DocumentTest () {
11		base("/DOM/Document");
12   		doc = new Document();
13		e1 = doc.createElement("e");
14		e2 = doc.createElement("e");
15
16		add ("getElementById/setId", () => {
17			e1.setAttribute("id", "e1");
18			e1_ref = doc.getElementById("e1");
19			assert(e1_ref == e1);
20		});
21
22		add ("getElementById/changeId", () => {
23			e1.setAttribute("id", "e1new");
24			e1_ref = doc.getElementById("e1");
25			assert(e1_ref == null);
26			e1_ref = doc.getElementById("e1new");
27			assert(e1_ref == e1);
28		});
29		
30		add ("getElementById/conflictId", () => {
31			e2.setAttribute("id", "e1new");
32			e1_ref = doc.getElementById("e1new");
33			assert(e1_ref == e1);
34		});
35
36		add ("getElementbyId/resolveConflictId", () => {
37			e2.setAttribute("id", "e2");
38			e2_ref = doc.getElementById("e2");
39			assert(e2_ref == e2);
40		});
41
42		add ("new/withElement", () => {
43			Document d = new Document.full(null, "root", null);
44			assert(d.documentElement != null);
45			assert(d.documentElement.nodeName == "root");
46		});
47
48		add ("insertBefore/doubleElements", () => {
49			Document d = new Document.full(null, "root", null);
50			assert(d.documentElement != null);
51			bool caught = false;
52			try {
53				d.appendChild(d.createElement("e"));
54			} catch (DOM.Exception.HIERARCHY_REQUEST_ERR e) {
55				Test.message("%s", e.message);
56				caught = true;
57			}
58			assert(caught);
59		});
60	}
61	public static int main(string[] args) {
62		Test.init(ref args);
63		TestMan c = new DocumentTest();
64		c.run();
65		return 0;
66	}
67	
68}
69