libxml-ruby 0.7.0-x86-mswin32-60 → 0.8.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/CHANGES +24 -1
  2. data/README +48 -3
  3. data/benchmark/depixelate.rb +632 -0
  4. data/benchmark/hamlet.xml +9055 -0
  5. data/benchmark/sock_entries.xml +507 -0
  6. data/benchmark/throughput.rb +39 -0
  7. data/benchmark/xml_benchmarks.rb +222 -0
  8. data/doc/classes/LibXML.html +237 -0
  9. data/doc/classes/LibXML/XML.html +178 -0
  10. data/doc/classes/{XML → LibXML/XML}/Attr.html +213 -182
  11. data/doc/classes/{XML → LibXML/XML}/Attributes.html +126 -54
  12. data/doc/classes/{XML → LibXML/XML}/Document.html +299 -297
  13. data/doc/classes/{XML → LibXML/XML}/Dtd.html +10 -10
  14. data/doc/classes/{XML/XInclude → LibXML/XML}/Error.html +4 -4
  15. data/doc/classes/{XML → LibXML/XML}/HTMLParser.html +40 -40
  16. data/doc/classes/{XML → LibXML/XML}/InputCallbacks.html +10 -10
  17. data/doc/classes/{XML → LibXML/XML}/NS.html +46 -46
  18. data/doc/classes/{XML → LibXML/XML}/Node.html +935 -788
  19. data/doc/classes/LibXML/XML/Node/FailedModify.html +111 -0
  20. data/doc/classes/{XML → LibXML/XML}/Node/Set.html +69 -68
  21. data/doc/classes/{XML → LibXML/XML}/Node/SetNamespace.html +4 -4
  22. data/doc/classes/{XML/Node/FailedModify.html → LibXML/XML/Node/UnknownType.html} +4 -4
  23. data/doc/classes/{XML → LibXML/XML}/Parser.html +426 -389
  24. data/doc/classes/{XML → LibXML/XML}/Parser/Context.html +208 -208
  25. data/doc/classes/{XML → LibXML/XML}/Parser/ParseError.html +4 -4
  26. data/doc/classes/{XML → LibXML/XML}/Reader.html +288 -287
  27. data/doc/classes/{XML → LibXML/XML}/SaxParser.html +52 -52
  28. data/doc/classes/{XML/XPath/Context.html → LibXML/XML/Schema.html} +60 -32
  29. data/doc/classes/{XML → LibXML/XML}/State.html +4 -4
  30. data/doc/classes/{XML/Node/UnknownType.html → LibXML/XML/Tree.html} +5 -5
  31. data/doc/classes/{XML → LibXML/XML}/XInclude.html +5 -5
  32. data/doc/classes/{XML → LibXML/XML/XInclude}/Error.html +5 -5
  33. data/doc/classes/{XML → LibXML/XML}/XMLParserOptions.html +5 -5
  34. data/doc/classes/{XML → LibXML/XML}/XPath.html +23 -64
  35. data/doc/classes/LibXML/XML/XPath/Context.html +403 -0
  36. data/doc/classes/{XML/XPointer/Context → LibXML/XML/XPath}/InvalidPath.html +4 -4
  37. data/doc/classes/LibXML/XML/XPath/Object.html +623 -0
  38. data/doc/classes/{XML → LibXML/XML}/XPointer.html +12 -12
  39. data/doc/classes/{XML → LibXML/XML}/XPointer/Context.html +5 -5
  40. data/doc/classes/{XML/XPath → LibXML/XML/XPointer/Context}/InvalidPath.html +5 -5
  41. data/doc/classes/{XML → LibXML/XML}/XPointer/InvalidExpression.html +4 -4
  42. data/doc/classes/XML.html +17 -123
  43. data/doc/created.rid +1 -1
  44. data/doc/files/CHANGES.html +49 -25
  45. data/doc/files/LICENSE.html +1 -1
  46. data/doc/files/README.html +79 -4
  47. data/doc/files/VERSION.html +2 -2
  48. data/doc/files/ext/libxml/cbg_c.html +1 -1
  49. data/doc/files/ext/libxml/libxml_c.html +1 -1
  50. data/doc/files/ext/libxml/ruby_xml_attr_c.html +1 -1
  51. data/doc/files/ext/libxml/ruby_xml_attributes_c.html +1 -1
  52. data/doc/files/ext/libxml/ruby_xml_document_c.html +1 -1
  53. data/doc/files/ext/libxml/ruby_xml_dtd_c.html +1 -1
  54. data/doc/files/ext/libxml/ruby_xml_html_parser_c.html +1 -1
  55. data/doc/files/ext/libxml/ruby_xml_input_cbg_c.html +1 -1
  56. data/doc/files/ext/libxml/ruby_xml_node_c.html +1 -1
  57. data/doc/files/ext/libxml/ruby_xml_node_set_c.html +1 -1
  58. data/doc/files/ext/libxml/ruby_xml_ns_c.html +1 -1
  59. data/doc/files/ext/libxml/ruby_xml_parser_c.html +1 -1
  60. data/doc/files/ext/libxml/ruby_xml_parser_context_c.html +1 -1
  61. data/doc/files/ext/libxml/ruby_xml_reader_c.html +1 -1
  62. data/doc/files/ext/libxml/ruby_xml_sax_parser_c.html +1 -1
  63. data/doc/files/ext/libxml/ruby_xml_schema_c.html +1 -1
  64. data/doc/files/ext/libxml/ruby_xml_state_c.html +1 -1
  65. data/doc/files/ext/libxml/ruby_xml_xinclude_c.html +1 -1
  66. data/doc/files/ext/libxml/ruby_xml_xpath_c.html +1 -1
  67. data/doc/files/ext/libxml/ruby_xml_xpath_context_c.html +1 -1
  68. data/doc/files/ext/libxml/ruby_xml_xpath_object_c.html +1 -1
  69. data/doc/files/ext/libxml/ruby_xml_xpointer_c.html +1 -1
  70. data/doc/files/ext/libxml/ruby_xml_xpointer_context_c.html +1 -1
  71. data/doc/files/lib/libxml/attr_rb.html +108 -0
  72. data/doc/files/lib/libxml/attributes_rb.html +108 -0
  73. data/doc/files/lib/libxml/document_rb.html +108 -0
  74. data/doc/files/lib/libxml/node_rb.html +108 -0
  75. data/doc/files/lib/libxml/node_set_rb.html +108 -0
  76. data/doc/files/lib/libxml/parser_options_rb.html +107 -0
  77. data/doc/files/{ext/libxml/ruby_xml_tree_c.html → lib/libxml/parser_rb.html} +4 -4
  78. data/doc/files/lib/libxml/properties_rb.html +108 -0
  79. data/doc/files/lib/libxml/tree_rb.html +107 -0
  80. data/doc/files/lib/libxml_rb.html +12 -3
  81. data/doc/fr_class_index.html +34 -32
  82. data/doc/fr_file_index.html +9 -1
  83. data/doc/fr_method_index.html +362 -347
  84. data/ext/libxml/cbg.c +76 -76
  85. data/ext/libxml/libxml.c +4 -3
  86. data/ext/libxml/ruby_libxml.h +1 -1
  87. data/ext/libxml/ruby_xml_attr.c +4 -3
  88. data/ext/libxml/ruby_xml_attr.h +16 -16
  89. data/ext/libxml/ruby_xml_attributes.c +267 -266
  90. data/ext/libxml/ruby_xml_attributes.h +17 -17
  91. data/ext/libxml/ruby_xml_document.c +30 -59
  92. data/ext/libxml/ruby_xml_document.h +27 -27
  93. data/ext/libxml/ruby_xml_dtd.c +2 -1
  94. data/ext/libxml/ruby_xml_dtd.h +17 -17
  95. data/ext/libxml/ruby_xml_html_parser.c +3 -2
  96. data/ext/libxml/ruby_xml_html_parser.h +29 -29
  97. data/ext/libxml/ruby_xml_input_cbg.c +2 -1
  98. data/ext/libxml/ruby_xml_input_cbg.h +20 -20
  99. data/ext/libxml/ruby_xml_node.c +127 -470
  100. data/ext/libxml/ruby_xml_node.h +17 -17
  101. data/ext/libxml/ruby_xml_node_set.c +5 -4
  102. data/ext/libxml/ruby_xml_node_set.h +20 -20
  103. data/ext/libxml/ruby_xml_ns.c +3 -2
  104. data/ext/libxml/ruby_xml_ns.h +12 -12
  105. data/ext/libxml/ruby_xml_parser.c +20 -48
  106. data/ext/libxml/ruby_xml_parser.h +31 -31
  107. data/ext/libxml/ruby_xml_parser_context.c +3 -2
  108. data/ext/libxml/ruby_xml_parser_context.h +20 -20
  109. data/ext/libxml/ruby_xml_reader.c +2 -1
  110. data/ext/libxml/ruby_xml_sax_parser.c +3 -2
  111. data/ext/libxml/ruby_xml_sax_parser.h +56 -56
  112. data/ext/libxml/ruby_xml_schema.c +6 -0
  113. data/ext/libxml/ruby_xml_schema.h +16 -16
  114. data/ext/libxml/ruby_xml_state.c +13 -12
  115. data/ext/libxml/ruby_xml_state.h +1 -1
  116. data/ext/libxml/ruby_xml_xinclude.c +3 -2
  117. data/ext/libxml/ruby_xml_xinclude.h +13 -13
  118. data/ext/libxml/ruby_xml_xpath.c +35 -228
  119. data/ext/libxml/ruby_xml_xpath.h +22 -23
  120. data/ext/libxml/ruby_xml_xpath_context.c +223 -62
  121. data/ext/libxml/ruby_xml_xpath_context.h +15 -20
  122. data/ext/libxml/ruby_xml_xpath_object.c +63 -19
  123. data/ext/libxml/ruby_xml_xpointer.c +19 -15
  124. data/ext/libxml/ruby_xml_xpointer.h +27 -27
  125. data/ext/libxml/ruby_xml_xpointer_context.c +3 -2
  126. data/ext/libxml/ruby_xml_xpointer_context.h +18 -18
  127. data/ext/libxml/version.h +9 -9
  128. data/lib/libxml.rb +16 -128
  129. data/lib/libxml/attr.rb +45 -0
  130. data/lib/libxml/attributes.rb +15 -0
  131. data/lib/libxml/document.rb +54 -0
  132. data/lib/libxml/node.rb +132 -0
  133. data/lib/libxml/node_set.rb +27 -0
  134. data/lib/libxml/parser.rb +42 -0
  135. data/lib/libxml/parser_options.rb +25 -0
  136. data/lib/libxml/properties.rb +19 -0
  137. data/lib/libxml/tree.rb +29 -0
  138. data/lib/libxml_ruby.so +0 -0
  139. data/mingw/libxml_ruby.so +0 -0
  140. data/{work/task/setup → setup.rb} +1585 -1616
  141. data/test/gc.log +0 -0
  142. data/test/model/books.xml +147 -0
  143. data/{work/test/runner.rb → test/model/default_validation_bug.rb} +0 -0
  144. data/test/model/merge_bug_data.xml +58 -0
  145. data/test/model/rubynet.xml +78 -0
  146. data/test/model/rubynet_project +1 -0
  147. data/test/model/saxtest.xml +5 -0
  148. data/test/model/shiporder.xml +23 -0
  149. data/test/model/shiporder.xsd +31 -0
  150. data/test/model/simple.xml +7 -0
  151. data/test/model/soap.xml +27 -0
  152. data/test/model/xinclude.xml +5 -0
  153. data/test/tc_deprecated_require.rb +13 -0
  154. data/test/tc_xml_document.rb +57 -16
  155. data/test/tc_xml_document_write.rb +125 -10
  156. data/test/tc_xml_dtd.rb +22 -1
  157. data/test/tc_xml_node.rb +13 -0
  158. data/test/tc_xml_node_edit.rb +1 -1
  159. data/test/tc_xml_node_xlink.rb +1 -1
  160. data/test/tc_xml_parser.rb +64 -7
  161. data/test/tc_xml_properties.rb +42 -0
  162. data/test/tc_xml_reader.rb +4 -4
  163. data/test/tc_xml_sax_parser.rb +50 -50
  164. data/test/tc_xml_schema.rb +2 -2
  165. data/test/tc_xml_traversal.rb +220 -0
  166. data/test/tc_xml_xinclude.rb +12 -15
  167. data/test/tc_xml_xpath.rb +74 -6
  168. data/test/tc_xml_xpath_context.rb +72 -0
  169. data/test/test_suite.rb +6 -4
  170. data/vc/libxml_ruby.vcproj +1 -9
  171. metadata +92 -65
  172. data/doc/classes/XML/SiblingEnum.html +0 -142
  173. data/doc/classes/XML/Tree.html +0 -224
  174. data/doc/classes/XML/XPath/Object.html +0 -439
  175. data/ext/libxml/ruby_xml_tree.c +0 -43
  176. data/ext/libxml/ruby_xml_tree.h +0 -12
  177. data/test/ets_copy_bug2.rb +0 -21
  178. data/test/tc_xml_document_write2.rb +0 -54
  179. data/test/tc_xml_document_write3.rb +0 -96
  180. data/test/tc_xml_sax_parser2.rb +0 -51
  181. data/work/Rakefile +0 -247
  182. data/work/task/make +0 -26
  183. data/work/task/memory +0 -37
  184. data/work/task/rdoc +0 -39
  185. data/work/task/test +0 -29
  186. data/work/test/ets_runner.rb +0 -33
  187. data/work/test/libxml_test.rb +0 -3
  188. data/work/test/runner_ets.rb +0 -33
@@ -4,7 +4,7 @@ require 'test/unit'
4
4
  class TestSchema < Test::Unit::TestCase
5
5
  def setup
6
6
  xp = XML::Parser.new
7
- @doc = XML::Document.file('model/shiporder.xml')
7
+ @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xml'))
8
8
  end
9
9
 
10
10
  def teardown
@@ -12,7 +12,7 @@ class TestSchema < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def schema
15
- document = XML::Document.file('model/shiporder.xsd')
15
+ document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd'))
16
16
  schema = XML::Schema.document(document)
17
17
  end
18
18
 
@@ -0,0 +1,220 @@
1
+ require "libxml"
2
+ require 'test/unit'
3
+
4
+ class TestTranversal < Test::Unit::TestCase
5
+ ROOT_NODES_LENGTH = 25
6
+ ROOT_ELEMENTS_LENGTH = 12
7
+
8
+ def setup
9
+ filename = File.join(File.dirname(__FILE__), 'model/books.xml')
10
+ @doc = XML::Document.file(filename)
11
+ end
12
+
13
+ def teardown
14
+ @doc = nil
15
+ end
16
+
17
+ def test_children
18
+ # Includes text nodes and such
19
+ assert_equal(ROOT_NODES_LENGTH, @doc.root.children.length)
20
+ end
21
+
22
+ def test_children_iteration
23
+ # Includes text nodes and such
24
+ nodes = @doc.root.children.inject([]) do |arr, node|
25
+ arr << node
26
+ arr
27
+ end
28
+
29
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
30
+ end
31
+
32
+ def test_each
33
+ # Includes text nodes and such
34
+ nodes = @doc.root.inject([]) do |arr, node|
35
+ arr << node
36
+ arr
37
+ end
38
+
39
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
40
+ end
41
+
42
+ def test_each_element
43
+ # Includes text nodes and such
44
+ nodes = []
45
+ @doc.root.each_element do |node|
46
+ nodes << node
47
+ end
48
+
49
+ assert_equal(ROOT_ELEMENTS_LENGTH, nodes.length)
50
+ end
51
+
52
+ def test_next
53
+ nodes = []
54
+
55
+ node = @doc.root.first
56
+
57
+ while node
58
+ nodes << node
59
+ node = node.next
60
+ end
61
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
62
+ end
63
+
64
+ def test_next?
65
+ first_node = @doc.root.first
66
+ assert(first_node.next?)
67
+
68
+ last_node = @doc.root.last
69
+ assert(!last_node.next?)
70
+ end
71
+
72
+ def test_prev
73
+ nodes = []
74
+
75
+ node = @doc.root.last
76
+
77
+ while node
78
+ nodes << node
79
+ node = node.prev
80
+ end
81
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
82
+ end
83
+
84
+ def test_prev?
85
+ first_node = @doc.root.first
86
+ assert(!first_node.prev?)
87
+
88
+ last_node = @doc.root.last
89
+ assert(last_node.prev?)
90
+ end
91
+
92
+ def test_parent?
93
+ assert(!@doc.parent?)
94
+ assert(@doc.root.parent?)
95
+ end
96
+
97
+ def test_child?
98
+ assert(@doc.child?)
99
+ assert(!@doc.root.first.child?)
100
+ end
101
+
102
+ def test_next_prev_equivalence
103
+ next_nodes = []
104
+ last_nodes = []
105
+
106
+ node = @doc.root.first
107
+ while node
108
+ next_nodes << node
109
+ node = node.next
110
+ end
111
+
112
+ node = @doc.root.last
113
+ while node
114
+ last_nodes << node
115
+ node = node.prev
116
+ end
117
+
118
+ assert_equal(next_nodes, last_nodes.reverse)
119
+ end
120
+
121
+ def test_next_children_equivalence
122
+ next_nodes = []
123
+
124
+ node = @doc.root.first
125
+ while node
126
+ next_nodes << node
127
+ node = node.next
128
+ end
129
+
130
+ assert_equal(@doc.root.children, next_nodes)
131
+ end
132
+
133
+ # node = @doc.find_first('book')
134
+ # node.children.each do |node|
135
+ # puts 1
136
+ #end
137
+ # @doc.root.children do |node|
138
+ # if node.node_type == XML::Node::ELEMENT_NODE
139
+ # puts node.name
140
+ #end
141
+ #end
142
+ #assert_equal(12,nodes.length)
143
+ #end
144
+
145
+ #def test_doc_class
146
+ #assert_instance_of(XML::Document, @doc)
147
+ #end
148
+
149
+ #def test_root_class
150
+ #assert_instance_of(XML::Node, @doc.root)
151
+ #end
152
+
153
+ #def test_node_class
154
+ #for n in nodes
155
+ #assert_instance_of(XML::Node, n)
156
+ #end
157
+ #end
158
+
159
+ #def test_find_class
160
+ #set = @doc.find('/ruby_array/fixnum')
161
+ #assert_instance_of(XML::XPath::Object, set)
162
+ #end
163
+
164
+ #def test_node_child_get
165
+ #assert_instance_of(TrueClass, @doc.root.child?)
166
+ #assert_instance_of(XML::Node, @doc.root.child)
167
+ #assert_equal('fixnum', @doc.root.child.name)
168
+ #end
169
+
170
+ #def test_node_doc
171
+ #for n in nodes
172
+ #assert_instance_of(XML::Document, n.doc) if n.document?
173
+ #end
174
+ #end
175
+
176
+ #def test_node_type_name
177
+ #assert_equal('element', nodes[0].node_type_name)
178
+ #assert_equal('element', nodes[1].node_type_name)
179
+ #end
180
+
181
+ #def test_node_find
182
+ #set = @doc.root.find('./fixnum').set
183
+ #assert_instance_of(XML::Node::Set, set)
184
+ #for node in set
185
+ #assert_instance_of(XML::Node, node)
186
+ #end
187
+ #end
188
+
189
+ #def test_equality
190
+ #node_a = @doc.find('/ruby_array/fixnum').first
191
+ #node_b = @doc.root.child
192
+ #assert(node_a == node_b)
193
+ #assert(node_a.eql?(node_b))
194
+ #assert(node_a.equal?(node_b))
195
+
196
+ #xp2 = XML::Parser.new()
197
+ #xp2.string = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
198
+ #doc2 = xp2.parse
199
+
200
+ #node_a2 = doc2.find('/ruby_array/fixnum').first
201
+
202
+ #assert(node_a.to_s == node_a2.to_s)
203
+ #assert(node_a == node_a2)
204
+ #assert(node_a.eql?(node_a2))
205
+ #assert(!node_a.equal?(node_a2))
206
+ #end
207
+
208
+ #def test_content()
209
+ #assert_equal('onetwo', @doc.root.content)
210
+
211
+ #first = @doc.root.child
212
+ #assert_equal('one', first.content)
213
+ #assert_equal('two', first.next.content)
214
+ #end
215
+
216
+ #def test_base
217
+ #doc = XML::Parser.string('<person />').parse
218
+ #assert_nil(doc.root.base)
219
+ #end
220
+ end
@@ -1,9 +1,9 @@
1
1
  require "libxml"
2
2
  require 'test/unit'
3
3
 
4
- class TextXInclude < Test::Unit::TestCase
4
+ class TestXInclude < Test::Unit::TestCase
5
5
  def setup
6
- @doc = XML::Document.file('model/xinclude.xml')
6
+ @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/xinclude.xml'))
7
7
  assert_instance_of(XML::Document, @doc)
8
8
  end
9
9
 
@@ -12,18 +12,15 @@ class TextXInclude < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_ruby_xml_xinclude
15
- xinclude_doc = "<?xml version=\"1.0\"?>\n<document xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n"
16
- xinclude_doc << " <p>This libxml2 binding has the following project information:\n <code>"
17
- msg = ''
18
- File.open('model/rubynet_project') do |f|
19
- for line in f
20
- msg << line
21
- end
22
- end
23
- xinclude_doc << msg << "</code></p>\n</document>\n"
15
+ expected = <<-EOS
16
+ <?xml version="1.0"?>
17
+ <document xmlns:xi="http://www.w3.org/2001/XInclude">
18
+ <p>This libxml2 binding has the following project information:
19
+ <code>This is some text to include in an xml file via XInclude.</code></p>
20
+ </document>
21
+ EOS
24
22
 
25
- ret = @doc.xinclude
26
- assert_equal(1, ret)
27
- assert_equal(xinclude_doc, @doc.to_s)
23
+ assert_equal(1, @doc.xinclude)
24
+ assert_equal(expected, @doc.to_s)
28
25
  end
29
- end
26
+ end
@@ -2,20 +2,27 @@ require "libxml"
2
2
  require "tempfile"
3
3
  require "test/unit"
4
4
 
5
- class TextXPath < Test::Unit::TestCase
6
- def setup()
7
- @doc = XML::Document.file('model/soap.xml')
5
+ class TestXPath < Test::Unit::TestCase
6
+ def setup
7
+ @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
8
8
  end
9
9
 
10
- def teardown()
10
+ def teardown
11
11
  @doc = nil
12
12
  end
13
13
 
14
- def test_basic
14
+ def test_doc_find
15
15
  nodes = @doc.find('/soap:Envelope')
16
16
  assert_instance_of(XML::XPath::Object, nodes)
17
- assert_instance_of(XML::Node::Set, nodes.set)
18
17
  assert_equal(1, nodes.length)
18
+ assert_equal(nodes.xpath_type, XML::XPath::NODESET)
19
+ assert_instance_of(XML::Node::Set, nodes.set)
20
+ assert_instance_of(XML::XPath::Context, nodes.context)
21
+ end
22
+
23
+ def test_doc_find_first
24
+ node = @doc.find_first('/soap:Envelope/soap:Body')
25
+ assert_instance_of(XML::Node, node)
19
26
  end
20
27
 
21
28
  def test_ns
@@ -51,6 +58,46 @@ class TextXPath < Test::Unit::TestCase
51
58
  assert_equal(3, nodes.length)
52
59
  end
53
60
 
61
+ def test_attribute_ns
62
+ # Pull all nodes with http://services.somewhere.com namespace
63
+ nodes = @doc.find('@soap:encodingStyle')
64
+ assert_equal(1, nodes.length)
65
+ assert_equal('encodingStyle', nodes.first.name)
66
+ assert_equal('http://www.w3.org/2001/12/soap-encoding', nodes.first.value)
67
+ end
68
+
69
+ def test_node_find
70
+ nodes = @doc.find('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
71
+ node = nodes.first
72
+
73
+ # Since we are searching on the node, don't have to register namespace
74
+ nodes = node.find('ns1:name')
75
+ assert_equal(1, nodes.length)
76
+ assert_equal('name', nodes.first.name)
77
+ assert_equal('man1', nodes.first.content)
78
+ end
79
+
80
+ def test_node_find_first
81
+ node = @doc.find_first('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
82
+
83
+ # Since we are searching on the node, don't have to register namespace
84
+ node = node.find_first('ns1:name')
85
+ assert_equal('name', node.name)
86
+ assert_equal('man1', node.content)
87
+ end
88
+
89
+ def test_node_no_doc
90
+ node = XML::Node.new('header', 'some content')
91
+ assert_raise(TypeError) do
92
+ node = node.find_first('/header')
93
+ end
94
+ end
95
+
96
+ def test_nodes_debug
97
+ # nodes = @doc.find('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
98
+ #nodes.debug
99
+ end
100
+
54
101
  #def test_custom_function
55
102
  #xml = Tempfile.new("xxx")
56
103
  #xml.puts("<a/>")
@@ -59,4 +106,25 @@ class TextXPath < Test::Unit::TestCase
59
106
  #doc = XML::Document.file(xml.path)
60
107
  #assert_nil(doc.find("//*[name(.)=normalize_space(' a ')]"))
61
108
  #end
109
+
110
+ #def test_memory
111
+ ## This sometimes causes a segmentation fault because
112
+ ## an xml document is sometimes freed before the
113
+ ## xpath_object used to query it. When the xpath_object
114
+ ## is free, it iterates over its results which are pointers
115
+ ## to the document's nodes. A segmentation fault then happens.
116
+
117
+ #100.times do
118
+ #doc = XML::Document.new('1.0')
119
+ #doc.root = XML::Node.new("header")
120
+
121
+ #1000.times do
122
+ #doc.root << XML::Node.new("footer")
123
+ #end
124
+
125
+ #nodes = doc.find('/header/footer')
126
+ #nodes.length
127
+ #nodes = nil
128
+ #end
129
+ #end
62
130
  end
@@ -0,0 +1,72 @@
1
+ require "libxml"
2
+ require "tempfile"
3
+ require "test/unit"
4
+
5
+ class TestXPathContext < Test::Unit::TestCase
6
+ SOAP_PREFIX = 'soap'
7
+ SOAP_URI = 'http://schemas.xmlsoap.org/soap/envelope/'
8
+
9
+ NS0_PREFIX = 'ns0'
10
+ NS0_URI = 'http://services.somewhere.com'
11
+
12
+ def setup()
13
+ doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
14
+ @context = XML::XPath::Context.new(doc)
15
+ end
16
+
17
+ def teardown()
18
+ @context = nil
19
+ end
20
+
21
+ #def test_no_ns
22
+ #assert_raise(XML::XPath::InvalidPath) do
23
+ #@context.find('/soap:Envelope')
24
+ #end
25
+ #end
26
+
27
+ def test_ns_register
28
+ @context.register_namespace(SOAP_PREFIX, SOAP_URI)
29
+ @context.register_namespace(NS0_PREFIX, NS0_URI)
30
+ nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
31
+ assert_equal(1, nodes.length)
32
+ end
33
+
34
+ def test_ns_register_string
35
+ @context.register_namespaces("#{SOAP_PREFIX}:#{SOAP_URI}")
36
+ @context.register_namespaces("#{NS0_PREFIX}:#{NS0_URI}")
37
+ nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
38
+ assert_equal(1, nodes.length)
39
+ end
40
+
41
+ def test_ns_register_array
42
+ @context.register_namespaces(["#{SOAP_PREFIX}:#{SOAP_URI}", "#{NS0_PREFIX}:#{NS0_URI}"])
43
+ nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
44
+ assert_equal(1, nodes.length)
45
+ end
46
+
47
+ def test_ns_register_hash
48
+ @context.register_namespaces(SOAP_PREFIX => SOAP_URI,
49
+ NS0_PREFIX => NS0_URI)
50
+
51
+ nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
52
+ assert_equal(1, nodes.length)
53
+ end
54
+
55
+ def test_ns_register_node
56
+ @context.register_namespaces_from_node(@context.doc.root)
57
+ nodes = @context.find('/soap:Envelope')
58
+ assert_equal(1, nodes.length)
59
+ end
60
+
61
+ def test_node
62
+ @context.register_namespaces_from_node(@context.doc.root)
63
+
64
+ nodes = @context.find('soap:Body')
65
+ assert_equal(0, nodes.length)
66
+
67
+
68
+ @context.node = @context.doc.root.child.next
69
+ nodes = @context.find('soap:Body')
70
+ assert_equal(0, nodes.length)
71
+ end
72
+ end