libxml-ruby 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/CHANGES +1 -1
  2. data/LICENSE +22 -22
  3. data/README +160 -160
  4. data/Rakefile +0 -9
  5. data/ext/libxml/Makefile +156 -0
  6. data/ext/libxml/extconf.h +5 -0
  7. data/ext/libxml/extconf.rb +4 -160
  8. data/ext/libxml/libxml-ruby.so.a +0 -0
  9. data/ext/libxml/libxml.o +0 -0
  10. data/ext/libxml/libxml_ruby.so +0 -0
  11. data/ext/libxml/mkmf.log +129 -0
  12. data/ext/libxml/ruby_xml.o +0 -0
  13. data/ext/libxml/ruby_xml_attr.c +1 -1
  14. data/ext/libxml/ruby_xml_attr.h +1 -1
  15. data/ext/libxml/ruby_xml_attr.o +0 -0
  16. data/ext/libxml/ruby_xml_attr_decl.o +0 -0
  17. data/ext/libxml/ruby_xml_attributes.o +0 -0
  18. data/ext/libxml/ruby_xml_cbg.o +0 -0
  19. data/ext/libxml/ruby_xml_document.c +936 -936
  20. data/ext/libxml/ruby_xml_document.h +1 -1
  21. data/ext/libxml/ruby_xml_document.o +0 -0
  22. data/ext/libxml/ruby_xml_dtd.o +0 -0
  23. data/ext/libxml/ruby_xml_encoding.o +0 -0
  24. data/ext/libxml/ruby_xml_error.o +0 -0
  25. data/ext/libxml/ruby_xml_html_parser.c +1 -1
  26. data/ext/libxml/ruby_xml_html_parser.h +1 -1
  27. data/ext/libxml/ruby_xml_html_parser.o +0 -0
  28. data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
  29. data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
  30. data/ext/libxml/ruby_xml_input_cbg.o +0 -0
  31. data/ext/libxml/ruby_xml_io.o +0 -0
  32. data/ext/libxml/ruby_xml_namespace.c +1 -1
  33. data/ext/libxml/ruby_xml_namespace.h +1 -1
  34. data/ext/libxml/ruby_xml_namespace.o +0 -0
  35. data/ext/libxml/ruby_xml_namespaces.o +0 -0
  36. data/ext/libxml/ruby_xml_node.c +1386 -1386
  37. data/ext/libxml/ruby_xml_node.h +1 -1
  38. data/ext/libxml/ruby_xml_node.o +0 -0
  39. data/ext/libxml/ruby_xml_parser.c +1 -1
  40. data/ext/libxml/ruby_xml_parser.h +1 -1
  41. data/ext/libxml/ruby_xml_parser.o +0 -0
  42. data/ext/libxml/ruby_xml_parser_context.c +1 -1
  43. data/ext/libxml/ruby_xml_parser_context.h +1 -1
  44. data/ext/libxml/ruby_xml_parser_context.o +0 -0
  45. data/ext/libxml/ruby_xml_parser_options.o +0 -0
  46. data/ext/libxml/ruby_xml_reader.o +0 -0
  47. data/ext/libxml/ruby_xml_relaxng.o +0 -0
  48. data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
  49. data/ext/libxml/ruby_xml_sax_parser.c +1 -1
  50. data/ext/libxml/ruby_xml_sax_parser.h +1 -1
  51. data/ext/libxml/ruby_xml_sax_parser.o +0 -0
  52. data/ext/libxml/ruby_xml_schema.o +0 -0
  53. data/ext/libxml/ruby_xml_version.h +3 -3
  54. data/ext/libxml/ruby_xml_xinclude.c +1 -1
  55. data/ext/libxml/ruby_xml_xinclude.h +1 -1
  56. data/ext/libxml/ruby_xml_xinclude.o +0 -0
  57. data/ext/libxml/ruby_xml_xpath.c +1 -1
  58. data/ext/libxml/ruby_xml_xpath.h +1 -1
  59. data/ext/libxml/ruby_xml_xpath.o +0 -0
  60. data/ext/libxml/ruby_xml_xpath_context.c +1 -1
  61. data/ext/libxml/ruby_xml_xpath_context.h +1 -1
  62. data/ext/libxml/ruby_xml_xpath_context.o +0 -0
  63. data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
  64. data/ext/libxml/ruby_xml_xpath_object.o +0 -0
  65. data/ext/libxml/ruby_xml_xpointer.c +1 -1
  66. data/ext/libxml/ruby_xml_xpointer.h +1 -1
  67. data/ext/libxml/ruby_xml_xpointer.o +0 -0
  68. data/ext/mingw/build.rake +3 -3
  69. data/lib/libxml.rb +29 -29
  70. data/test/model/merge_bug_data.xml +58 -58
  71. data/test/model/rubynet.xml +79 -79
  72. data/test/model/xinclude.xml +4 -4
  73. data/test/tc_attr.rb +170 -170
  74. data/test/tc_document.rb +113 -113
  75. data/test/tc_document_write.rb +117 -117
  76. data/test/tc_dtd.rb +123 -123
  77. data/test/tc_html_parser.rb +137 -137
  78. data/test/tc_node.rb +180 -180
  79. data/test/tc_node_cdata.rb +49 -49
  80. data/test/tc_node_comment.rb +30 -30
  81. data/test/tc_node_edit.rb +157 -157
  82. data/test/tc_node_xlink.rb +26 -26
  83. data/test/tc_parser.rb +329 -329
  84. data/test/tc_parser_context.rb +185 -185
  85. data/test/tc_reader.rb +283 -283
  86. data/test/tc_sax_parser.rb +273 -273
  87. data/test/tc_schema.rb +51 -51
  88. data/test/tc_xinclude.rb +19 -19
  89. data/test/tc_xpath.rb +193 -193
  90. data/test/tc_xpointer.rb +72 -72
  91. metadata +55 -14
  92. data/ext/libxml/build.log +0 -4
@@ -1,51 +1,51 @@
1
- require 'xml'
2
- require 'test/unit'
3
-
4
- class TestSchema < Test::Unit::TestCase
5
- def setup
6
- file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
7
- @doc = XML::Document.file(file)
8
- end
9
-
10
- def teardown
11
- @doc = nil
12
- end
13
-
14
- def schema
15
- document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd'))
16
- schema = XML::Schema.document(document)
17
- end
18
-
19
- def test_from_doc
20
- assert_instance_of(XML::Schema, schema)
21
- end
22
-
23
- def test_valid
24
- assert(@doc.validate_schema(schema))
25
- end
26
-
27
- def test_invalid
28
- new_node = XML::Node.new('invalid', 'this will mess up validation')
29
- @doc.root.child_add(new_node)
30
-
31
- error = assert_raise(XML::Error) do
32
- @doc.validate_schema(schema)
33
- end
34
-
35
- assert_not_nil(error)
36
- assert_kind_of(XML::Error, error)
37
- assert(error.message.match(/Error: Element 'invalid': This element is not expected. Expected is \( item \)/))
38
- assert_equal(XML::Error::SCHEMASV, error.domain)
39
- assert_equal(XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code)
40
- assert_equal(XML::Error::ERROR, error.level)
41
- assert(error.file.match(/shiporder.xml/))
42
- assert_nil(error.line)
43
- assert_nil(error.str1)
44
- assert_nil(error.str2)
45
- assert_nil(error.str3)
46
- assert_equal(0, error.int1)
47
- assert_equal(0, error.int2)
48
- assert_not_nil(error.node)
49
- assert_equal('invalid', error.node.name)
50
- end
51
- end
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class TestSchema < Test::Unit::TestCase
5
+ def setup
6
+ file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
7
+ @doc = XML::Document.file(file)
8
+ end
9
+
10
+ def teardown
11
+ @doc = nil
12
+ end
13
+
14
+ def schema
15
+ document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd'))
16
+ schema = XML::Schema.document(document)
17
+ end
18
+
19
+ def test_from_doc
20
+ assert_instance_of(XML::Schema, schema)
21
+ end
22
+
23
+ def test_valid
24
+ assert(@doc.validate_schema(schema))
25
+ end
26
+
27
+ def test_invalid
28
+ new_node = XML::Node.new('invalid', 'this will mess up validation')
29
+ @doc.root.child_add(new_node)
30
+
31
+ error = assert_raise(XML::Error) do
32
+ @doc.validate_schema(schema)
33
+ end
34
+
35
+ assert_not_nil(error)
36
+ assert_kind_of(XML::Error, error)
37
+ assert(error.message.match(/Error: Element 'invalid': This element is not expected. Expected is \( item \)/))
38
+ assert_equal(XML::Error::SCHEMASV, error.domain)
39
+ assert_equal(XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code)
40
+ assert_equal(XML::Error::ERROR, error.level)
41
+ assert(error.file.match(/shiporder.xml/))
42
+ assert_nil(error.line)
43
+ assert_nil(error.str1)
44
+ assert_nil(error.str2)
45
+ assert_nil(error.str3)
46
+ assert_equal(0, error.int1)
47
+ assert_equal(0, error.int2)
48
+ assert_not_nil(error.node)
49
+ assert_equal('invalid', error.node.name)
50
+ end
51
+ end
@@ -1,19 +1,19 @@
1
- require 'xml'
2
- require 'test/unit'
3
-
4
- class TestXInclude < Test::Unit::TestCase
5
- def setup
6
- @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/xinclude.xml'))
7
- assert_instance_of(XML::Document, @doc)
8
- end
9
-
10
- def teardown
11
- @doc = nil
12
- end
13
-
14
- def test_ruby_xml_xinclude
15
- assert_equal(1, @doc.xinclude)
16
- assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<document xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n <p>This libxml2 binding has the following project information:\n <code>This is some text to include in an xml file via XInclude.</code></p>\n</document>\n",
17
- @doc.to_s)
18
- end
19
- end
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class TestXInclude < Test::Unit::TestCase
5
+ def setup
6
+ @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/xinclude.xml'))
7
+ assert_instance_of(XML::Document, @doc)
8
+ end
9
+
10
+ def teardown
11
+ @doc = nil
12
+ end
13
+
14
+ def test_ruby_xml_xinclude
15
+ assert_equal(1, @doc.xinclude)
16
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<document xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n <p>This libxml2 binding has the following project information:\n <code>This is some text to include in an xml file via XInclude.</code></p>\n</document>\n",
17
+ @doc.to_s)
18
+ end
19
+ end
@@ -1,193 +1,193 @@
1
- require 'xml'
2
- require 'tempfile'
3
- require 'test/unit'
4
-
5
- class TestXPath < Test::Unit::TestCase
6
- def setup
7
- @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
8
- end
9
-
10
- def teardown
11
- @doc = nil
12
- end
13
-
14
- def test_doc_find
15
- nodes = @doc.find('/soap:Envelope')
16
- assert_instance_of(XML::XPath::Object, nodes)
17
- assert_equal(1, nodes.length)
18
- assert_equal(nodes.xpath_type, XML::XPath::NODESET)
19
- end
20
-
21
- def test_doc_find_first
22
- node = @doc.find_first('/soap:Envelope/soap:Body')
23
- assert_instance_of(XML::Node, node)
24
- end
25
-
26
- def test_ns
27
- nodes = @doc.find('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
28
- assert_equal(3, nodes.length)
29
- end
30
-
31
- def test_ns_array
32
- nodes = @doc.find('//ns1:IdAndName', ['ns1:http://domain.somewhere.com'])
33
- assert_equal(3, nodes.length)
34
- end
35
-
36
- def test_default_ns1
37
- # Find all nodes with http://services.somewhere.com namespace
38
- nodes = @doc.find('//*[namespace-uri()="http://services.somewhere.com"]')
39
- assert_equal(2, nodes.length)
40
- assert_equal('getManufacturerNamesResponse', nodes[0].name)
41
- assert_equal('IDAndNameList', nodes[1].name)
42
- end
43
-
44
- def test_default_ns2
45
- # Find all nodes with http://services.somewhere.com namespace
46
- nodes = @doc.find('//ns:*', 'ns:http://services.somewhere.com')
47
- assert_equal(2, nodes.length)
48
- assert_equal('getManufacturerNamesResponse', nodes[0].name)
49
- assert_equal('IDAndNameList', nodes[1].name)
50
-
51
- # Get getManufacturerNamesResponse node
52
- nodes = @doc.find('//ns:getManufacturerNamesResponse', 'ns:http://services.somewhere.com')
53
- assert_equal(1, nodes.length)
54
-
55
- # Get IdAndName node
56
- nodes = @doc.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse/ns0:IDAndNameList/ns1:IdAndName',
57
- ['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
58
- assert_equal(3, nodes.length)
59
- end
60
-
61
- def test_default_ns3
62
- # Find all nodes with http://services.somewhere.com namespace
63
- nodes = @doc.find('//ns:*', 'ns' => 'http://services.somewhere.com')
64
- assert_equal(2, nodes.length)
65
- assert_equal('getManufacturerNamesResponse', nodes[0].name)
66
- assert_equal('IDAndNameList', nodes[1].name)
67
- end
68
-
69
- def test_default_ns4
70
- # Find all nodes with http://services.somewhere.com namespace
71
- nodes = @doc.find('//ns:*', :ns => 'http://services.somewhere.com')
72
- assert_equal(2, nodes.length)
73
- assert_equal('getManufacturerNamesResponse', nodes[0].name)
74
- assert_equal('IDAndNameList', nodes[1].name)
75
- end
76
-
77
- def test_default_ns5
78
- # Find all nodes with http://services.somewhere.com namespace
79
- XML::Namespace.new(@doc.root, 'ns', 'http://services.somewhere.com')
80
- nodes = @doc.find('//ns:*')
81
- assert_equal(2, nodes.length)
82
- assert_equal('getManufacturerNamesResponse', nodes[0].name)
83
- assert_equal('IDAndNameList', nodes[1].name)
84
- end
85
-
86
- def test_attribute_ns
87
- # Pull all nodes with http://services.somewhere.com namespace
88
- nodes = @doc.find('@soap:encodingStyle')
89
- assert_equal(1, nodes.length)
90
- assert_equal('encodingStyle', nodes.first.name)
91
- assert_equal('http://www.w3.org/2001/12/soap-encoding', nodes.first.value)
92
- end
93
-
94
- def test_register_default_ns
95
- doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/atom.xml'))
96
-
97
- # No namespace has been yet defined
98
- assert_raise(XML::Error) do
99
- node = doc.find("atom:title")
100
- end
101
-
102
- node = doc.find('atom:title', 'atom:http://www.w3.org/2005/Atom')
103
- assert_not_nil(node)
104
-
105
- # Register namespace
106
- doc.root.namespaces.default_prefix = 'atom'
107
- node = doc.find("atom:title")
108
- assert_not_nil(node)
109
- end
110
-
111
- def test_node_find
112
- nodes = @doc.find('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
113
- node = nodes.first
114
-
115
- # Since we are searching on the node, don't have to register namespace
116
- nodes = node.find('ns1:name')
117
- assert_equal(1, nodes.length)
118
- assert_equal(nodes.first.object_id, nodes.last.object_id, 'First and last should be the same')
119
- assert_equal('name', nodes.first.name)
120
- assert_equal('man1', nodes.first.content)
121
- end
122
-
123
- def test_node_find_first
124
- node = @doc.find_first('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
125
-
126
- # Since we are searching on the node, don't have to register namespace
127
- node = node.find_first('ns1:name')
128
- assert_equal('name', node.name)
129
- assert_equal('man1', node.content)
130
- end
131
-
132
- def test_node_no_doc
133
- node = XML::Node.new('header', 'some content')
134
- assert_raise(TypeError) do
135
- node = node.find_first('/header')
136
- end
137
- end
138
-
139
- def test_memory
140
- # This sometimes causes a segmentation fault because
141
- # an xml document is sometimes freed before the
142
- # xpath_object used to query it. When the xpath_object
143
- # is free, it iterates over its results which are pointers
144
- # to the document's nodes. A segmentation fault then happens.
145
-
146
- 1000.times do
147
- doc = XML::Document.new('1.0')
148
- doc.root = XML::Node.new("header")
149
-
150
- 1000.times do
151
- doc.root << XML::Node.new("footer")
152
- end
153
-
154
- nodes = doc.find('/header/footer')
155
- end
156
- end
157
-
158
- # Test that document doesn't get freed before nodes
159
- def test_xpath_free
160
- doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
161
- nodes = doc.find('//*')
162
- GC.start
163
- assert_equal('Envelope', nodes.first.name)
164
- end
165
-
166
- def test_xpath_namespace_nodes
167
- doc = XML::Document.string('<feed xmlns="http://www.w3.org/2005/Atom" xmlns:xhtml="http://www.w3.org/1999/xhtml"><entry/></feed>')
168
- nodes = doc.find('//atom:entry|namespace::*', :atom => "http://www.w3.org/2005/Atom")
169
- assert_equal(4, nodes.length)
170
-
171
- node = nodes[0]
172
- assert_equal(XML::Node::ELEMENT_NODE, node.node_type)
173
-
174
- node = nodes[1]
175
- assert_equal(XML::Node::NAMESPACE_DECL, node.node_type)
176
-
177
- node = nodes[2]
178
- assert_equal(XML::Node::NAMESPACE_DECL, node.node_type)
179
-
180
- node = nodes[3]
181
- assert_equal(XML::Node::NAMESPACE_DECL, node.node_type)
182
- end
183
-
184
- # Test to make sure we don't get nil on empty results.
185
- # This is also to test that we don't segfault due to our C code getting a NULL pointer
186
- # and not handling it properly.
187
- def test_xpath_empty_result
188
- doc = XML::Document.string('<html><body><p>Welcome to XHTML land!</p></body></html>')
189
- nodes = doc.find("//object/param[translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'wmode']")
190
- assert_not_nil nodes
191
- end
192
-
193
- end
1
+ require 'xml'
2
+ require 'tempfile'
3
+ require 'test/unit'
4
+
5
+ class TestXPath < Test::Unit::TestCase
6
+ def setup
7
+ @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
8
+ end
9
+
10
+ def teardown
11
+ @doc = nil
12
+ end
13
+
14
+ def test_doc_find
15
+ nodes = @doc.find('/soap:Envelope')
16
+ assert_instance_of(XML::XPath::Object, nodes)
17
+ assert_equal(1, nodes.length)
18
+ assert_equal(nodes.xpath_type, XML::XPath::NODESET)
19
+ end
20
+
21
+ def test_doc_find_first
22
+ node = @doc.find_first('/soap:Envelope/soap:Body')
23
+ assert_instance_of(XML::Node, node)
24
+ end
25
+
26
+ def test_ns
27
+ nodes = @doc.find('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
28
+ assert_equal(3, nodes.length)
29
+ end
30
+
31
+ def test_ns_array
32
+ nodes = @doc.find('//ns1:IdAndName', ['ns1:http://domain.somewhere.com'])
33
+ assert_equal(3, nodes.length)
34
+ end
35
+
36
+ def test_default_ns1
37
+ # Find all nodes with http://services.somewhere.com namespace
38
+ nodes = @doc.find('//*[namespace-uri()="http://services.somewhere.com"]')
39
+ assert_equal(2, nodes.length)
40
+ assert_equal('getManufacturerNamesResponse', nodes[0].name)
41
+ assert_equal('IDAndNameList', nodes[1].name)
42
+ end
43
+
44
+ def test_default_ns2
45
+ # Find all nodes with http://services.somewhere.com namespace
46
+ nodes = @doc.find('//ns:*', 'ns:http://services.somewhere.com')
47
+ assert_equal(2, nodes.length)
48
+ assert_equal('getManufacturerNamesResponse', nodes[0].name)
49
+ assert_equal('IDAndNameList', nodes[1].name)
50
+
51
+ # Get getManufacturerNamesResponse node
52
+ nodes = @doc.find('//ns:getManufacturerNamesResponse', 'ns:http://services.somewhere.com')
53
+ assert_equal(1, nodes.length)
54
+
55
+ # Get IdAndName node
56
+ nodes = @doc.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse/ns0:IDAndNameList/ns1:IdAndName',
57
+ ['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
58
+ assert_equal(3, nodes.length)
59
+ end
60
+
61
+ def test_default_ns3
62
+ # Find all nodes with http://services.somewhere.com namespace
63
+ nodes = @doc.find('//ns:*', 'ns' => 'http://services.somewhere.com')
64
+ assert_equal(2, nodes.length)
65
+ assert_equal('getManufacturerNamesResponse', nodes[0].name)
66
+ assert_equal('IDAndNameList', nodes[1].name)
67
+ end
68
+
69
+ def test_default_ns4
70
+ # Find all nodes with http://services.somewhere.com namespace
71
+ nodes = @doc.find('//ns:*', :ns => 'http://services.somewhere.com')
72
+ assert_equal(2, nodes.length)
73
+ assert_equal('getManufacturerNamesResponse', nodes[0].name)
74
+ assert_equal('IDAndNameList', nodes[1].name)
75
+ end
76
+
77
+ def test_default_ns5
78
+ # Find all nodes with http://services.somewhere.com namespace
79
+ XML::Namespace.new(@doc.root, 'ns', 'http://services.somewhere.com')
80
+ nodes = @doc.find('//ns:*')
81
+ assert_equal(2, nodes.length)
82
+ assert_equal('getManufacturerNamesResponse', nodes[0].name)
83
+ assert_equal('IDAndNameList', nodes[1].name)
84
+ end
85
+
86
+ def test_attribute_ns
87
+ # Pull all nodes with http://services.somewhere.com namespace
88
+ nodes = @doc.find('@soap:encodingStyle')
89
+ assert_equal(1, nodes.length)
90
+ assert_equal('encodingStyle', nodes.first.name)
91
+ assert_equal('http://www.w3.org/2001/12/soap-encoding', nodes.first.value)
92
+ end
93
+
94
+ def test_register_default_ns
95
+ doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/atom.xml'))
96
+
97
+ # No namespace has been yet defined
98
+ assert_raise(XML::Error) do
99
+ node = doc.find("atom:title")
100
+ end
101
+
102
+ node = doc.find('atom:title', 'atom:http://www.w3.org/2005/Atom')
103
+ assert_not_nil(node)
104
+
105
+ # Register namespace
106
+ doc.root.namespaces.default_prefix = 'atom'
107
+ node = doc.find("atom:title")
108
+ assert_not_nil(node)
109
+ end
110
+
111
+ def test_node_find
112
+ nodes = @doc.find('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
113
+ node = nodes.first
114
+
115
+ # Since we are searching on the node, don't have to register namespace
116
+ nodes = node.find('ns1:name')
117
+ assert_equal(1, nodes.length)
118
+ assert_equal(nodes.first.object_id, nodes.last.object_id, 'First and last should be the same')
119
+ assert_equal('name', nodes.first.name)
120
+ assert_equal('man1', nodes.first.content)
121
+ end
122
+
123
+ def test_node_find_first
124
+ node = @doc.find_first('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
125
+
126
+ # Since we are searching on the node, don't have to register namespace
127
+ node = node.find_first('ns1:name')
128
+ assert_equal('name', node.name)
129
+ assert_equal('man1', node.content)
130
+ end
131
+
132
+ def test_node_no_doc
133
+ node = XML::Node.new('header', 'some content')
134
+ assert_raise(TypeError) do
135
+ node = node.find_first('/header')
136
+ end
137
+ end
138
+
139
+ def test_memory
140
+ # This sometimes causes a segmentation fault because
141
+ # an xml document is sometimes freed before the
142
+ # xpath_object used to query it. When the xpath_object
143
+ # is free, it iterates over its results which are pointers
144
+ # to the document's nodes. A segmentation fault then happens.
145
+
146
+ 1000.times do
147
+ doc = XML::Document.new('1.0')
148
+ doc.root = XML::Node.new("header")
149
+
150
+ 1000.times do
151
+ doc.root << XML::Node.new("footer")
152
+ end
153
+
154
+ nodes = doc.find('/header/footer')
155
+ end
156
+ end
157
+
158
+ # Test that document doesn't get freed before nodes
159
+ def test_xpath_free
160
+ doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
161
+ nodes = doc.find('//*')
162
+ GC.start
163
+ assert_equal('Envelope', nodes.first.name)
164
+ end
165
+
166
+ def test_xpath_namespace_nodes
167
+ doc = XML::Document.string('<feed xmlns="http://www.w3.org/2005/Atom" xmlns:xhtml="http://www.w3.org/1999/xhtml"><entry/></feed>')
168
+ nodes = doc.find('//atom:entry|namespace::*', :atom => "http://www.w3.org/2005/Atom")
169
+ assert_equal(4, nodes.length)
170
+
171
+ node = nodes[0]
172
+ assert_equal(XML::Node::ELEMENT_NODE, node.node_type)
173
+
174
+ node = nodes[1]
175
+ assert_equal(XML::Node::NAMESPACE_DECL, node.node_type)
176
+
177
+ node = nodes[2]
178
+ assert_equal(XML::Node::NAMESPACE_DECL, node.node_type)
179
+
180
+ node = nodes[3]
181
+ assert_equal(XML::Node::NAMESPACE_DECL, node.node_type)
182
+ end
183
+
184
+ # Test to make sure we don't get nil on empty results.
185
+ # This is also to test that we don't segfault due to our C code getting a NULL pointer
186
+ # and not handling it properly.
187
+ def test_xpath_empty_result
188
+ doc = XML::Document.string('<html><body><p>Welcome to XHTML land!</p></body></html>')
189
+ nodes = doc.find("//object/param[translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'wmode']")
190
+ assert_not_nil nodes
191
+ end
192
+
193
+ end