File: test_document.py

package info (click to toggle)
qm 1.1.3-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,628 kB
  • ctags: 10,249
  • sloc: python: 41,482; ansic: 20,611; xml: 12,837; sh: 485; makefile: 226
file content (156 lines) | stat: -rw-r--r-- 3,076 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from util import error
from util import testAttribute

CLONE_TEST_ENABLED = 0

def test():
	print 'Testing Syntax'
	from xml.dom.html.HTMLDocument import HTMLDocument
	from xml.dom import implementation

	d = implementation.createHTMLDocument('')
	print 'testing title'
	
	if d._get_title() != '':
		error('getTitle failed with no title');

	#This will test ADC
	d._set_title('TEST');
	if d._get_title() != 'TEST':
		error('get/set title failed with body')

	#Print test replace of a child

	d._set_title('TEST2');

	if d._get_title() != 'TEST2':
		error('replace a title failed')

	print 'title works'
	#d.removeChild(h);

	print 'testing documentElement'
	if d.documentElement == None:
		error('documentElement ADC failed');
	print 'documentElement works'

	print 'testing body'

	if d._get_body() == None:
		error('body ADC failed');

	b = d.createElement('BODY');
	d._set_body(b)
	if d._get_body().nodeName != b.nodeName:
		error('body failed on replace');
	
	print 'get/set Body works'

	print 'testing getImages'

	i = d.createElement('Img');

	b.appendChild(i);

	hc = d._get_images()
	if hc.length != 1:
		error('getImages failed');

	print 'getImages works'

	print 'getApplets'

	a = d.createElement('Applet');
	o = d.createElement('Object');
	o._set_code('TEST');

	hc = d._get_applets()
	if hc.length != 0:
		error('getApplets failed with none');

	b.appendChild(a);

	hc = d._get_applets();

	if hc.length != 1:
		error('getApplets failed for applets');

	b.appendChild(o)
	
	hc = d._get_applets()

	if hc.length != 2:
		error('getApplets failed for object');

	print 'getApplets works'

	print 'testing getLinks'

	a1 = d.createElement('Area');
	a1._set_href('TEST')
	a2 = d.createElement('A');
	a2._set_href('TEST')

	if d._get_links().length != 0:
		error('getLinks failed with no Links');

	b.appendChild(a1);

	if d._get_links().length != 1:
		error('getLinks failed with Area');

	b.appendChild(a2);
	if d._get_links().length != 2:
		error('getLinks failed with Anchor');

	print 'getLinks works'

	print 'testing getForms';

	if d._get_forms().length != 0:
		error('getForms failed with no Forms');

	f = d.createElement('FORM');

	b.appendChild(f);
	if d._get_forms().length != 1:
		error('getForms failed with a form');	

	print 'getForms works'

	print 'testing getAnchors'

	if d._get_anchors().length != 0:
		error('get Anchors failed with none in there');

	a2._set_name('TEST');

	if d._get_anchors().length != 1:
		error('getAnchors failed with an Anchor');

	print 'getAnchors works'

	testAttribute(d,'cookie');


	if CLONE_TEST_ENABLED:
		print 'test cloneNode (deep)'
		d2 = d.cloneNode(1)

		if d2._get_referrer() != d._get_referrer():
			error('cloneNode did not set referrer');	
		if d2._get_domain() != d._get_domain():
			error('cloneNode did not set Domain');	
		if d2._get_URL() != d._get_URL():
			error('cloneNode did not set URL');	
		if d2._get_cookie() != d._get_cookie():
			error('cloneNode did not set cookie');	
	else:
		print "NOTE: DOCUMENT CLONE TEST SKIPPED"

	print 'cloneNode works'


if __name__ == '__main__':

	test();