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
@@ -2,23 +2,138 @@ require "libxml"
2
2
  require 'test/unit'
3
3
 
4
4
  class TC_XML_Document_Write < Test::Unit::TestCase
5
- def setup()
5
+ def setup
6
6
  @doc = XML::Document.new('1.0')
7
- assert_instance_of(XML::Document, @doc)
8
7
  end
9
8
 
10
- def teardown()
9
+ def teardown
11
10
  @doc = nil
12
11
  end
13
12
 
14
- def test_ruby_xml_document_write_initialize()
15
- assert_instance_of(XML::Document, XML::Document.new())
13
+ def test_klass
14
+ assert_instance_of(XML::Document, @doc)
15
+ end
16
+
17
+ def test_version
16
18
  assert_equal('1.0', @doc.version)
17
- end # def test_ruby_xml_document_initialize()
18
19
 
19
- def test_ruby_xml_document_write_initialize2()
20
20
  doc = XML::Document.new('6.9')
21
- assert_instance_of(XML::Document, doc)
22
21
  assert_equal('6.9', doc.version)
23
- end # def test_ruby_xml_document_initialize2()
24
- end # TC_XML_Document_Write
22
+ end
23
+
24
+ def test_write_root
25
+ @doc.root = XML::Node.new('rubynet')
26
+ assert_instance_of(XML::Node, @doc.root)
27
+ assert_instance_of(XML::Document, @doc.root.doc)
28
+ assert_equal("<?xml version=\"1.0\"?>\n<rubynet/>\n", @doc.to_s)
29
+ end
30
+
31
+ def test_write_root
32
+ @doc.root = XML::Node.new('rubynet')
33
+ assert_instance_of(XML::Node, @doc.root)
34
+ assert_instance_of(XML::Document, @doc.root.doc)
35
+ assert_equal("<?xml version=\"1.0\"?>\n<rubynet/>\n", @doc.to_s(false))
36
+ end
37
+
38
+ def test_encoding
39
+ @doc.root = XML::Node.new('rubynet')
40
+ @doc.encoding = 'UTF-8'
41
+ assert_instance_of(XML::Node, @doc.root)
42
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n", @doc.to_s)
43
+ end
44
+
45
+ def test_child()
46
+ xml = "<?xml version=\"1.0\"?>\n<rubynet>\n <pkg/>\n</rubynet>\n"
47
+ @doc.root = XML::Node.new('rubynet')
48
+ @doc.root.child = XML::Node.new('pkg')
49
+ assert_equal(xml, @doc.to_s)
50
+ end
51
+
52
+ def test_append
53
+ xml = "<?xml version=\"1.0\"?>\n"
54
+ xml << "<rubynet>\n"
55
+ xml << " <pkg>\n"
56
+ xml << " <meta>\n"
57
+ xml << " <pkgname>libxml</pkgname>\n"
58
+ xml << " </meta>\n"
59
+ xml << " </pkg>\n"
60
+ xml << "</rubynet>\n"
61
+
62
+ @doc.root = XML::Node.new('rubynet')
63
+ pkg = @doc.root.child = XML::Node.new('pkg')
64
+ meta = pkg.child = XML::Node.new('meta')
65
+ assert_equal(meta, meta << (pkgname = XML::Node.new('pkgname')))
66
+ pkgname << 'libxml'
67
+ assert_equal(xml, @doc.to_s)
68
+ end
69
+
70
+ def test_node_search_href
71
+ prefix = 'xlink'
72
+ uri = 'http://www.rubynet.org'
73
+ xml = "<?xml version=\"1.0\"?>\n"
74
+ xml << "<rubynet xmlns:#{prefix}=\"#{uri}\">\n"
75
+ xml << " <pkg/>\n"
76
+ xml << "</rubynet>\n"
77
+
78
+ @doc.root = XML::Node.new('rubynet')
79
+ @doc = XML::Parser.string(xml).parse
80
+ assert_equal(xml, @doc.to_s)
81
+ ns = @doc.root.search_href(uri)
82
+ assert_instance_of(XML::NS, ns)
83
+ assert_equal(uri, ns.href)
84
+ assert_equal(prefix, ns.prefix)
85
+ end
86
+
87
+ def test_sibling
88
+ xml = "<?xml version=\"1.0\"?>\n<rubynet>\n <pkg/>\n <pkg2/>\n</rubynet>\n"
89
+
90
+ @doc.root = XML::Node.new('rubynet')
91
+ child = @doc.root.child = XML::Node.new('pkg')
92
+ assert_instance_of(XML::Node, child)
93
+ child.sibling = XML::Node.new('pkg2')
94
+ assert_equal(xml, @doc.to_s)
95
+ end
96
+
97
+ def test_set_doc_property
98
+ xml = "<?xml version=\"1.0\"?>\n"
99
+ xml << "<rubynet xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
100
+ xml << " <pkg/>\n"
101
+ xml << "</rubynet>\n"
102
+
103
+ @doc.root = XML::Node.new('rubynet')
104
+ @doc.root['xmlns:xlink'] = "http://www.w3.org/1999/xlink"
105
+ pkg = @doc.root.child = XML::Node.new('pkg')
106
+ assert_equal(xml, @doc.to_s)
107
+ end
108
+
109
+ def test_set_node_base
110
+ xml = "<?xml version=\"1.0\"?>\n"
111
+ xml << "<rubynet>\n"
112
+ xml << " <pkg xml:base=\"http://www.rubynet.org/\"/>\n"
113
+ xml << "</rubynet>\n"
114
+
115
+ @doc.root = XML::Node.new('rubynet')
116
+ pkg = @doc.root.child = XML::Node.new('pkg')
117
+ pkg.base = 'http://www.rubynet.org/'
118
+ assert_equal(xml, @doc.to_s)
119
+ end
120
+
121
+ def test_set_node_property
122
+ xml = "<?xml version=\"1.0\"?>\n"
123
+ xml << "<rubynet xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
124
+ xml << " <pkg version=\"1.0\">\n"
125
+ xml << " <meta>\n"
126
+ xml << " <pkgname>libxml</pkgname>\n"
127
+ xml << " </meta>\n"
128
+ xml << " </pkg>\n"
129
+ xml << "</rubynet>\n"
130
+
131
+ @doc.root = XML::Node.new('rubynet')
132
+ @doc.root['xmlns:xlink'] = "http://www.w3.org/1999/xlink"
133
+ pkg = @doc.root.child = XML::Node.new('pkg')
134
+ pkg['version'] = '1.0'
135
+ meta = pkg.child = XML::Node.new('meta')
136
+ pkgname = meta.child = XML::Node.new('pkgname', 'libxml')
137
+ assert_equal(xml, @doc.to_s)
138
+ end
139
+ end
@@ -46,4 +46,25 @@ class TestDtd < Test::Unit::TestCase
46
46
 
47
47
  assert_equal(expected, messages)
48
48
  end
49
- end
49
+
50
+ def test_external_dtd
51
+ xml = <<-EOS
52
+ <!DOCTYPE test PUBLIC "-//TEST" "test.dtd" []>
53
+ <test>
54
+ <title>T1</title>
55
+ </test>
56
+ EOS
57
+
58
+ messages = Array.new
59
+ XML::Parser.register_error_handler(lambda { |msg| messages << msg })
60
+
61
+ XML::Parser.default_load_external_dtd = false
62
+ doc = XML::Parser.string(xml).parse
63
+ assert_equal(Array.new, messages)
64
+
65
+ XML::Parser.default_load_external_dtd = true
66
+ doc = XML::Parser.string(xml).parse
67
+ assert_equal('I/O warning : failed to load external entity "test.dtd" <!DOCTYPE test PUBLIC "-//TEST" "test.dtd" []> ^',
68
+ messages.map{|msg| msg.strip}.join(' '))
69
+ end
70
+ end
@@ -80,6 +80,19 @@ class TestNode < Test::Unit::TestCase
80
80
  assert(!node_a.equal?(node_a2))
81
81
  end
82
82
 
83
+ def test_equality_nil
84
+ node = @doc.root
85
+ assert(node != nil)
86
+ end
87
+
88
+ def test_equality_wrong_type
89
+ node = @doc.root
90
+
91
+ assert_raises(TypeError) do
92
+ assert(node != 'abc')
93
+ end
94
+ end
95
+
83
96
  def test_content()
84
97
  assert_equal('onetwo', @doc.root.content)
85
98
 
@@ -1,7 +1,7 @@
1
1
  require "libxml"
2
2
  require 'test/unit'
3
3
 
4
- class TextNodeEdit < Test::Unit::TestCase
4
+ class TestNodeEdit < Test::Unit::TestCase
5
5
  def setup
6
6
  xp = XML::Parser.new()
7
7
  xp.string = '<test><num>one</num><num>two</num><num>three</num></test>'
@@ -1,4 +1,4 @@
1
- # $Id: tc_xml_node_xlink.rb 251 2008-01-22 18:12:00Z transami $
1
+ # $Id: tc_xml_node_xlink.rb 453 2008-07-15 19:36:12Z cfis $
2
2
  require "libxml"
3
3
  require 'test/unit'
4
4
 
@@ -1,14 +1,18 @@
1
1
  require "libxml"
2
2
  require 'test/unit'
3
3
 
4
- class TextParser < Test::Unit::TestCase
4
+ class TestParser < Test::Unit::TestCase
5
5
  def setup
6
+ XML::Parser.register_error_handler(nil)
6
7
  @xp = XML::Parser.new
7
- assert_not_nil(@xp)
8
8
  end
9
9
 
10
10
  def teardown
11
11
  @xp = nil
12
+ XML::Parser.register_error_handler(nil)
13
+ # Clear out all the files we opened up in
14
+ # the test_fd_gc test
15
+ GC.start
12
16
  end
13
17
 
14
18
  # ----- Constants ------
@@ -157,7 +161,7 @@ class TextParser < Test::Unit::TestCase
157
161
  end
158
162
 
159
163
  def test_file
160
- file = File.expand_path('model/rubynet.xml')
164
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
161
165
 
162
166
  @xp.filename = file
163
167
  assert_equal(file, @xp.filename)
@@ -167,21 +171,71 @@ class TextParser < Test::Unit::TestCase
167
171
  end
168
172
 
169
173
  def test_io
170
- File.open('model/rubynet.xml') do |f|
174
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |f|
171
175
  assert_kind_of(IO, f)
172
176
  assert_kind_of(IO, @xp.io = f)
173
177
  assert_instance_of(XML::Document, @xp.parse)
174
178
  end # File.open
175
179
  end # def test_libxml_parser_io
176
180
 
181
+ def test_fd_gc
182
+ # Test opening # of documents up to the file limit for the OS.
183
+ # Ideally it should run until libxml emits a warning,
184
+ # thereby knowing we've done a GC sweep. For the time being,
185
+ # re-open the same doc `limit descriptors` times.
186
+ # If we make it to the end, then we've succeeded,
187
+ # otherwise an exception will be thrown.
188
+ XML::Parser.register_error_handler(lambda {|msg| nil })
189
+
190
+ max_fd = if RUBY_PLATFORM.match(/mswin32/i)
191
+ 500
192
+ else
193
+ (`ulimit -n`.chomp.to_i) + 1
194
+ end
195
+
196
+ filename = File.join(File.dirname(__FILE__), 'model/rubynet.xml')
197
+ max_fd.times do
198
+ XML::Document.file(filename)
199
+ end
200
+ end
201
+
177
202
  def test_libxml_parser_features
178
203
  assert_instance_of(Array, XML::Parser::features)
179
204
  end
180
-
205
+
181
206
  # ----- Errors ------
182
207
  def test_error_handler
183
- $stderr.puts "\nEXPECTING: TWO ERRORS:"
184
- # this will send message to stderr
208
+ assert_raise(XML::Parser::ParseError) do
209
+ XML::Parser.string('<foo><bar/></foz>').parse
210
+ end
211
+
212
+ ary = []
213
+ XML::Parser.register_error_handler do |msg|
214
+ ary << msg
215
+ end
216
+
217
+ # this will use our error handler
218
+ assert_raise(XML::Parser::ParseError) do
219
+ XML::Parser.string('<foo><bar/></foz>').parse
220
+ end
221
+
222
+ assert_equal(["Entity: line 1: ",
223
+ "parser ",
224
+ "error : ",
225
+ "Opening and ending tag mismatch: foo line 1 and foz\n",
226
+ "<foo><bar/></foz>\n",
227
+ " ^\n"], ary)
228
+
229
+ assert_instance_of(Proc, XML::Parser.register_error_handler(nil))
230
+
231
+ # this will go to stderr again
232
+ assert_raise(XML::Parser::ParseError) do
233
+ d = XML::Parser.string('<foo><bar/></foz>').parse
234
+ end
235
+ end
236
+
237
+ def test_error_handler_lambda
238
+ XML::Parser.register_error_handler(nil)
185
239
  assert_raise(XML::Parser::ParseError) do
186
240
  XML::Parser.string('<foo><bar/></foz>').parse
187
241
  end
@@ -211,12 +265,14 @@ class TextParser < Test::Unit::TestCase
211
265
 
212
266
  def test_bad_xml
213
267
  @xp.string = '<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
268
+ XML::Parser.register_error_handler(lambda {|msg| nil })
214
269
  assert_raise(XML::Parser::ParseError) do
215
270
  assert_not_nil(@xp.parse)
216
271
  end
217
272
  end
218
273
 
219
274
  def test_double_parse
275
+ XML::Parser.register_error_handler(lambda {|msg| nil })
220
276
  parser = XML::Parser.string("<test>something</test>")
221
277
  doc = parser.parse
222
278
 
@@ -228,6 +284,7 @@ class TextParser < Test::Unit::TestCase
228
284
  def test_libxml_parser_empty_string
229
285
  assert_raise(XML::Parser::ParseError) do
230
286
  @xp.string = ''
287
+ @xp.parse
231
288
  end
232
289
 
233
290
  assert_raise(TypeError) do
@@ -0,0 +1,42 @@
1
+ require "libxml"
2
+ require 'test/unit'
3
+
4
+ # Properties is deprecated - use attributes instead.
5
+ # Tests for backwards compatibility
6
+
7
+ class TestProperties < Test::Unit::TestCase
8
+ def setup()
9
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
10
+ @doc = xp.parse
11
+ end
12
+
13
+ def teardown()
14
+ @doc = nil
15
+ end
16
+
17
+ def test_traversal
18
+ properties = @doc.root.properties
19
+
20
+ assert_instance_of(XML::Attributes, properties)
21
+ attribute = properties.first
22
+ assert_equal('uga', attribute.name)
23
+ assert_equal('booga', attribute.value)
24
+
25
+ attribute = attribute.next
26
+ assert_instance_of(XML::Attr, attribute)
27
+ assert_equal('foo', attribute.name)
28
+ assert_equal('bar', attribute.value)
29
+ end
30
+
31
+ def test_each_attr
32
+ @doc.root.properties.each_attr do |attribute|
33
+ assert_instance_of(XML::Attr, attribute)
34
+ end
35
+ end
36
+
37
+ def test_no_properties
38
+ properties = @doc.root.child.properties
39
+ assert_instance_of(XML::Attributes, properties)
40
+ assert_equal(0, properties.length)
41
+ end
42
+ end
@@ -7,18 +7,18 @@ class TC_XML_Reader < Test::Unit::TestCase
7
7
 
8
8
  def test_new_file
9
9
  reader = XML::Reader.file(SIMPLE_XML)
10
- do_test_simple(reader)
10
+ verify_simple(reader)
11
11
  assert_raises(RuntimeError) { XML::Reader.file('/does/not/exist') }
12
12
  end
13
13
 
14
14
  def test_new_data
15
15
  reader = XML::Reader.new(File.read(SIMPLE_XML))
16
- do_test_simple(reader)
16
+ verify_simple(reader)
17
17
  end
18
18
 
19
19
  def test_new_walker
20
20
  reader = XML::Reader.walker(XML::Document.file(SIMPLE_XML))
21
- do_test_simple(reader)
21
+ verify_simple(reader)
22
22
  end
23
23
 
24
24
  def test_reader_error
@@ -81,7 +81,7 @@ class TC_XML_Reader < Test::Unit::TestCase
81
81
  doc.standalone?
82
82
  end
83
83
 
84
- def do_test_simple(reader)
84
+ def verify_simple(reader)
85
85
  node_types = []
86
86
  19.times do
87
87
  assert_equal(1, reader.read)
@@ -3,58 +3,72 @@ require 'test/unit'
3
3
 
4
4
  # TODO this is woefully inadequate
5
5
 
6
- class TC_XML_SaxParser2 < Test::Unit::TestCase
7
- class TestCaseCallbacks
8
- include XML::SaxParser::Callbacks
6
+ class TestCaseCallbacks
7
+ include XML::SaxParser::Callbacks
9
8
 
10
- attr_accessor :test
9
+ attr_accessor :test
11
10
 
12
- def initialize
13
- @test = Hash.new { |h,k| h[k] = [] }
14
- @i = 0
15
- end
11
+ def initialize
12
+ @test = Hash.new { |h,k| h[k] = [] }
13
+ @i = 0
14
+ end
16
15
 
17
- def on_start_document
18
- @test[:startdoc] << @i+=1
19
- end
16
+ def on_start_document
17
+ @test[:startdoc] << @i+=1
18
+ end
20
19
 
21
- def on_start_element(name, attr_hash)
22
- @test[:startel] << [@i+=1,name,attr_hash]
23
- end
20
+ def on_start_element(name, attr_hash)
21
+ @test[:startel] << [@i+=1,name,attr_hash]
22
+ end
24
23
 
25
- def on_characters(chars)
26
- @test[:chars] << [@i+=1,chars]
27
- end
24
+ def on_characters(chars)
25
+ @test[:chars] << [@i+=1,chars]
26
+ end
28
27
 
29
- def on_comment(msg)
30
- @test[:comment] << [@i+=1,msg]
31
- end
28
+ def on_comment(msg)
29
+ @test[:comment] << [@i+=1,msg]
30
+ end
32
31
 
33
- def on_processing_instruction(target, data)
34
- @test[:pinstr] << [@i+=1, target, data]
35
- end
32
+ def on_processing_instruction(target, data)
33
+ @test[:pinstr] << [@i+=1, target, data]
34
+ end
36
35
 
37
- def on_cdata_block(cdata)
38
- @test[:cdata] << [@i+=1,cdata]
39
- end
36
+ def on_cdata_block(cdata)
37
+ @test[:cdata] << [@i+=1,cdata]
38
+ end
40
39
 
41
- def on_end_element(name)
42
- @test[:endel] << [@i+=1,name]
43
- end
40
+ def on_end_element(name)
41
+ @test[:endel] << [@i+=1,name]
42
+ end
44
43
 
45
- def on_end_document
46
- @test[:enddoc] << @i+=1
47
- end
44
+ def on_end_document
45
+ @test[:enddoc] << @i+=1
48
46
  end
47
+ end
49
48
 
50
- def setup()
49
+ class TestSaxParser < Test::Unit::TestCase
50
+ def setup
51
51
  @xp = XML::SaxParser.new
52
52
  end
53
53
 
54
- def teardown()
54
+ def teardown
55
55
  @xp = nil
56
56
  end
57
57
 
58
+ def verify
59
+ @xp.parse
60
+ assert_equal [1], @xp.callbacks.test[:startdoc]
61
+ assert_equal [[2,'test',{'uga'=>'booga','foo'=>'bar'}],[3,'fixnum',{}],[6,'fixnum',{}]],
62
+ @xp.callbacks.test[:startel]
63
+ assert_equal [[4,'one'],[7,'two'],[9,"\n "],[11,"\n "],[13,"\n "],[15,"\n"]],
64
+ @xp.callbacks.test[:chars]
65
+ assert_equal [[10, ' msg ']], @xp.callbacks.test[:comment]
66
+ assert_equal [[12, 'custom', 'foo="bar"']], @xp.callbacks.test[:pinstr]
67
+ assert_equal [[14, 'here it goes']], @xp.callbacks.test[:cdata]
68
+ assert_equal [[5,'fixnum'],[8,'fixnum'],[16,'test']], @xp.callbacks.test[:endel]
69
+ assert_equal [17], @xp.callbacks.test[:enddoc]
70
+ end
71
+
58
72
  def test_string_without_callbacks
59
73
  @xp.string = File.read(File.join(File.dirname(__FILE__), 'model/saxtest.xml'))
60
74
  assert_equal true, @xp.parse
@@ -68,29 +82,15 @@ class TC_XML_SaxParser2 < Test::Unit::TestCase
68
82
  def test_callbacks_with_string
69
83
  @xp.callbacks = TestCaseCallbacks.new
70
84
  @xp.string = File.read(File.join(File.dirname(__FILE__), 'model/saxtest.xml'))
71
- do_test
85
+ verify
72
86
  end
73
87
 
74
88
  def test_callbacks_with_file
75
89
  @xp.callbacks = TestCaseCallbacks.new
76
90
  @xp.filename = File.join(File.dirname(__FILE__), 'model/saxtest.xml')
77
- do_test
91
+ verify
78
92
  end
79
93
 
80
- def do_test
81
- @xp.parse
82
- assert_equal [1], @xp.callbacks.test[:startdoc]
83
- assert_equal [[2,'test',{'uga'=>'booga','foo'=>'bar'}],[3,'fixnum',{}],[6,'fixnum',{}]],
84
- @xp.callbacks.test[:startel]
85
- assert_equal [[4,'one'],[7,'two'],[9,"\n "],[11,"\n "],[13,"\n "],[15,"\n"]],
86
- @xp.callbacks.test[:chars]
87
- assert_equal [[10, ' msg ']], @xp.callbacks.test[:comment]
88
- assert_equal [[12, 'custom', 'foo="bar"']], @xp.callbacks.test[:pinstr]
89
- assert_equal [[14, 'here it goes']], @xp.callbacks.test[:cdata]
90
- assert_equal [[5,'fixnum'],[8,'fixnum'],[16,'test']], @xp.callbacks.test[:endel]
91
- assert_equal [17], @xp.callbacks.test[:enddoc]
92
- end
93
-
94
94
  def test_doctype
95
95
  @xp.callbacks = TestCaseCallbacks.new
96
96
  @xp.string = <<-EOS