summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rss
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/test/rss
Fresh start
Diffstat (limited to 'jni/ruby/test/rss')
-rw-r--r--jni/ruby/test/rss/dot.pngbin0 -> 111 bytes
-rw-r--r--jni/ruby/test/rss/rss-assertions.rb2090
-rw-r--r--jni/ruby/test/rss/rss-testcase.rb478
-rw-r--r--jni/ruby/test/rss/test_1.0.rb307
-rw-r--r--jni/ruby/test/rss/test_2.0.rb411
-rw-r--r--jni/ruby/test/rss/test_accessor.rb103
-rw-r--r--jni/ruby/test/rss/test_atom.rb683
-rw-r--r--jni/ruby/test/rss/test_content.rb104
-rw-r--r--jni/ruby/test/rss/test_dublincore.rb269
-rw-r--r--jni/ruby/test/rss/test_image.rb214
-rw-r--r--jni/ruby/test/rss/test_inherit.rb40
-rw-r--r--jni/ruby/test/rss/test_itunes.rb347
-rw-r--r--jni/ruby/test/rss/test_maker_0.9.rb474
-rw-r--r--jni/ruby/test/rss/test_maker_1.0.rb516
-rw-r--r--jni/ruby/test/rss/test_maker_2.0.rb757
-rw-r--r--jni/ruby/test/rss/test_maker_atom_entry.rb393
-rw-r--r--jni/ruby/test/rss/test_maker_atom_feed.rb454
-rw-r--r--jni/ruby/test/rss/test_maker_content.rb47
-rw-r--r--jni/ruby/test/rss/test_maker_dc.rb149
-rw-r--r--jni/ruby/test/rss/test_maker_image.rb62
-rw-r--r--jni/ruby/test/rss/test_maker_itunes.rb469
-rw-r--r--jni/ruby/test/rss/test_maker_slash.rb37
-rw-r--r--jni/ruby/test/rss/test_maker_sy.rb44
-rw-r--r--jni/ruby/test/rss/test_maker_taxo.rb81
-rw-r--r--jni/ruby/test/rss/test_maker_trackback.rb41
-rw-r--r--jni/ruby/test/rss/test_maker_xml-stylesheet.rb83
-rw-r--r--jni/ruby/test/rss/test_parser.rb64
-rw-r--r--jni/ruby/test/rss/test_parser_1.0.rb528
-rw-r--r--jni/ruby/test/rss/test_parser_2.0.rb122
-rw-r--r--jni/ruby/test/rss/test_parser_atom_entry.rb163
-rw-r--r--jni/ruby/test/rss/test_parser_atom_feed.rb276
-rw-r--r--jni/ruby/test/rss/test_setup_maker_0.9.rb246
-rw-r--r--jni/ruby/test/rss/test_setup_maker_1.0.rb550
-rw-r--r--jni/ruby/test/rss/test_setup_maker_2.0.rb308
-rw-r--r--jni/ruby/test/rss/test_setup_maker_atom_entry.rb409
-rw-r--r--jni/ruby/test/rss/test_setup_maker_atom_feed.rb445
-rw-r--r--jni/ruby/test/rss/test_setup_maker_itunes.rb143
-rw-r--r--jni/ruby/test/rss/test_setup_maker_slash.rb38
-rw-r--r--jni/ruby/test/rss/test_slash.rb64
-rw-r--r--jni/ruby/test/rss/test_syndication.rb125
-rw-r--r--jni/ruby/test/rss/test_taxonomy.rb172
-rw-r--r--jni/ruby/test/rss/test_to_s.rb670
-rw-r--r--jni/ruby/test/rss/test_trackback.rb135
-rw-r--r--jni/ruby/test/rss/test_version.rb9
-rw-r--r--jni/ruby/test/rss/test_xml-stylesheet.rb108
45 files changed, 13228 insertions, 0 deletions
diff --git a/jni/ruby/test/rss/dot.png b/jni/ruby/test/rss/dot.png
new file mode 100644
index 0000000..9c6960f
--- /dev/null
+++ b/jni/ruby/test/rss/dot.png
Binary files differ
diff --git a/jni/ruby/test/rss/rss-assertions.rb b/jni/ruby/test/rss/rss-assertions.rb
new file mode 100644
index 0000000..f2e9dc0
--- /dev/null
+++ b/jni/ruby/test/rss/rss-assertions.rb
@@ -0,0 +1,2090 @@
+require 'erb'
+
+module RSS
+ module Assertions
+ def _wrap_assertion
+ yield
+ end
+
+ def assert_parse(rss, assert_method, *args)
+ __send__("assert_#{assert_method}", *args) do
+ ::RSS::Parser.parse(rss)
+ end
+ __send__("assert_#{assert_method}", *args) do
+ ::RSS::Parser.parse(rss, false).validate
+ end
+ end
+
+ def assert_ns(prefix, uri)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise NSError")
+ rescue ::RSS::NSError => e
+ assert_equal(prefix, e.prefix)
+ assert_equal(uri, e.uri)
+ end
+ end
+ end
+
+ def assert_missing_tag(tag, parent)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise MissingTagError")
+ rescue ::RSS::MissingTagError => e
+ assert_equal(tag, e.tag)
+ assert_equal(parent, e.parent)
+ end
+ end
+ end
+
+ def assert_too_much_tag(tag, parent)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise TooMuchTagError")
+ rescue ::RSS::TooMuchTagError => e
+ assert_equal(tag, e.tag)
+ assert_equal(parent, e.parent)
+ end
+ end
+ end
+
+ def assert_missing_attribute(tag, attrname)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise MissingAttributeError")
+ rescue ::RSS::MissingAttributeError => e
+ assert_equal(tag, e.tag)
+ assert_equal(attrname, e.attribute)
+ end
+ end
+ end
+
+ def assert_not_expected_tag(tag, uri, parent)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise NotExpectedTagError")
+ rescue ::RSS::NotExpectedTagError => e
+ assert_equal(tag, e.tag)
+ assert_equal(uri, e.uri)
+ assert_equal(parent, e.parent)
+ end
+ end
+ end
+
+ def assert_not_available_value(tag, value, attribute=nil)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise NotAvailableValueError")
+ rescue ::RSS::NotAvailableValueError => e
+ assert_equal(tag, e.tag)
+ assert_equal(value, e.value)
+ assert_equal(attribute, e.attribute)
+ end
+ end
+ end
+
+ def assert_not_set_error(name, variables)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise NotSetError")
+ rescue ::RSS::NotSetError => e
+ assert_equal(name, e.name)
+ assert_kind_of(Array, variables)
+ assert_equal(variables.sort, e.variables.sort)
+ end
+ end
+ end
+
+ def assert_xml_declaration(version, encoding, standalone, rss)
+ _wrap_assertion do
+ assert_equal(version, rss.version)
+ assert_equal(encoding, rss.encoding)
+ assert_equal(standalone, rss.standalone)
+ end
+ end
+
+ def assert_xml_stylesheet_attrs(attrs, xsl)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+ ::RSS::XMLStyleSheet::ATTRIBUTES.each do |name|
+ assert_equal(n_attrs[name], xsl.__send__(name))
+ end
+ end
+ end
+
+ def assert_xml_stylesheet(target, attrs, xsl)
+ _wrap_assertion do
+ if attrs.has_key?(:href)
+ if !attrs.has_key?(:type) and attrs.has_key?(:guess_type)
+ attrs[:type] = attrs[:guess_type]
+ end
+ assert_equal("xml-stylesheet", target)
+ assert_xml_stylesheet_attrs(attrs, xsl)
+ else
+ assert_nil(target)
+ assert_equal("", xsl.to_s)
+ end
+ end
+ end
+
+ def assert_xml_stylesheet_pis(attrs_ary, rss=nil)
+ _wrap_assertion do
+ if rss.nil?
+ rss = ::RSS::RDF.new
+ setup_rss10(rss)
+ end
+ xss_strs = []
+ attrs_ary.each do |attrs|
+ xss = ::RSS::XMLStyleSheet.new(attrs)
+ xss_strs.push(xss.to_s)
+ rss.xml_stylesheets.push(xss)
+ end
+ pi_str = rss.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<[^\?].*\z/m, "")
+ assert_equal(xss_strs.join("\n"), pi_str)
+ end
+ end
+
+ def assert_xml_stylesheets(attrs, xss)
+ _wrap_assertion do
+ xss.each_with_index do |xs, i|
+ assert_xml_stylesheet_attrs(attrs[i], xs)
+ end
+ end
+ end
+
+
+ def assert_atom_person(tag_name, generator)
+ _wrap_assertion do
+ name = "Mark Pilgrim"
+ uri = "http://example.org/"
+ email = "f8dy@example.com"
+
+ assert_parse(generator.call(<<-EOA), :missing_tag, "name", tag_name)
+ <#{tag_name}/>
+EOA
+
+ assert_parse(generator.call(<<-EOA), :missing_tag, "name", tag_name)
+ <#{tag_name}>
+ <uri>#{uri}</uri>
+ <email>#{email}</email>
+ </#{tag_name}>
+EOA
+
+ assert_parse(generator.call(<<-EOA), :nothing_raised)
+ <#{tag_name}>
+ <name>#{name}</name>
+ </#{tag_name}>
+EOA
+
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <#{tag_name}>
+ <name>#{name}</name>
+ <uri>#{uri}</uri>
+ <email>#{email}</email>
+ </#{tag_name}>
+EOA
+
+ person = yield(feed)
+ assert_not_nil(person)
+ assert_equal(name, person.name.content)
+ assert_equal(uri, person.uri.content)
+ assert_equal(email, person.email.content)
+ end
+ end
+
+ def assert_atom_category(generator)
+ _wrap_assertion do
+ term = "Music"
+ scheme = "http://xmlns.com/wordnet/1.6/"
+ label = "music"
+
+ missing_args = [:missing_attribute, "category", "term"]
+ assert_parse(generator.call(<<-EOA), *missing_args)
+ <category/>
+EOA
+
+ assert_parse(generator.call(<<-EOA), *missing_args)
+ <category scheme="#{scheme}" label="#{label}"/>
+EOA
+
+ assert_parse(generator.call(<<-EOA), :nothing_raised)
+ <category term="#{term}"/>
+EOA
+
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <category term="#{term}" scheme="#{scheme}" label="#{label}"/>
+EOA
+
+ category = yield(feed)
+ assert_not_nil(category)
+ assert_equal(term, category.term)
+ assert_equal(scheme, category.scheme)
+ assert_equal(label, category.label)
+ end
+ end
+
+ def assert_atom_link(generator)
+ _wrap_assertion do
+ href = "http://example.org/feed.atom"
+ rel = "self"
+ type = "application/atom+xml"
+ hreflang = "en"
+ title = "Atom"
+ length = "1024"
+
+ assert_parse(generator.call(<<-EOA), :missing_attribute, "link", "href")
+ <link/>
+EOA
+
+ assert_parse(generator.call(<<-EOA), :missing_attribute, "link", "href")
+ <link rel="#{rel}" type="#{type}" hreflang="#{hreflang}"
+ title="#{title}" length="#{length}"/>
+EOA
+
+ assert_parse(generator.call(<<-EOA), :nothing_raised)
+ <link href="#{href}"/>
+EOA
+
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <link href="#{href}" rel="#{rel}" type="#{type}" hreflang="#{hreflang}"
+ title="#{title}" length="#{length}"/>
+EOA
+
+ link = yield(feed)
+ assert_not_nil(link)
+ assert_equal(href, link.href)
+ assert_equal(rel, link.rel)
+ assert_equal(type, link.type)
+ assert_equal(hreflang, link.hreflang)
+ assert_equal(title, link.title)
+ assert_equal(length, link.length)
+
+
+ href = "http://example.org/index.html.ja"
+ parent = link.parent.tag_name
+ return if parent == "source"
+
+ optional_attributes = %w(hreflang="ja" type="text/html")
+ 0.upto(optional_attributes.size) do |i|
+ combination(optional_attributes, i).each do |attributes|
+ attrs = attributes.join(" ")
+ assert_parse(generator.call(<<-EOA), :too_much_tag, "link", parent)
+ <link rel="alternate" #{attrs} href="#{href}"/>
+ <link rel="alternate" #{attrs} href="#{href}"/>
+EOA
+ end
+ end
+ end
+ end
+
+ def assert_atom_generator(generator)
+ _wrap_assertion do
+ uri = "http://www.example.com/"
+ version = "1.0"
+ content = "Example Toolkit"
+
+ assert_parse(generator.call(<<-EOA), :nothing_raised)
+ <generator/>
+EOA
+
+ assert_parse(generator.call(<<-EOA), :nothing_raised)
+ <generator uri="#{uri}" version="#{version}"/>
+EOA
+
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <generator uri="#{uri}" version="#{version}">#{content}</generator>
+EOA
+
+ gen = yield(feed)
+ assert_not_nil(gen)
+ assert_equal(uri, gen.uri)
+ assert_equal(version, gen.version)
+ assert_equal(content, gen.content)
+ end
+ end
+
+ def assert_atom_icon(generator)
+ _wrap_assertion do
+ content = "http://www.example.com/example.png"
+
+ assert_parse(generator.call(<<-EOA), :nothing_raised)
+ <icon/>
+EOA
+
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <icon>#{content}</icon>
+EOA
+
+ icon = yield(feed)
+ assert_not_nil(icon)
+ assert_equal(content, icon.content)
+ end
+ end
+
+ def assert_atom_text_construct(tag_name, generator)
+ _wrap_assertion do
+ [nil, "text", "html"].each do |type|
+ attr = ""
+ attr = " type=\"#{type}\"" if type
+ assert_parse(generator.call(<<-EOA), :nothing_raised)
+ <#{tag_name}#{attr}/>
+EOA
+ end
+
+ assert_parse(generator.call(<<-EOA), :missing_tag, "div", tag_name)
+ <#{tag_name} type="xhtml"/>
+EOA
+
+ args = ["x", Atom::URI, tag_name]
+ assert_parse(generator.call(<<-EOA), :not_expected_tag, *args)
+ <#{tag_name} type="xhtml"><x/></#{tag_name}>
+EOA
+
+ invalid_value = "invalid"
+ args = ["type", invalid_value]
+ assert_parse(generator.call(<<-EOA), :not_available_value, *args)
+ <#{tag_name} type="#{invalid_value}"/>
+EOA
+
+ [
+ [nil, "A lot of effort went into making this effortless"],
+ ["text", "A lot of effort went into making this effortless"],
+ ["html", "A <em>lot</em> of effort went into making this effortless"],
+ ].each do |type, content|
+ attr = ""
+ attr = " type=\"#{type}\"" if type
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <#{tag_name}#{attr}>#{h content}</#{tag_name}>
+EOA
+
+ element = yield(feed)
+ assert_not_nil(element)
+ assert_equal(type, element.type)
+ assert_equal(content, element.content)
+ end
+
+ [false, true].each do |with_space|
+ xhtml_uri = "http://www.w3.org/1999/xhtml"
+ xhtml_content = "<div xmlns=\"#{xhtml_uri}\">abc</div>"
+ xhtml_element = RSS::XML::Element.new("div", nil, xhtml_uri,
+ {"xmlns" => xhtml_uri},
+ ["abc"])
+ content = xhtml_content
+ content = " #{content} " if with_space
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <#{tag_name} type="xhtml">#{content}</#{tag_name}>
+EOA
+
+ element = yield(feed)
+ assert_not_nil(element)
+ assert_equal("xhtml", element.type)
+ assert_equal(xhtml_content, element.content)
+ assert_equal(xhtml_element, element.xhtml)
+ end
+ end
+ end
+
+ def assert_atom_date_construct(tag_name, generator)
+ _wrap_assertion do
+ args = [tag_name, ""]
+ assert_parse(generator.call(<<-EOR), :not_available_value, *args)
+ <#{tag_name}/>
+EOR
+
+ [
+ ["xxx", false],
+ ["2007", false],
+ ["2007/02/09", true],
+ ].each do |invalid_value, can_parse|
+ assert_not_available_value(tag_name, invalid_value) do
+ RSS::Parser.parse(generator.call(<<-EOR))
+ <#{tag_name}>#{invalid_value}</#{tag_name}>
+EOR
+ end
+
+ feed = RSS::Parser.parse(generator.call(<<-EOR), false)
+ <#{tag_name}>#{invalid_value}</#{tag_name}>
+EOR
+ value = yield(feed).content
+ if can_parse
+ assert_equal(Time.parse(invalid_value), value)
+ else
+ assert_nil(value)
+ end
+ end
+
+ [
+ "2003-12-13T18:30:02Z",
+ "2003-12-13T18:30:02.25Z",
+ "2003-12-13T18:30:02+01:00",
+ "2003-12-13T18:30:02.25+01:00",
+ ].each do |valid_value|
+ assert_parse(generator.call(<<-EOR), :nothing_raised)
+ <#{tag_name}>#{valid_value}</#{tag_name}>
+EOR
+
+ feed = RSS::Parser.parse(generator.call(<<-EOR))
+ <#{tag_name}>#{valid_value}</#{tag_name}>
+EOR
+ assert_equal(Time.parse(valid_value), yield(feed).content)
+ end
+ end
+ end
+
+ def assert_atom_logo(generator)
+ _wrap_assertion do
+ content = "http://www.example.com/example.png"
+
+ assert_parse(generator.call(<<-EOA), :nothing_raised)
+ <logo/>
+EOA
+
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <logo>#{content}</logo>
+EOA
+
+ logo = yield(feed)
+ assert_not_nil(logo)
+ assert_equal(content, logo.content)
+ end
+ end
+
+ def assert_atom_content(generator, &getter)
+ _wrap_assertion do
+ assert_atom_content_inline_text(generator, &getter)
+ assert_atom_content_inline_xhtml(generator, &getter)
+ assert_atom_content_inline_other(generator, &getter)
+ assert_atom_content_out_of_line(generator, &getter)
+ end
+ end
+
+ def assert_atom_content_inline_text(generator)
+ _wrap_assertion do
+ [nil, "text", "html"].each do |type|
+ content = "<content"
+ content << " type='#{type}'" if type
+
+ suffix = "/>"
+ assert_parse(generator.call(content + suffix), :nothing_raised)
+ suffix = ">xxx</content>"
+ assert_parse(generator.call(content + suffix), :nothing_raised)
+ end
+
+ [
+ ["text", "sample content"],
+ ["text/plain", "sample content"],
+ ["html", "<em>sample</em> content"]
+ ].each do |type, content_content|
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <content type="#{type}">#{h content_content}</content>
+EOA
+ content = yield(feed)
+ assert_equal(type, content.type)
+ if %w(text html).include?(type)
+ assert(content.inline_text?)
+ else
+ assert(!content.inline_text?)
+ end
+ if type == "html"
+ assert(content.inline_html?)
+ else
+ assert(!content.inline_html?)
+ end
+ assert(!content.inline_xhtml?)
+ if type == "text/plain"
+ assert(content.inline_other?)
+ assert(content.inline_other_text?)
+ else
+ assert(!content.inline_other?)
+ assert(!content.inline_other_text?)
+ end
+ assert(!content.inline_other_xml?)
+ assert(!content.inline_other_base64?)
+ assert(!content.out_of_line?)
+ assert(!content.have_xml_content?)
+ assert_equal(content_content, content.content)
+ end
+ end
+ end
+
+ def assert_atom_content_inline_xhtml(generator)
+ _wrap_assertion do
+ args = ["div", "content"]
+ assert_parse(generator.call(<<-EOA), :missing_tag, *args)
+ <content type="xhtml"/>
+EOA
+
+ args = ["x", Atom::URI, "content"]
+ assert_parse(generator.call(<<-EOA), :not_expected_tag, *args)
+ <content type="xhtml"><x/></content>
+EOA
+
+ xhtml_uri = "http://www.w3.org/1999/xhtml"
+ xhtml_content = "<div xmlns=\"#{xhtml_uri}\">abc</div>"
+ xhtml_element = RSS::XML::Element.new("div", nil, xhtml_uri,
+ {"xmlns" => xhtml_uri},
+ ["abc"])
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <content type="xhtml">#{xhtml_content}</content>
+EOA
+
+ content = yield(feed)
+ assert_not_nil(content)
+ assert_equal("xhtml", content.type)
+ assert(!content.inline_text?)
+ assert(!content.inline_html?)
+ assert(content.inline_xhtml?)
+ assert(!content.inline_other?)
+ assert(!content.inline_other_text?)
+ assert(!content.inline_other_xml?)
+ assert(!content.inline_other_base64?)
+ assert(!content.out_of_line?)
+ assert(content.have_xml_content?)
+ assert_equal(xhtml_content, content.content)
+ assert_equal(xhtml_element, content.xhtml)
+ end
+ end
+
+ def assert_atom_content_inline_other(generator, &getter)
+ _wrap_assertion do
+ assert_atom_content_inline_other_text(generator, &getter)
+ assert_atom_content_inline_other_xml(generator, &getter)
+ end
+ end
+
+ def assert_atom_content_inline_other_text(generator)
+ _wrap_assertion do
+ type = "image/png"
+ assert_parse(generator.call(<<-EOA), :nothing_raised)
+ <content type="#{type}"/>
+EOA
+
+ png_file = File.join(File.dirname(__FILE__), "dot.png")
+ png = File.open(png_file, "rb") do |file|
+ file.read.force_encoding("binary")
+ end
+ base64_content = [png].pack("m").delete("\n")
+
+ [false, true].each do |with_space|
+ xml_content = base64_content
+ xml_content = " #{base64_content}" if with_space
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <content type="#{type}">#{xml_content}</content>
+EOA
+
+ content = yield(feed)
+ assert_not_nil(content)
+ assert_equal(type, content.type)
+ assert(!content.inline_text?)
+ assert(!content.inline_html?)
+ assert(!content.inline_xhtml?)
+ assert(content.inline_other?)
+ assert(!content.inline_other_text?)
+ assert(!content.inline_other_xml?)
+ assert(content.inline_other_base64?)
+ assert(!content.out_of_line?)
+ assert(!content.have_xml_content?)
+ assert_equal(png, content.content)
+
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([], {"type" => type}, base64_content, xml)
+ end
+ end
+ end
+
+ def assert_atom_content_inline_other_xml(generator)
+ _wrap_assertion do
+ type = "image/svg+xml"
+
+ assert_parse(generator.call(<<-EOA), :nothing_raised)
+ <content type="#{type}"/>
+EOA
+
+ svg_uri = "http://www.w3.org/2000/svg"
+ svg_width = "50pt"
+ svg_height = "20pt"
+ svg_version = "1.0"
+ text_x = "15"
+ text_y = "15"
+ text = "text"
+ svg_content = <<-EOS
+<svg
+ xmlns="#{svg_uri}"
+ width="#{svg_width}"
+ height="#{svg_height}"
+ version="#{svg_version}"
+><text x="#{text_x}" y="#{text_y}">#{text}</text
+></svg>
+EOS
+
+ text_element = RSS::XML::Element.new("text", nil, svg_uri,
+ {
+ "x" => text_x,
+ "y" => text_y,
+ },
+ [text])
+ svg_element = RSS::XML::Element.new("svg", nil, svg_uri,
+ {
+ "xmlns" => svg_uri,
+ "width" => svg_width,
+ "height" => svg_height,
+ "version" => svg_version,
+ },
+ [text_element])
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <content type="#{type}">#{svg_content}</content>
+EOA
+
+ content = yield(feed)
+ assert_not_nil(content)
+ assert_equal(type, content.type)
+ assert(!content.inline_text?)
+ assert(!content.inline_html?)
+ assert(!content.inline_xhtml?)
+ assert(content.inline_other?)
+ assert(!content.inline_other_text?)
+ assert(content.inline_other_xml?)
+ assert(!content.inline_other_base64?)
+ assert(!content.out_of_line?)
+ assert(content.have_xml_content?)
+ assert_equal(REXML::Document.new(svg_content).to_s.chomp,
+ REXML::Document.new(content.content).to_s.chomp)
+ assert_equal(svg_element, content.xml)
+ assert_nil(content.xhtml)
+ end
+ end
+
+ def assert_atom_content_out_of_line(generator)
+ _wrap_assertion do
+ text_type = "text/plain"
+ text_src = "http://example.com/README.txt"
+
+ missing_args = [:missing_attribute, "content", "type"]
+ # RSS Parser raises error even if this is "should" not "must".
+ assert_parse(generator.call(<<-EOA), *missing_args)
+ <content src="#{text_src}"/>
+EOA
+
+ content_content = "xxx"
+ not_available_value_args = [:not_available_value,
+ "content", content_content]
+ assert_parse(generator.call(<<-EOA), *not_available_value_args)
+ <content type="#{text_type}" src="#{text_src}">#{content_content}</content>
+EOA
+
+ feed = RSS::Parser.parse(generator.call(<<-EOA))
+ <content type="#{text_type}" src="#{text_src}"/>
+EOA
+ content = yield(feed)
+ assert_not_nil(content)
+ assert_equal(text_type, content.type)
+ assert_equal(text_src, content.src)
+ assert(!content.inline_text?)
+ assert(!content.inline_html?)
+ assert(!content.inline_xhtml?)
+ assert(!content.inline_other?)
+ assert(!content.inline_other_text?)
+ assert(!content.inline_other_xml?)
+ assert(!content.inline_other_base64?)
+ assert(content.out_of_line?)
+ assert(!content.have_xml_content?)
+ assert_nil(content.xml)
+ assert_nil(content.xhtml)
+ assert_equal("", content.content)
+ end
+ end
+
+ def assert_atom_source(generator, &getter)
+ _wrap_assertion do
+ assert_atom_source_author(generator, &getter)
+ assert_atom_source_category(generator, &getter)
+ assert_atom_source_contributor(generator, &getter)
+ assert_atom_source_generator(generator, &getter)
+ assert_atom_source_icon(generator, &getter)
+ assert_atom_source_id(generator, &getter)
+ assert_atom_source_link(generator, &getter)
+ assert_atom_source_logo(generator, &getter)
+ assert_atom_source_rights(generator, &getter)
+ assert_atom_source_subtitle(generator, &getter)
+ assert_atom_source_title(generator, &getter)
+ assert_atom_source_updated(generator, &getter)
+ end
+ end
+
+ def assert_atom_source_author(generator)
+ assert_atom_person("author", generator) do |feed|
+ source = yield(feed)
+ assert_equal(1, source.authors.size)
+ source.author
+ end
+ end
+
+ def assert_atom_source_category(generator)
+ assert_atom_category(generator) do |feed|
+ source = yield(feed)
+ assert_equal(1, source.categories.size)
+ source.category
+ end
+ end
+
+ def assert_atom_source_contributor(generator)
+ assert_atom_person("contributor", generator) do |feed|
+ source = yield(feed)
+ assert_equal(1, source.contributors.size)
+ source.contributor
+ end
+ end
+
+ def assert_atom_source_generator(generator)
+ assert_atom_generator(generator) do |feed|
+ yield(feed).generator
+ end
+ end
+
+ def assert_atom_source_icon(generator)
+ assert_atom_icon(generator) do |feed|
+ yield(feed).icon
+ end
+ end
+
+ def assert_atom_source_id(generator)
+ id_content = "urn:uuid:a2fb588b-5674-4898-b420-265a734fea69"
+ id = "<id>#{id_content}</id>"
+ feed = RSS::Parser.parse(generator.call(id))
+ assert_equal(id_content, yield(feed).id.content)
+ end
+
+ def assert_atom_source_link(generator)
+ assert_atom_link(generator) do |feed|
+ source = yield(feed)
+ assert_equal(1, source.links.size)
+ source.link
+ end
+ end
+
+ def assert_atom_source_logo(generator)
+ assert_atom_logo(generator) do |feed|
+ yield(feed).logo
+ end
+ end
+
+ def assert_atom_source_rights(generator)
+ assert_atom_text_construct("rights", generator) do |feed|
+ yield(feed).rights
+ end
+ end
+
+ def assert_atom_source_subtitle(generator)
+ assert_atom_text_construct("subtitle", generator) do |feed|
+ yield(feed).subtitle
+ end
+ end
+
+ def assert_atom_source_title(generator)
+ assert_atom_text_construct("title", generator) do |feed|
+ yield(feed).title
+ end
+ end
+
+ def assert_atom_source_updated(generator)
+ assert_atom_date_construct("updated", generator) do |feed|
+ yield(feed).updated
+ end
+ end
+
+ def assert_dublin_core(elems, target)
+ _wrap_assertion do
+ elems.each do |name, value|
+ assert_equal(value, target.__send__("dc_#{name}"))
+ end
+ end
+ end
+
+ def assert_multiple_dublin_core(elems, target)
+ _wrap_assertion do
+ elems.each do |name, values, plural|
+ plural ||= "#{name}s"
+ actual = target.__send__("dc_#{plural}").collect{|x| x.value}
+ assert_equal(values, actual)
+ end
+ end
+ end
+
+ def assert_syndication(elems, target)
+ _wrap_assertion do
+ elems.each do |name, value|
+ meth = "sy_#{name}"
+ value = value.to_i if meth == "sy_updateFrequency"
+ assert_equal(value, target.__send__(meth ))
+ end
+ end
+ end
+
+ def assert_content(elems, target)
+ _wrap_assertion do
+ elems.each do |name, value|
+ assert_equal(value, target.__send__("content_#{name}"))
+ end
+ end
+ end
+
+ def assert_trackback(attrs, target)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+ if n_attrs["ping"]
+ assert_equal(n_attrs["ping"], target.trackback_ping)
+ end
+ if n_attrs["abouts"]
+ n_attrs["abouts"].each_with_index do |about, i|
+ assert_equal(about, target.trackback_abouts[i].value)
+ end
+ end
+ end
+ end
+
+ def assert_taxo_topic(topics, target)
+ _wrap_assertion do
+ topics.each_with_index do |topic, i|
+ taxo_topic = target.taxo_topics[i]
+ topic.each do |name, value|
+ case name
+ when :link
+ assert_equal(value, taxo_topic.about)
+ assert_equal(value, taxo_topic.taxo_link)
+ when :topics
+ assert_equal(value, taxo_topic.taxo_topics.resources)
+ else
+ assert_equal(value, taxo_topic.__send__("dc_#{name}"))
+ end
+ end
+ end
+ end
+ end
+
+
+ def assert_attributes(attrs, names, target)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+ names.each do |info|
+ if info.is_a?(String)
+ name = info
+ type = nil
+ else
+ name, type = info
+ end
+ value = n_attrs[name]
+ if value.is_a?(Time)
+ actual = target.__send__(name)
+ assert_instance_of(Time, actual)
+ assert_equal(value.to_i, actual.to_i)
+ elsif value
+ case type
+ when :integer
+ value = value.to_i
+ when :boolean
+ value = value == "true" if value.is_a?(String)
+ end
+ assert_equal(value, target.__send__(name))
+ end
+ end
+ end
+ end
+
+ def assert_rexml_element(children, attrs, text, element, text_type=nil)
+ _wrap_assertion do
+ if children
+ children_info = element.elements.collect {|e| [e.namespace, e.name]}
+ assert_equal(children.collect {|uri, name| [uri, name]}.sort,
+ children_info.sort)
+ end
+ if attrs
+ assert_equal(attrs.collect {|k, v| [k, v]}.sort,
+ element.attributes.collect {|k, v| [k, v]}.sort)
+ end
+ case text_type
+ when :time
+ assert_not_nil(element.text)
+ assert_equal(Time.parse(text).to_s, Time.parse(element.text).to_s)
+ else
+ assert_equal(text, element.text)
+ end
+ end
+ end
+
+ def _assert_maker_atom_persons(feed_type, maker_readers, feed_readers)
+ _wrap_assertion do
+ persons = []
+ feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ targets.each do |target|
+ person = {
+ :name => target.name,
+ :uri => target.uri,
+ :email => target.email,
+ }
+ persons << person if person[:name]
+ end
+ end
+
+ actual_persons = chain_reader(feed, feed_readers) || []
+ actual_persons = actual_persons.collect do |person|
+ {
+ :name => person.name ? person.name.content : nil,
+ :uri => person.uri ? person.uri.content : nil,
+ :email => person.email ? person.email.content : nil,
+ }
+ end
+ assert_equal(persons, actual_persons)
+ end
+ end
+
+ def assert_maker_atom_persons(feed_type, maker_readers, feed_readers,
+ not_set_error_name=nil,
+ parent_not_set_error_name=nil,
+ parent_not_set_variable=nil)
+ _wrap_assertion do
+ not_set_error_name ||= "maker.#{maker_readers.join('.')}"
+
+ args = [feed_type, maker_readers, feed_readers]
+ if parent_not_set_error_name or parent_not_set_variable
+ assert_not_set_error(parent_not_set_error_name,
+ parent_not_set_variable) do
+ _assert_maker_atom_persons(*args) do |maker|
+ yield maker
+ end
+ end
+ else
+ _assert_maker_atom_persons(*args) do |maker|
+ yield maker
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(name)) do
+ _assert_maker_atom_persons(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ targets.new_child
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(name)) do
+ _assert_maker_atom_persons(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ target = targets.new_child
+ target.uri = "http://example.com/~me/"
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(name)) do
+ _assert_maker_atom_persons(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ target = targets.new_child
+ target.email = "me@example.com"
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(name)) do
+ _assert_maker_atom_persons(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ target = targets.new_child
+ target.uri = "http://example.com/~me/"
+ target.email = "me@example.com"
+ end
+ end
+
+ _assert_maker_atom_persons(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ target = targets.new_child
+ target.name = "me"
+ end
+
+ _assert_maker_atom_persons(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ target = targets.new_child
+ target.name = "me"
+ target.uri = "http://example.com/~me/"
+ end
+
+ _assert_maker_atom_persons(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ target = targets.new_child
+ target.name = "me"
+ target.email = "me@example.com"
+ end
+
+ _assert_maker_atom_persons(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ target = targets.new_child
+ target.name = "me"
+ target.uri = "http://example.com/~me/"
+ target.email = "me@example.com"
+ end
+
+ _assert_maker_atom_persons(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+
+ target = targets.new_child
+ target.name = "me"
+ target.uri = "http://example.com/~me/"
+ target.email = "me@example.com"
+
+ target = targets.new_child
+ target.name = "you"
+ target.uri = "http://example.com/~you/"
+ target.email = "you@example.com"
+ end
+
+ assert_not_set_error(not_set_error_name, %w(name)) do
+ _assert_maker_atom_persons(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+
+ target = targets.new_child
+ target.name = "me"
+ target.uri = "http://example.com/~me/"
+ target.email = "me@example.com"
+
+ targets.new_child
+ end
+ end
+ end
+ end
+
+ def _assert_maker_atom_text_construct(feed_type, maker_readers,
+ feed_readers, &block)
+ maker_extractor = Proc.new do |target|
+ text = {
+ :type => target.type,
+ :content => target.content,
+ :xml_content => target.xml_content,
+ }
+ if text[:type] == "xhtml"
+ if text[:xml_content]
+ xml_content = text[:xml_content]
+ xhtml_uri = "http://www.w3.org/1999/xhtml"
+ unless xml_content.is_a?(RSS::XML::Element) and
+ ["div", xhtml_uri] == [xml_content.name, xml_content.uri]
+ children = xml_content
+ children = [children] unless children.is_a?(Array)
+ xml_content = RSS::XML::Element.new("div", nil, xhtml_uri,
+ {"xmlns" => xhtml_uri},
+ children)
+ text[:xml_content] = xml_content
+ end
+ text
+ else
+ nil
+ end
+ else
+ text[:content] ? text : nil
+ end
+ end
+ feed_extractor = Proc.new do |target|
+ {
+ :type => target.type,
+ :content => target.content,
+ :xml_content => target.xhtml,
+ }
+ end
+ _assert_maker_atom_element(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor,
+ &block)
+ end
+
+ def assert_maker_atom_text_construct(feed_type, maker_readers, feed_readers,
+ parent_not_set_error_name=nil,
+ parent_not_set_variable=nil,
+ not_set_error_name=nil)
+ _wrap_assertion do
+ not_set_error_name ||= "maker.#{maker_readers.join('.')}"
+
+ args = [feed_type, maker_readers, feed_readers]
+ if parent_not_set_error_name or parent_not_set_variable
+ assert_not_set_error(parent_not_set_error_name,
+ parent_not_set_variable) do
+ _assert_maker_atom_text_construct(*args) do |maker|
+ yield maker
+ end
+ end
+ else
+ _assert_maker_atom_text_construct(*args) do |maker|
+ yield maker
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(content)) do
+ _assert_maker_atom_text_construct(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ target.type = "text"
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(content)) do
+ _assert_maker_atom_text_construct(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ target.type = "html"
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(xml_content)) do
+ _assert_maker_atom_text_construct(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ target.type = "xhtml"
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(xml_content)) do
+ _assert_maker_atom_text_construct(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ target.type = "xhtml"
+ target.content = "Content"
+ end
+ end
+
+ _assert_maker_atom_text_construct(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ target.type = "text"
+ target.content = "Content"
+ end
+
+ _assert_maker_atom_text_construct(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ target.type = "html"
+ target.content = "<em>Content</em>"
+ end
+
+ _assert_maker_atom_text_construct(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ target.type = "xhtml"
+ target.xml_content = "text only"
+ end
+
+ _assert_maker_atom_text_construct(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ target.type = "xhtml"
+ target.xml_content = RSS::XML::Element.new("unknown")
+ end
+ end
+ end
+
+ def _assert_maker_atom_date_construct(feed_type, maker_readers,
+ feed_readers, &block)
+ maker_extractor = Proc.new do |target|
+ date = {
+ :content => target,
+ }
+ date[:content] ? date : nil
+ end
+ feed_extractor = Proc.new do |target|
+ {
+ :content => target.content,
+ }
+ end
+ _assert_maker_atom_element(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor,
+ &block)
+ end
+
+ def assert_maker_atom_date_construct(feed_type, maker_readers, feed_readers,
+ parent_not_set_error_name=nil,
+ parent_not_set_variable=nil)
+ _wrap_assertion do
+ args = [feed_type, maker_readers, feed_readers]
+ if parent_not_set_error_name or parent_not_set_variable
+ assert_not_set_error(parent_not_set_error_name,
+ parent_not_set_variable) do
+ _assert_maker_atom_date_construct(*args) do |maker|
+ yield maker
+ end
+ end
+ else
+ _assert_maker_atom_date_construct(*args) do |maker|
+ yield maker
+ end
+ end
+
+ maker_readers = maker_readers.dup
+ writer = "#{maker_readers.pop}="
+ _assert_maker_atom_date_construct(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.__send__(writer, Time.now)
+ end
+ end
+ end
+
+ def _assert_maker_atom_element(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor)
+ _wrap_assertion do
+ element = nil
+ feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ element = maker_extractor.call(target)
+ end
+
+ target = chain_reader(feed, feed_readers)
+ if target
+ actual_element = feed_extractor.call(target)
+ else
+ actual_element = nil
+ end
+ assert_equal(element, actual_element)
+ end
+ end
+
+ def _assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor,
+ invalid_feed_checker=nil)
+ _wrap_assertion do
+ elements = []
+ invalid_feed_exception = nil
+ feed = nil
+ begin
+ feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ targets.each do |target|
+ element = maker_extractor.call(target)
+ elements << element if element
+ end
+ if invalid_feed_checker
+ invalid_feed_exception = invalid_feed_checker.call(targets)
+ end
+ end
+ rescue RSS::Error
+ if invalid_feed_exception.is_a?(RSS::TooMuchTagError)
+ assert_too_much_tag(invalid_feed_exception.tag,
+ invalid_feed_exception.parent) do
+ raise
+ end
+ else
+ raise
+ end
+ end
+
+ if invalid_feed_exception.nil?
+ actual_elements = chain_reader(feed, feed_readers) || []
+ actual_elements = actual_elements.collect do |target|
+ feed_extractor.call(target)
+ end
+ assert_equal(elements, actual_elements)
+ end
+ end
+ end
+
+ def assert_maker_atom_element(feed_type, maker_readers, feed_readers,
+ setup_target, optional_variables,
+ required_variable, assert_method_name,
+ not_set_error_name=nil,
+ *additional_args)
+ _wrap_assertion do
+ not_set_error_name ||= "maker.#{maker_readers.join('.')}"
+
+ 0.upto(optional_variables.size) do |i|
+ combination(optional_variables, i).each do |names|
+ have = {}
+ names.each do |name|
+ have[name.intern] = true
+ end
+ have_required_variable_too =
+ have.merge({required_variable.intern => true})
+
+ assert_not_set_error(not_set_error_name, [required_variable]) do
+ __send__(assert_method_name, feed_type, maker_readers,
+ feed_readers, *additional_args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ setup_target.call(target, have)
+ end
+ end
+
+ __send__(assert_method_name, feed_type, maker_readers, feed_readers,
+ *additional_args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers) {|x| x}
+ setup_target.call(target, have_required_variable_too)
+ end
+ end
+ end
+ end
+ end
+
+ def assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
+ setup_target, optional_variables,
+ required_variable, assert_method_name,
+ not_set_error_name=nil,
+ *additional_args)
+ _wrap_assertion do
+ not_set_error_name ||= "maker.#{maker_readers.join('.')}"
+
+ 0.upto(optional_variables.size) do |i|
+ combination(optional_variables, i).each do |names|
+ have = {}
+ names.each do |name|
+ have[name.intern] = true
+ end
+ have_required_variable_too =
+ have.merge({required_variable.intern => true})
+
+ assert_not_set_error(not_set_error_name, [required_variable]) do
+ __send__(assert_method_name, feed_type, maker_readers,
+ feed_readers, *additional_args) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ setup_target.call(targets, have)
+ end
+ end
+
+ __send__(assert_method_name, feed_type, maker_readers, feed_readers,
+ *additional_args) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ setup_target.call(targets, have_required_variable_too)
+ end
+
+ __send__(assert_method_name, feed_type, maker_readers, feed_readers,
+ *additional_args) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ setup_target.call(targets, have_required_variable_too)
+ setup_target.call(targets, have_required_variable_too)
+ end
+
+ assert_not_set_error(not_set_error_name, [required_variable]) do
+ __send__(assert_method_name, feed_type, maker_readers, feed_readers,
+ *additional_args) do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ setup_target.call(targets, have_required_variable_too)
+ setup_target.call(targets, have)
+ end
+ end
+ end
+ end
+ end
+ end
+
+ def _assert_maker_atom_categories(feed_type, maker_readers,
+ feed_readers, &block)
+ maker_extractor = Proc.new do |target|
+ category = {
+ :term => target.term,
+ :scheme => target.scheme,
+ :label => target.label,
+ }
+ category[:term] ? category : nil
+ end
+ feed_extractor = Proc.new do |target|
+ {
+ :term => target.term,
+ :scheme => target.scheme,
+ :label => target.label,
+ }
+ end
+ _assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor, &block)
+ end
+
+ def assert_maker_atom_categories(feed_type, maker_readers, feed_readers,
+ not_set_error_name=nil, &block)
+ _wrap_assertion do
+ _assert_maker_atom_categories(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ end
+
+ setup_target = Proc.new do |targets, have|
+ target = targets.new_child
+ target.term = "music" if have[:term]
+ target.scheme = "http://example.com/category/music" if have[:scheme]
+ target.label = "Music" if have[:label]
+ end
+
+ optional_variables = %w(scheme label)
+
+ assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
+ setup_target, optional_variables,
+ "term", :_assert_maker_atom_categories,
+ not_set_error_name, &block)
+ end
+ end
+
+ def _assert_maker_atom_generator(feed_type, maker_readers,
+ feed_readers, &block)
+ maker_extractor = Proc.new do |target|
+ generator = {
+ :uri => target.uri,
+ :version => target.version,
+ :content => target.content,
+ }
+ generator[:content] ? generator : nil
+ end
+ feed_extractor = Proc.new do |target|
+ {
+ :uri => target.uri,
+ :version => target.version,
+ :content => target.content,
+ }
+ end
+ _assert_maker_atom_element(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor,
+ &block)
+ end
+
+ def assert_maker_atom_generator(feed_type, maker_readers, feed_readers,
+ not_set_error_name=nil, &block)
+ _wrap_assertion do
+ not_set_error_name ||= "maker.#{maker_readers.join('.')}"
+
+ _assert_maker_atom_generator(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ end
+
+ setup_target = Proc.new do |target, have|
+ target.content = "RSS Maker" if have[:content]
+ target.uri = "http://example.com/rss/maker" if have[:uri]
+ target.version = "0.0.1" if have[:version]
+ end
+
+ optional_variables = %w(uri version)
+
+ assert_maker_atom_element(feed_type, maker_readers, feed_readers,
+ setup_target, optional_variables,
+ "content", :_assert_maker_atom_generator,
+ not_set_error_name, &block)
+ end
+ end
+
+ def _assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
+ accessor_base, &block)
+ maker_extractor = Proc.new do |target|
+ icon = {
+ :content => target.__send__(accessor_base),
+ }
+ icon[:content] ? icon : nil
+ end
+ feed_extractor = Proc.new do |target|
+ {
+ :content => target.content,
+ }
+ end
+ _assert_maker_atom_element(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor,
+ &block)
+ end
+
+ def assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
+ accessor_base=nil, not_set_error_name=nil)
+ _wrap_assertion do
+ accessor_base ||= "url"
+ not_set_error_name ||= "maker.#{maker_readers.join('.')}"
+
+ _assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
+ accessor_base) do |maker|
+ yield maker
+ end
+
+ _assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
+ accessor_base) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.__send__("#{accessor_base}=", "http://example.com/icon.png")
+ end
+ end
+ end
+
+ def _assert_maker_atom_links(feed_type, maker_readers, feed_readers,
+ allow_duplication=false, &block)
+ maker_extractor = Proc.new do |target|
+ link = {
+ :href => target.href,
+ :rel => target.rel,
+ :type => target.type,
+ :hreflang => target.hreflang,
+ :title => target.title,
+ :length => target.length,
+ }
+ link[:href] ? link : nil
+ end
+ feed_extractor = Proc.new do |target|
+ {
+ :href => target.href,
+ :rel => target.rel,
+ :type => target.type,
+ :hreflang => target.hreflang,
+ :title => target.title,
+ :length => target.length,
+ }
+ end
+
+ if feed_readers.first == "entries"
+ parent = "entry"
+ else
+ parent = feed_type
+ end
+ invalid_feed_checker = Proc.new do |targets|
+ infos = {}
+ invalid_exception = nil
+ targets.each do |target|
+ key = [target.hreflang, target.type]
+ if infos.has_key?(key)
+ invalid_exception = RSS::TooMuchTagError.new("link", parent)
+ break
+ end
+ infos[key] = true if target.rel.nil? or target.rel == "alternate"
+ end
+ invalid_exception
+ end
+ invalid_feed_checker = nil if allow_duplication
+ _assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor,
+ invalid_feed_checker,
+ &block)
+ end
+
+ def assert_maker_atom_links(feed_type, maker_readers, feed_readers,
+ not_set_error_name=nil, allow_duplication=false,
+ &block)
+ _wrap_assertion do
+ _assert_maker_atom_links(feed_type, maker_readers,
+ feed_readers) do |maker|
+ yield maker
+ end
+
+ langs = %(ja en fr zh po)
+ setup_target = Proc.new do |targets, have|
+ target = targets.new_child
+ lang = langs[targets.size % langs.size]
+ target.href = "http://example.com/index.html.#{lang}" if have[:href]
+ target.rel = "alternate" if have[:rel]
+ target.type = "text/xhtml" if have[:type]
+ target.hreflang = lang if have[:hreflang]
+ target.title = "FrontPage(#{lang})" if have[:title]
+ target.length = 1024 if have[:length]
+ end
+
+ optional_variables = %w(rel type hreflang title length)
+
+ assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
+ setup_target, optional_variables,
+ "href", :_assert_maker_atom_links,
+ not_set_error_name, allow_duplication,
+ &block)
+ end
+ end
+
+ def _assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
+ accessor_base, &block)
+ maker_extractor = Proc.new do |target|
+ logo = {
+ :uri => target.__send__(accessor_base),
+ }
+ logo[:uri] ? logo : nil
+ end
+ feed_extractor = Proc.new do |target|
+ {
+ :uri => target.content,
+ }
+ end
+ _assert_maker_atom_element(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor,
+ &block)
+ end
+
+ def assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
+ accessor_base=nil, not_set_error_name=nil)
+ _wrap_assertion do
+ accessor_base ||= "uri"
+ not_set_error_name ||= "maker.#{maker_readers.join('.')}"
+
+ _assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
+ accessor_base) do |maker|
+ yield maker
+ end
+
+ _assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
+ accessor_base) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.__send__("#{accessor_base}=", "http://example.com/logo.png")
+ end
+ end
+ end
+
+ def _assert_maker_atom_id(feed_type, maker_readers, feed_readers, &block)
+ maker_extractor = Proc.new do |target|
+ id = {
+ :uri => target.id,
+ }
+ id[:uri] ? id : nil
+ end
+ feed_extractor = Proc.new do |target|
+ if target.id
+ {
+ :uri => target.id.content,
+ }
+ else
+ nil
+ end
+ end
+ _assert_maker_atom_element(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor,
+ &block)
+ end
+
+ def assert_maker_atom_id(feed_type, maker_readers, feed_readers,
+ not_set_error_name=nil)
+ _wrap_assertion do
+ not_set_error_name ||= "maker.#{maker_readers.join('.')}"
+
+ args = [feed_type, maker_readers, feed_readers]
+ _assert_maker_atom_id(*args) do |maker|
+ yield maker
+ end
+
+ _assert_maker_atom_id(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.id = "http://example.com/id/1"
+ end
+ end
+ end
+
+ def _assert_maker_atom_content(feed_type, maker_readers,
+ feed_readers, &block)
+ maker_extractor = Proc.new do |target|
+ content = {
+ :type => target.type,
+ :src => target.src,
+ :content => target.content,
+ :xml => target.xml,
+ :inline_text => target.inline_text?,
+ :inline_html => target.inline_html?,
+ :inline_xhtml => target.inline_xhtml?,
+ :inline_other => target.inline_other?,
+ :inline_other_text => target.inline_other_text?,
+ :inline_other_xml => target.inline_other_xml?,
+ :inline_other_base64 => target.inline_other_base64?,
+ :out_of_line => target.out_of_line?,
+ }
+ content[:src] = nil if content[:src] and content[:content]
+ if content[:type] or content[:content]
+ content
+ else
+ nil
+ end
+ end
+ feed_extractor = Proc.new do |target|
+ {
+ :type => target.type,
+ :src => target.src,
+ :content => target.content,
+ :xml => target.xml,
+ :inline_text => target.inline_text?,
+ :inline_html => target.inline_html?,
+ :inline_xhtml => target.inline_xhtml?,
+ :inline_other => target.inline_other?,
+ :inline_other_text => target.inline_other_text?,
+ :inline_other_xml => target.inline_other_xml?,
+ :inline_other_base64 => target.inline_other_base64?,
+ :out_of_line => target.out_of_line?,
+ }
+ end
+ _assert_maker_atom_element(feed_type, maker_readers, feed_readers,
+ maker_extractor, feed_extractor,
+ &block)
+ end
+
+ def assert_maker_atom_content(feed_type, maker_readers, feed_readers,
+ not_set_error_name=nil, &block)
+ _wrap_assertion do
+ not_set_error_name ||= "maker.#{maker_readers.join('.')}"
+ args = [feed_type, maker_readers, feed_readers, not_set_error_name]
+ assert_maker_atom_content_inline_text(*args, &block)
+ assert_maker_atom_content_inline_xhtml(*args, &block)
+ assert_maker_atom_content_inline_other(*args, &block)
+ assert_maker_atom_content_out_of_line(*args, &block)
+ end
+ end
+
+ def assert_maker_atom_content_inline_text(feed_type, maker_readers,
+ feed_readers, not_set_error_name)
+ _wrap_assertion do
+ args = [feed_type, maker_readers, feed_readers]
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ end
+
+ assert_not_set_error(not_set_error_name, %w(content)) do
+ RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "text"
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(content)) do
+ RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "html"
+ end
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.content = ""
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "text"
+ target.content = "example content"
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "html"
+ target.content = "<em>text</em>"
+ end
+ end
+ end
+
+ def assert_maker_atom_content_inline_xhtml(feed_type, maker_readers,
+ feed_readers, not_set_error_name)
+ _wrap_assertion do
+ args = [feed_type, maker_readers, feed_readers]
+ assert_not_set_error(not_set_error_name, %w(xml_content)) do
+ RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "xhtml"
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(xml_content)) do
+ RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "xhtml"
+ target.content = "dummy"
+ end
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "xhtml"
+ target.xml_content = "text"
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "xhtml"
+ target.xml = "text"
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "xhtml"
+ target.xml_content =
+ RSS::XML::Element.new("em", nil, nil, {}, ["text"])
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "xhtml"
+ target.xml = RSS::XML::Element.new("em", nil, nil, {}, ["text"])
+ end
+
+
+ xhtml_uri = "http://www.w3.org/1999/xhtml"
+ em = RSS::XML::Element.new("em", nil, nil, {}, ["text"])
+ em_with_xhtml_uri =
+ RSS::XML::Element.new("em", nil, xhtml_uri, {}, ["text"])
+ feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "xhtml"
+ target.xml = em
+ end
+ assert_equal(RSS::XML::Element.new("div", nil, xhtml_uri,
+ {"xmlns" => xhtml_uri},
+ [em_with_xhtml_uri]),
+ chain_reader(feed, feed_readers).xml)
+
+ div = RSS::XML::Element.new("div", nil, xhtml_uri,
+ {"xmlns" => xhtml_uri,
+ "class" => "sample"},
+ ["text"])
+ feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "xhtml"
+ target.xml = div
+ end
+ assert_equal(div, chain_reader(feed, feed_readers).xml)
+ end
+ end
+
+ def assert_maker_atom_content_inline_other(*args, &block)
+ _wrap_assertion do
+ assert_maker_atom_content_inline_other_xml(*args, &block)
+ assert_maker_atom_content_inline_other_text(*args, &block)
+ assert_maker_atom_content_inline_other_base64(*args, &block)
+ end
+ end
+
+ def assert_maker_atom_content_inline_other_xml(feed_type, maker_readers,
+ feed_readers,
+ not_set_error_name)
+ _wrap_assertion do
+ args = [feed_type, maker_readers, feed_readers]
+ assert_not_set_error(not_set_error_name, %w(xml_content)) do
+ RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "application/xml"
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(xml_content)) do
+ RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "svg/image+xml"
+ end
+ end
+
+ svg_uri = "http://www.w3.org/2000/svg"
+ rect = RSS::XML::Element.new("rect", nil, svg_uri,
+ {"x" => "0.5cm",
+ "y" => "0.5cm",
+ "width" => "2cm",
+ "height" => "1cm"})
+ svg = RSS::XML::Element.new("svg", nil, svg_uri,
+ {"xmlns" => svg_uri,
+ "version" => "1.1",
+ "width" => "5cm",
+ "height" => "4cm"},
+ [rect])
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "image/svg+xml"
+ target.xml = svg
+ end
+
+ feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "image/svg+xml"
+ target.xml = svg
+ end
+ assert_equal(svg, chain_reader(feed, feed_readers).xml)
+ end
+ end
+
+ def assert_maker_atom_content_inline_other_text(feed_type, maker_readers,
+ feed_readers,
+ not_set_error_name)
+ _wrap_assertion do
+ args = [feed_type, maker_readers, feed_readers]
+ assert_not_set_error(not_set_error_name, %w(content)) do
+ RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "text/plain"
+ end
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "text/plain"
+ target.content = "text"
+ end
+ end
+ end
+
+ def assert_maker_atom_content_inline_other_base64(feed_type, maker_readers,
+ feed_readers,
+ not_set_error_name)
+ _wrap_assertion do
+ args = [feed_type, maker_readers, feed_readers]
+ content = "\211PNG\r\n\032\n"
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "image/png"
+ target.content = content
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "image/png"
+ target.src = "http://example.com/logo.png"
+ target.content = content
+ end
+
+ feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "image/png"
+ target.src = "http://example.com/logo.png"
+ target.content = content
+ end
+ target = chain_reader(feed, feed_readers)
+ assert_nil(target.src)
+ assert_equal(content, target.content)
+ end
+ end
+
+ def assert_maker_atom_content_out_of_line(feed_type, maker_readers,
+ feed_readers, not_set_error_name)
+ _wrap_assertion do
+ args = [feed_type, maker_readers, feed_readers]
+ assert_not_set_error(not_set_error_name, %w(content)) do
+ RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "image/png"
+ end
+ end
+
+ assert_not_set_error(not_set_error_name, %w(type)) do
+ RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.src = "http://example.com/logo.png"
+ end
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "image/png"
+ target.src = "http://example.com/logo.png"
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "image/png"
+ target.content = "\211PNG\r\n\032\n"
+ end
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "application/xml"
+ target.src = "http://example.com/sample.xml"
+ end
+
+
+ _assert_maker_atom_content(*args) do |maker|
+ yield maker
+ target = chain_reader(maker, maker_readers)
+ target.type = "text/plain"
+ target.src = "http://example.com/README.txt"
+ end
+ end
+ end
+
+ def assert_slash_elements(expected, target)
+ assert_equal(expected,
+ {
+ "section" => target.slash_section,
+ "department" => target.slash_department,
+ "comments" => target.slash_comments,
+ "hit_parades" => target.slash_hit_parades,
+ })
+ assert_equal(expected["hit_parades"].join(","),
+ target.slash_hit_parade)
+ end
+
+ def chain_reader(target, readers, &block)
+ readers.inject(target) do |result, reader|
+ return nil if result.nil?
+ result.__send__(reader, &block)
+ end
+ end
+
+ def normalized_attrs(attrs)
+ n_attrs = {}
+ attrs.each do |name, value|
+ n_attrs[name.to_s] = value
+ end
+ n_attrs
+ end
+
+ def combination(elements, n)
+ if n <= 0 or elements.size < n
+ []
+ elsif n == 1
+ elements.collect {|element| [element]}
+ else
+ first, *rest = elements
+ combination(rest, n - 1).collect do |sub_elements|
+ [first, *sub_elements]
+ end + combination(rest, n)
+ end
+ end
+
+ def tag(name, content=nil, attributes={})
+ attributes = attributes.collect do |key, value|
+ "#{ERB::Util.h(key)}=\"#{ERB::Util.h(value)}\""
+ end.join(" ")
+ begin_tag = "<#{name}"
+ begin_tag << " #{attributes}" unless attributes.empty?
+ if content
+ "#{begin_tag}>#{content}</#{name}>\n"
+ else
+ "#{begin_tag}/>\n"
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/rss-testcase.rb b/jni/ruby/test/rss/rss-testcase.rb
new file mode 100644
index 0000000..2e39433
--- /dev/null
+++ b/jni/ruby/test/rss/rss-testcase.rb
@@ -0,0 +1,478 @@
+require "erb"
+
+require "test/unit"
+require_relative 'rss-assertions'
+
+require "rss"
+
+module RSS
+ class TestCase < Test::Unit::TestCase
+ include ERB::Util
+
+ include RSS
+ include Assertions
+
+ XMLDECL_VERSION = "1.0"
+ XMLDECL_ENCODING = "UTF-8"
+ XMLDECL_STANDALONE = "no"
+
+ RDF_ABOUT = "http://www.xml.com/xml/news.rss"
+ RDF_RESOURCE = "http://xml.com/universal/images/xml_tiny.gif"
+ TITLE_VALUE = "XML.com"
+ LINK_VALUE = "http://xml.com/pub"
+ URL_VALUE = "http://xml.com/universal/images/xml_tiny.gif"
+ NAME_VALUE = "hogehoge"
+ LANGUAGE_VALUE = "ja"
+ DESCRIPTION_VALUE = "
+ XML.com features a rich mix of information and services
+ for the XML community.
+ "
+ RESOURCES = [
+ "http://xml.com/pub/2000/08/09/xslt/xslt.html",
+ "http://xml.com/pub/2000/08/09/rdfdb/index.html",
+ ]
+
+ CLOUD_DOMAIN = "data.ourfavoritesongs.com"
+ CLOUD_PORT = "80"
+ CLOUD_PATH = "/RPC2"
+ CLOUD_REGISTER_PROCEDURE = "ourFavoriteSongs.rssPleaseNotify"
+ CLOUD_PROTOCOL = "xml-rpc"
+
+ ENCLOSURE_URL = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
+ ENCLOSURE_LENGTH = "12216320"
+ ENCLOSURE_TYPE = "audio/mpeg"
+
+ CATEGORY_DOMAIN = "http://www.superopendirectory.com/"
+
+ FEED_TITLE = "dive into mark"
+ FEED_UPDATED = "2003-12-13T18:30:02Z"
+ FEED_AUTHOR_NAME = "John Doe"
+ FEED_ID = "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"
+
+ ENTRY_TITLE = "Atom-Powered Robots Run Amok"
+ ENTRY_LINK = "http://example.org/2003/12/13/atom03"
+ ENTRY_ID = "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"
+ ENTRY_UPDATED = "2003-12-13T18:30:02Z"
+ ENTRY_SUMMARY = "Some text."
+
+ t = Time.iso8601("2000-01-01T12:00:05+00:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ DC_ELEMENTS = {
+ :title => "hoge",
+ :description =>
+ " XML is placing increasingly heavy loads on
+ the existing technical infrastructure of the Internet.",
+ :creator => "Rael Dornfest (mailto:rael@oreilly.com)",
+ :subject => "XML",
+ :publisher => "The O'Reilly Network",
+ :contributor => "hogehoge",
+ :type => "fugafuga",
+ :format => "hohoho",
+ :identifier => "fufufu",
+ :source => "barbar",
+ :language => "ja",
+ :relation => "cococo",
+ :rights => "Copyright (c) 2000 O'Reilly &amp; Associates, Inc.",
+ :date => t,
+ }
+
+ DC_NODES = DC_ELEMENTS.collect do |name, value|
+ "<#{DC_PREFIX}:#{name}>#{value}</#{DC_PREFIX}:#{name}>"
+ end.join("\n")
+
+ def default_test
+ # This class isn't tested
+ end
+
+ private
+ def make_xmldecl(v=XMLDECL_VERSION, e=XMLDECL_ENCODING, s=XMLDECL_STANDALONE)
+ rv = "<?xml version='#{v}'"
+ rv << " encoding='#{e}'" if e
+ rv << " standalone='#{s}'" if s
+ rv << "?>"
+ rv
+ end
+
+ def make_RDF(content=nil, xmlns=[])
+ <<-EORSS
+#{make_xmldecl}
+<rdf:RDF xmlns="#{URI}" xmlns:rdf="#{RDF::URI}"
+#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
+#{block_given? ? yield : content}
+</rdf:RDF>
+EORSS
+ end
+
+ def make_channel(content=nil)
+ <<-EOC
+<channel rdf:about="#{RDF_ABOUT}">
+ <title>#{TITLE_VALUE}</title>
+ <link>#{LINK_VALUE}</link>
+ <description>#{DESCRIPTION_VALUE}</description>
+
+ <image rdf:resource="#{RDF_RESOURCE}" />
+
+ <items>
+ <rdf:Seq>
+#{RESOURCES.collect do |res| '<rdf:li resource="' + res + '" />' end.join("\n")}
+ </rdf:Seq>
+ </items>
+
+ <textinput rdf:resource="#{RDF_RESOURCE}" />
+
+#{block_given? ? yield : content}
+</channel>
+EOC
+ end
+
+ def make_image(content=nil)
+ <<-EOI
+<image rdf:about="#{RDF_ABOUT}">
+ <title>#{TITLE_VALUE}</title>
+ <url>#{URL_VALUE}</url>
+ <link>#{LINK_VALUE}</link>
+#{block_given? ? yield : content}
+</image>
+EOI
+ end
+
+ def make_item(content=nil)
+ <<-EOI
+<item rdf:about="#{RDF_ABOUT}">
+ <title>#{TITLE_VALUE}</title>
+ <link>#{LINK_VALUE}</link>
+ <description>#{DESCRIPTION_VALUE}</description>
+#{block_given? ? yield : content}
+</item>
+EOI
+ end
+
+ def make_textinput(content=nil)
+ <<-EOT
+<textinput rdf:about="#{RDF_ABOUT}">
+ <title>#{TITLE_VALUE}</title>
+ <description>#{DESCRIPTION_VALUE}</description>
+ <name>#{NAME_VALUE}</name>
+ <link>#{LINK_VALUE}</link>
+#{block_given? ? yield : content}
+</textinput>
+EOT
+ end
+
+ def make_sample_RDF
+ make_RDF(<<-EOR)
+#{make_channel}
+#{make_image}
+#{make_item}
+#{make_textinput}
+EOR
+ end
+
+ def make_rss20(content=nil, xmlns=[])
+ <<-EORSS
+#{make_xmldecl}
+<rss version="2.0"
+#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
+#{block_given? ? yield : content}
+</rss>
+EORSS
+ end
+
+ def make_sample_items20
+ RESOURCES.collect do |res|
+ elems = ["<link>#{res}</link>"]
+ elems << "<title>title of #{res}</title>"
+ elems = elems.join("\n")
+ "<item>\n#{elems}\n</item>"
+ end.join("\n")
+ end
+
+ def make_channel20(content=nil)
+ <<-EOC
+<channel>
+ <title>#{TITLE_VALUE}</title>
+ <link>#{LINK_VALUE}</link>
+ <description>#{DESCRIPTION_VALUE}</description>
+ <language>#{LANGUAGE_VALUE}</language>
+
+ <image>
+ <url>#{RDF_RESOURCE}</url>
+ <title>#{TITLE_VALUE}</title>
+ <link>#{LINK_VALUE}</link>
+ </image>
+
+#{make_sample_items20}
+
+ <textInput>
+ <title>#{TITLE_VALUE}</title>
+ <description>#{DESCRIPTION_VALUE}</description>
+ <name>#{NAME_VALUE}</name>
+ <link>#{RDF_RESOURCE}</link>
+ </textInput>
+
+#{block_given? ? yield : content}
+</channel>
+EOC
+ end
+
+ def make_item20(content=nil)
+ <<-EOI
+<item>
+ <title>#{TITLE_VALUE}</title>
+ <link>#{LINK_VALUE}</link>
+ <description>#{DESCRIPTION_VALUE}</description>
+#{block_given? ? yield : content}
+</item>
+EOI
+ end
+
+ def make_cloud20
+ <<-EOC
+<cloud
+ domain="#{CLOUD_DOMAIN}"
+ port="#{CLOUD_PORT}"
+ path="#{CLOUD_PATH}"
+ registerProcedure="#{CLOUD_REGISTER_PROCEDURE}"
+ protocol="#{CLOUD_PROTOCOL}" />
+EOC
+ end
+
+ def make_sample_rss20
+ make_rss20(<<-EOR)
+#{make_channel20}
+EOR
+ end
+
+ def make_feed_without_entry(content=nil, xmlns=[])
+ <<-EOA
+<feed xmlns="#{Atom::URI}"
+#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
+ <id>#{FEED_ID}</id>
+ <title>#{FEED_TITLE}</title>
+ <updated>#{FEED_UPDATED}</updated>
+ <author>
+ <name>#{FEED_AUTHOR_NAME}</name>
+ </author>
+#{block_given? ? yield : content}
+</feed>
+EOA
+ end
+
+ def make_entry(content=nil)
+ <<-EOA
+ <entry>
+ <title>#{ENTRY_TITLE}</title>
+ <id>#{ENTRY_ID}</id>
+ <updated>#{ENTRY_UPDATED}</updated>
+#{block_given? ? yield : content}
+ </entry>
+EOA
+ end
+
+ def make_feed_with_open_entry(content=nil, xmlns=[], &block)
+ make_feed_without_entry(<<-EOA, xmlns)
+#{make_entry(content, &block)}
+EOA
+ end
+
+ def make_feed_with_open_entry_source(content=nil, xmlns=[])
+ make_feed_with_open_entry(<<-EOA, xmlns)
+ <source>
+#{block_given? ? yield : content}
+ </source>
+EOA
+ end
+
+ def make_feed(content=nil, xmlns=[])
+ make_feed_without_entry(<<-EOA, xmlns)
+ <entry>
+ <title>#{ENTRY_TITLE}</title>
+ <link href="#{ENTRY_LINK}"/>
+ <id>#{ENTRY_ID}</id>
+ <updated>#{ENTRY_UPDATED}</updated>
+ <summary>#{ENTRY_SUMMARY}</summary>
+ </entry>
+#{block_given? ? yield : content}
+EOA
+ end
+
+ def make_entry_document(content=nil, xmlns=[])
+ <<-EOA
+<entry xmlns="#{Atom::URI}"
+#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
+ <id>#{ENTRY_ID}</id>
+ <title>#{ENTRY_TITLE}</title>
+ <updated>#{ENTRY_UPDATED}</updated>
+ <author>
+ <name>#{FEED_AUTHOR_NAME}</name>
+ </author>
+#{block_given? ? yield : content}
+</entry>
+EOA
+ end
+
+ def make_entry_document_with_open_source(content=nil, xmlns=[])
+ make_entry_document(<<-EOA, xmlns)
+ <source>
+#{block_given? ? yield : content}
+ </source>
+EOA
+ end
+
+ def make_element(elem_name, attrs, contents)
+ attrs_str = attrs.collect do |name, value|
+ "#{h name}='#{h value}'"
+ end.join(" ")
+ attrs_str = " #{attrs_str}" unless attrs_str.empty?
+
+ if contents.is_a?(String)
+ contents_str = h(contents)
+ else
+ contents_str = contents.collect do |name, value|
+ "#{Element::INDENT}<#{h name}>#{h value}</#{h name}>"
+ end.join("\n")
+ contents_str = "\n#{contents_str}\n"
+ end
+
+ "<#{h elem_name}#{attrs_str}>#{contents_str}</#{h elem_name}>"
+ end
+
+ def xmlns_container(xmlns_decls, content)
+ attributes = xmlns_decls.collect do |prefix, uri|
+ "xmlns:#{h prefix}=\"#{h uri}\""
+ end.join(" ")
+ "<dummy #{attributes}>#{content}</dummy>"
+ end
+
+ private
+ def setup_rss10(rdf)
+ assert_equal("", rdf.to_s)
+
+ channel = RDF::Channel.new
+ assert_equal("", channel.to_s)
+ channel.about = "http://example.com/index.rdf"
+ channel.title = "title"
+ channel.link = "http://example.com/"
+ channel.description = "description"
+ assert_equal("", channel.to_s)
+
+ item_title = "item title"
+ item_link = "http://example.com/item"
+ channel.items = RDF::Channel::Items.new
+ channel.items.Seq.lis << RDF::Channel::Items::Seq::Li.new(item_link)
+ assert_not_equal("", channel.to_s)
+
+ rdf.channel = channel
+ assert_equal("", rdf.to_s)
+
+ item = RDF::Item.new
+ item.title = item_title
+ item.link = item_link
+ item.about = item_link
+ rdf.items << item
+ assert_not_equal("", rdf.to_s)
+ end
+
+ def setup_rss20(rss)
+ assert_equal("", rss.to_s)
+
+ channel = Rss::Channel.new
+ assert_equal("", channel.to_s)
+ channel.title = "title"
+ channel.link = "http://example.com/"
+ channel.description = "description"
+ assert_not_equal("", channel.to_s)
+
+ rss.channel = channel
+ assert_not_equal("", rss.to_s)
+ end
+
+ def setup_dummy_channel(maker)
+ about = "http://hoge.com"
+ title = "fugafuga"
+ link = "http://hoge.com/feed.xml"
+ description = "fugafugafugafuga"
+ language = "ja"
+
+ maker.channel.about = about
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ maker.channel.language = language
+ end
+
+ def setup_dummy_channel_atom(maker)
+ updated = Time.now
+ author = "Foo"
+
+ setup_dummy_channel(maker)
+ maker.channel.links.first.rel = "self"
+ maker.channel.links.first.type = "application/atom+xml"
+ maker.channel.updated = updated
+ maker.channel.author = author
+ end
+
+ def setup_dummy_image(maker)
+ title = "fugafuga"
+ link = "http://hoge.com"
+ url = "http://hoge.com/hoge.png"
+
+ maker.channel.link = link if maker.channel.link.nil?
+
+ maker.image.title = title
+ maker.image.url = url
+ end
+
+ def setup_dummy_textinput(maker)
+ title = "fugafuga"
+ description = "text hoge fuga"
+ name = "hoge"
+ link = "http://hoge.com/search.cgi"
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+
+ def setup_dummy_item(maker)
+ title = "TITLE"
+ link = "http://hoge.com/"
+
+ item = maker.items.new_item
+ item.title = title
+ item.link = link
+ end
+
+ def setup_dummy_item_atom(maker)
+ setup_dummy_item(maker)
+
+ item = maker.items.first
+ item.id = "http://example.net/xxx"
+ item.updated = Time.now
+ end
+
+ def setup_taxo_topic(target, topics)
+ topics.each do |topic|
+ taxo_topic = target.taxo_topics.new_taxo_topic
+ topic.each do |name, value|
+ case name
+ when :link
+ taxo_topic.taxo_link = value
+ when :topics
+ value.each do |t|
+ taxo_topic.taxo_topics << t
+ end
+ else
+ dc_elems = taxo_topic.__send__("dc_#{name}s")
+ dc_elem = dc_elems.__send__("new_#{name}")
+ dc_elem.value = value
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_1.0.rb b/jni/ruby/test/rss/test_1.0.rb
new file mode 100644
index 0000000..758eecf
--- /dev/null
+++ b/jni/ruby/test/rss/test_1.0.rb
@@ -0,0 +1,307 @@
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/1.0"
+
+module RSS
+ class TestRSS10Core < TestCase
+
+ def setup
+ @rdf_prefix = "rdf"
+ @rdf_uri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ @uri = "http://purl.org/rss/1.0/"
+ end
+
+ def test_RDF
+ version = "1.0"
+ encoding = "UTF-8"
+ standalone = false
+
+ rdf = RDF.new(version, encoding, standalone)
+ setup_rss10(rdf)
+ doc = REXML::Document.new(rdf.to_s)
+
+ xmldecl = doc.xml_decl
+
+ assert_equal(version, xmldecl.version)
+ assert_equal(encoding, xmldecl.encoding.to_s)
+ assert_equal(standalone, !xmldecl.standalone.nil?)
+
+ assert_equal(@rdf_uri, doc.root.namespace)
+ end
+
+ def test_not_displayed_xml_stylesheets
+ rdf = RDF.new()
+ plain_rdf = rdf.to_s
+ 3.times do
+ rdf.xml_stylesheets.push(XMLStyleSheet.new)
+ assert_equal(plain_rdf, rdf.to_s)
+ end
+ end
+
+ def test_xml_stylesheets
+ [
+ [{:href => "a.xsl", :type => "text/xsl"}],
+ [
+ {:href => "a.xsl", :type => "text/xsl"},
+ {:href => "a.css", :type => "text/css"},
+ ],
+ ].each do |attrs_ary|
+ assert_xml_stylesheet_pis(attrs_ary)
+ end
+ end
+
+ def test_channel
+ about = "http://hoge.com"
+ resource = "http://hoge.com/hoge.png"
+
+ item_title = "item title"
+ item_link = "http://hoge.com/item"
+
+ image = RDF::Channel::Image.new(resource)
+ items = RDF::Channel::Items.new
+ items.Seq.lis << items.class::Seq::Li.new(item_link)
+ textinput = RDF::Channel::Textinput.new(resource)
+
+ rss_item = RDF::Item.new
+ rss_item.title = item_title
+ rss_item.link = item_link
+ rss_item.about = item_link
+
+ h = {
+ 'title' => "fugafuga",
+ 'link' => "http://hoge.com",
+ 'description' => "fugafugafugafuga",
+ 'image' => image,
+ 'items' => items,
+ 'textinput' => textinput,
+ }
+
+ channel = RDF::Channel.new(about)
+ %w(title link description image items textinput).each do |x|
+ channel.__send__("#{x}=", h[x])
+ end
+
+ doc = REXML::Document.new(make_RDF(<<-EOR))
+#{channel}
+<items>
+#{rss_item}
+</items>
+EOR
+ c = doc.root.elements[1]
+
+ assert_equal(about, c.attributes["about"])
+ %w(title link description image textinput).each do |x|
+ elem = c.elements[x]
+ assert_equal(x, elem.name)
+ assert_equal(@uri, elem.namespace)
+ if x == "image" or x == "textinput"
+ excepted = resource
+ res = elem.attributes.get_attribute("resource")
+ assert_equal(@rdf_uri, res.namespace)
+ value = res.value
+ else
+ excepted = h[x]
+ value = elem.text
+ end
+ assert_equal(excepted, value)
+ end
+ assert_equal(@uri, c.elements["items"].namespace)
+ assert_equal("items", c.elements["items"].name)
+ end
+
+ def test_channel_image
+ resource = "http://hoge.com/hoge.png"
+ image = RDF::Channel::Image.new(resource)
+
+ doc = REXML::Document.new(make_RDF(image.to_s))
+ i = doc.root.elements[1]
+
+ assert_equal("image", i.name)
+ assert_equal(@uri, i.namespace)
+
+ res = i.attributes.get_attribute("resource")
+
+ assert_equal(@rdf_uri, res.namespace)
+ assert_equal(resource, res.value)
+ end
+
+ def test_channel_textinput
+ resource = "http://hoge.com/hoge.png"
+ textinput = RDF::Channel::Textinput.new(resource)
+
+ doc = REXML::Document.new(make_RDF(textinput.to_s))
+ t = doc.root.elements[1]
+
+ assert_equal("textinput", t.name)
+ assert_equal(@uri, t.namespace)
+
+ res = t.attributes.get_attribute("resource")
+
+ assert_equal(@rdf_uri, res.namespace)
+ assert_equal(resource, res.value)
+ end
+
+ def test_channel_items
+ item_link = "http://example.com/item"
+
+ items = RDF::Channel::Items.new
+ li = items.Seq.class::Li.new(item_link)
+ items.Seq.lis << li
+
+ doc = REXML::Document.new(make_RDF(items.to_s))
+ i = doc.root.elements[1]
+
+ assert_equal("items", i.name)
+ assert_equal(@uri, i.namespace)
+
+ assert_equal(1, i.elements.size)
+ seq = i.elements[1]
+ assert_equal("Seq", seq.name)
+ assert_equal(@rdf_uri, seq.namespace)
+
+ assert_equal(1, seq.elements.size)
+ l = seq.elements[1]
+ assert_equal("li", l.name)
+ assert_equal(@rdf_uri, l.namespace)
+ assert_equal(item_link, l.attributes["resource"])
+ end
+
+ def test_seq
+ item_link = "http://example.com/item"
+ seq = RDF::Seq.new
+ li = seq.class::Li.new(item_link)
+ seq.lis << li
+
+ doc = REXML::Document.new(make_RDF(seq.to_s))
+ s = doc.root.elements[1]
+
+ assert_equal("Seq", s.name)
+ assert_equal(@rdf_uri, s.namespace)
+
+ assert_equal(1, s.elements.size)
+ l = s.elements[1]
+ assert_equal("li", l.name)
+ assert_equal(@rdf_uri, l.namespace)
+ assert_equal(item_link, l.attributes["resource"])
+ end
+
+ def test_li
+ resource = "http://hoge.com/"
+ li = RDF::Li.new(resource)
+
+ doc = REXML::Document.new(make_RDF(li.to_s))
+ l = doc.root.elements[1]
+
+ assert_equal("li", l.name)
+ assert_equal(@rdf_uri, l.namespace(l.prefix))
+
+ res = l.attributes.get_attribute("resource")
+
+ assert_equal('', res.instance_eval("@prefix"))
+ assert_equal(resource, res.value)
+ end
+
+ def test_image
+ about = "http://hoge.com"
+ h = {
+ 'title' => "fugafuga",
+ 'url' => "http://hoge.com/hoge",
+ 'link' => "http://hoge.com/fuga",
+ }
+
+ image = RDF::Image.new(about)
+ %w(title url link).each do |x|
+ image.__send__("#{x}=", h[x])
+ end
+
+ doc = REXML::Document.new(make_RDF(image.to_s))
+ i = doc.root.elements[1]
+
+ assert_equal(about, i.attributes["about"])
+ %w(title url link).each do |x|
+ elem = i.elements[x]
+ assert_equal(x, elem.name)
+ assert_equal(@uri, elem.namespace)
+ assert_equal(h[x], elem.text)
+ end
+ end
+
+ def test_item
+ about = "http://hoge.com"
+ h = {
+ 'title' => "fugafuga",
+ 'link' => "http://hoge.com/fuga",
+ 'description' => "hogehogehoge",
+ }
+
+ item = RDF::Item.new(about)
+ %w(title link description).each do |x|
+ item.__send__("#{x}=", h[x])
+ end
+
+ doc = REXML::Document.new(make_RDF(item.to_s))
+ i = doc.root.elements[1]
+
+ assert_equal(about, i.attributes["about"])
+ %w(title link description).each do |x|
+ elem = i.elements[x]
+ assert_equal(x, elem.name)
+ assert_equal(@uri, elem.namespace)
+ assert_equal(h[x], elem.text)
+ end
+ end
+
+ def test_textinput
+ about = "http://hoge.com"
+ h = {
+ 'title' => "fugafuga",
+ 'link' => "http://hoge.com/fuga",
+ 'name' => "foo",
+ 'description' => "hogehogehoge",
+ }
+
+ textinput = RDF::Textinput.new(about)
+ %w(title link name description).each do |x|
+ textinput.__send__("#{x}=", h[x])
+ end
+
+ doc = REXML::Document.new(make_RDF(textinput.to_s))
+ t = doc.root.elements[1]
+
+ assert_equal(about, t.attributes["about"])
+ %w(title link name description).each do |x|
+ elem = t.elements[x]
+ assert_equal(x, elem.name)
+ assert_equal(@uri, elem.namespace)
+ assert_equal(h[x], elem.text)
+ end
+ end
+
+ def test_to_xml
+ rss = RSS::Parser.parse(make_sample_RDF)
+ assert_equal(rss.to_s, rss.to_xml)
+ assert_equal(rss.to_s, rss.to_xml("1.0"))
+ rss09 = rss.to_xml("0.91") do |maker|
+ maker.channel.language = "en-us"
+ end
+ rss09 = RSS::Parser.parse(rss09)
+ assert_equal("0.91", rss09.rss_version)
+ assert_equal(["rss", "0.91", nil], rss09.feed_info)
+ rss20 = RSS::Parser.parse(rss.to_xml("2.0"))
+ assert_equal("2.0", rss20.rss_version)
+ assert_equal(["rss", "2.0", nil], rss20.feed_info)
+
+ atom_xml = rss.to_xml("atom") do |maker|
+ maker.channel.author = "Alice"
+ maker.channel.updated ||= Time.now
+ maker.items.each do |item|
+ item.updated ||= Time.now
+ end
+ end
+ atom = RSS::Parser.parse(atom_xml)
+ assert_equal(["atom", "1.0", "feed"], atom.feed_info)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_2.0.rb b/jni/ruby/test/rss/test_2.0.rb
new file mode 100644
index 0000000..37285ce
--- /dev/null
+++ b/jni/ruby/test/rss/test_2.0.rb
@@ -0,0 +1,411 @@
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+module RSS
+ class TestRSS20Core < TestCase
+
+ def setup
+ @rss_version = "2.0"
+ end
+
+ def test_Rss
+ version = "1.0"
+ encoding = "UTF-8"
+ standalone = false
+
+ rss = Rss.new(@rss_version, version, encoding, standalone)
+ setup_rss20(rss)
+
+ doc = REXML::Document.new(rss.to_s(false))
+
+ xmldecl = doc.xml_decl
+
+ assert_equal(version, xmldecl.version)
+ assert_equal(encoding, xmldecl.encoding.to_s)
+ assert_equal(standalone, !xmldecl.standalone.nil?)
+
+ assert_equal("", doc.root.namespace)
+ assert_equal(@rss_version, doc.root.attributes["version"])
+ end
+
+ def test_not_displayed_xml_stylesheets
+ rss = Rss.new(@rss_version)
+ plain_rss = rss.to_s
+ 3.times do
+ rss.xml_stylesheets.push(XMLStyleSheet.new)
+ assert_equal(plain_rss, rss.to_s)
+ end
+ end
+
+ def test_xml_stylesheets
+ [
+ [{:href => "a.xsl", :type => "text/xsl"}],
+ [
+ {:href => "a.xsl", :type => "text/xsl"},
+ {:href => "a.css", :type => "text/css"},
+ ],
+ ].each do |attrs_ary|
+ rss = Rss.new(@rss_version)
+ setup_rss20(rss)
+ assert_xml_stylesheet_pis(attrs_ary, rss)
+ end
+ end
+
+ def test_channel
+ h = {
+ 'title' => "fugafuga",
+ 'link' => "http://hoge.com",
+ 'description' => "fugafugafugafuga",
+
+ 'language' => "en-us",
+ 'copyright' => "Copyright 2002, Spartanburg Herald-Journal",
+ 'managingEditor' => "geo@herald.com (George Matesky)",
+ 'webMaster' => "betty@herald.com (Betty Guernsey)",
+ 'pubDate' => Time.parse("Sat, 07 Sep 2002 00:00:01 GMT"),
+ 'lastBuildDate' => Time.parse("Sat, 07 Sep 2002 09:42:31 GMT"),
+ 'generator' => "MightyInHouse Content System v2.3",
+ 'docs' => "http://blogs.law.harvard.edu/tech/rss",
+ 'ttl' => "60",
+ 'rating' => '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))',
+ }
+ categories = [
+ {
+ :content => "Newspapers",
+ },
+ {
+ :domain => "Syndic8",
+ :content => "1765",
+ }
+ ]
+
+ channel = Rss::Channel.new
+
+ elems = %w(title link description language copyright
+ managingEditor webMaster pubDate lastBuildDate
+ generator docs ttl rating)
+ elems.each do |x|
+ value = h[x]
+ value = value.rfc822 if %w(pubDate lastBuildDate).include?(x)
+ channel.__send__("#{x}=", value)
+ end
+ categories.each do |cat|
+ channel.categories << Rss::Channel::Category.new(cat[:domain],
+ cat[:content])
+ end
+
+ doc = REXML::Document.new(make_rss20(channel.to_s))
+ c = doc.root.elements[1]
+
+ elems.each do |x|
+ elem = c.elements[x]
+ assert_equal(x, elem.name)
+ assert_equal("", elem.namespace)
+ expected = h[x]
+ case x
+ when "pubDate", "lastBuildDate"
+ assert_equal(expected, Time.parse(elem.text))
+ when "ttl"
+ expected = channel.__send__(x)
+ assert_equal(expected, elem.text.to_i)
+ else
+ assert_equal(expected, elem.text)
+ end
+ end
+ categories.each_with_index do |cat, i|
+ cat = cat.dup
+ cat[:domain] ||= nil
+ category = c.elements["category[#{i+1}]"]
+ actual = {
+ :domain => category.attributes["domain"],
+ :content => category.text,
+ }
+ assert_equal(cat, actual)
+ end
+ end
+
+ def test_channel_cloud
+ cloud_params = {
+ :domain => "rpc.sys.com",
+ :port => "80",
+ :path => "/RPC2",
+ :registerProcedure => "myCloud.rssPleaseNotify",
+ :protocol => "xml-rpc",
+ }
+ cloud = Rss::Channel::Cloud.new(cloud_params[:domain],
+ cloud_params[:port],
+ cloud_params[:path],
+ cloud_params[:registerProcedure],
+ cloud_params[:protocol])
+ cloud_params[:port] = cloud.port
+
+ doc = REXML::Document.new(cloud.to_s)
+ cloud_elem = doc.root
+
+ actual = {}
+ cloud_elem.attributes.each do |name, value|
+ value = value.to_i if name == "port"
+ actual[name.intern] = value
+ end
+ assert_equal(cloud_params, actual)
+ end
+
+ def test_channel_image
+ image_params = {
+ :url => "http://hoge.com/hoge.png",
+ :title => "fugafuga",
+ :link => "http://hoge.com",
+ :width => "144",
+ :height => "400",
+ :description => "an image",
+ }
+ image = Rss::Channel::Image.new(image_params[:url],
+ image_params[:title],
+ image_params[:link],
+ image_params[:width],
+ image_params[:height],
+ image_params[:description])
+
+ doc = REXML::Document.new(image.to_s)
+ image_elem = doc.root
+
+ image_params.each do |name, value|
+ value = image.__send__(name)
+ actual = image_elem.elements[name.to_s].text
+ actual = actual.to_i if [:width, :height].include?(name)
+ assert_equal(value, actual)
+ end
+ end
+
+ def test_channel_textInput
+ textInput_params = {
+ :title => "fugafuga",
+ :description => "text hoge fuga",
+ :name => "hoge",
+ :link => "http://hoge.com",
+ }
+ textInput = Rss::Channel::TextInput.new(textInput_params[:title],
+ textInput_params[:description],
+ textInput_params[:name],
+ textInput_params[:link])
+
+ doc = REXML::Document.new(textInput.to_s)
+ input_elem = doc.root
+
+ textInput_params.each do |name, value|
+ actual = input_elem.elements[name.to_s].text
+ assert_equal(value, actual)
+ end
+ end
+
+ def test_channel_skip_days
+ skipDays_values = [
+ "Sunday",
+ "Monday",
+ ]
+ skipDays = Rss::Channel::SkipDays.new
+ skipDays_values.each do |value|
+ skipDays.days << Rss::Channel::SkipDays::Day.new(value)
+ end
+
+ doc = REXML::Document.new(skipDays.to_s)
+ days_elem = doc.root
+
+ skipDays_values.each_with_index do |value, i|
+ assert_equal(value, days_elem.elements[i + 1].text)
+ end
+ end
+
+ def test_channel_skip_hours
+ skipHours_values = [
+ "0",
+ "13",
+ ]
+ skipHours = Rss::Channel::SkipHours.new
+ skipHours_values.each do |value|
+ skipHours.hours << Rss::Channel::SkipHours::Hour.new(value)
+ end
+
+ doc = REXML::Document.new(skipHours.to_s)
+ hours_elem = doc.root
+
+ skipHours_values.each_with_index do |value, i|
+ expected = skipHours.hours[i].content
+ assert_equal(expected, hours_elem.elements[i + 1].text.to_i)
+ end
+ end
+
+ def test_item
+ h = {
+ 'title' => "fugafuga",
+ 'link' => "http://hoge.com/",
+ 'description' => "text hoge fuga",
+ 'author' => "oprah@oxygen.net",
+ 'comments' => "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290",
+ 'pubDate' => Time.parse("Sat, 07 Sep 2002 00:00:01 GMT"),
+ }
+ categories = [
+ {
+ :content => "Newspapers",
+ },
+ {
+ :domain => "Syndic8",
+ :content => "1765",
+ }
+ ]
+
+ channel = Rss::Channel.new
+ channel.title = "title"
+ channel.link = "http://example.com/"
+ channel.description = "description"
+
+ item = Rss::Channel::Item.new
+ channel.items << item
+
+ elems = %w(title link description author comments pubDate)
+ elems.each do |x|
+ value = h[x]
+ value = value.rfc822 if x == "pubDate"
+ item.__send__("#{x}=", value)
+ end
+ categories.each do |cat|
+ item.categories << Rss::Channel::Category.new(cat[:domain],
+ cat[:content])
+ end
+
+ doc = REXML::Document.new(channel.to_s)
+ channel_elem = doc.root
+
+ item_elem = channel_elem.elements["item[1]"]
+ elems.each do |x|
+ elem = item_elem.elements[x]
+ assert_equal(x, elem.name)
+ assert_equal("", elem.namespace)
+ expected = h[x]
+ case x
+ when "pubDate"
+ assert_equal(expected, Time.parse(elem.text))
+ else
+ assert_equal(expected, elem.text)
+ end
+ end
+ categories.each_with_index do |cat, i|
+ cat = cat.dup
+ cat[:domain] ||= nil
+ category = item_elem.elements["category[#{i+1}]"]
+ actual = {
+ :domain => category.attributes["domain"],
+ :content => category.text,
+ }
+ assert_equal(cat, actual)
+ end
+ end
+
+ def test_item_enclosure
+ enclosure_params = {
+ :url => "http://www.scripting.com/mp3s/weatherReportSuite.mp3",
+ :length => "12216320",
+ :type => "audio/mpeg",
+ }
+
+ enclosure = Rss::Channel::Item::Enclosure.new(enclosure_params[:url],
+ enclosure_params[:length],
+ enclosure_params[:type])
+ enclosure_params[:length] = enclosure.length
+
+ doc = REXML::Document.new(enclosure.to_s)
+ enclosure_elem = doc.root
+
+ actual = {}
+ enclosure_elem.attributes.each do |name, value|
+ value = value.to_i if name == "length"
+ actual[name.intern] = value
+ end
+ assert_equal(enclosure_params, actual)
+ end
+
+ def test_item_guid
+ test_params = [
+ {
+ :content => "http://some.server.com/weblogItem3207",
+ },
+ {
+ :isPermaLink => "true",
+ :content => "http://inessential.com/2002/09/01.php#a2",
+ },
+ ]
+
+ test_params.each do |guid_params|
+ guid = Rss::Channel::Item::Guid.new(guid_params[:isPermaLink],
+ guid_params[:content])
+ if guid_params.has_key?(:isPermaLink)
+ guid_params[:isPermaLink] = guid.isPermaLink
+ end
+ if guid.isPermaLink.nil?
+ assert_equal(true, guid.PermaLink?)
+ else
+ assert_equal(guid.isPermaLink, guid.PermaLink?)
+ end
+
+ doc = REXML::Document.new(guid.to_s)
+ guid_elem = doc.root
+
+ actual = {}
+ actual[:content] = guid_elem.text if guid_elem.text
+ guid_elem.attributes.each do |name, value|
+ value = value == "true" if name == "isPermaLink"
+ actual[name.intern] = value
+ end
+ assert_equal(guid_params, actual)
+ end
+ end
+
+ def test_item_source
+ source_params = {
+ :url => "http://www.tomalak.org/links2.xml",
+ :content => "Tomalak's Realm",
+ }
+
+ source = Rss::Channel::Item::Source.new(source_params[:url],
+ source_params[:content])
+
+ doc = REXML::Document.new(source.to_s)
+ source_elem = doc.root
+
+ actual = {}
+ actual[:content] = source_elem.text
+ source_elem.attributes.each do |name, value|
+ actual[name.intern] = value
+ end
+ assert_equal(source_params, actual)
+ end
+
+ def test_to_xml
+ rss = RSS::Parser.parse(make_sample_rss20)
+ assert_equal(rss.to_s, rss.to_xml)
+ assert_equal(rss.to_s, rss.to_xml("2.0"))
+ rss09_xml = rss.to_xml("0.91") do |maker|
+ setup_dummy_image(maker)
+ end
+ rss09 = RSS::Parser.parse(rss09_xml)
+ assert_equal("0.91", rss09.rss_version)
+ rss10 = rss.to_xml("1.0") do |maker|
+ maker.channel.about = "http://www.example.com/index.rdf"
+ end
+ rss10 = RSS::Parser.parse(rss10)
+ assert_equal("1.0", rss10.rss_version)
+
+ atom_xml = rss.to_xml("atom1.0") do |maker|
+ maker.channel.id = "http://www.example.com/atom.xml"
+ maker.channel.author = "Alice"
+ maker.channel.updated = Time.now
+ maker.items.each do |item|
+ item.author = "Bob"
+ item.updated = Time.now
+ end
+ end
+ atom = RSS::Parser.parse(atom_xml)
+ assert_equal(["atom", "1.0", "feed"], atom.feed_info)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_accessor.rb b/jni/ruby/test/rss/test_accessor.rb
new file mode 100644
index 0000000..ea15316
--- /dev/null
+++ b/jni/ruby/test/rss/test_accessor.rb
@@ -0,0 +1,103 @@
+require_relative "rss-testcase"
+
+require "rss/1.0"
+require "rss/2.0"
+require "rss/syndication"
+require "rss/image"
+
+module RSS
+ class TestAccessor < TestCase
+ def test_date
+ channel = Rss::Channel.new
+ channel.pubDate = nil
+ assert_nil(channel.pubDate)
+
+ time = Time.now
+ channel.pubDate = time
+ assert_equal(time, channel.pubDate)
+
+ time = Time.parse(Time.now.rfc822)
+ channel.pubDate = time.rfc822
+ assert_equal(time, channel.pubDate)
+
+ time = Time.parse(Time.now.iso8601)
+ value = time.iso8601
+ assert_not_available_value("pubDate", value) do
+ channel.pubDate = value
+ end
+
+ channel.do_validate = false
+ time = Time.parse(Time.now.iso8601)
+ value = time.iso8601
+ channel.pubDate = value
+ assert_equal(time, channel.pubDate)
+
+ channel.pubDate = nil
+ assert_nil(channel.pubDate)
+ end
+
+ def test_integer
+ image_item = RDF::Item::ImageItem.new
+
+ image_item.width = nil
+ assert_nil(image_item.width)
+
+ width = 10
+ image_item.width = width
+ assert_equal(width, image_item.width)
+
+ width = 10.0
+ image_item.width = width
+ assert_equal(width, image_item.width)
+
+ width = "10"
+ image_item.width = width
+ assert_equal(width.to_i, image_item.width)
+
+ width = "10.0"
+ assert_not_available_value("image:width", width) do
+ image_item.width = width
+ end
+
+ image_item.do_validate = false
+ width = "10.0"
+ image_item.width = width
+ assert_equal(width.to_i, image_item.width)
+
+ image_item.width = nil
+ assert_nil(image_item.width)
+ end
+
+ def test_positive_integer
+ channel = RDF::Channel.new
+
+ channel.sy_updateFrequency = nil
+ assert_nil(channel.sy_updateFrequency)
+
+ freq = 10
+ channel.sy_updateFrequency = freq
+ assert_equal(freq, channel.sy_updateFrequency)
+
+ freq = 10.0
+ channel.sy_updateFrequency = freq
+ assert_equal(freq, channel.sy_updateFrequency)
+
+ freq = "10"
+ channel.sy_updateFrequency = freq
+ assert_equal(freq.to_i, channel.sy_updateFrequency)
+
+ freq = "10.0"
+ assert_not_available_value("sy:updateFrequency", freq) do
+ channel.sy_updateFrequency = freq
+ end
+
+ channel.do_validate = false
+ freq = "10.0"
+ channel.sy_updateFrequency = freq
+ assert_equal(freq.to_i, channel.sy_updateFrequency)
+
+ channel.sy_updateFrequency = nil
+ assert_nil(channel.sy_updateFrequency)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_atom.rb b/jni/ruby/test/rss/test_atom.rb
new file mode 100644
index 0000000..557cb80
--- /dev/null
+++ b/jni/ruby/test/rss/test_atom.rb
@@ -0,0 +1,683 @@
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/atom"
+
+module RSS
+ class TestAtomCore < TestCase
+ def setup
+ @uri = "http://www.w3.org/2005/Atom"
+ @xhtml_uri = "http://www.w3.org/1999/xhtml"
+ end
+
+ def test_feed
+ version = "1.0"
+ encoding = "UTF-8"
+ standalone = false
+
+ feed = Atom::Feed.new(version, encoding, standalone)
+ assert_equal("", feed.to_s)
+
+ author = feed.class::Author.new
+ name = feed.class::Author::Name.new
+ name.content = "an author"
+ author.name = name
+ assert_not_equal("", author.to_s)
+ feed.authors << author
+ assert_equal("", feed.to_s)
+
+ id = feed.class::Id.new
+ id.content = "http://example.com/atom.xml"
+ assert_not_equal("", id.to_s)
+ feed.id = id
+ assert_equal("", feed.to_s)
+
+ title = feed.class::Title.new
+ title.content = "a title"
+ assert_not_equal("", title.to_s)
+ feed.title = title
+ assert_equal("", feed.to_s)
+
+ updated = feed.class::Updated.new
+ updated.content = Time.now
+ assert_not_equal("", updated.to_s)
+ feed.updated = updated
+ assert_not_equal("", feed.to_s)
+
+
+ feed.authors.clear
+ assert_equal("", feed.to_s)
+ entry = Atom::Feed::Entry.new
+ setup_entry(entry)
+ assert_not_equal("", entry.to_s)
+
+ author = entry.authors.first
+ entry.authors.clear
+ assert_equal("", entry.to_s)
+ entry.parent = feed
+ assert_equal("", entry.to_s)
+ feed.authors << author
+ assert_not_equal("", entry.to_s)
+ feed.authors.clear
+ feed.entries << entry
+ assert_equal("", feed.to_s)
+ entry.authors << author
+ assert_not_equal("", entry.to_s)
+ assert_not_equal("", feed.to_s)
+
+ doc = REXML::Document.new(feed.to_s)
+ xmldecl = doc.xml_decl
+
+ assert_equal(version, xmldecl.version)
+ assert_equal(encoding, xmldecl.encoding.to_s)
+ assert_equal(standalone, !xmldecl.standalone.nil?)
+
+ assert_equal(@uri, doc.root.namespace)
+ end
+
+ def test_entry
+ version = "1.0"
+ encoding = "UTF-8"
+ standalone = false
+
+ entry = Atom::Entry.new(version, encoding, standalone)
+ setup_entry(entry)
+
+ author = entry.authors.first
+ entry.authors.clear
+ assert_equal("", entry.to_s)
+ source = Atom::Entry::Source.new
+ source.authors << author
+ entry.source = source
+ assert_not_equal("", entry.to_s)
+
+ doc = REXML::Document.new(entry.to_s)
+ xmldecl = doc.xml_decl
+
+ assert_equal(version, xmldecl.version)
+ assert_equal(encoding, xmldecl.encoding.to_s)
+ assert_equal(standalone, !xmldecl.standalone.nil?)
+
+ assert_equal(@uri, doc.root.namespace)
+ end
+
+ def test_not_displayed_xml_stylesheets
+ feed = Atom::Feed.new
+ plain_feed = feed.to_s
+ 3.times do
+ feed.xml_stylesheets.push(XMLStyleSheet.new)
+ assert_equal(plain_feed, feed.to_s)
+ end
+ end
+
+ def test_atom_author
+ assert_atom_person_to_s(Atom::Feed::Author)
+ assert_atom_person_to_s(Atom::Feed::Entry::Author)
+ assert_atom_person_to_s(Atom::Entry::Author)
+ assert_atom_person_to_s(Atom::Feed::Entry::Source::Author)
+ assert_atom_person_to_s(Atom::Entry::Source::Author)
+ end
+
+ def test_atom_category
+ assert_atom_category_to_s(Atom::Feed::Category)
+ assert_atom_category_to_s(Atom::Feed::Entry::Category)
+ assert_atom_category_to_s(Atom::Entry::Category)
+ assert_atom_category_to_s(Atom::Feed::Entry::Source::Category)
+ assert_atom_category_to_s(Atom::Entry::Source::Category)
+ end
+
+ def test_atom_contributor
+ assert_atom_person_to_s(Atom::Feed::Contributor)
+ assert_atom_person_to_s(Atom::Feed::Entry::Contributor)
+ assert_atom_person_to_s(Atom::Entry::Contributor)
+ assert_atom_person_to_s(Atom::Feed::Entry::Source::Contributor)
+ assert_atom_person_to_s(Atom::Entry::Source::Contributor)
+ end
+
+ def test_atom_generator
+ assert_atom_generator_to_s(Atom::Feed::Generator)
+ assert_atom_generator_to_s(Atom::Feed::Entry::Source::Generator)
+ assert_atom_generator_to_s(Atom::Entry::Source::Generator)
+ end
+
+ def test_atom_icon
+ assert_atom_icon_to_s(Atom::Feed::Icon)
+ assert_atom_icon_to_s(Atom::Feed::Entry::Source::Icon)
+ assert_atom_icon_to_s(Atom::Entry::Source::Icon)
+ end
+
+ def test_atom_id
+ assert_atom_id_to_s(Atom::Feed::Id)
+ assert_atom_id_to_s(Atom::Feed::Entry::Id)
+ assert_atom_id_to_s(Atom::Entry::Id)
+ assert_atom_id_to_s(Atom::Feed::Entry::Source::Id)
+ assert_atom_id_to_s(Atom::Entry::Source::Id)
+ end
+
+ def test_atom_link
+ assert_atom_link_to_s(Atom::Feed::Link)
+ assert_atom_link_to_s(Atom::Feed::Entry::Link)
+ assert_atom_link_to_s(Atom::Entry::Link)
+ assert_atom_link_to_s(Atom::Feed::Entry::Source::Link)
+ assert_atom_link_to_s(Atom::Entry::Source::Link)
+ end
+
+ def test_atom_logo
+ assert_atom_logo_to_s(Atom::Feed::Logo)
+ assert_atom_logo_to_s(Atom::Feed::Entry::Source::Logo)
+ assert_atom_logo_to_s(Atom::Entry::Source::Logo)
+ end
+
+ def test_atom_rights
+ assert_atom_text_construct_to_s(Atom::Feed::Rights)
+ assert_atom_text_construct_to_s(Atom::Feed::Entry::Rights)
+ assert_atom_text_construct_to_s(Atom::Entry::Rights)
+ assert_atom_text_construct_to_s(Atom::Feed::Entry::Source::Rights)
+ assert_atom_text_construct_to_s(Atom::Entry::Source::Rights)
+ end
+
+ def test_atom_subtitle
+ assert_atom_text_construct_to_s(Atom::Feed::Subtitle)
+ assert_atom_text_construct_to_s(Atom::Feed::Entry::Source::Subtitle)
+ assert_atom_text_construct_to_s(Atom::Entry::Source::Subtitle)
+ end
+
+ def test_atom_title
+ assert_atom_text_construct_to_s(Atom::Feed::Title)
+ assert_atom_text_construct_to_s(Atom::Feed::Entry::Title)
+ assert_atom_text_construct_to_s(Atom::Entry::Title)
+ assert_atom_text_construct_to_s(Atom::Feed::Entry::Source::Title)
+ assert_atom_text_construct_to_s(Atom::Entry::Source::Title)
+ end
+
+ def test_atom_updated
+ assert_atom_date_construct_to_s(Atom::Feed::Updated)
+ assert_atom_date_construct_to_s(Atom::Feed::Entry::Updated)
+ assert_atom_date_construct_to_s(Atom::Entry::Updated)
+ assert_atom_date_construct_to_s(Atom::Feed::Entry::Source::Updated)
+ assert_atom_date_construct_to_s(Atom::Entry::Source::Updated)
+ end
+
+ def test_atom_content
+ assert_atom_content_to_s(Atom::Feed::Entry::Content)
+ assert_atom_content_to_s(Atom::Entry::Content)
+ end
+
+ def test_atom_published
+ assert_atom_date_construct_to_s(Atom::Feed::Entry::Published)
+ assert_atom_date_construct_to_s(Atom::Entry::Published)
+ end
+
+ def test_atom_summary
+ assert_atom_text_construct_to_s(Atom::Feed::Entry::Summary)
+ assert_atom_text_construct_to_s(Atom::Entry::Summary)
+ end
+
+
+ def test_to_xml(with_convenience_way=true)
+ atom = RSS::Parser.parse(make_feed)
+ assert_equal(atom.to_s, atom.to_xml)
+ assert_equal(atom.to_s, atom.to_xml("atom"))
+ assert_equal(atom.to_s, atom.to_xml("atom1.0"))
+ assert_equal(atom.to_s, atom.to_xml("atom1.0:feed"))
+ assert_equal(atom.to_s, atom.to_xml("atom:feed"))
+
+ rss09_xml = atom.to_xml("0.91") do |maker|
+ maker.channel.language = "en-us"
+ maker.channel.link = "http://example.com/"
+ if with_convenience_way
+ maker.channel.description = atom.title.content
+ else
+ maker.channel.description {|d| d.content = atom.title.content}
+ end
+
+ maker.image.url = "http://example.com/logo.png"
+ maker.image.title = "Logo"
+ end
+ rss09 = RSS::Parser.parse(rss09_xml)
+ assert_equal(["rss", "0.91", nil], rss09.feed_info)
+
+ rss20_xml = atom.to_xml("2.0") do |maker|
+ maker.channel.link = "http://example.com/"
+ if with_convenience_way
+ maker.channel.description = atom.title.content
+ else
+ maker.channel.description {|d| d.content = atom.title.content}
+ end
+ end
+ rss20 = RSS::Parser.parse(rss20_xml)
+ assert_equal("2.0", rss20.rss_version)
+ assert_equal(["rss", "2.0", nil], rss20.feed_info)
+ end
+
+ def test_to_xml_with_new_api_since_018
+ test_to_xml(false)
+ end
+
+ private
+ def setup_entry(entry)
+ _wrap_assertion do
+ assert_equal("", entry.to_s)
+
+ author = entry.class::Author.new
+ name = entry.class::Author::Name.new
+ name.content = "an author"
+ author.name = name
+ assert_not_equal("", author.to_s)
+ entry.authors << author
+ assert_equal("", entry.to_s)
+
+ id = entry.class::Id.new
+ id.content = "http://example.com/atom.xml"
+ assert_not_equal("", id.to_s)
+ entry.id = id
+ assert_equal("", entry.to_s)
+
+ title = entry.class::Title.new
+ title.content = "a title"
+ assert_not_equal("", title.to_s)
+ entry.title = title
+ assert_equal("", entry.to_s)
+
+ updated = entry.class::Updated.new
+ updated.content = Time.now
+ assert_not_equal("", updated.to_s)
+ entry.updated = updated
+ assert_not_equal("", entry.to_s)
+ end
+ end
+
+
+ def assert_atom_person_to_s(target_class)
+ _wrap_assertion do
+ name = "A person"
+ uri = "http://example.com/person/"
+ email = "person@example.com"
+
+ target = target_class.new
+ assert_equal("", target.to_s)
+
+ target = target_class.new
+ person_name = target_class::Name.new
+ person_name.content = name
+ target.name = person_name
+ xml_target = REXML::Document.new(target.to_s).root
+ assert_equal(["name"], xml_target.elements.collect {|e| e.name})
+ assert_equal([name], xml_target.elements.collect {|e| e.text})
+
+ person_uri = target_class::Uri.new
+ person_uri.content = uri
+ target.uri = person_uri
+ xml_target = REXML::Document.new(target.to_s).root
+ assert_equal(["name", "uri"], xml_target.elements.collect {|e| e.name})
+ assert_equal([name, uri], xml_target.elements.collect {|e| e.text})
+
+ person_email = target_class::Email.new
+ person_email.content = email
+ target.email = person_email
+ xml_target = REXML::Document.new(target.to_s).root
+ assert_equal(["name", "uri", "email"],
+ xml_target.elements.collect {|e| e.name})
+ assert_equal([name, uri, email],
+ xml_target.elements.collect {|e| e.text})
+ end
+ end
+
+ def assert_atom_category_to_s(target_class)
+ _wrap_assertion do
+ term = "music"
+ scheme = "http://example.com/music"
+ label = "Music"
+
+ category = target_class.new
+ assert_equal("", category.to_s)
+
+ category = target_class.new
+ category.scheme = scheme
+ assert_equal("", category.to_s)
+
+ category = target_class.new
+ category.label = label
+ assert_equal("", category.to_s)
+
+ category = target_class.new
+ category.scheme = scheme
+ category.label = label
+ assert_equal("", category.to_s)
+
+ category = target_class.new
+ category.term = term
+ xml = REXML::Document.new(category.to_s).root
+ assert_rexml_element([], {"term" => term}, nil, xml)
+
+ category = target_class.new
+ category.term = term
+ category.scheme = scheme
+ xml = REXML::Document.new(category.to_s).root
+ assert_rexml_element([], {"term" => term, "scheme" => scheme}, nil, xml)
+
+ category = target_class.new
+ category.term = term
+ category.label = label
+ xml = REXML::Document.new(category.to_s).root
+ assert_rexml_element([], {"term" => term, "label" => label}, nil, xml)
+
+ category = target_class.new
+ category.term = term
+ category.scheme = scheme
+ category.label = label
+ xml = REXML::Document.new(category.to_s).root
+ attrs = {"term" => term, "scheme" => scheme, "label" => label}
+ assert_rexml_element([], attrs, nil, xml)
+ end
+ end
+
+ def assert_atom_generator_to_s(target_class)
+ _wrap_assertion do
+ content = "Feed generator"
+ uri = "http://example.com/generator"
+ version = "0.0.1"
+
+ generator = target_class.new
+ assert_equal("", generator.to_s)
+
+ generator = target_class.new
+ generator.uri = uri
+ assert_equal("", generator.to_s)
+
+ generator = target_class.new
+ generator.version = version
+ assert_equal("", generator.to_s)
+
+ generator = target_class.new
+ generator.uri = uri
+ generator.version = version
+ assert_equal("", generator.to_s)
+
+ generator = target_class.new
+ generator.content = content
+ xml = REXML::Document.new(generator.to_s).root
+ assert_rexml_element([], {}, content, xml)
+
+ generator = target_class.new
+ generator.content = content
+ generator.uri = uri
+ xml = REXML::Document.new(generator.to_s).root
+ assert_rexml_element([], {"uri" => uri}, content, xml)
+
+ generator = target_class.new
+ generator.content = content
+ generator.version = version
+ xml = REXML::Document.new(generator.to_s).root
+ assert_rexml_element([], {"version" => version}, content, xml)
+
+ generator = target_class.new
+ generator.content = content
+ generator.uri = uri
+ generator.version = version
+ xml = REXML::Document.new(generator.to_s).root
+ assert_rexml_element([], {"uri" => uri, "version" => version},
+ content, xml)
+ end
+ end
+
+ def assert_atom_icon_to_s(target_class)
+ _wrap_assertion do
+ content = "http://example.com/icon.png"
+
+ icon = target_class.new
+ assert_equal("", icon.to_s)
+
+ icon = target_class.new
+ icon.content = content
+ xml = REXML::Document.new(icon.to_s).root
+ assert_rexml_element([], {}, content, xml)
+ end
+ end
+
+ def assert_atom_id_to_s(target_class)
+ _wrap_assertion do
+ content = "http://example.com/1"
+
+ id = target_class.new
+ assert_equal("", id.to_s)
+
+ id = target_class.new
+ id.content = content
+ xml = REXML::Document.new(id.to_s).root
+ assert_rexml_element([], {}, content, xml)
+ end
+ end
+
+ def assert_atom_link_to_s(target_class)
+ _wrap_assertion do
+ href = "http://example.com/atom.xml"
+ optvs = {
+ 'rel' => "self",
+ 'type' => "application/atom+xml",
+ 'hreflang' => "ja",
+ 'title' => "Atom Feed",
+ 'length' => "801",
+ }
+
+ link = target_class.new
+ assert_equal("", link.to_s)
+
+ link = target_class.new
+ link.href = href
+ xml = REXML::Document.new(link.to_s).root
+ assert_rexml_element([], {"href" => href}, nil, xml)
+
+ optional_arguments = %w(rel type hreflang title length)
+ optional_arguments.each do |name|
+ rest = optional_arguments.reject {|x| x == name}
+
+ link = target_class.new
+ link.__send__("#{name}=", optvs[name])
+ assert_equal("", link.to_s)
+
+ rest.each do |n|
+ link.__send__("#{n}=", optvs[n])
+ assert_equal("", link.to_s)
+ end
+
+ link = target_class.new
+ link.href = href
+ link.__send__("#{name}=", optvs[name])
+ attrs = [["href", href], [name, optvs[name]]]
+ xml = REXML::Document.new(link.to_s).root
+ assert_rexml_element([], attrs, nil, xml)
+
+ rest.each do |n|
+ link.__send__("#{n}=", optvs[n])
+ attrs << [n, optvs[n]]
+ xml = REXML::Document.new(link.to_s).root
+ assert_rexml_element([], attrs, nil, xml)
+ end
+ end
+ end
+ end
+
+ def assert_atom_logo_to_s(target_class)
+ _wrap_assertion do
+ content = "http://example.com/logo.png"
+
+ logo = target_class.new
+ assert_equal("", logo.to_s)
+
+ logo = target_class.new
+ logo.content = content
+ xml = REXML::Document.new(logo.to_s).root
+ assert_rexml_element([], {}, content, xml)
+ end
+ end
+
+ def assert_atom_text_construct_to_s(target_class)
+ _wrap_assertion do
+ text_content = "plain text"
+ html_content = "<em>#{text_content}</em>"
+ xhtml_uri = "http://www.w3.org/1999/xhtml"
+ xhtml_em = RSS::XML::Element.new("em", nil, xhtml_uri, {}, text_content)
+ xhtml_content = RSS::XML::Element.new("div", nil, xhtml_uri,
+ {"xmlns" => xhtml_uri},
+ [xhtml_em])
+
+ text = target_class.new
+ assert_equal("", text.to_s)
+
+ text = target_class.new
+ text.type = "text"
+ assert_equal("", text.to_s)
+
+ text = target_class.new
+ text.content = text_content
+ xml = REXML::Document.new(text.to_s).root
+ assert_rexml_element([], {}, text_content, xml)
+
+ text = target_class.new
+ text.type = "text"
+ text.content = text_content
+ xml = REXML::Document.new(text.to_s).root
+ assert_rexml_element([], {"type" => "text"}, text_content, xml)
+
+ text = target_class.new
+ text.type = "html"
+ text.content = html_content
+ xml = REXML::Document.new(text.to_s).root
+ assert_rexml_element([], {"type" => "html"}, html_content, xml)
+
+ text = target_class.new
+ text.type = "xhtml"
+ text.content = xhtml_content
+ assert_equal("", text.to_s)
+
+ text = target_class.new
+ text.type = "xhtml"
+ text.__send__(target_class.xml_setter, xhtml_content)
+ xml = REXML::Document.new(text.to_s).root
+ assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
+ nil, xml)
+ assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
+ assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
+
+ text = target_class.new
+ text.type = "xhtml"
+ text.__send__(target_class.xml_setter, xhtml_em)
+ xml = REXML::Document.new(text.to_s).root
+ assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
+ nil, xml)
+ assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
+ assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
+ end
+ end
+
+ def assert_atom_date_construct_to_s(target_class)
+ _wrap_assertion do
+ date = target_class.new
+ assert_equal("", date.to_s)
+
+ [
+ "2003-12-13T18:30:02Z",
+ "2003-12-13T18:30:02.25Z",
+ "2003-12-13T18:30:02+01:00",
+ "2003-12-13T18:30:02.25+01:00",
+ ].each do |content|
+ date = target_class.new
+ date.content = content
+ xml = REXML::Document.new(date.to_s).root
+ assert_rexml_element([], {}, content, xml, :time)
+
+ date = target_class.new
+ date.content = Time.parse(content)
+ xml = REXML::Document.new(date.to_s).root
+ assert_rexml_element([], {}, content, xml, :time)
+ end
+ end
+ end
+
+ def assert_atom_content_to_s(target_class)
+ _wrap_assertion do
+ assert_atom_text_construct_to_s(target_class)
+ assert_atom_content_inline_other_xml_to_s(target_class)
+ assert_atom_content_inline_other_text_to_s(target_class)
+ assert_atom_content_inline_other_base64_to_s(target_class)
+ assert_atom_content_out_of_line_to_s(target_class)
+ end
+ end
+
+ def assert_atom_content_inline_other_xml_to_s(target_class)
+ _wrap_assertion do
+ content = target_class.new
+ content.type = "text/xml"
+ assert_equal("", content.to_s)
+
+ content = target_class.new
+ content.type = "text/xml"
+ content.xml = RSS::XML::Element.new("em")
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([["", "em"]], {"type" => "text/xml"}, nil, xml)
+ end
+ end
+
+ def assert_atom_content_inline_other_text_to_s(target_class)
+ _wrap_assertion do
+ content = target_class.new
+ content.type = "text/plain"
+ assert_equal("", content.to_s)
+
+ content = target_class.new
+ content.type = "text/plain"
+ content.xml = RSS::XML::Element.new("em")
+ assert_equal("", content.to_s)
+
+ content = target_class.new
+ content.type = "text/plain"
+ content.content = "content"
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([], {"type" => "text/plain"}, "content", xml)
+ end
+ end
+
+ def assert_atom_content_inline_other_base64_to_s(target_class)
+ _wrap_assertion do
+ type = "image/png"
+ png_file = File.join(File.dirname(__FILE__), "dot.png")
+ original_content = File.open(png_file, "rb") do |file|
+ file.read.force_encoding("binary")
+ end
+
+ content = target_class.new
+ content.type = type
+ content.content = original_content
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([], {"type" => type},
+ [original_content].pack("m").delete("\n"),
+ xml)
+ end
+ end
+
+ def assert_atom_content_out_of_line_to_s(target_class)
+ _wrap_assertion do
+ type = "application/zip"
+ src = "http://example.com/xxx.zip"
+
+ content = target_class.new
+ assert(!content.out_of_line?)
+ content.src = src
+ assert(content.out_of_line?)
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([], {"src" => src}, nil, xml)
+
+ content = target_class.new
+ assert(!content.out_of_line?)
+ content.type = type
+ assert(!content.out_of_line?)
+ content.src = src
+ assert(content.out_of_line?)
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([], {"type" => type, "src" => src}, nil, xml)
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_content.rb b/jni/ruby/test/rss/test_content.rb
new file mode 100644
index 0000000..13f22a2
--- /dev/null
+++ b/jni/ruby/test/rss/test_content.rb
@@ -0,0 +1,104 @@
+require "cgi"
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/content"
+
+module RSS
+ class TestContent < TestCase
+ def setup
+ @prefix = "content"
+ @uri = "http://purl.org/rss/1.0/modules/content/"
+
+ @elems = {
+ :encoded => "<em>ATTENTION</em>",
+ }
+
+ @content_nodes = @elems.collect do |name, value|
+ "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
+ end.join("\n")
+
+ @rss10_source = make_RDF(<<-EOR, {@prefix => @uri})
+#{make_channel()}
+#{make_image()}
+#{make_item(@content_nodes)}
+#{make_textinput()}
+EOR
+
+ @rss10 = Parser.parse(@rss10_source)
+
+
+ @rss20_source = make_rss20(<<-EOR, {@prefix => @uri})
+#{make_channel20(make_item20(@content_nodes))}
+EOR
+
+ @rss20 = Parser.parse(@rss20_source)
+ end
+
+ def test_parser
+ assert_nothing_raised do
+ Parser.parse(@rss10_source)
+ end
+
+ assert_nothing_raised do
+ Parser.parse(@rss20_source)
+ end
+
+ @elems.each do |tag, value|
+ tag_name = "#{@prefix}:#{tag}"
+ content_encodes = make_element(tag_name, {}, value) * 2
+
+ assert_too_much_tag(tag.to_s, "item") do
+ Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
+#{make_channel}
+#{make_item(content_encodes)}
+EOR
+ end
+
+ assert_too_much_tag(tag.to_s, "item") do
+ Parser.parse(make_rss20(<<-EOR, {@prefix => @uri}))
+#{make_channel20(make_item20(content_encodes))}
+EOR
+ end
+ end
+ end
+
+ def test_accessor
+ new_value = {
+ :encoded => "<![CDATA[<it>hoge</it>]]>",
+ }
+
+ @elems.each do |name, value|
+ [@rss10, @rss20].each do |rss|
+ meth = "#{RSS::CONTENT_PREFIX}_#{name}"
+ parent = rss.items.last
+ assert_equal(value, parent.__send__(meth))
+ parent.__send__("#{meth}=", new_value[name].to_s)
+ assert_equal(new_value[name], parent.__send__(meth))
+ end
+ end
+ end
+
+ def test_to_s
+ @elems.each do |name, value|
+ excepted = make_element("#{@prefix}:#{name}", {}, value)
+ meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
+ [@rss10, @rss20].each do |rss|
+ assert_equal(excepted, rss.items.last.__send__(meth))
+ end
+ end
+
+ [@rss10_source, @rss20_source].each do |source|
+ REXML::Document.new(source).root.each_element do |parent|
+ next unless parent.name != "item"
+ parent.each_element do |elem|
+ if elem.namespace == @uri
+ assert_equal(elem.text, @elems[elem.name.intern].to_s)
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_dublincore.rb b/jni/ruby/test/rss/test_dublincore.rb
new file mode 100644
index 0000000..eb03d84
--- /dev/null
+++ b/jni/ruby/test/rss/test_dublincore.rb
@@ -0,0 +1,269 @@
+require "cgi"
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/1.0"
+require "rss/dublincore"
+
+module RSS
+ class TestDublinCore < TestCase
+ def setup
+ @rss10_parents = [%w(channel), %w(image), %w(item), %w(textinput)]
+
+ @rss10_source = make_RDF(<<-EOR, {DC_PREFIX => DC_URI})
+#{make_channel(DC_NODES)}
+#{make_image(DC_NODES)}
+#{make_item(DC_NODES)}
+#{make_textinput(DC_NODES)}
+EOR
+
+ @rss20_parents = [%w(channel), %w(items last)]
+
+ @rss20_source = make_rss20(<<-EOR, {DC_PREFIX => DC_URI})
+#{make_channel20(DC_NODES + make_item20(DC_NODES))}
+EOR
+
+ @atom_feed_parents = [[], %w(entries last)]
+
+ @atom_feed_source = make_feed(<<-EOR, {DC_PREFIX => DC_URI})
+#{DC_NODES}
+#{make_entry(DC_NODES)}
+EOR
+
+ @atom_entry_parents = [[]]
+
+ @atom_entry_source = make_entry_document(<<-EOR, {DC_PREFIX => DC_URI})
+#{DC_NODES}
+EOR
+ end
+
+ def test_parser
+ rss10_maker = Proc.new do |content, xmlns|
+ make_RDF(<<-EOR, xmlns)
+#{make_channel(content)}
+#{make_image(content)}
+#{make_item(content)}
+#{make_textinput(content)}
+EOR
+ end
+ assert_dc_parse(@rss10_source, @rss10_parents, false, &rss10_maker)
+ assert_dc_parse(@rss10_source, @rss10_parents, true, &rss10_maker)
+
+ rss20_maker = Proc.new do |content, xmlns|
+ make_rss20(<<-EOR, xmlns)
+#{make_channel20(content + make_item20(content))}
+EOR
+ end
+ assert_dc_parse(@rss20_source, @rss20_parents, false, &rss20_maker)
+ assert_dc_parse(@rss20_source, @rss20_parents, true, &rss20_maker)
+
+ atom_feed_maker = Proc.new do |content, xmlns|
+ make_feed(<<-EOR, xmlns)
+#{content}
+#{make_entry(content)}
+EOR
+ end
+ assert_dc_parse(@atom_feed_source, @atom_feed_parents, false,
+ &atom_feed_maker)
+ assert_dc_parse(@atom_feed_source, @atom_feed_parents, true,
+ &atom_feed_maker)
+
+ atom_entry_maker = Proc.new do |content, xmlns|
+ make_entry_document(<<-EOR, xmlns)
+#{content}
+EOR
+ end
+ assert_dc_parse(@atom_entry_source, @atom_entry_parents, false,
+ &atom_entry_maker)
+ assert_dc_parse(@atom_entry_source, @atom_entry_parents, true,
+ &atom_entry_maker)
+ end
+
+ def test_singular_accessor
+ assert_dc_singular_accessor(@rss10_source, @rss10_parents)
+ assert_dc_singular_accessor(@rss20_source, @rss20_parents)
+ assert_dc_singular_accessor(@atom_feed_source, @atom_feed_parents)
+ assert_dc_singular_accessor(@atom_entry_source, @atom_entry_parents)
+ end
+
+ def test_plural_accessor
+ assert_dc_plural_accessor(@rss10_source, @rss10_parents, false)
+ assert_dc_plural_accessor(@rss10_source, @rss10_parents, true)
+
+ assert_dc_plural_accessor(@rss20_source, @rss20_parents, false)
+ assert_dc_plural_accessor(@rss20_source, @rss20_parents, true)
+
+ assert_dc_plural_accessor(@atom_feed_source, @atom_feed_parents, false)
+ assert_dc_plural_accessor(@atom_feed_source, @atom_feed_parents, true)
+
+ assert_dc_plural_accessor(@atom_entry_source, @atom_entry_parents, false)
+ assert_dc_plural_accessor(@atom_entry_source, @atom_entry_parents, true)
+ end
+
+ def test_to_s
+ assert_dc_to_s(@rss10_source, @rss10_parents, false)
+ assert_dc_to_s(@rss10_source, @rss10_parents, true)
+
+ targets = ["channel", "channel/item[3]"]
+ assert_dc_to_s(@rss20_source, @rss20_parents, false, targets)
+ assert_dc_to_s(@rss20_source, @rss20_parents, true, targets)
+
+ targets = [".", "entry"]
+ assert_dc_to_s(@atom_feed_source, @atom_feed_parents, false, targets)
+ assert_dc_to_s(@atom_feed_source, @atom_feed_parents, true, targets)
+
+ targets = ["."]
+ assert_dc_to_s(@atom_entry_source, @atom_entry_parents, false, targets)
+ assert_dc_to_s(@atom_entry_source, @atom_entry_parents, true, targets)
+ end
+
+ private
+ def dc_plural_suffix(name, check_backward_compatibility)
+ if name == :rights
+ if check_backward_compatibility
+ "es"
+ else
+ "_list"
+ end
+ else
+ "s"
+ end
+ end
+
+ def assert_dc_parse(source, parents, check_backward_compatibility, &maker)
+ assert_nothing_raised do
+ Parser.parse(source)
+ end
+
+ DC_ELEMENTS.each do |name, value|
+ parents.each do |parent_readers|
+ feed = nil
+ assert_nothing_raised do
+ tag = "#{DC_PREFIX}:#{name}"
+ dc_content = "<#{tag}>#{value}</#{tag}>\n"
+ dc_content *= 2
+ feed = Parser.parse(maker.call(dc_content, {DC_PREFIX => DC_URI}))
+ end
+ parent = chain_reader(feed, parent_readers)
+
+ plural_suffix = dc_plural_suffix(name, check_backward_compatibility)
+ plural_reader = "dc_#{name}#{plural_suffix}"
+ values = parent.__send__(plural_reader).collect(&:value)
+ value = CGI.unescapeHTML(value) if value.kind_of?(String)
+ assert_equal([value, value], values)
+ end
+ end
+ end
+
+ def assert_dc_singular_accessor(source, parents)
+ feed = Parser.parse(source)
+ new_value = "hoge"
+
+ parents.each do |parent_readers|
+ parent = chain_reader(feed, parent_readers)
+ DC_ELEMENTS.each do |name, value|
+ parsed_value = parent.__send__("dc_#{name}")
+ value = CGI.unescapeHTML(value) if value.kind_of?(String)
+ assert_equal(value, parsed_value)
+ if name == :date
+ t = Time.iso8601("2003-01-01T02:30:23+09:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+ parent.__send__("dc_#{name}=", t.iso8601)
+ assert_equal(t, parent.__send__("dc_#{name}"))
+ if parent.class.method_defined?(:date_without_dc_date=)
+ assert_nil(parent.date)
+ else
+ assert_equal(t, parent.date)
+ end
+
+ parent.date = value
+ assert_equal(value, parent.date)
+ assert_equal(value, parent.__send__("dc_#{name}"))
+ else
+ parent.__send__("dc_#{name}=", new_value)
+ assert_equal(new_value, parent.__send__("dc_#{name}"))
+ end
+ end
+ end
+ end
+
+ def assert_dc_plural_accessor(source, parents, check_backward_compatibility)
+ feed = Parser.parse(source)
+ new_value = "hoge"
+
+ DC_ELEMENTS.each do |name, value|
+ parents.each do |parent_readers|
+ parent = chain_reader(feed, parent_readers)
+ parsed_value = parent.__send__("dc_#{name}")
+ value = CGI.unescapeHTML(value) if value.kind_of?(String)
+ assert_equal(value, parsed_value)
+
+ plural_suffix = dc_plural_suffix(name, check_backward_compatibility)
+ plural_reader = "dc_#{name}#{plural_suffix}"
+ klass_name = "DublinCore#{Utils.to_class_name(name.to_s)}"
+ klass = DublinCoreModel.const_get(klass_name)
+ if name == :date
+ t = Time.iso8601("2003-01-01T02:30:23+09:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+ elems = parent.__send__(plural_reader)
+ elems << klass.new(t.iso8601)
+ new_elems = parent.__send__(plural_reader)
+ values = new_elems.collect{|x| x.value}
+ assert_equal([parent.__send__("dc_#{name}"), t], values)
+ else
+ elems = parent.__send__(plural_reader)
+ elems << klass.new(new_value)
+ new_elems = parent.__send__(plural_reader)
+ values = new_elems.collect{|x| x.value}
+ assert_equal([parent.__send__("dc_#{name}"), new_value],
+ values)
+ end
+ end
+ end
+ end
+
+ def assert_dc_to_s(source, parents, check_backward_compatibility,
+ targets=nil)
+ feed = Parser.parse(source)
+
+ DC_ELEMENTS.each do |name, value|
+ excepted = "<#{DC_PREFIX}:#{name}>#{value}</#{DC_PREFIX}:#{name}>"
+ parents.each do |parent_readers|
+ parent = chain_reader(feed, parent_readers)
+ assert_equal(excepted, parent.__send__("dc_#{name}_elements"))
+ end
+
+ plural_suffix = dc_plural_suffix(name, check_backward_compatibility)
+ reader = "dc_#{name}#{plural_suffix}"
+ excepted = Array.new(2, excepted).join("\n")
+ parents.each do |parent_readers|
+ parent = chain_reader(feed, parent_readers)
+ elems = parent.__send__(reader)
+ klass_name = "DublinCore#{Utils.to_class_name(name.to_s)}"
+ klass = DublinCoreModel.const_get(klass_name)
+ elems << klass.new(parent.__send__("dc_#{name}"))
+ assert_equal(excepted, parent.__send__("dc_#{name}_elements"))
+ end
+ end
+
+ targets ||= parents.collect do |parent_readers|
+ parent_readers.first
+ end
+ feed_root = REXML::Document.new(source).root
+ targets.each do |target_xpath|
+ parent = feed_root.elements[target_xpath]
+ parent.each_element do |elem|
+ if elem.namespace == DC_URI
+ assert_equal(elem.text,
+ CGI.unescapeHTML(DC_ELEMENTS[elem.name.intern].to_s))
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_image.rb b/jni/ruby/test/rss/test_image.rb
new file mode 100644
index 0000000..d8f0b26
--- /dev/null
+++ b/jni/ruby/test/rss/test_image.rb
@@ -0,0 +1,214 @@
+require "cgi"
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/1.0"
+require "rss/image"
+
+module RSS
+ class TestImage < TestCase
+
+ def setup
+ @prefix = "image"
+ @uri = "http://purl.org/rss/1.0/modules/image/"
+
+ @favicon_attrs = {
+ "rdf:about" => "http://www.kuro5hin.org/favicon.ico",
+ "#{@prefix}:size" => "small",
+ }
+ @favicon_contents = {"dc:title" => "Kuro5hin",}
+ @items = [
+ [
+ {
+ "rdf:about" => "http://www.example.org/item.png",
+ "rdf:resource" => "http://www.example.org/item",
+ },
+ {
+ "dc:title" => "Example Image",
+ "#{@prefix}:width" => "100",
+ "#{@prefix}:height" => "65",
+ },
+ ],
+ [
+ {
+ "rdf:about" => "http://www.kuro5hin.org/images/topics/culture.jpg",
+ },
+ {
+ "dc:title" => "Culture",
+ "#{@prefix}:width" => "80",
+ "#{@prefix}:height" => "50",
+ },
+ ]
+ ]
+
+
+ @channel_nodes = make_element("#{@prefix}:favicon",
+ @favicon_attrs,
+ @favicon_contents)
+ items = ""
+ @items.each do |attrs, contents|
+ image_item = make_element("#{@prefix}:item", attrs, contents)
+ items << make_item(image_item)
+ end
+
+ @ns = {
+ @prefix => @uri,
+ DC_PREFIX => DC_URI,
+ }
+ @rss_source = make_RDF(<<-EOR, @ns)
+#{make_channel(@channel_nodes)}
+#{make_image}
+#{items}
+#{make_textinput}
+EOR
+
+ @rss = Parser.parse(@rss_source)
+ end
+
+ def test_parser
+ assert_nothing_raised do
+ Parser.parse(@rss_source)
+ end
+
+ assert_too_much_tag("favicon", "channel") do
+ Parser.parse(make_RDF(<<-EOR, @ns))
+#{make_channel(@channel_nodes * 2)}
+#{make_item}
+EOR
+ end
+
+ attrs = {"rdf:about" => "http://www.example.org/item.png"}
+ contents = [["#{@prefix}:width", "80"]] * 5
+ image_item = make_element("#{@prefix}:item", attrs, contents)
+ assert_too_much_tag("width", "item") do
+ Parser.parse(make_RDF(<<-EOR, @ns))
+#{make_channel}
+#{make_item(image_item)}
+EOR
+ end
+ end
+
+ def test_favicon_accessor
+ favicon = @rss.channel.image_favicon
+ [
+ %w(about rdf:about http://example.com/favicon.ico),
+ %w(size image:size large),
+ %w(image_size image:size medium),
+ ].each do |name, full_name, new_value|
+ assert_equal(@favicon_attrs[full_name], favicon.__send__(name))
+ favicon.__send__("#{name}=", new_value)
+ assert_equal(new_value, favicon.__send__(name))
+ favicon.__send__("#{name}=", @favicon_attrs[full_name])
+ assert_equal(@favicon_attrs[full_name], favicon.__send__(name))
+ end
+
+ %w(small medium large).each do |value|
+ assert_nothing_raised do
+ favicon.size = value
+ favicon.image_size = value
+ end
+ end
+
+ %w(aaa AAA SMALL MEDIUM LARGE).each do |value|
+ args = ["#{@prefix}:favicon", value, "#{@prefix}:size"]
+ assert_not_available_value(*args) do
+ favicon.size = value
+ end
+ assert_not_available_value(*args) do
+ favicon.image_size = value
+ end
+ end
+
+ [
+ %w(dc_title dc:title sample-favicon),
+ ].each do |name, full_name, new_value|
+ assert_equal(@favicon_contents[full_name], favicon.__send__(name))
+ favicon.__send__("#{name}=", new_value)
+ assert_equal(new_value, favicon.__send__(name))
+ favicon.__send__("#{name}=", @favicon_contents[full_name])
+ assert_equal(@favicon_contents[full_name], favicon.__send__(name))
+ end
+ end
+
+ def test_item_accessor
+ @rss.items.each_with_index do |item, i|
+ image_item = item.image_item
+ attrs, contents = @items[i]
+ [
+ %w(about rdf:about http://example.com/image.png),
+ %w(resource rdf:resource http://example.com/),
+ ].each do |name, full_name, new_value|
+ assert_equal(attrs[full_name], image_item.__send__(name))
+ image_item.__send__("#{name}=", new_value)
+ assert_equal(new_value, image_item.__send__(name))
+ image_item.__send__("#{name}=", attrs[full_name])
+ assert_equal(attrs[full_name], image_item.__send__(name))
+ end
+
+ [
+ ["width", "image:width", "111"],
+ ["image_width", "image:width", "44"],
+ ["height", "image:height", "222"],
+ ["image_height", "image:height", "88"],
+ ].each do |name, full_name, new_value|
+ assert_equal(contents[full_name].to_i, image_item.__send__(name))
+ image_item.__send__("#{name}=", new_value)
+ assert_equal(new_value.to_i, image_item.__send__(name))
+ image_item.__send__("#{name}=", contents[full_name])
+ assert_equal(contents[full_name].to_i, image_item.__send__(name))
+ end
+
+ [
+ ["dc_title", "dc:title", "sample-image"],
+ ].each do |name, full_name, new_value|
+ assert_equal(contents[full_name], image_item.__send__(name))
+ image_item.__send__("#{name}=", new_value)
+ assert_equal(new_value, image_item.__send__(name))
+ image_item.__send__("#{name}=", contents[full_name])
+ assert_equal(contents[full_name], image_item.__send__(name))
+ end
+ end
+ end
+
+ def test_favicon_to_s
+ favicon = @rss.channel.image_favicon
+ expected_xml = image_xmlns_container(make_element("#{@prefix}:favicon",
+ @favicon_attrs,
+ @favicon_contents))
+ expected = REXML::Document.new(expected_xml)
+ actual_xml = image_xmlns_container(favicon.to_s(false, ""))
+ actual = REXML::Document.new(actual_xml)
+ assert_equal(expected.to_s, actual.to_s)
+ end
+
+ def test_item_to_s
+ @rss.items.each_with_index do |item, i|
+ attrs, contents = @items[i]
+ expected_xml = make_element("#{@prefix}:item", attrs, contents)
+ expected_xml = image_xmlns_container(expected_xml)
+ expected = REXML::Document.new(expected_xml)
+ actual_xml = image_xmlns_container(item.image_item.to_s(false, ""))
+ actual = REXML::Document.new(actual_xml)
+
+ assert_equal(expected[0].attributes, actual[0].attributes)
+
+ %w(image:height image:width dc:title).each do |name|
+ actual_target = actual.elements["//#{name}"]
+ expected_target = expected.elements["//#{name}"]
+ assert_equal(expected_target.to_s, actual_target.to_s)
+ end
+ end
+ end
+
+ private
+ def image_xmlns_container(content)
+ xmlns_container({
+ @prefix => @uri,
+ "dc" => "http://purl.org/dc/elements/1.1/",
+ "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ },
+ content)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_inherit.rb b/jni/ruby/test/rss/test_inherit.rb
new file mode 100644
index 0000000..8b640dc
--- /dev/null
+++ b/jni/ruby/test/rss/test_inherit.rb
@@ -0,0 +1,40 @@
+require_relative "rss-testcase"
+
+require "rss/1.0"
+
+module RSS
+ class TestInherit < TestCase
+
+ class InheritedImage < RSS::RDF::Image
+ def self.indent_size; 1; end
+ def self.tag_name; 'image'; end
+ end
+
+ def setup
+ @rss = make_RDF(<<-EOR)
+#{make_channel}
+#{make_image}
+#{make_item}
+#{make_textinput}
+EOR
+ end
+
+ def test_inherit
+ rss = RSS::Parser.parse(@rss)
+ orig_image = rss.image
+ prefix = "[INHERIT]"
+ image = InheritedImage.new("#{prefix} #{orig_image.about}")
+ image.title = "#{prefix} #{orig_image.title}"
+ image.url = "#{prefix} #{orig_image.url}"
+ image.link = "#{prefix} #{orig_image.link}"
+ rss.image = image
+
+ new_rss = RSS::Parser.parse(rss.to_s)
+ new_image = new_rss.image
+ assert_equal("#{prefix} #{orig_image.about}", new_image.about)
+ assert_equal("#{prefix} #{orig_image.title}", new_image.title)
+ assert_equal("#{prefix} #{orig_image.url}", new_image.url)
+ assert_equal("#{prefix} #{orig_image.link}", new_image.link)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_itunes.rb b/jni/ruby/test/rss/test_itunes.rb
new file mode 100644
index 0000000..ec06337
--- /dev/null
+++ b/jni/ruby/test/rss/test_itunes.rb
@@ -0,0 +1,347 @@
+require "cgi"
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/2.0"
+require "rss/itunes"
+
+module RSS
+ class TestITunes < TestCase
+ def test_author
+ assert_itunes_author(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+
+ assert_itunes_author(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_block
+ assert_itunes_block(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_category
+ assert_itunes_category(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+ end
+
+ def test_image
+ assert_itunes_image(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+ end
+
+ def test_duration
+ assert_itunes_duration(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_explicit
+ assert_itunes_explicit(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+
+ assert_itunes_explicit(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_keywords
+ assert_itunes_keywords(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+
+ assert_itunes_keywords(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_new_feed_url
+ assert_itunes_new_feed_url(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+ end
+
+ def test_owner
+ assert_itunes_owner(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+ end
+
+ def test_subtitle
+ assert_itunes_subtitle(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+
+ assert_itunes_subtitle(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_summary
+ assert_itunes_summary(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+
+ assert_itunes_summary(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ private
+ def itunes_rss20_parse(content, &maker)
+ xmlns = {"itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd"}
+ rss20_xml = maker.call(content, xmlns)
+ ::RSS::Parser.parse(rss20_xml)
+ end
+
+ def assert_itunes_author(readers, &rss20_maker)
+ _wrap_assertion do
+ author = "John Lennon"
+ rss20 = itunes_rss20_parse(tag("itunes:author", author), &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(author, target.itunes_author)
+ end
+ end
+
+ def _assert_itunes_block(value, boolean_value, readers, &rss20_maker)
+ rss20 = itunes_rss20_parse(tag("itunes:block", value), &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(value, target.itunes_block)
+ assert_equal(boolean_value, target.itunes_block?)
+ end
+
+ def assert_itunes_block(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_block("yes", true, readers, &rss20_maker)
+ _assert_itunes_block("Yes", true, readers, &rss20_maker)
+ _assert_itunes_block("no", false, readers, &rss20_maker)
+ _assert_itunes_block("", false, readers, &rss20_maker)
+ end
+ end
+
+ def _assert_itunes_category(categories, readers, &rss20_maker)
+ cats = categories.collect do |category|
+ if category.is_a?(Array)
+ category, sub_category = category
+ tag("itunes:category",
+ tag("itunes:category", nil, {"text" => sub_category}),
+ {"text" => category})
+ else
+ tag("itunes:category", nil, {"text" => category})
+ end
+ end.join
+ rss20 = itunes_rss20_parse(cats, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ actual_categories = target.itunes_categories.collect do |category|
+ cat = category.text
+ if category.itunes_categories.empty?
+ cat
+ else
+ [cat, *category.itunes_categories.collect {|c| c.text}]
+ end
+ end
+ assert_equal(categories, actual_categories)
+ end
+
+ def assert_itunes_category(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_category(["Audio Blogs"], readers, &rss20_maker)
+ _assert_itunes_category([["Arts & Entertainment", "Games"]],
+ readers, &rss20_maker)
+ _assert_itunes_category([["Arts & Entertainment", "Games"],
+ ["Technology", "Computers"],
+ "Audio Blogs"],
+ readers, &rss20_maker)
+ end
+ end
+
+ def assert_itunes_image(readers, &rss20_maker)
+ _wrap_assertion do
+ url = "http://example.com/podcasts/everything/AllAboutEverything.jpg"
+ content = tag("itunes:image", nil, {"href" => url})
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_not_nil(target.itunes_image)
+ assert_equal(url, target.itunes_image.href)
+
+ assert_missing_attribute("image", "href") do
+ content = tag("itunes:image")
+ itunes_rss20_parse(content, &rss20_maker)
+ end
+ end
+ end
+
+ def _assert_itunes_duration(hour, minute, second, value,
+ readers, &rss20_maker)
+ content = tag("itunes:duration", value)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ duration = chain_reader(rss20, readers).itunes_duration
+ assert_equal(value, duration.content)
+ assert_equal(hour, duration.hour)
+ assert_equal(minute, duration.minute)
+ assert_equal(second, duration.second)
+ end
+
+ def _assert_itunes_duration_not_available_value(value, &rss20_maker)
+ assert_not_available_value("duration", value) do
+ content = tag("itunes:duration", value)
+ itunes_rss20_parse(content, &rss20_maker)
+ end
+ end
+
+ def assert_itunes_duration(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_duration(7, 14, 5, "07:14:05", readers, &rss20_maker)
+ _assert_itunes_duration(7, 14, 5, "7:14:05", readers, &rss20_maker)
+ _assert_itunes_duration(0, 4, 55, "04:55", readers, &rss20_maker)
+ _assert_itunes_duration(0, 4, 5, "4:05", readers, &rss20_maker)
+
+ _assert_itunes_duration_not_available_value("5", &rss20_maker)
+ _assert_itunes_duration_not_available_value("09:07:14:05", &rss20_maker)
+ _assert_itunes_duration_not_available_value("10:5", &rss20_maker)
+ _assert_itunes_duration_not_available_value("10:03:5", &rss20_maker)
+ _assert_itunes_duration_not_available_value("10:3:05", &rss20_maker)
+
+ _assert_itunes_duration_not_available_value("xx:xx:xx", &rss20_maker)
+ end
+ end
+
+ def _assert_itunes_explicit(explicit, value, readers, &rss20_maker)
+ content = tag("itunes:explicit", value)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(value, target.itunes_explicit)
+ assert_equal(explicit, target.itunes_explicit?)
+ end
+
+ def assert_itunes_explicit(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_explicit(true, "yes", readers, &rss20_maker)
+ _assert_itunes_explicit(false, "clean", readers, &rss20_maker)
+ _assert_itunes_explicit(nil, "no", readers, &rss20_maker)
+ end
+ end
+
+ def _assert_itunes_keywords(keywords, value, readers, &rss20_maker)
+ content = tag("itunes:keywords", value)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(keywords, target.itunes_keywords)
+ end
+
+ def assert_itunes_keywords(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_keywords(["salt"], "salt", readers, &rss20_maker)
+ _assert_itunes_keywords(["salt"], " salt ", readers, &rss20_maker)
+ _assert_itunes_keywords(["salt", "pepper", "shaker", "exciting"],
+ "salt, pepper, shaker, exciting",
+ readers, &rss20_maker)
+ _assert_itunes_keywords(["metric", "socket", "wrenches", "toolsalt"],
+ "metric, socket, wrenches, toolsalt",
+ readers, &rss20_maker)
+ _assert_itunes_keywords(["olitics", "red", "blue", "state"],
+ "olitics, red, blue, state",
+ readers, &rss20_maker)
+ end
+ end
+
+ def assert_itunes_new_feed_url(readers, &rss20_maker)
+ _wrap_assertion do
+ url = "http://newlocation.com/example.rss"
+ content = tag("itunes:new-feed-url", url)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(url, target.itunes_new_feed_url)
+ end
+ end
+
+ def _assert_itunes_owner(name, email, readers, &rss20_maker)
+ content = tag("itunes:owner",
+ tag("itunes:name", name) + tag("itunes:email", email))
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ owner = chain_reader(rss20, readers).itunes_owner
+ assert_equal(name, owner.itunes_name)
+ assert_equal(email, owner.itunes_email)
+ end
+
+ def assert_itunes_owner(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_owner("John Doe", "john.doe@example.com",
+ readers, &rss20_maker)
+
+ assert_missing_tag("name", "owner") do
+ content = tag("itunes:owner")
+ itunes_rss20_parse(content, &rss20_maker)
+ end
+
+ assert_missing_tag("name", "owner") do
+ content = tag("itunes:owner",
+ tag("itunes:email", "john.doe@example.com"))
+ itunes_rss20_parse(content, &rss20_maker)
+ end
+
+ assert_missing_tag("email", "owner") do
+ content = tag("itunes:owner", tag("itunes:name", "John Doe"))
+ itunes_rss20_parse(content, &rss20_maker)
+ end
+ end
+ end
+
+ def _assert_itunes_subtitle(value, readers, &rss20_maker)
+ content = tag("itunes:subtitle", value)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(value, target.itunes_subtitle)
+ end
+
+ def assert_itunes_subtitle(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_subtitle("A show about everything", readers, &rss20_maker)
+ _assert_itunes_subtitle("A short primer on table spices",
+ readers, &rss20_maker)
+ _assert_itunes_subtitle("Comparing socket wrenches is fun!",
+ readers, &rss20_maker)
+ _assert_itunes_subtitle("Red + Blue != Purple", readers, &rss20_maker)
+ end
+ end
+
+ def _assert_itunes_summary(value, readers, &rss20_maker)
+ content = tag("itunes:summary", value)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(value, target.itunes_summary)
+ end
+
+ def assert_itunes_summary(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_summary("All About Everything is a show about " +
+ "everything. Each week we dive into any " +
+ "subject known to man and talk about it as " +
+ "much as we can. Look for our Podcast in " +
+ "the iTunes Music Store",
+ readers, &rss20_maker)
+ _assert_itunes_summary("This week we talk about salt and pepper " +
+ "shakers, comparing and contrasting pour " +
+ "rates, construction materials, and overall " +
+ "aesthetics. Come and join the party!",
+ readers, &rss20_maker)
+ _assert_itunes_summary("This week we talk about metric vs. old " +
+ "english socket wrenches. Which one is " +
+ "better? Do you really need both? Get all " +
+ "of your answers here.",
+ readers, &rss20_maker)
+ _assert_itunes_summary("This week we talk about surviving in a " +
+ "Red state if you're a Blue person. Or " +
+ "vice versa.",
+ readers, &rss20_maker)
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_0.9.rb b/jni/ruby/test/rss/test_maker_0.9.rb
new file mode 100644
index 0000000..f6e39c6
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_0.9.rb
@@ -0,0 +1,474 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMaker09 < TestCase
+ def test_supported?
+ assert(RSS::Maker.supported?("0.9"))
+ assert(RSS::Maker.supported?("rss0.9"))
+ assert(RSS::Maker.supported?("0.91"))
+ assert(RSS::Maker.supported?("rss0.91"))
+ assert(RSS::Maker.supported?("0.92"))
+ assert(RSS::Maker.supported?("rss0.92"))
+ assert(!RSS::Maker.supported?("0.93"))
+ assert(!RSS::Maker.supported?("rss0.93"))
+ end
+
+ def test_find_class
+ assert_equal(RSS::Maker::RSS091, RSS::Maker["0.91"])
+ assert_equal(RSS::Maker::RSS091, RSS::Maker["rss0.91"])
+ assert_equal(RSS::Maker::RSS092, RSS::Maker["0.9"])
+ assert_equal(RSS::Maker::RSS092, RSS::Maker["0.92"])
+ assert_equal(RSS::Maker::RSS092, RSS::Maker["rss0.92"])
+ end
+
+ def test_rss
+ assert_raise(LocalJumpError) do
+ RSS::Maker.make("0.91")
+ end
+
+ rss = RSS::Maker.make("0.9") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+ end
+ assert_equal("0.92", rss.rss_version)
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+ end
+ assert_equal("0.91", rss.rss_version)
+
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ maker.encoding = "EUC-JP"
+ end
+ assert_equal("0.91", rss.rss_version)
+ assert_equal("EUC-JP", rss.encoding)
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ maker.standalone = "yes"
+ end
+ assert_equal("0.91", rss.rss_version)
+ assert_equal("yes", rss.standalone)
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ maker.encoding = "EUC-JP"
+ maker.standalone = "yes"
+ end
+ assert_equal("0.91", rss.rss_version)
+ assert_equal("EUC-JP", rss.encoding)
+ assert_equal("yes", rss.standalone)
+ end
+
+ def test_channel
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+ language = "ja"
+ copyright = "foo"
+ managingEditor = "bar"
+ webMaster = "web master"
+ rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
+ docs = "http://foo.com/doc"
+ skipDays = [
+ "Sunday",
+ "Monday",
+ ]
+ skipHours = [
+ "0",
+ "13",
+ ]
+ pubDate = Time.now
+ lastBuildDate = Time.now
+
+ image_url = "http://example.com/logo.png"
+ image_title = "Logo"
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ maker.channel.language = language
+ maker.channel.copyright = copyright
+ maker.channel.managingEditor = managingEditor
+ maker.channel.webMaster = webMaster
+ maker.channel.rating = rating
+ maker.channel.docs = docs
+ maker.channel.pubDate = pubDate
+ maker.channel.lastBuildDate = lastBuildDate
+
+ skipDays.each do |day|
+ maker.channel.skipDays.new_day do |new_day|
+ new_day.content = day
+ end
+ end
+ skipHours.each do |hour|
+ maker.channel.skipHours.new_hour do |new_hour|
+ new_hour.content = hour
+ end
+ end
+
+ maker.image.url = image_url
+ maker.image.title = image_title
+ end
+ channel = rss.channel
+
+ assert_equal(title, channel.title)
+ assert_equal(link, channel.link)
+ assert_equal(description, channel.description)
+ assert_equal(language, channel.language)
+ assert_equal(copyright, channel.copyright)
+ assert_equal(managingEditor, channel.managingEditor)
+ assert_equal(webMaster, channel.webMaster)
+ assert_equal(rating, channel.rating)
+ assert_equal(docs, channel.docs)
+ assert_equal(pubDate, channel.pubDate)
+ assert_equal(pubDate, channel.date)
+ assert_equal(lastBuildDate, channel.lastBuildDate)
+
+ skipDays.each_with_index do |day, i|
+ assert_equal(day, channel.skipDays.days[i].content)
+ end
+ skipHours.each_with_index do |hour, i|
+ assert_equal(hour.to_i, channel.skipHours.hours[i].content)
+ end
+
+ assert(channel.items.empty?)
+
+ assert_equal(image_url, channel.image.url)
+ assert_equal(image_title, channel.image.title)
+ assert_equal(link, channel.image.link)
+
+ assert_nil(channel.textInput)
+ end
+
+ def test_not_valid_channel
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+ language = "ja"
+
+ assert_not_set_error("maker.channel", %w(title)) do
+ RSS::Maker.make("0.91") do |maker|
+ # maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ maker.channel.language = language
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(link)) do
+ RSS::Maker.make("0.91") do |maker|
+ maker.channel.title = title
+ # maker.channel.link = link
+ maker.channel.link = nil
+ maker.channel.description = description
+ maker.channel.language = language
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(description)) do
+ RSS::Maker.make("0.91") do |maker|
+ maker.channel.title = title
+ maker.channel.link = link
+ # maker.channel.description = description
+ maker.channel.language = language
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(language)) do
+ RSS::Maker.make("0.91") do |maker|
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ # maker.channel.language = language
+ end
+ end
+ end
+
+ def test_image
+ title = "fugafuga"
+ link = "http://hoge.com"
+ url = "http://hoge.com/hoge.png"
+ width = "144"
+ height = "400"
+ description = "an image"
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+ image = rss.image
+ assert_equal(title, image.title)
+ assert_equal(link, image.link)
+ assert_equal(url, image.url)
+ assert_equal(width.to_i, image.width)
+ assert_equal(height.to_i, image.height)
+ assert_equal(description, image.description)
+
+ assert_not_set_error("maker.channel", %w(description title language)) do
+ RSS::Maker.make("0.91") do |maker|
+ # setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+ end
+ end
+
+ def test_not_valid_image
+ title = "fugafuga"
+ link = "http://hoge.com"
+ url = "http://hoge.com/hoge.png"
+ width = "144"
+ height = "400"
+ description = "an image"
+
+ assert_not_set_error("maker.image", %w(title)) do
+ RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ # maker.image.title = title
+ maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(link)) do
+ RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ # maker.channel.link = link
+ maker.channel.link = nil
+
+ maker.image.title = title
+ maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+ end
+
+ assert_not_set_error("maker.image", %w(url)) do
+ RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ # maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+ end
+ end
+
+ def test_items(with_convenience_way=true)
+ title = "TITLE"
+ link = "http://hoge.com/"
+ description = "text hoge fuga"
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+ end
+ assert(rss.channel.items.empty?)
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.items.new_item do |item|
+ item.title = title
+ item.link = link
+ # item.description = description
+ end
+
+ setup_dummy_image(maker)
+ end
+ assert_equal(1, rss.channel.items.size)
+ item = rss.channel.items.first
+ assert_equal(title, item.title)
+ assert_equal(link, item.link)
+ assert_nil(item.description)
+
+
+ item_size = 5
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
+ end
+ end
+ maker.items.do_sort = true
+
+ setup_dummy_image(maker)
+ end
+ assert_equal(item_size, rss.items.size)
+ rss.channel.items.each_with_index do |_item, i|
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
+ end
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
+ end
+ end
+ maker.items.do_sort = Proc.new do |x, y|
+ if with_convenience_way
+ y.title[-1] <=> x.title[-1]
+ else
+ y.title {|t| t.content[-1]} <=> x.title {|t| t.content[-1]}
+ end
+ end
+
+ setup_dummy_image(maker)
+ end
+ assert_equal(item_size, rss.items.size)
+ rss.channel.items.reverse.each_with_index do |_item, i|
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
+ end
+ end
+
+ def test_items_with_new_api_since_018
+ test_items(false)
+ end
+
+ def test_textInput
+ title = "fugafuga"
+ description = "text hoge fuga"
+ name = "hoge"
+ link = "http://hoge.com"
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+ textInput = rss.channel.textInput
+ assert_equal(title, textInput.title)
+ assert_equal(description, textInput.description)
+ assert_equal(name, textInput.name)
+ assert_equal(link, textInput.link)
+
+ assert_not_set_error("maker.channel",
+ %w(link language description title)) do
+ RSS::Maker.make("0.91") do |maker|
+ # setup_dummy_channel(maker)
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+ end
+ end
+
+ def test_not_valid_textInput
+ title = "fugafuga"
+ description = "text hoge fuga"
+ name = "hoge"
+ link = "http://hoge.com"
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ # maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+ assert_nil(rss.channel.textInput)
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ maker.textinput.title = title
+ # maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+ assert_nil(rss.channel.textInput)
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ # maker.textinput.name = name
+ maker.textinput.link = link
+ end
+ assert_nil(rss.channel.textInput)
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ # maker.textinput.link = link
+ end
+ assert_nil(rss.channel.textInput)
+ end
+
+ def test_date_in_string
+ date = Time.now
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ maker.items.new_item do |item|
+ item.title = "The first item"
+ item.link = "http://example.com/blog/1.html"
+ item.date = date.rfc822
+ end
+ end
+
+ assert_equal(date.iso8601, rss.items[0].date.iso8601)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_1.0.rb b/jni/ruby/test/rss/test_maker_1.0.rb
new file mode 100644
index 0000000..b31abb9
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_1.0.rb
@@ -0,0 +1,516 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMaker10 < TestCase
+ def test_supported?
+ assert(RSS::Maker.supported?("1.0"))
+ assert(RSS::Maker.supported?("rss1.0"))
+ assert(!RSS::Maker.supported?("1.1"))
+ assert(!RSS::Maker.supported?("rss1.1"))
+ end
+
+ def test_find_class
+ assert_equal(RSS::Maker::RSS10, RSS::Maker["1.0"])
+ assert_equal(RSS::Maker::RSS10, RSS::Maker["rss1.0"])
+ end
+
+ def test_rdf
+ assert_raise(LocalJumpError) do
+ RSS::Maker.make("1.0")
+ end
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+ end
+ assert_equal("1.0", rss.rss_version)
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.encoding = "EUC-JP"
+
+ setup_dummy_item(maker)
+ end
+ assert_equal("1.0", rss.rss_version)
+ assert_equal("EUC-JP", rss.encoding)
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.standalone = "yes"
+
+ setup_dummy_item(maker)
+ end
+ assert_equal("1.0", rss.rss_version)
+ assert_equal("yes", rss.standalone)
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.encoding = "EUC-JP"
+ maker.standalone = "yes"
+
+ setup_dummy_item(maker)
+ end
+ assert_equal("1.0", rss.rss_version)
+ assert_equal("EUC-JP", rss.encoding)
+ assert_equal("yes", rss.standalone)
+ end
+
+ def test_channel
+ about = "http://hoge.com"
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ maker.channel.about = about
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+
+ setup_dummy_item(maker)
+ end
+ channel = rss.channel
+ assert_equal(about, channel.about)
+ assert_equal(title, channel.title)
+ assert_equal(link, channel.link)
+ assert_equal(description, channel.description)
+ assert_equal(1, channel.items.Seq.lis.size)
+ assert_nil(channel.image)
+ assert_nil(channel.textinput)
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ maker.channel.about = about
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+
+ setup_dummy_image(maker)
+
+ setup_dummy_textinput(maker)
+
+ setup_dummy_item(maker)
+ end
+ channel = rss.channel
+ assert_equal(about, channel.about)
+ assert_equal(title, channel.title)
+ assert_equal(link, channel.link)
+ assert_equal(description, channel.description)
+ assert_equal(1, channel.items.Seq.lis.size)
+ assert_equal(rss.image.about, channel.image.resource)
+ assert_equal(rss.textinput.about, channel.textinput.resource)
+ end
+
+ def test_channel_language
+ about = "http://hoge.com"
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+ language = "ja"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ maker.channel.about = about
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ maker.channel.language = language
+
+ setup_dummy_item(maker)
+ end
+ channel = rss.channel
+ assert_equal(language, channel.dc_language)
+ end
+
+ def test_not_valid_channel
+ about = "http://hoge.com"
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+
+ assert_not_set_error("maker.channel", %w(about)) do
+ RSS::Maker.make("1.0") do |maker|
+ # maker.channel.about = about
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(title)) do
+ RSS::Maker.make("1.0") do |maker|
+ maker.channel.about = about
+ # maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(link)) do
+ RSS::Maker.make("1.0") do |maker|
+ maker.channel.about = about
+ maker.channel.title = title
+ # maker.channel.link = link
+ maker.channel.description = description
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(description)) do
+ RSS::Maker.make("1.0") do |maker|
+ maker.channel.about = about
+ maker.channel.title = title
+ maker.channel.link = link
+ # maker.channel.description = description
+ end
+ end
+ end
+
+
+ def test_image
+ title = "fugafuga"
+ link = "http://hoge.com"
+ url = "http://hoge.com/hoge.png"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ maker.image.url = url
+
+ setup_dummy_item(maker)
+ end
+ image = rss.image
+ assert_equal(url, image.about)
+ assert_equal(url, rss.channel.image.resource)
+ assert_equal(title, image.title)
+ assert_equal(link, image.link)
+ assert_equal(url, image.url)
+
+ assert_not_set_error("maker.channel", %w(about title description)) do
+ RSS::Maker.make("1.0") do |maker|
+ # setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ maker.image.url = url
+ end
+ end
+ end
+
+ def test_not_valid_image
+ title = "fugafuga"
+ link = "http://hoge.com"
+ url = "http://hoge.com/hoge.png"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ # maker.image.url = url
+ maker.image.title = title
+
+ setup_dummy_item(maker)
+ end
+ assert_nil(rss.channel.image)
+ assert_nil(rss.image)
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.url = url
+ # maker.image.title = title
+
+ setup_dummy_item(maker)
+ end
+ assert_nil(rss.channel.image)
+ assert_nil(rss.image)
+
+ assert_not_set_error("maker.channel", %w(link)) do
+ RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ # maker.channel.link = link
+ maker.channel.link = nil
+
+ maker.image.url = url
+ maker.image.title = title
+
+ setup_dummy_item(maker)
+ end
+ end
+ end
+
+ def test_items(with_convenience_way=true)
+ title = "TITLE"
+ link = "http://hoge.com/"
+ description = "text hoge fuga"
+
+ assert_not_set_error("maker", %w(items)) do
+ RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ end
+ end
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.items.new_item do |item|
+ item.title = title
+ item.link = link
+ # item.description = description
+ end
+ end
+ assert_equal(1, rss.items.size)
+ item = rss.items.first
+ assert_equal(link, item.about)
+ assert_equal(title, item.title)
+ assert_equal(link, item.link)
+ assert_nil(item.description)
+
+
+ item_size = 5
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
+ end
+ end
+ maker.items.do_sort = true
+ end
+ assert_equal(item_size, rss.items.size)
+ rss.items.each_with_index do |_item, i|
+ assert_equal("#{link}#{i}", _item.about)
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
+ end
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
+ end
+ end
+ maker.items.do_sort = Proc.new do |x, y|
+ if with_convenience_way
+ y.title[-1] <=> x.title[-1]
+ else
+ y.title {|t| t.content[-1]} <=> x.title {|t| t.content[-1]}
+ end
+ end
+ end
+ assert_equal(item_size, rss.items.size)
+ rss.items.reverse.each_with_index do |_item, i|
+ assert_equal("#{link}#{i}", _item.about)
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
+ end
+
+ max_size = item_size / 2
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
+ end
+ end
+ maker.items.max_size = max_size
+ end
+ assert_equal(max_size, rss.items.size)
+ rss.items.each_with_index do |_item, i|
+ assert_equal("#{link}#{i}", _item.about)
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
+ end
+
+ max_size = 0
+ assert_not_set_error("maker", %w(items)) do
+ RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
+ end
+ end
+ maker.items.max_size = max_size
+ end
+ end
+
+ max_size = -2
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
+ end
+ end
+ maker.items.max_size = max_size
+ end
+ assert_equal(item_size + max_size + 1, rss.items.size)
+ rss.items.each_with_index do |_item, i|
+ assert_equal("#{link}#{i}", _item.about)
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
+ end
+ end
+
+ def test_items_with_new_api_since_018
+ test_items(false)
+ end
+
+ def test_not_valid_items
+ title = "TITLE"
+ link = "http://hoge.com/"
+
+ assert_not_set_error("maker.item", %w(title)) do
+ RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.items.new_item do |item|
+ # item.title = title
+ item.link = link
+ end
+ end
+ end
+
+ assert_not_set_error("maker.item", %w(link)) do
+ RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.items.new_item do |item|
+ item.title = title
+ # item.link = link
+ end
+ end
+ end
+
+ assert_not_set_error("maker.item", %w(title link)) do
+ RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.items.new_item do |item|
+ # item.title = title
+ # item.link = link
+ end
+ end
+ end
+ end
+
+ def test_textinput
+ title = "fugafuga"
+ description = "text hoge fuga"
+ name = "hoge"
+ link = "http://hoge.com"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.textinput.link = link
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+
+ setup_dummy_item(maker)
+ end
+ textinput = rss.textinput
+ assert_equal(link, textinput.about)
+ assert_equal(link, rss.channel.textinput.resource)
+ assert_equal(title, textinput.title)
+ assert_equal(name, textinput.name)
+ assert_equal(description, textinput.description)
+ assert_equal(link, textinput.link)
+
+ assert_not_set_error("maker.channel", %w(about link description title)) do
+ RSS::Maker.make("1.0") do |maker|
+ # setup_dummy_channel(maker)
+
+ maker.textinput.link = link
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ end
+ end
+ end
+
+ def test_not_valid_textinput
+ title = "fugafuga"
+ description = "text hoge fuga"
+ name = "hoge"
+ link = "http://hoge.com"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ # maker.textinput.link = link
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+
+ setup_dummy_item(maker)
+ end
+ assert_nil(rss.channel.textinput)
+ assert_nil(rss.textinput)
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.textinput.link = link
+ # maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+
+ setup_dummy_item(maker)
+ end
+ assert_nil(rss.channel.textinput)
+ assert_nil(rss.textinput)
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.textinput.link = link
+ maker.textinput.title = title
+ # maker.textinput.description = description
+ maker.textinput.name = name
+
+ setup_dummy_item(maker)
+ end
+ assert_nil(rss.channel.textinput)
+ assert_nil(rss.textinput)
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.textinput.link = link
+ maker.textinput.title = title
+ maker.textinput.description = description
+ # maker.textinput.name = name
+
+ setup_dummy_item(maker)
+ end
+ assert_nil(rss.channel.textinput)
+ assert_nil(rss.textinput)
+ end
+
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_2.0.rb b/jni/ruby/test/rss/test_maker_2.0.rb
new file mode 100644
index 0000000..48c0f91
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_2.0.rb
@@ -0,0 +1,757 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMaker20 < TestCase
+ def test_supported?
+ assert(RSS::Maker.supported?("2.0"))
+ assert(RSS::Maker.supported?("rss2.0"))
+ assert(!RSS::Maker.supported?("2.2"))
+ assert(!RSS::Maker.supported?("rss2.2"))
+ end
+
+ def test_find_class
+ assert_equal(RSS::Maker::RSS20, RSS::Maker["2.0"])
+ assert_equal(RSS::Maker::RSS20, RSS::Maker["rss2.0"])
+ end
+
+ def test_rss
+ assert_raise(LocalJumpError) do
+ RSS::Maker.make("2.0")
+ end
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ end
+ assert_equal("2.0", rss.rss_version)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.encoding = "EUC-JP"
+ end
+ assert_equal("2.0", rss.rss_version)
+ assert_equal("EUC-JP", rss.encoding)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.standalone = "yes"
+ end
+ assert_equal("2.0", rss.rss_version)
+ assert_equal("yes", rss.standalone)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.encoding = "EUC-JP"
+ maker.standalone = "yes"
+ end
+ assert_equal("2.0", rss.rss_version)
+ assert_equal("EUC-JP", rss.encoding)
+ assert_equal("yes", rss.standalone)
+ end
+
+ def test_channel
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+ language = "ja"
+ copyright = "foo"
+ managingEditor = "bar"
+ webMaster = "web master"
+ rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
+ docs = "http://foo.com/doc"
+ skipDays = [
+ "Sunday",
+ "Monday",
+ ]
+ skipHours = [
+ "0",
+ "13",
+ ]
+ pubDate = Time.now
+ lastBuildDate = Time.now
+ categories = [
+ "Nespapers",
+ "misc",
+ ]
+ generator = "RSS Maker"
+ ttl = "60"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ maker.channel.language = language
+ maker.channel.copyright = copyright
+ maker.channel.managingEditor = managingEditor
+ maker.channel.webMaster = webMaster
+ maker.channel.rating = rating
+ maker.channel.docs = docs
+ maker.channel.pubDate = pubDate
+ maker.channel.lastBuildDate = lastBuildDate
+
+ skipDays.each do |day|
+ maker.channel.skipDays.new_day do |new_day|
+ new_day.content = day
+ end
+ end
+ skipHours.each do |hour|
+ maker.channel.skipHours.new_hour do |new_hour|
+ new_hour.content = hour
+ end
+ end
+
+ categories.each do |category|
+ maker.channel.categories.new_category do |new_category|
+ new_category.content = category
+ end
+ end
+
+ maker.channel.generator = generator
+ maker.channel.ttl = ttl
+ end
+ channel = rss.channel
+
+ assert_equal(title, channel.title)
+ assert_equal(link, channel.link)
+ assert_equal(description, channel.description)
+ assert_equal(language, channel.language)
+ assert_equal(copyright, channel.copyright)
+ assert_equal(managingEditor, channel.managingEditor)
+ assert_equal(webMaster, channel.webMaster)
+ assert_equal(rating, channel.rating)
+ assert_equal(docs, channel.docs)
+ assert_equal(pubDate, channel.pubDate)
+ assert_equal(pubDate, channel.date)
+ assert_equal(lastBuildDate, channel.lastBuildDate)
+
+ skipDays.each_with_index do |day, i|
+ assert_equal(day, channel.skipDays.days[i].content)
+ end
+ skipHours.each_with_index do |hour, i|
+ assert_equal(hour.to_i, channel.skipHours.hours[i].content)
+ end
+
+ channel.categories.each_with_index do |category, i|
+ assert_equal(categories[i], category.content)
+ end
+
+ assert_equal(generator, channel.generator)
+ assert_equal(ttl.to_i, channel.ttl)
+
+ assert(channel.items.empty?)
+ assert_nil(channel.image)
+ assert_nil(channel.textInput)
+ end
+
+ def test_not_valid_channel
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+ language = "ja"
+
+ assert_not_set_error("maker.channel", %w(title)) do
+ RSS::Maker.make("2.0") do |maker|
+ # maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ maker.channel.language = language
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(link)) do
+ RSS::Maker.make("2.0") do |maker|
+ maker.channel.title = title
+ # maker.channel.link = link
+ maker.channel.description = description
+ maker.channel.language = language
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(description)) do
+ RSS::Maker.make("2.0") do |maker|
+ maker.channel.title = title
+ maker.channel.link = link
+ # maker.channel.description = description
+ maker.channel.language = language
+ end
+ end
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ # maker.channel.language = language
+ end
+ assert_not_nil(rss)
+ end
+
+
+ def test_cloud
+ domain = "rpc.sys.com"
+ port = "80"
+ path = "/RPC2"
+ registerProcedure = "myCloud.rssPleaseNotify"
+ protocol = "xml-rpc"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.channel.cloud.domain = domain
+ maker.channel.cloud.port = port
+ maker.channel.cloud.path = path
+ maker.channel.cloud.registerProcedure = registerProcedure
+ maker.channel.cloud.protocol = protocol
+ end
+ cloud = rss.channel.cloud
+ assert_equal(domain, cloud.domain)
+ assert_equal(port.to_i, cloud.port)
+ assert_equal(path, cloud.path)
+ assert_equal(registerProcedure, cloud.registerProcedure)
+ assert_equal(protocol, cloud.protocol)
+ end
+
+ def test_not_valid_cloud
+ domain = "rpc.sys.com"
+ port = "80"
+ path = "/RPC2"
+ registerProcedure = "myCloud.rssPleaseNotify"
+ protocol = "xml-rpc"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ # maker.channel.cloud.domain = domain
+ maker.channel.cloud.port = port
+ maker.channel.cloud.path = path
+ maker.channel.cloud.registerProcedure = registerProcedure
+ maker.channel.cloud.protocol = protocol
+ end
+ assert_nil(rss.channel.cloud)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.channel.cloud.domain = domain
+ # maker.channel.cloud.port = port
+ maker.channel.cloud.path = path
+ maker.channel.cloud.registerProcedure = registerProcedure
+ maker.channel.cloud.protocol = protocol
+ end
+ assert_nil(rss.channel.cloud)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.channel.cloud.domain = domain
+ maker.channel.cloud.port = port
+ # maker.channel.cloud.path = path
+ maker.channel.cloud.registerProcedure = registerProcedure
+ maker.channel.cloud.protocol = protocol
+ end
+ assert_nil(rss.channel.cloud)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.channel.cloud.domain = domain
+ maker.channel.cloud.port = port
+ maker.channel.cloud.path = path
+ # maker.channel.cloud.registerProcedure = registerProcedure
+ maker.channel.cloud.protocol = protocol
+ end
+ assert_nil(rss.channel.cloud)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.channel.cloud.domain = domain
+ maker.channel.cloud.port = port
+ maker.channel.cloud.path = path
+ maker.channel.cloud.registerProcedure = registerProcedure
+ # maker.channel.cloud.protocol = protocol
+ end
+ assert_nil(rss.channel.cloud)
+ end
+
+
+ def test_image
+ title = "fugafuga"
+ link = "http://hoge.com"
+ url = "http://hoge.com/hoge.png"
+ width = "144"
+ height = "400"
+ description = "an image"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+ image = rss.image
+ assert_equal(title, image.title)
+ assert_equal(link, image.link)
+ assert_equal(url, image.url)
+ assert_equal(width.to_i, image.width)
+ assert_equal(height.to_i, image.height)
+ assert_equal(description, image.description)
+
+ assert_not_set_error("maker.channel", %w(title description)) do
+ RSS::Maker.make("2.0") do |maker|
+ # setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+ end
+ end
+
+ def test_not_valid_image
+ title = "fugafuga"
+ link = "http://hoge.com"
+ url = "http://hoge.com/hoge.png"
+ width = "144"
+ height = "400"
+ description = "an image"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ # maker.image.title = title
+ maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+ assert_nil(rss.image)
+
+ assert_not_set_error("maker.channel", %w(link)) do
+ RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ # maker.channel.link = link
+ maker.channel.link = nil
+
+ maker.image.title = title
+ maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+ end
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ # maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+ assert_nil(rss.image)
+ end
+
+ def test_items(with_convenience_way=true)
+ title = "TITLE"
+ link = "http://hoge.com/"
+ description = "text hoge fuga"
+ author = "oprah@oxygen.net"
+ comments = "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290"
+ pubDate = Time.now
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ end
+ assert(rss.channel.items.empty?)
+
+ item_size = 5
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |item|
+ item.title = "#{title}#{i}"
+ item.link = "#{link}#{i}"
+ item.description = "#{description}#{i}"
+ item.author = "#{author}#{i}"
+ item.comments = "#{comments}#{i}"
+ item.date = pubDate
+ end
+ end
+ maker.items.do_sort = true
+ end
+ assert_equal(item_size, rss.items.size)
+ rss.channel.items.each_with_index do |item, i|
+ assert_equal("#{title}#{i}", item.title)
+ assert_equal("#{link}#{i}", item.link)
+ assert_equal("#{description}#{i}", item.description)
+ assert_equal("#{author}#{i}", item.author)
+ assert_equal("#{comments}#{i}", item.comments)
+ assert_equal(pubDate, item.pubDate)
+ assert_equal(pubDate, item.date)
+ end
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |item|
+ item.title = "#{title}#{i}"
+ item.link = "#{link}#{i}"
+ item.description = "#{description}#{i}"
+ item.author = "#{author}#{i}"
+ item.comments = "#{comments}#{i}"
+ item.date = pubDate
+ end
+ end
+ maker.items.do_sort = Proc.new do |x, y|
+ if with_convenience_way
+ y.title[-1] <=> x.title[-1]
+ else
+ y.title {|t| t.content[-1]} <=> x.title {|t| t.content[-1]}
+ end
+ end
+ end
+ assert_equal(item_size, rss.items.size)
+ rss.channel.items.reverse.each_with_index do |item, i|
+ assert_equal("#{title}#{i}", item.title)
+ assert_equal("#{link}#{i}", item.link)
+ assert_equal("#{description}#{i}", item.description)
+ assert_equal("#{author}#{i}", item.author)
+ assert_equal("#{comments}#{i}", item.comments)
+ assert_equal(pubDate, item.pubDate)
+ assert_equal(pubDate, item.date)
+ end
+ end
+
+ def test_items_with_new_api_since_018
+ test_items(false)
+ end
+
+ def test_pubDate_without_description
+ title = "TITLE"
+ link = "http://hoge.com/"
+ # description = "text hoge fuga"
+ author = "oprah@oxygen.net"
+ pubDate = Time.now
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.items.new_item do |item|
+ item.title = title
+ item.link = link
+ # item.description = description
+ item.author = author
+ item.pubDate = pubDate
+ end
+ end
+ assert_equal(1, rss.items.size)
+ rss.channel.items.each_with_index do |item, i|
+ assert_equal(title, item.title)
+ assert_equal(link, item.link)
+ # assert_equal(description, item.description)
+ assert_equal(author, item.author)
+ assert_equal(pubDate, item.pubDate)
+ assert_equal(pubDate, item.date)
+ end
+ end
+
+ def test_guid
+ isPermaLink = "true"
+ content = "http://inessential.com/2002/09/01.php#a2"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ guid = maker.items.last.guid
+ guid.isPermaLink = isPermaLink
+ guid.content = content
+ end
+ guid = rss.channel.items.last.guid
+ assert_equal(isPermaLink == "true", guid.isPermaLink)
+ assert_equal(content, guid.content)
+ end
+
+ def test_guid_permanent_link
+ content = "http://inessential.com/2002/09/01.php#a2"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ guid = maker.items.last.guid
+ assert_equal(nil, guid.permanent_link?)
+ assert_equal(guid.isPermaLink, guid.permanent_link?)
+ guid.permanent_link = true
+ assert_equal(true, guid.permanent_link?)
+ assert_equal(guid.isPermaLink, guid.permanent_link?)
+ guid.content = content
+ end
+ guid = rss.channel.items.last.guid
+ assert_equal(true, guid.isPermaLink)
+ assert_equal(content, guid.content)
+ end
+
+ def test_guid_permanent_link_false
+ content = "http://inessential.com/2002/09/01.php#a2"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ guid = maker.items.last.guid
+ assert_equal(nil, guid.permanent_link?)
+ assert_equal(guid.isPermaLink, guid.permanent_link?)
+ guid.permanent_link = false
+ assert_equal(false, guid.permanent_link?)
+ assert_equal(guid.isPermaLink, guid.permanent_link?)
+ guid.content = content
+ end
+ guid = rss.channel.items.last.guid
+ assert_equal(false, guid.isPermaLink)
+ assert_equal(content, guid.content)
+ end
+
+ def test_not_valid_guid
+ # content = "http://inessential.com/2002/09/01.php#a2"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ # guid = maker.items.last.guid
+ # guid.content = content
+ end
+ assert_nil(rss.channel.items.last.guid)
+ end
+
+ def test_enclosure
+ url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
+ length = "12216320"
+ type = "audio/mpeg"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ enclosure = maker.items.last.enclosure
+ enclosure.url = url
+ enclosure.length = length
+ enclosure.type = type
+ end
+ enclosure = rss.channel.items.last.enclosure
+ assert_equal(url, enclosure.url)
+ assert_equal(length.to_i, enclosure.length)
+ assert_equal(type, enclosure.type)
+ end
+
+ def test_not_valid_enclosure
+ url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
+ length = "12216320"
+ type = "audio/mpeg"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ enclosure = maker.items.last.enclosure
+ # enclosure.url = url
+ enclosure.length = length
+ enclosure.type = type
+ end
+ assert_nil(rss.channel.items.last.enclosure)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ enclosure = maker.items.last.enclosure
+ enclosure.url = url
+ # enclosure.length = length
+ enclosure.type = type
+ end
+ assert_nil(rss.channel.items.last.enclosure)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ enclosure = maker.items.last.enclosure
+ enclosure.url = url
+ enclosure.length = length
+ # enclosure.type = type
+ end
+ assert_nil(rss.channel.items.last.enclosure)
+ end
+
+
+ def test_source
+ url = "http://static.userland.com/tomalak/links2.xml"
+ content = "Tomalak's Realm"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ source = maker.items.last.source
+ source.url = url
+ source.content = content
+ end
+ source = rss.channel.items.last.source
+ assert_equal(url, source.url)
+ assert_equal(content, source.content)
+ end
+
+ def test_not_valid_source
+ url = "http://static.userland.com/tomalak/links2.xml"
+ content = "Tomalak's Realm"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ source = maker.items.last.source
+ # source.url = url
+ source.content = content
+ end
+ assert_nil(rss.channel.items.last.source)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ source = maker.items.last.source
+ source.url = url
+ # source.content = content
+ end
+ assert_nil(rss.channel.items.last.source)
+ end
+
+ def test_category
+ domain = "http://www.fool.com/cusips"
+ content = "MSFT"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ maker.items.last.categories.new_category do |category|
+ category.domain = domain
+ category.content = content
+ end
+ end
+ category = rss.channel.items.last.categories.last
+ assert_equal(domain, category.domain)
+ assert_equal(content, category.content)
+ end
+
+ def test_not_valid_category
+ # content = "Grateful Dead"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ maker.items.last.categories.new_category do |category|
+ # category.content = content
+ end
+ end
+ assert(rss.channel.items.last.categories.empty?)
+ end
+
+ def test_textInput
+ title = "fugafuga"
+ description = "text hoge fuga"
+ name = "hoge"
+ link = "http://hoge.com"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+ textInput = rss.channel.textInput
+ assert_equal(title, textInput.title)
+ assert_equal(description, textInput.description)
+ assert_equal(name, textInput.name)
+ assert_equal(link, textInput.link)
+
+ assert_not_set_error("maker.channel", %w(link description title)) do
+ RSS::Maker.make("2.0") do |maker|
+ # setup_dummy_channel(maker)
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+ end
+ end
+
+ def test_not_valid_textInput
+ title = "fugafuga"
+ description = "text hoge fuga"
+ name = "hoge"
+ link = "http://hoge.com"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ # maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+ assert_nil(rss.channel.textInput)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.textinput.title = title
+ # maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+ assert_nil(rss.channel.textInput)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ # maker.textinput.name = name
+ maker.textinput.link = link
+ end
+ assert_nil(rss.channel.textInput)
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ # maker.textinput.link = link
+ end
+ assert_nil(rss.channel.textInput)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_atom_entry.rb b/jni/ruby/test/rss/test_maker_atom_entry.rb
new file mode 100644
index 0000000..9618723
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_atom_entry.rb
@@ -0,0 +1,393 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerAtomEntry < TestCase
+ def test_supported?
+ assert(RSS::Maker.supported?("atom:entry"))
+ assert(RSS::Maker.supported?("atom1.0:entry"))
+ assert(!RSS::Maker.supported?("atom2.0:entry"))
+ end
+
+ def test_find_class
+ assert_equal(RSS::Maker::Atom::Entry, RSS::Maker["atom:entry"])
+ assert_equal(RSS::Maker::Atom::Entry, RSS::Maker["atom1.0:entry"])
+ end
+
+ def test_root_element
+ entry = Maker.make("atom:entry") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ assert_equal(["atom", "1.0", "entry"], entry.feed_info)
+
+ entry = Maker.make("atom:entry") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.encoding = "EUC-JP"
+ end
+ assert_equal(["atom", "1.0", "entry"], entry.feed_info)
+ assert_equal("EUC-JP", entry.encoding)
+
+ entry = Maker.make("atom:entry") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.standalone = "yes"
+ end
+ assert_equal(["atom", "1.0", "entry"], entry.feed_info)
+ assert_equal("yes", entry.standalone)
+
+ entry = Maker.make("atom:entry") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.encoding = "EUC-JP"
+ maker.standalone = "yes"
+ end
+ assert_equal(["atom", "1.0", "entry"], entry.feed_info)
+ assert_equal("EUC-JP", entry.encoding)
+ assert_equal("yes", entry.standalone)
+ end
+
+ def test_invalid_feed
+ assert_not_set_error("maker.item", %w(id title author updated)) do
+ Maker.make("atom:entry") do |maker|
+ end
+ end
+
+ assert_not_set_error("maker.item", %w(id title updated)) do
+ Maker.make("atom:entry") do |maker|
+ maker.channel.author = "foo"
+ end
+ end
+
+ assert_not_set_error("maker.item", %w(title updated)) do
+ Maker.make("atom:entry") do |maker|
+ maker.channel.author = "foo"
+ maker.channel.id = "http://example.com"
+ end
+ end
+
+ assert_not_set_error("maker.item", %w(updated)) do
+ Maker.make("atom:entry") do |maker|
+ maker.channel.author = "foo"
+ maker.channel.id = "http://example.com"
+ maker.channel.title = "Atom Feed"
+ end
+ end
+
+ assert_not_set_error("maker.item", %w(author)) do
+ Maker.make("atom:entry") do |maker|
+ maker.channel.id = "http://example.com"
+ maker.channel.title = "Atom Feed"
+ maker.channel.updated = Time.now
+ end
+ end
+
+ entry = Maker.make("atom:entry") do |maker|
+ maker.channel.author = "Foo"
+ maker.channel.id = "http://example.com"
+ maker.channel.title = "Atom Feed"
+ maker.channel.updated = Time.now
+ end
+ assert_not_nil(entry)
+ end
+
+ def test_author
+ assert_maker_atom_persons("entry",
+ ["channel", "authors"],
+ ["authors"],
+ "maker.channel.author") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_persons("entry",
+ ["items", "first", "authors"],
+ ["authors"],
+ "maker.item.author",
+ "maker.item", ["author"]) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.channel.authors.clear
+ maker.items.first.authors.clear
+ end
+
+ assert_maker_atom_persons("entry",
+ ["items", "first", "source", "authors"],
+ ["source", "authors"],
+ "maker.item.source.author") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_category
+ assert_maker_atom_categories("entry",
+ ["channel", "categories"],
+ ["categories"],
+ "maker.channel.category") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_categories("entry",
+ ["items", "first", "categories"],
+ ["categories"],
+ "maker.item.category") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_categories("entry",
+ ["items", "first", "source", "categories"],
+ ["source", "categories"],
+ "maker.item.source.category") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_content
+ assert_maker_atom_content("entry",
+ ["items", "first", "content"],
+ ["content"],
+ "maker.item.content") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_contributor
+ assert_maker_atom_persons("entry",
+ ["channel", "contributors"],
+ ["contributors"],
+ "maker.channel.contributor") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_persons("entry",
+ ["items", "first", "contributors"],
+ ["contributors"],
+ "maker.item.contributor") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_persons("entry",
+ ["items", "first", "source", "contributors"],
+ ["source", "contributors"],
+ "maker.item.source.contributor") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_link
+ assert_maker_atom_links("entry",
+ ["channel", "links"],
+ ["links"],
+ "maker.channel.link") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.channel.links.clear
+ maker.items.first.links.clear
+ end
+
+ assert_maker_atom_links("entry",
+ ["items", "first", "links"],
+ ["links"],
+ "maker.item.link") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.channel.links.clear
+ maker.items.first.links.clear
+ end
+
+ assert_maker_atom_links("entry",
+ ["items", "first", "source", "links"],
+ ["source", "links"],
+ "maker.item.source.link", true) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_published
+ assert_maker_atom_date_construct("entry",
+ ["items", "first", "published"],
+ ["published"]
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_rights
+ assert_maker_atom_text_construct("entry",
+ ["channel", "copyright"],
+ ["rights"]) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_text_construct("entry",
+ ["items", "first", "rights"],
+ ["rights"],
+ nil, nil, "maker.item.rights"
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_text_construct("entry",
+ ["items", "first", "source", "rights"],
+ ["source", "rights"],
+ nil, nil, "maker.item.source.rights"
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+
+ def test_source_generator
+ assert_maker_atom_generator("entry",
+ ["items", "first", "source", "generator"],
+ ["source", "generator"],
+ "maker.item.source.generator") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_source_icon
+ assert_maker_atom_icon("entry",
+ ["items", "first", "source", "icon"],
+ ["source", "icon"],
+ nil, "maker.item.source.icon") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_source_id
+ assert_maker_atom_id("entry",
+ ["items", "first", "source"],
+ ["source"],
+ "maker.item.source") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_source_logo
+ assert_maker_atom_logo("entry",
+ ["items", "first", "source", "logo"],
+ ["source", "logo"],
+ nil,
+ "maker.item.source.logo") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_source_subtitle
+ assert_maker_atom_text_construct("entry",
+ ["items", "first", "source", "subtitle"],
+ ["source", "subtitle"],
+ nil, nil,
+ "maker.item.source.subtitle") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_summary
+ assert_maker_atom_text_construct("entry",
+ ["items", "first", "description"],
+ ["summary"],
+ nil, nil, "maker.item.description"
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_title
+ assert_maker_atom_text_construct("entry",
+ ["channel", "title"], ["title"],
+ "maker.item", ["title"],
+ "maker.channel.title") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.channel.title = nil
+ maker.items.first.title = nil
+ end
+
+ assert_maker_atom_text_construct("entry",
+ ["items", "first", "title"],
+ ["title"],
+ "maker.item", ["title"],
+ "maker.item.title") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.channel.title = nil
+ maker.items.first.title = nil
+ end
+
+ assert_maker_atom_text_construct("entry",
+ ["items", "first", "source", "title"],
+ ["source", "title"],
+ nil, nil, "maker.item.source.title"
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_updated
+ assert_maker_atom_date_construct("entry",
+ ["channel", "updated"], ["updated"],
+ "maker.item", ["updated"]) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.channel.updated = nil
+ maker.items.first.updated = nil
+ end
+
+ assert_maker_atom_date_construct("entry",
+ ["items", "first", "updated"],
+ ["updated"],
+ "maker.item", ["updated"]) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.channel.updated = nil
+ maker.items.first.updated = nil
+ end
+
+ assert_maker_atom_date_construct("entry",
+ ["items", "first", "source", "updated"],
+ ["source", "updated"]) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_date
+ date = Time.parse("2004/11/1 10:10")
+ feed = Maker.make("atom:entry") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.channel.date = nil
+ maker.items.new_item do |item|
+ item.link = "http://example.com/article.html"
+ item.title = "Sample Article"
+ item.date = date
+ end
+ end
+ assert_equal(date, feed.items[0].updated.content)
+ assert_equal([date], feed.items[0].dc_dates.collect {|_date| _date.value})
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_atom_feed.rb b/jni/ruby/test/rss/test_maker_atom_feed.rb
new file mode 100644
index 0000000..d866001
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_atom_feed.rb
@@ -0,0 +1,454 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerAtomFeed < TestCase
+ def test_supported?
+ assert(RSS::Maker.supported?("atom"))
+ assert(RSS::Maker.supported?("atom:feed"))
+ assert(RSS::Maker.supported?("atom1.0"))
+ assert(RSS::Maker.supported?("atom1.0:feed"))
+ assert(!RSS::Maker.supported?("atom2.0"))
+ assert(!RSS::Maker.supported?("atom2.0:feed"))
+ end
+
+ def test_find_class
+ assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom"])
+ assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom:feed"])
+ assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom1.0"])
+ assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom1.0:feed"])
+ end
+
+ def test_root_element
+ feed = Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+ end
+ assert_equal(["atom", "1.0", "feed"], feed.feed_info)
+
+ feed = Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.encoding = "EUC-JP"
+ end
+ assert_equal(["atom", "1.0", "feed"], feed.feed_info)
+ assert_equal("EUC-JP", feed.encoding)
+
+ feed = Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.standalone = "yes"
+ end
+ assert_equal(["atom", "1.0", "feed"], feed.feed_info)
+ assert_equal("yes", feed.standalone)
+
+ feed = Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.encoding = "EUC-JP"
+ maker.standalone = "yes"
+ end
+ assert_equal(["atom", "1.0", "feed"], feed.feed_info)
+ assert_equal("EUC-JP", feed.encoding)
+ assert_equal("yes", feed.standalone)
+ end
+
+ def test_invalid_feed
+ assert_not_set_error("maker.channel", %w(id title author updated)) do
+ Maker.make("atom") do |maker|
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(id title updated)) do
+ Maker.make("atom") do |maker|
+ maker.channel.author = "foo"
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(title updated)) do
+ Maker.make("atom") do |maker|
+ maker.channel.author = "foo"
+ maker.channel.id = "http://example.com"
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(updated)) do
+ Maker.make("atom") do |maker|
+ maker.channel.author = "foo"
+ maker.channel.id = "http://example.com"
+ maker.channel.title = "Atom Feed"
+ end
+ end
+
+ assert_not_set_error("maker.channel", %w(author)) do
+ Maker.make("atom") do |maker|
+ maker.channel.id = "http://example.com"
+ maker.channel.title = "Atom Feed"
+ maker.channel.updated = Time.now
+ end
+ end
+
+ feed = Maker.make("atom") do |maker|
+ maker.channel.author = "Foo"
+ maker.channel.id = "http://example.com"
+ maker.channel.title = "Atom Feed"
+ maker.channel.updated = Time.now
+ end
+ assert_not_nil(feed)
+ end
+
+ def test_author
+ assert_maker_atom_persons("feed",
+ ["channel", "authors"],
+ ["authors"],
+ "maker.channel.author") do |maker|
+ setup_dummy_channel_atom(maker)
+ end
+
+ assert_not_set_error("maker.channel", %w(author)) do
+ RSS::Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.channel.authors.clear
+ end
+ end
+
+ assert_maker_atom_persons("feed",
+ ["items", "first", "authors"],
+ ["entries", "first", "authors"],
+ "maker.item.author") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_persons("feed",
+ ["items", "first", "source", "authors"],
+ ["entries", "first", "source", "authors"],
+ "maker.item.source.author") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_category
+ assert_maker_atom_categories("feed",
+ ["channel", "categories"],
+ ["categories"],
+ "maker.channel.category") do |maker|
+ setup_dummy_channel_atom(maker)
+ end
+
+ assert_maker_atom_categories("feed",
+ ["items", "first", "categories"],
+ ["entries", "first", "categories"],
+ "maker.item.category") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_categories("feed",
+ ["items", "first", "source", "categories"],
+ ["entries", "first", "source", "categories"],
+ "maker.item.source.category") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_contributor
+ assert_maker_atom_persons("feed",
+ ["channel", "contributors"],
+ ["contributors"],
+ "maker.channel.contributor") do |maker|
+ setup_dummy_channel_atom(maker)
+ end
+
+ assert_maker_atom_persons("feed",
+ ["items", "first", "contributors"],
+ ["entries", "first", "contributors"],
+ "maker.item.contributor") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_persons("feed",
+ ["items", "first", "source", "contributors"],
+ ["entries", "first", "source", "contributors"],
+ "maker.item.source.contributor") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_generator
+ assert_maker_atom_generator("feed",
+ ["channel", "generator"],
+ ["generator"]) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_generator("feed",
+ ["items", "first", "source", "generator"],
+ ["entries", "first", "source", "generator"],
+ "maker.item.source.generator") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_icon
+ assert_maker_atom_icon("feed", ["channel"], ["icon"], "icon") do |maker|
+ setup_dummy_channel_atom(maker)
+ end
+
+ assert_maker_atom_icon("feed",
+ ["items", "first", "source", "icon"],
+ ["entries", "first", "source", "icon"],
+ nil, "maker.item.source.icon") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_link
+ assert_maker_atom_links("feed",
+ ["channel", "links"],
+ ["links"],
+ "maker.channel.link") do |maker|
+ setup_dummy_channel_atom(maker)
+ end
+
+ assert_maker_atom_links("feed",
+ ["items", "first", "links"],
+ ["entries", "first", "links"],
+ "maker.item.link") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_links("feed",
+ ["items", "first", "source", "links"],
+ ["entries", "first", "source", "links"],
+ "maker.item.source.link", true) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_logo
+ assert_maker_atom_logo("feed", ["channel"], ["logo"], "logo") do |maker|
+ setup_dummy_channel_atom(maker)
+ end
+
+ assert_maker_atom_logo("feed", ["image"], ["logo"], "url") do |maker|
+ setup_dummy_channel_atom(maker)
+ end
+
+ assert_maker_atom_logo("feed",
+ ["items", "first", "source", "logo"],
+ ["entries", "first", "source", "logo"],
+ nil, "maker.item.source.logo") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_rights
+ assert_maker_atom_text_construct("feed",
+ ["channel", "copyright"],
+ ["rights"]) do |maker|
+ setup_dummy_channel_atom(maker)
+ end
+
+ assert_maker_atom_text_construct("feed",
+ ["items", "first", "rights"],
+ ["entries", "first", "rights"],
+ nil, nil, "maker.item.rights"
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+
+ assert_maker_atom_text_construct("feed",
+ ["items", "first", "source", "rights"],
+ ["entries", "first", "source", "rights"],
+ nil, nil, "maker.item.source.rights"
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_subtitle
+ assert_maker_atom_text_construct("feed",
+ ["channel", "subtitle"],
+ ["subtitle"],
+ nil, nil,
+ "maker.channel.description") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.channel.description = nil
+ end
+
+ assert_maker_atom_text_construct("feed",
+ ["channel", "subtitle"],
+ ["subtitle"],
+ nil, nil,
+ "maker.channel.description") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.channel.description {|d| d.content = nil}
+ end
+
+ assert_maker_atom_text_construct("feed",
+ ["items", "first", "source", "subtitle"],
+ ["entries", "first",
+ "source", "subtitle"],
+ nil, nil,
+ "maker.item.source.subtitle") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_title
+ assert_maker_atom_text_construct("feed",
+ ["channel", "title"], ["title"],
+ "maker.channel", ["title"]) do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.channel.title = nil
+ end
+
+ assert_maker_atom_text_construct("feed",
+ ["items", "first", "title"],
+ ["entries", "first", "title"],
+ "maker.item", ["title"],
+ "maker.item.title") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.items.first.title = nil
+ end
+
+ assert_maker_atom_text_construct("feed",
+ ["items", "first", "source", "title"],
+ ["entries", "first", "source", "title"],
+ nil, nil, "maker.item.source.title"
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_updated
+ assert_maker_atom_date_construct("feed",
+ ["channel", "updated"], ["updated"],
+ "maker.channel", ["updated"]) do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.channel.updated = nil
+ end
+
+ assert_maker_atom_date_construct("feed",
+ ["items", "first", "updated"],
+ ["entries", "first", "updated"],
+ "maker.item", ["updated"]) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ maker.items.first.updated = nil
+ end
+
+ assert_maker_atom_date_construct("feed",
+ ["items", "first", "source", "updated"],
+ ["entries", "first", "source", "updated"]
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_published
+ assert_maker_atom_date_construct("feed",
+ ["items", "first", "published"],
+ ["entries", "first", "published"]
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_summary
+ assert_maker_atom_text_construct("feed",
+ ["items", "first", "description"],
+ ["entries", "first", "summary"],
+ nil, nil, "maker.item.description"
+ ) do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_content
+ assert_maker_atom_content("feed",
+ ["items", "first", "content"],
+ ["entries", "first", "content"],
+ "maker.item.content") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_id
+ assert_maker_atom_id("feed",
+ ["items", "first", "source"],
+ ["entries", "first", "source"],
+ "maker.item.source") do |maker|
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ end
+
+ def test_language
+ language = "ja"
+ feed = Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.channel.language = "ja"
+ end
+ assert_equal(language, feed.dc_language)
+ end
+
+ def test_date
+ date = Time.parse("2004/11/1 10:10")
+ feed = Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.items.new_item do |item|
+ item.link = "http://example.com/article.html"
+ item.title = "sample article"
+ item.date = date
+ end
+ end
+ assert_equal(date, feed.items[0].updated.content)
+ assert_equal([date], feed.items[0].dc_dates.collect {|_date| _date.value})
+ end
+
+ def test_channel_dc_date
+ date = Time.parse("2004/11/1 10:10")
+ feed = Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.channel.updated = nil
+ maker.channel.dc_date = date
+ setup_dummy_item_atom(maker)
+ end
+ assert_equal(date, feed.updated.content)
+ assert_equal([date], feed.dc_dates.collect {|_date| _date.value})
+ end
+
+ def test_item_dc_date
+ date = Time.parse("2004/11/1 10:10")
+ feed = Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.items.new_item do |item|
+ item.link = "http://example.com/article.html"
+ item.title = "sample article"
+ item.dc_date = date
+ end
+ end
+ assert_equal(date, feed.items[0].updated.content)
+ assert_equal([date], feed.items[0].dc_dates.collect {|_date| _date.value})
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_content.rb b/jni/ruby/test/rss/test_maker_content.rb
new file mode 100644
index 0000000..ba884f1
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_content.rb
@@ -0,0 +1,47 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerContent < TestCase
+
+ def setup
+ @uri = "http://purl.org/rss/1.0/modules/content/"
+
+ @elements = {
+ :encoded => "<em>ATTENTION</em>",
+ }
+ end
+
+ def test_rss10
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ @elements.each do |name, value|
+ item.__send__("#{accessor_name(name)}=", value)
+ end
+ end
+ assert_content(@elements, rss.items.last)
+ end
+
+ def test_rss20
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ @elements.each do |name, value|
+ item.__send__("#{accessor_name(name)}=", value)
+ end
+ end
+ assert_content(@elements, rss.items.last)
+ end
+
+ private
+ def accessor_name(name)
+ "content_#{name}"
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_dc.rb b/jni/ruby/test/rss/test_maker_dc.rb
new file mode 100644
index 0000000..977350c
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_dc.rb
@@ -0,0 +1,149 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerDublinCore < TestCase
+
+ def setup
+ @uri = "http://purl.org/dc/elements/1.1/"
+
+ t = Time.iso8601("2000-01-01T12:00:05+00:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ @elements = {
+ :title => "hoge",
+ :description =>
+ " XML is placing increasingly heavy loads on
+ the existing technical infrastructure of the Internet.",
+ :creator => "Rael Dornfest (mailto:rael@oreilly.com)",
+ :subject => "XML",
+ :publisher => "The O'Reilly Network",
+ :contributor => "hogehoge",
+ :type => "fugafuga",
+ :format => "hohoho",
+ :identifier => "fufufu",
+ :source => "barbar",
+ :language => "ja",
+ :relation => "cococo",
+ :rights => "Copyright (c) 2000 O'Reilly &amp; Associates, Inc.",
+ :date => t,
+ }
+ end
+
+ def test_rss10
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ set_elements(maker.channel)
+
+ setup_dummy_image(maker)
+ set_elements(maker.image)
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ @elements.each do |name, value|
+ item.__send__("#{accessor_name(name)}=", value)
+ end
+
+ setup_dummy_textinput(maker)
+ set_elements(maker.textinput)
+ end
+ assert_dublin_core(@elements, rss.channel)
+ assert_dublin_core(@elements, rss.image)
+ assert_dublin_core(@elements, rss.items.last)
+ assert_dublin_core(@elements, rss.textinput)
+ end
+
+ def test_rss10_multiple
+ assert_multiple_dublin_core_rss10("_list")
+ assert_multiple_dublin_core_rss10("es")
+ end
+
+ def assert_multiple_dublin_core_rss10(multiple_rights_suffix)
+ elems = []
+ @elements.each do |name, value|
+ plural = name.to_s + (name == :rights ? multiple_rights_suffix : "s")
+ values = [value]
+ if name == :date
+ values << value + 60
+ else
+ values << value * 2
+ end
+ elems << [name, values, plural]
+ end
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ set_multiple_elements(maker.channel, elems)
+
+ setup_dummy_image(maker)
+ set_multiple_elements(maker.image, elems)
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ elems.each do |name, values, plural|
+ dc_elems = item.__send__("dc_#{plural}")
+ values.each do |value|
+ elem = dc_elems.__send__("new_#{name}")
+ elem.value = value
+ end
+ end
+
+ setup_dummy_textinput(maker)
+ set_multiple_elements(maker.textinput, elems)
+ end
+ assert_multiple_dublin_core(elems, rss.channel)
+ assert_multiple_dublin_core(elems, rss.image)
+ assert_multiple_dublin_core(elems, rss.items.last)
+ assert_multiple_dublin_core(elems, rss.textinput)
+ end
+
+ def test_date
+ t1 = Time.iso8601("2000-01-01T12:00:05+00:00")
+ t2 = Time.iso8601("2005-01-01T12:00:05+00:00")
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.date = t1
+ maker.channel.dc_dates.new_date do |date|
+ date.value = t2
+ end
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ item.date = t2
+ item.dc_dates.new_date do |date|
+ date.value = t1
+ end
+ end
+ assert_equal([t1, t2], rss.channel.dc_dates.collect{|x| x.value})
+ assert_equal([t2, t1], rss.items.last.dc_dates.collect{|x| x.value})
+ end
+
+ private
+ def accessor_name(name)
+ "dc_#{name}"
+ end
+
+ def set_elements(target, elems=@elements)
+ elems.each do |name, value|
+ target.__send__("#{accessor_name(name)}=", value)
+ end
+ end
+
+ def set_multiple_elements(target, elems)
+ elems.each do |name, values, plural|
+ plural ||= "#{name}s"
+ dc_elems = target.__send__("dc_#{plural}")
+ values.each do |value|
+ dc_elems.__send__("new_#{name}") do |new_dc_elem|
+ new_dc_elem.value = value
+ end
+ end
+ end
+ end
+
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_image.rb b/jni/ruby/test/rss/test_maker_image.rb
new file mode 100644
index 0000000..d01654c
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_image.rb
@@ -0,0 +1,62 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerImage < TestCase
+
+ def setup
+ @uri = "http://web.resource.org/rss/1.0/modules/image/"
+
+ @favicon_infos = {
+ "about" => "http://www.kuro5hin.org/favicon.ico",
+ "image_size" => "small",
+ "dc_title" => "example",
+ }
+ @item_infos = {
+ "about" => "http://www.example.org/item.png",
+ "resource" => "http://www.example.org/item",
+ "dc_title" => "Example Image",
+ "image_width" => "100",
+ "image_height" => "65",
+ }
+ end
+
+ def test_rss10
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ @favicon_infos.each do |name, value|
+ maker.channel.image_favicon.__send__("#{name}=", value)
+ end
+
+ setup_dummy_image(maker)
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ @item_infos.each do |name, value|
+ item.image_item.__send__("#{name}=", value)
+ end
+
+ setup_dummy_textinput(maker)
+ end
+
+ setup_rss = RSS::Maker.make("1.0") do |maker|
+ rss.setup_maker(maker)
+ end
+
+ [rss, setup_rss].each_with_index do |target, i|
+ favicon = target.channel.image_favicon
+ assert_equal(@favicon_infos["about"], favicon.about)
+ assert_equal(@favicon_infos["image_size"], favicon.image_size)
+ assert_equal(@favicon_infos["dc_title"], favicon.dc_title)
+
+ item = target.items.last.image_item
+ assert_equal(@item_infos["about"], item.about)
+ assert_equal(@item_infos["resource"], item.resource)
+ assert_equal(@item_infos["image_width"].to_i, item.image_width)
+ assert_equal(@item_infos["image_height"].to_i, item.image_height)
+ assert_equal(@item_infos["dc_title"], item.dc_title)
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_itunes.rb b/jni/ruby/test/rss/test_maker_itunes.rb
new file mode 100644
index 0000000..0d47171
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_itunes.rb
@@ -0,0 +1,469 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerITunes < TestCase
+ def test_author
+ assert_maker_itunes_author(%w(channel))
+ assert_maker_itunes_author(%w(items last))
+ end
+
+ def test_block
+ assert_maker_itunes_block(%w(channel))
+ assert_maker_itunes_block(%w(items last))
+ end
+
+ def test_category
+ assert_maker_itunes_category(%w(channel))
+ end
+
+ def test_image
+ assert_maker_itunes_image(%w(channel))
+ end
+
+ def test_duration
+ assert_maker_itunes_duration(%w(items last))
+ end
+
+ def test_explicit
+ assert_maker_itunes_explicit(%w(channel))
+ assert_maker_itunes_explicit(%w(items last))
+ end
+
+ def test_keywords
+ assert_maker_itunes_keywords(%w(channel))
+ assert_maker_itunes_keywords(%w(items last))
+ end
+
+ def test_new_feed_url
+ assert_maker_itunes_new_feed_url(%w(channel))
+ end
+
+ def test_owner
+ assert_maker_itunes_owner(%w(channel))
+ end
+
+ def test_subtitle
+ assert_maker_itunes_subtitle(%w(channel))
+ assert_maker_itunes_subtitle(%w(items last))
+ end
+
+ def test_summary
+ assert_maker_itunes_summary(%w(channel))
+ assert_maker_itunes_summary(%w(items last))
+ end
+
+ private
+
+ def assert_maker_itunes_author(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ author = "John Doe"
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_author = author
+ end
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(author, target.itunes_author)
+ end
+ end
+
+ def _assert_maker_itunes_block(value, boolean_value, maker_readers,
+ feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_block = value
+ assert_equal(value, target.itunes_block)
+ assert_equal(boolean_value, target.itunes_block?)
+ end
+ target = chain_reader(rss20, feed_readers)
+ if [true, false].include?(value)
+ value = value ? "yes" : "no"
+ end
+ assert_equal(value, target.itunes_block)
+ assert_equal(boolean_value, target.itunes_block?)
+ end
+
+ def assert_maker_itunes_block(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_block("yes", true, maker_readers, feed_readers)
+ _assert_maker_itunes_block("Yes", true, maker_readers, feed_readers)
+ _assert_maker_itunes_block("no", false, maker_readers, feed_readers)
+ _assert_maker_itunes_block("", false, maker_readers, feed_readers)
+ _assert_maker_itunes_block(true, true, maker_readers, feed_readers)
+ _assert_maker_itunes_block(false, false, maker_readers, feed_readers)
+ _assert_maker_itunes_block(nil, false, maker_readers, feed_readers)
+ end
+ end
+
+ def _assert_maker_itunes_category(categories, maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ categories.each do |category|
+ sub_target = target.itunes_categories
+ if category.is_a?(Array)
+ category.each do |sub_category|
+ sub_target = sub_target.new_category
+ sub_target.text = sub_category
+ end
+ else
+ sub_target.new_category.text = category
+ end
+ end
+ end
+
+ target = chain_reader(rss20, feed_readers)
+ actual_categories = target.itunes_categories.collect do |category|
+ cat = category.text
+ if category.itunes_categories.empty?
+ cat
+ else
+ [cat, *category.itunes_categories.collect {|c| c.text}]
+ end
+ end
+ assert_equal(categories, actual_categories)
+ end
+
+ def assert_maker_itunes_category(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_category(["Audio Blogs"],
+ maker_readers, feed_readers)
+ _assert_maker_itunes_category([["Arts & Entertainment", "Games"]],
+ maker_readers, feed_readers)
+ _assert_maker_itunes_category([["Arts & Entertainment", "Games"],
+ ["Technology", "Computers"],
+ "Audio Blogs"],
+ maker_readers, feed_readers)
+ end
+ end
+
+ def assert_maker_itunes_image(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ url = "http://example.com/podcasts/everything/AllAboutEverything.jpg"
+
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_image = url
+ end
+
+ target = chain_reader(rss20, feed_readers)
+ assert_not_nil(target.itunes_image)
+ assert_equal(url, target.itunes_image.href)
+ end
+ end
+
+ def _assert_maker_itunes_duration(hour, minute, second, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_duration_by_value(hour, minute, second, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_duration_by_hour_minute_second(hour, minute, second,
+ value,
+ maker_readers,
+ feed_readers)
+ end
+
+ def _assert_maker_itunes_duration_by(hour, minute, second, value,
+ maker_readers, feed_readers)
+ expected_value = nil
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ expected_value = yield(target)
+ assert_equal(expected_value, target.itunes_duration)
+ target.itunes_duration do |duration|
+ assert_equal([hour, minute, second, expected_value],
+ [duration.hour, duration.minute,
+ duration.second, duration.content])
+ end
+ end
+ target = chain_reader(rss20, feed_readers)
+ duration = target.itunes_duration
+ assert_not_nil(duration)
+ assert_equal([hour, minute, second, expected_value],
+ [duration.hour, duration.minute,
+ duration.second, duration.content])
+ end
+
+ def _assert_maker_itunes_duration_by_value(hour, minute, second, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_duration_by(hour, minute, second, value,
+ maker_readers, feed_readers) do |target|
+ target.itunes_duration = value
+ value
+ end
+ end
+
+ def _assert_maker_itunes_duration_by_hour_minute_second(hour, minute, second,
+ value,
+ maker_readers,
+ feed_readers)
+ _assert_maker_itunes_duration_by(hour, minute, second, value,
+ maker_readers, feed_readers) do |target|
+ target.itunes_duration do |duration|
+ duration.hour = hour
+ duration.minute = minute
+ duration.second = second
+ end
+ value.split(":").collect {|v| "%02d" % v.to_i}.join(":")
+ end
+ end
+
+ def _assert_maker_itunes_duration_invalid_value(value, maker_readers)
+ assert_raise(ArgumentError) do
+ ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_duration = value
+ end
+ end
+ end
+
+ def assert_maker_itunes_duration(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_duration(7, 14, 5, "07:14:05", maker_readers,
+ feed_readers)
+ _assert_maker_itunes_duration(7, 14, 5, "7:14:05", maker_readers,
+ feed_readers)
+ _assert_maker_itunes_duration(0, 4, 55, "04:55", maker_readers,
+ feed_readers)
+ _assert_maker_itunes_duration(0, 4, 5, "4:05", maker_readers,
+ feed_readers)
+
+ _assert_maker_itunes_duration_invalid_value("5", maker_readers)
+ _assert_maker_itunes_duration_invalid_value("09:07:14:05", maker_readers)
+ _assert_maker_itunes_duration_invalid_value("10:5", maker_readers)
+ _assert_maker_itunes_duration_invalid_value("10:03:5", maker_readers)
+ _assert_maker_itunes_duration_invalid_value("10:3:05", maker_readers)
+
+ _assert_maker_itunes_duration_invalid_value("xx:xx:xx", maker_readers)
+ end
+ end
+
+ def _assert_maker_itunes_explicit(explicit, value,
+ maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_explicit = value
+ assert_equal(explicit, target.itunes_explicit?)
+ end
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(value, target.itunes_explicit)
+ assert_equal(explicit, target.itunes_explicit?)
+ end
+
+ def assert_maker_itunes_explicit(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_explicit(true, "yes", maker_readers, feed_readers)
+ _assert_maker_itunes_explicit(false, "clean",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_explicit(nil, "no", maker_readers, feed_readers)
+ end
+ end
+
+ def _assert_maker_itunes_keywords(keywords, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords_by_value(keywords, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords_by_keywords(keywords, maker_readers,
+ feed_readers)
+ end
+
+ def _assert_maker_itunes_keywords_by(keywords, maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ yield(target)
+ end
+ assert_nothing_raised do
+ rss20 = ::RSS::Parser.parse(rss20.to_s)
+ end
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(keywords, target.itunes_keywords)
+ end
+
+ def _assert_maker_itunes_keywords_by_value(keywords, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords_by(keywords, maker_readers,
+ feed_readers) do |target|
+ target.itunes_keywords = value
+ end
+ end
+
+ def _assert_maker_itunes_keywords_by_keywords(keywords,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords_by(keywords, maker_readers,
+ feed_readers) do |target|
+ target.itunes_keywords = keywords
+ end
+ end
+
+ def assert_maker_itunes_keywords(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_keywords(["salt"], "salt",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords(["salt"], " salt ",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords(["salt", "pepper", "shaker", "exciting"],
+ "salt, pepper, shaker, exciting",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords(["metric", "socket", "wrenches",
+ "toolsalt"],
+ "metric, socket, wrenches, toolsalt",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords(["olitics", "red", "blue", "state"],
+ "olitics, red, blue, state",
+ maker_readers, feed_readers)
+ end
+ end
+
+ def assert_maker_itunes_new_feed_url(maker_readers, feed_readers=nil)
+ feed_readers ||= maker_readers
+ url = "http://newlocation.com/example.rss"
+
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_new_feed_url = url
+ end
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(url, target.itunes_new_feed_url)
+ end
+
+ def _assert_maker_itunes_owner(name, email, maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ owner = target.itunes_owner
+ owner.itunes_name = name
+ owner.itunes_email = email
+ end
+ owner = chain_reader(rss20, feed_readers).itunes_owner
+ if name.nil? and email.nil?
+ assert_nil(owner)
+ else
+ assert_not_nil(owner)
+ assert_equal(name, owner.itunes_name)
+ assert_equal(email, owner.itunes_email)
+ end
+ end
+
+ def assert_maker_itunes_owner(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_owner("John Doe", "john.doe@example.com",
+ maker_readers, feed_readers)
+
+ not_set_name = (["maker"] + maker_readers + ["itunes_owner"]).join(".")
+ assert_not_set_error(not_set_name, ["itunes_name"]) do
+ _assert_maker_itunes_owner(nil, "john.doe@example.com",
+ maker_readers, feed_readers)
+ end
+ assert_not_set_error(not_set_name, ["itunes_email"]) do
+ _assert_maker_itunes_owner("John Doe", nil,
+ maker_readers, feed_readers)
+ end
+
+ _assert_maker_itunes_owner(nil, nil, maker_readers, feed_readers)
+ end
+ end
+
+ def _assert_maker_itunes_subtitle(subtitle, maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_subtitle = subtitle
+ end
+
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(subtitle, target.itunes_subtitle)
+ end
+
+ def assert_maker_itunes_subtitle(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_subtitle("A show about everything",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_subtitle("A short primer on table spices",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_subtitle("Comparing socket wrenches is fun!",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_subtitle("Red + Blue != Purple",
+ maker_readers, feed_readers)
+ end
+ end
+
+ def _assert_maker_itunes_summary(summary, maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_summary = summary
+ end
+
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(summary, target.itunes_summary)
+ end
+
+ def assert_maker_itunes_summary(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_summary("All About Everything is a show about " +
+ "everything. Each week we dive into any " +
+ "subject known to man and talk about it " +
+ "as much as we can. Look for our Podcast " +
+ "in the iTunes Music Store",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_summary("This week we talk about salt and pepper " +
+ "shakers, comparing and contrasting pour " +
+ "rates, construction materials, and " +
+ "overall aesthetics. Come and join the " +
+ "party!",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_summary("This week we talk about metric vs. old " +
+ "english socket wrenches. Which one is " +
+ "better? Do you really need both? Get " +
+ "all of your answers here.",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_summary("This week we talk about surviving in a " +
+ "Red state if you're a Blue person. Or " +
+ "vice versa.",
+ maker_readers, feed_readers)
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_slash.rb b/jni/ruby/test/rss/test_maker_slash.rb
new file mode 100644
index 0000000..ea95a99
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_slash.rb
@@ -0,0 +1,37 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerSlash < TestCase
+ def setup
+ @elements = {
+ "section" => "articles",
+ "department" => "not-an-ocean-unless-there-are-lobsters",
+ "comments" => 177,
+ "hit_parades" => [177, 155, 105, 33, 6, 3, 0],
+ }
+ end
+
+ def test_rss10
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ @elements.each do |name, value|
+ item.send("slash_#{name}=", value)
+ end
+ end
+
+ item = rss.items.last
+ assert_not_nil(item)
+ assert_slash_elements(item)
+ end
+
+ private
+ def assert_slash_elements(target)
+ super(@elements, target)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_sy.rb b/jni/ruby/test/rss/test_maker_sy.rb
new file mode 100644
index 0000000..7117e3a
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_sy.rb
@@ -0,0 +1,44 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerSyndication < TestCase
+
+ def setup
+ @uri = "http://purl.org/rss/1.0/modules/syndication/"
+
+ t = Time.iso8601("2000-01-01T12:00:05+00:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ @elements = {
+ :updatePeriod => "hourly",
+ :updateFrequency => "2",
+ :updateBase => t,
+ }
+ end
+
+ def test_rss10
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ set_elements(maker.channel)
+ setup_dummy_item(maker)
+ end
+ assert_syndication(@elements, rss.channel)
+ end
+
+ private
+ def accessor_name(name)
+ "sy_#{name}"
+ end
+
+ def set_elements(target)
+ @elements.each do |name, value|
+ target.__send__("#{accessor_name(name)}=", value)
+ end
+ end
+
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_taxo.rb b/jni/ruby/test/rss/test_maker_taxo.rb
new file mode 100644
index 0000000..4c4c2e3
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_taxo.rb
@@ -0,0 +1,81 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerTaxonomy < TestCase
+
+ def setup
+ @uri = "http://purl.org/rss/1.0/modules/taxonomy/"
+
+ @resources = [
+ "http://meerkat.oreillynet.com/?c=cat23",
+ "http://meerkat.oreillynet.com/?c=47",
+ "http://dmoz.org/Computers/Data_Formats/Markup_Languages/XML/",
+ ]
+
+ @topics = [
+ {
+ :link => "http://meerkat.oreillynet.com/?c=cat23",
+ :title => "Data: XML",
+ :description => "A Meerkat channel",
+ },
+ {
+ :link => "http://dmoz.org/Computers/Data_Formats/Markup_Languages/XML/",
+ :title => "XML",
+ :subject => "XML",
+ :description => "DMOZ category",
+ :topics => [
+ "http://meerkat.oreillynet.com/?c=cat23",
+ "http://dmoz.org/Computers/Data_Formats/Markup_Languages/SGML/",
+ "http://dmoz.org/Computers/Programming/Internet/",
+ ]
+ },
+ ]
+ end
+
+ def test_rss10
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ set_topics(maker.channel)
+
+ setup_dummy_item(maker)
+ set_topics(maker.items.last)
+
+ setup_taxo_topic(maker, @topics)
+ end
+ assert_equal(@resources, rss.channel.taxo_topics.resources)
+ assert_equal(@resources, rss.items.last.taxo_topics.resources)
+ assert_taxo_topic(@topics, rss)
+ end
+
+ def _test_date
+ t1 = Time.iso8601("2000-01-01T12:00:05+00:00")
+ t2 = Time.iso8601("2005-01-01T12:00:05+00:00")
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.date = t1
+ maker.channel.dc_dates.new_date do |date|
+ date.value = t2
+ end
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ item.date = t2
+ item.dc_dates.new_date do |date|
+ date.value = t1
+ end
+ end
+ assert_equal([t1, t2], rss.channel.dc_dates.collect{|x| x.value})
+ assert_equal([t2, t1], rss.items.last.dc_dates.collect{|x| x.value})
+ end
+
+ private
+ def set_topics(target, resources=@resources)
+ resources.each do |value|
+ target.taxo_topics << value
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_trackback.rb b/jni/ruby/test/rss/test_maker_trackback.rb
new file mode 100644
index 0000000..411bf31
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_trackback.rb
@@ -0,0 +1,41 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerTrackBack < TestCase
+
+ def setup
+ @uri = "http://madskills.com/public/xml/rss/module/trackback/"
+
+ @elements = {
+ :ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
+ :abouts => [
+ "http://foo.com/trackback/tb.cgi?tb_id=20020923",
+ "http://bar.com/trackback/tb.cgi?tb_id=20041114",
+ ],
+ }
+ end
+
+ def test_rss10
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ setup_dummy_item(maker)
+ item = maker.items.last
+ item.trackback_ping = @elements[:ping]
+ @elements[:abouts].each do |about|
+ item.trackback_abouts.new_about do |new_about|
+ new_about.value = about
+ end
+ end
+ end
+ assert_trackback(@elements, rss.items.last)
+ end
+
+ private
+ def accessor_name(name)
+ "trackback_#{name}"
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_maker_xml-stylesheet.rb b/jni/ruby/test/rss/test_maker_xml-stylesheet.rb
new file mode 100644
index 0000000..4f7c62a
--- /dev/null
+++ b/jni/ruby/test/rss/test_maker_xml-stylesheet.rb
@@ -0,0 +1,83 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerXMLStyleSheet < TestCase
+
+ def test_xml_stylesheet
+ href = 'a.xsl'
+ type = 'text/xsl'
+ title = 'sample'
+ media = 'printer'
+ charset = 'UTF-8'
+ alternate = 'yes'
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ xss.href = href
+ xss.type = type
+ xss.title = title
+ xss.media = media
+ xss.charset = charset
+ xss.alternate = alternate
+ end
+
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+ end
+
+ xss = rss.xml_stylesheets.first
+ assert_equal(href, xss.href)
+ assert_equal(type, xss.type)
+ assert_equal(title, xss.title)
+ assert_equal(media, xss.media)
+ assert_equal(charset, xss.charset)
+ assert_equal(alternate, xss.alternate)
+
+
+ href = 'http://example.com/index.xsl'
+ type = 'text/xsl'
+ rss = RSS::Maker.make("1.0") do |maker|
+ maker.xml_stylesheets.new_xml_stylesheet do |_xss|
+ _xss.href = href
+ end
+
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+ end
+
+ xss = rss.xml_stylesheets.first
+ assert_equal(href, xss.href)
+ assert_equal(type, xss.type)
+ end
+
+ def test_not_valid_xml_stylesheet
+ href = 'xss.XXX'
+ type = "text/xsl"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ # xss.href = href
+ xss.type = type
+ end
+
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+ end
+ assert(rss.xml_stylesheets.empty?)
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ xss.href = href
+ # xss.type = type
+ end
+
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+ end
+ assert(rss.xml_stylesheets.empty?)
+ end
+
+ end
+end
diff --git a/jni/ruby/test/rss/test_parser.rb b/jni/ruby/test/rss/test_parser.rb
new file mode 100644
index 0000000..8d8d1e1
--- /dev/null
+++ b/jni/ruby/test/rss/test_parser.rb
@@ -0,0 +1,64 @@
+require "tempfile"
+
+require_relative "rss-testcase"
+
+require "rss/1.0"
+require "rss/dublincore"
+
+module RSS
+ class TestParser < TestCase
+ def setup
+ @_default_parser = Parser.default_parser
+ @rss10 = make_RDF(<<-EOR)
+#{make_channel}
+#{make_item}
+#{make_textinput}
+#{make_image}
+EOR
+ @rss_tmp = Tempfile.new(%w"rss10- .rdf")
+ @rss_tmp.print(@rss10)
+ @rss_tmp.close
+ @rss_file = @rss_tmp.path.untaint
+ end
+
+ def teardown
+ Parser.default_parser = @_default_parser
+ @rss_tmp.close(true)
+ end
+
+ def test_default_parser
+ assert_nothing_raised do
+ Parser.default_parser = RSS::AVAILABLE_PARSERS.first
+ end
+
+ assert_raise(RSS::NotValidXMLParser) do
+ Parser.default_parser = RSS::Parser
+ end
+ end
+
+ def test_parse
+ assert_not_nil(RSS::Parser.parse(@rss_file))
+
+ garbage_rss_file = @rss_file + "-garbage"
+ if RSS::Parser.default_parser.name == "RSS::XMLParserParser"
+ assert_raise(RSS::NotWellFormedError) do
+ RSS::Parser.parse(garbage_rss_file)
+ end
+ else
+ assert_nil(RSS::Parser.parse(garbage_rss_file))
+ end
+ end
+
+ def test_parse_tag_includes_hyphen
+ assert_nothing_raised do
+ RSS::Parser.parse(make_RDF(<<-EOR))
+<xCal:x-calconnect-venue xmlns:xCal="urn:ietf:params:xml:ns:xcal" />
+#{make_channel}
+#{make_item}
+#{make_textinput}
+#{make_image}
+EOR
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_parser_1.0.rb b/jni/ruby/test/rss/test_parser_1.0.rb
new file mode 100644
index 0000000..2efecda
--- /dev/null
+++ b/jni/ruby/test/rss/test_parser_1.0.rb
@@ -0,0 +1,528 @@
+require_relative "rss-testcase"
+
+require "rss/1.0"
+require "rss/dublincore"
+
+module RSS
+ class TestParser10 < TestCase
+ def test_RDF
+ assert_ns("", RDF::URI) do
+ Parser.parse(<<-EOR)
+#{make_xmldecl}
+<RDF/>
+EOR
+ end
+
+ assert_ns("", RDF::URI) do
+ Parser.parse(<<-EOR)
+#{make_xmldecl}
+<RDF xmlns="hoge"/>
+EOR
+ end
+
+ assert_ns("rdf", RDF::URI) do
+ Parser.parse(<<-EOR)
+#{make_xmldecl}
+<rdf:RDF xmlns:rdf="hoge"/>
+EOR
+ end
+
+ assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
+#{make_xmldecl}
+<rdf:RDF xmlns:rdf="#{RSS::RDF::URI}"/>
+EOR
+
+ assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
+#{make_xmldecl}
+<RDF xmlns="#{RSS::RDF::URI}"/>
+EOR
+
+ assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
+#{make_xmldecl}
+<RDF xmlns="#{RSS::RDF::URI}"/>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+#{make_channel}
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+#{make_channel}
+#{make_image}
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+#{make_channel}
+#{make_textinput}
+EOR
+
+ assert_too_much_tag("image", "RDF") do
+ Parser.parse(make_RDF(<<-EOR))
+#{make_channel}
+#{make_image}
+#{make_image}
+#{make_item}
+#{make_textinput}
+EOR
+ end
+
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
+#{make_channel}
+#{make_item}
+#{make_image}
+#{make_textinput}
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
+#{make_channel}
+#{make_item}
+#{make_textinput}
+#{make_image}
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
+#{make_channel}
+#{make_image}
+#{make_item}
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
+#{make_channel}
+#{make_image}
+#{make_item}
+#{make_textinput}
+EOR
+
+ 1.step(15, 3) do |i|
+ rss = make_RDF() do
+ res = make_channel
+ i.times { res << make_item }
+ res
+ end
+ assert_parse(rss, :nothing_raised)
+ end
+ end
+
+ def test_undefined_entity
+ return unless RSS::Parser.default_parser.raise_for_undefined_entity?
+ assert_parse(make_RDF(<<-EOR), :raises, RSS::NotWellFormedError)
+#{make_channel}
+#{make_image}
+<item rdf:about="#{RDF_ABOUT}">
+ <title>#{TITLE_VALUE} &UNKNOWN_ENTITY;</title>
+ <link>#{LINK_VALUE}</link>
+ <description>#{DESCRIPTION_VALUE}</description>
+</item>
+#{make_textinput}
+EOR
+ end
+
+ def test_channel
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "rdf:about")
+<channel />
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "channel")
+<channel rdf:about="http://example.com/"/>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "channel")
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+</channel>
+EOR
+
+ assert_parse(make_RDF(<<EOR), :missing_tag, "description", "channel")
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+ <link>http://example.com/</link>
+</channel>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel")
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+ <link>http://example.com/</link>
+ <description>hogehoge</description>
+</channel>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:resource")
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+ <link>http://example.com/</link>
+ <description>hogehoge</description>
+ <image/>
+</channel>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel")
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+ <link>http://example.com/</link>
+ <description>hogehoge</description>
+ <image rdf:resource="http://example.com/hoge.png" />
+</channel>
+EOR
+
+ rss = make_RDF(<<-EOR)
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+ <link>http://example.com/</link>
+ <description>hogehoge</description>
+ <image rdf:resource="http://example.com/hoge.png" />
+ <items/>
+</channel>
+EOR
+
+ assert_missing_tag("Seq", "items") do
+ Parser.parse(rss)
+ end
+
+ assert_missing_tag("item", "RDF") do
+ Parser.parse(rss, false).validate
+ end
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+ <link>http://example.com/</link>
+ <description>hogehoge</description>
+ <image rdf:resource="http://example.com/hoge.png" />
+ <items>
+ <rdf:Seq>
+ </rdf:Seq>
+ </items>
+</channel>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:resource")
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+ <link>http://example.com/</link>
+ <description>hogehoge</description>
+ <image rdf:resource="http://example.com/hoge.png" />
+ <items>
+ <rdf:Seq>
+ </rdf:Seq>
+ </items>
+ <textinput/>
+</channel>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+ <link>http://example.com/</link>
+ <description>hogehoge</description>
+ <image rdf:resource="http://example.com/hoge.png" />
+ <items>
+ <rdf:Seq>
+ </rdf:Seq>
+ </items>
+ <textinput rdf:resource="http://example.com/search" />
+</channel>
+EOR
+ end
+
+ def test_rdf_li
+ rss = make_RDF(<<-EOR)
+<channel rdf:about="http://example.com/">
+ <title>hoge</title>
+ <link>http://example.com/</link>
+ <description>hogehoge</description>
+ <image rdf:resource="http://example.com/hoge.png" />
+ <items>
+ <rdf:Seq>
+ <rdf:li \#{rdf_li_attr}/>
+ </rdf:Seq>
+ </items>
+ <textinput rdf:resource="http://example.com/search" />
+</channel>
+#{make_item}
+EOR
+
+ source = Proc.new do |rdf_li_attr|
+ eval(%Q[%Q[#{rss}]], binding)
+ end
+
+ attr = %q[resource="http://example.com/hoge"]
+ assert_parse(source.call(attr), :nothing_raised)
+
+ attr = %q[rdf:resource="http://example.com/hoge"]
+ assert_parse(source.call(attr), :nothing_raised)
+
+ assert_parse(source.call(""), :missing_attribute, "li", "resource")
+ end
+
+ def test_image
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:about")
+#{make_channel}
+<image>
+</image>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "image")
+#{make_channel}
+<image rdf:about="http://example.com/hoge.png">
+</image>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "url", "image")
+#{make_channel}
+<image rdf:about="http://example.com/hoge.png">
+ <title>hoge</title>
+</image>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "image")
+#{make_channel}
+<image rdf:about="http://example.com/hoge.png">
+ <title>hoge</title>
+ <url>http://example.com/hoge.png</url>
+</image>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+#{make_channel}
+<image rdf:about="http://example.com/hoge.png">
+ <title>hoge</title>
+ <url>http://example.com/hoge.png</url>
+ <link>http://example.com/</link>
+</image>
+EOR
+
+ rss = make_RDF(<<-EOR)
+#{make_channel}
+<image rdf:about="http://example.com/hoge.png">
+ <link>http://example.com/</link>
+ <url>http://example.com/hoge.png</url>
+ <title>hoge</title>
+</image>
+EOR
+
+ assert_missing_tag("item", "RDF") do
+ Parser.parse(rss)
+ end
+
+ assert_missing_tag("item", "RDF") do
+ Parser.parse(rss, false).validate
+ end
+ end
+
+ def test_item
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "rdf:about")
+#{make_channel}
+#{make_image}
+<item>
+</item>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "item")
+#{make_channel}
+#{make_image}
+<item rdf:about="http://example.com/hoge.html">
+</item>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "item")
+#{make_channel}
+#{make_image}
+<item rdf:about="http://example.com/hoge.html">
+ <title>hoge</title>
+</item>
+EOR
+
+ assert_too_much_tag("title", "item") do
+ Parser.parse(make_RDF(<<-EOR))
+#{make_channel}
+#{make_image}
+<item rdf:about="http://example.com/hoge.html">
+ <title>hoge</title>
+ <title>hoge</title>
+ <link>http://example.com/hoge.html</link>
+</item>
+EOR
+ end
+
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
+#{make_channel}
+#{make_image}
+<item rdf:about="http://example.com/hoge.html">
+ <title>hoge</title>
+ <link>http://example.com/hoge.html</link>
+</item>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
+#{make_channel}
+#{make_image}
+<item rdf:about="http://example.com/hoge.html">
+ <title>hoge</title>
+ <link>http://example.com/hoge.html</link>
+ <description>hogehoge</description>
+</item>
+EOR
+ end
+
+ def test_textinput
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:about")
+#{make_channel}
+#{make_image}
+#{make_item}
+<textinput>
+</textinput>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "textinput")
+#{make_channel}
+#{make_image}
+#{make_item}
+<textinput rdf:about="http://example.com/search.html">
+</textinput>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "description", "textinput")
+#{make_channel}
+#{make_image}
+#{make_item}
+<textinput rdf:about="http://example.com/search.html">
+ <title>hoge</title>
+</textinput>
+EOR
+
+ assert_too_much_tag("title", "textinput") do
+ Parser.parse(make_RDF(<<-EOR))
+#{make_channel}
+#{make_image}
+#{make_item}
+<textinput rdf:about="http://example.com/search.html">
+ <title>hoge</title>
+ <title>hoge</title>
+ <description>hogehoge</description>
+</textinput>
+EOR
+ end
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "name", "textinput")
+#{make_channel}
+#{make_image}
+#{make_item}
+<textinput rdf:about="http://example.com/search.html">
+ <title>hoge</title>
+ <description>hogehoge</description>
+</textinput>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "textinput")
+#{make_channel}
+#{make_image}
+#{make_item}
+<textinput rdf:about="http://example.com/search.html">
+ <title>hoge</title>
+ <description>hogehoge</description>
+ <name>key</name>
+</textinput>
+EOR
+
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
+#{make_channel}
+#{make_image}
+#{make_item}
+<textinput rdf:about="http://example.com/search.html">
+ <title>hoge</title>
+ <description>hogehoge</description>
+ <name>key</name>
+ <link>http://example.com/search.html</link>
+</textinput>
+EOR
+ end
+
+ def test_ignore
+ name = "a"
+ rss = make_RDF(<<-EOR)
+#{make_channel}
+#{make_item}
+<#{name}/>
+EOR
+ assert_not_expected_tag(name, ::RSS::URI, "RDF") do
+ Parser.parse(rss, true, false)
+ end
+
+ uri = ""
+ name = "a"
+ rss = make_RDF(<<-EOR)
+#{make_channel}
+#{make_item}
+<#{name} xmlns=""/>
+EOR
+ assert_parse(rss, :nothing_raised)
+ assert_not_expected_tag(name, uri, "RDF") do
+ Parser.parse(rss, true, false)
+ end
+
+ uri = "http://example.com/"
+ name = "a"
+ rss = make_RDF(<<-EOR)
+#{make_channel}
+#{make_item}
+<x:#{name} xmlns:x="#{uri}"/>
+EOR
+ assert_parse(rss, :nothing_raised)
+ assert_not_expected_tag(name, uri, "RDF") do
+ Parser.parse(rss, true, false)
+ end
+
+ uri = ::RSS::URI
+ name = "a"
+ rss = make_RDF(<<-EOR)
+#{make_channel}
+#{make_item}
+#{make_image("<#{name}/>")}
+EOR
+ assert_parse(rss, :nothing_raised)
+ assert_not_expected_tag(name, uri, "image") do
+ Parser.parse(rss, true, false)
+ end
+
+ uri = CONTENT_URI
+ name = "encoded"
+ elem = "<#{name} xmlns='#{uri}'/>"
+ rss = make_RDF(<<-EOR)
+#{make_channel}
+#{make_item}
+#{make_image(elem)}
+EOR
+ assert_parse(rss, :nothing_raised)
+ assert_not_expected_tag(name, uri, "image") do
+ Parser.parse(rss, true, false)
+ end
+ end
+
+ def test_unknown_duplicated_element
+ xmlns = {"test" => "http://localhost/test"}
+ assert_parse(make_RDF(<<-EOR, xmlns), :nothing_raised)
+ #{make_channel("<test:string/>")}
+ #{make_item}
+ #{make_image}
+ EOR
+ end
+
+ def test_unknown_case_insensitive_duplicated_element
+ xmlns = {
+ "foaf" => "http://xmlns.com/foaf/0.1/",
+ "dc" => "http://purl.org/dc/elements/1.1/",
+ }
+ assert_parse(make_RDF(<<-EOR, xmlns), :nothing_raised)
+ #{make_channel}
+ #{make_item}
+ #{make_image}
+ <foaf:Image rdf:about="http://example.com/myself.png">
+ <dc:title>Myself</dc:title>
+ <dc:link>http://example.com/</dc:link>
+ </foaf:Image>
+ EOR
+ end
+ end
+end
+
diff --git a/jni/ruby/test/rss/test_parser_2.0.rb b/jni/ruby/test/rss/test_parser_2.0.rb
new file mode 100644
index 0000000..68c7d1c
--- /dev/null
+++ b/jni/ruby/test/rss/test_parser_2.0.rb
@@ -0,0 +1,122 @@
+require_relative "rss-testcase"
+
+require "rss/2.0"
+
+module RSS
+ class TestParser20 < TestCase
+ def test_rss20
+ assert_parse(make_rss20(<<-EOR), :missing_tag, "channel", "rss")
+EOR
+
+ assert_parse(make_rss20(<<-EOR), :nothing_raised)
+#{make_channel20("")}
+EOR
+ end
+
+ def test_cloud20
+ attrs = [
+ ["domain", CLOUD_DOMAIN],
+ ["port", CLOUD_PORT],
+ ["path", CLOUD_PATH],
+ ["registerProcedure", CLOUD_REGISTER_PROCEDURE],
+ ["protocol", CLOUD_PROTOCOL],
+ ]
+
+ (attrs.size + 1).times do |i|
+ missing_attr = attrs[i]
+ if missing_attr
+ meth = :missing_attribute
+ args = ["cloud", missing_attr[0]]
+ else
+ meth = :nothing_raised
+ args = []
+ end
+
+ cloud_attrs = []
+ attrs.each_with_index do |attr, j|
+ unless i == j
+ cloud_attrs << %Q[#{attr[0]}="#{attr[1]}"]
+ end
+ end
+
+ assert_parse(make_rss20(<<-EOR), meth, *args)
+#{make_channel20(%Q[<cloud #{cloud_attrs.join("\n")}/>])}
+EOR
+ end
+ end
+
+ def test_source20
+ assert_parse(make_rss20(<<-EOR), :missing_attribute, "source", "url")
+#{make_channel20(make_item20(%Q[<source>Example</source>]))}
+EOR
+
+ assert_parse(make_rss20(<<-EOR), :nothing_raised)
+#{make_channel20(make_item20(%Q[<source url="http://example.com/" />]))}
+EOR
+
+ assert_parse(make_rss20(<<-EOR), :nothing_raised)
+#{make_channel20(make_item20(%Q[<source url="http://example.com/">Example</source>]))}
+EOR
+ end
+
+ def test_enclosure20
+ attrs = [
+ ["url", ENCLOSURE_URL],
+ ["length", ENCLOSURE_LENGTH],
+ ["type", ENCLOSURE_TYPE],
+ ]
+
+ (attrs.size + 1).times do |i|
+ missing_attr = attrs[i]
+ if missing_attr
+ meth = :missing_attribute
+ args = ["enclosure", missing_attr[0]]
+ else
+ meth = :nothing_raised
+ args = []
+ end
+
+ enclosure_attrs = []
+ attrs.each_with_index do |attr, j|
+ unless i == j
+ enclosure_attrs << %Q[#{attr[0]}="#{attr[1]}"]
+ end
+ end
+
+ assert_parse(make_rss20(<<-EOR), meth, *args)
+#{make_channel20(%Q[
+#{make_item20(%Q[
+<enclosure
+ #{enclosure_attrs.join("\n")} />
+ ])}
+ ])}
+EOR
+ end
+ end
+
+ def test_category20
+ values = [nil, CATEGORY_DOMAIN]
+ values.each do |value|
+ domain = ""
+ domain << %Q[domain="#{value}"] if value
+
+ ["", "Example Text"].each do |text|
+ rss_src = make_rss20(<<-EOR)
+#{make_channel20(%Q[
+#{make_item20(%Q[
+<category #{domain}>#{text}</category>
+ ])}
+ ])}
+EOR
+ assert_parse(rss_src, :nothing_raised)
+
+ rss = RSS::Parser.parse(rss_src)
+ category = rss.items.last.categories.first
+ assert_equal(value, category.domain)
+ assert_equal(text, category.content)
+ end
+ end
+ end
+ end
+end
+
diff --git a/jni/ruby/test/rss/test_parser_atom_entry.rb b/jni/ruby/test/rss/test_parser_atom_entry.rb
new file mode 100644
index 0000000..352fbbe
--- /dev/null
+++ b/jni/ruby/test/rss/test_parser_atom_entry.rb
@@ -0,0 +1,163 @@
+require_relative "rss-testcase"
+
+require "rss/atom"
+
+module RSS
+ class TestParserAtom < TestCase
+ def test_entry_validation
+ assert_ns("", Atom::URI) do
+ Parser.parse(<<-EOA)
+<entry/>
+EOA
+ end
+
+ assert_ns("", Atom::URI) do
+ Parser.parse(<<-EOA)
+<entry xmlns="hoge"/>
+EOA
+ end
+
+ assert_parse(<<-EOA, :missing_tag, "id", "entry") do
+<entry xmlns="#{Atom::URI}"/>
+EOA
+ end
+
+ assert_parse(<<-EOA, :missing_tag, "title", "entry") do
+<entry xmlns="#{Atom::URI}">
+ <id>urn:uuid:506e336c-a26e-4457-917b-b89dca7ae746</id>
+</entry>
+EOA
+ end
+
+ assert_parse(<<-EOA, :missing_tag, "updated", "entry") do
+<entry xmlns="#{Atom::URI}">
+ <id>urn:uuid:506e336c-a26e-4457-917b-b89dca7ae746</id>
+ <title>Example Entry</title>
+</entry>
+EOA
+ end
+
+ assert_parse(<<-EOA, :missing_tag, "author", "entry") do
+<entry xmlns="#{Atom::URI}">
+ <id>urn:uuid:506e336c-a26e-4457-917b-b89dca7ae746</id>
+ <title>Example Entry</title>
+ <updated>2003-10-10T18:30:02Z</updated>
+</entry>
+EOA
+ end
+
+ assert_parse(<<-EOA, :nothing_raised) do
+<entry xmlns="#{Atom::URI}">
+ <id>urn:uuid:506e336c-a26e-4457-917b-b89dca7ae746</id>
+ <title>Example Entry</title>
+ <updated>2003-10-10T18:30:02Z</updated>
+ <author>
+ <name>A person</name>
+ </author>
+</entry>
+EOA
+ end
+ end
+
+ def test_entry
+ entry = RSS::Parser.parse(<<-EOA)
+<?xml version="1.0" encoding="utf-8"?>
+<entry xmlns="http://www.w3.org/2005/Atom">
+ <author>
+ <name>A person</name>
+ </author>
+ <title>Atom-Powered Robots Run Amok</title>
+ <link href="http://example.org/2003/12/13/atom03"/>
+ <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
+ <updated>2003-12-13T18:30:02Z</updated>
+ <summary>Some text.</summary>
+</entry>
+EOA
+ assert_not_nil(entry)
+ assert_equal("Atom-Powered Robots Run Amok", entry.title.content)
+ assert_equal("http://example.org/2003/12/13/atom03", entry.link.href)
+ assert_equal("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a",
+ entry.id.content)
+ assert_equal(Time.parse("2003-12-13T18:30:02Z"), entry.updated.content)
+ assert_equal("Some text.", entry.summary.content)
+ end
+
+ def test_entry_author
+ assert_atom_person("author", method(:make_entry_document)) do |entry|
+ assert_equal(2, entry.authors.size)
+ entry.authors.last
+ end
+ end
+
+ def test_entry_category
+ assert_atom_category(method(:make_entry_document)) do |entry|
+ assert_equal(1, entry.categories.size)
+ entry.category
+ end
+ end
+
+ def test_entry_content_text
+ assert_atom_content(method(:make_entry_document)) do |entry|
+ entry.content
+ end
+ end
+
+ def test_entry_contributor
+ assert_atom_person("contributor", method(:make_entry_document)) do |entry|
+ assert_equal(1, entry.contributors.size)
+ entry.contributor
+ end
+ end
+
+ def test_entry_id
+ entry = RSS::Parser.parse(make_entry_document)
+ assert_equal(ENTRY_ID, entry.id.content)
+ end
+
+ def test_entry_link
+ assert_atom_link(method(:make_entry_document)) do |entry|
+ assert_equal(1, entry.links.size)
+ entry.link
+ end
+ end
+
+ def test_published
+ generator = method(:make_entry_document)
+ assert_atom_date_construct("published", generator) do |entry|
+ entry.published
+ end
+ end
+
+ def test_entry_rights
+ generator = method(:make_entry_document)
+ assert_atom_text_construct("rights", generator) do |entry|
+ entry.rights
+ end
+ end
+
+ def test_entry_source
+ generator = method(:make_entry_document_with_open_source)
+ assert_atom_source(generator) do |entry|
+ assert_not_nil(entry.source)
+ entry.source
+ end
+ end
+
+ def test_entry_summary
+ generator = method(:make_entry_document)
+ assert_atom_text_construct("summary", generator) do |entry|
+ entry.summary
+ end
+ end
+
+ def test_entry_title
+ entry = RSS::Parser.parse(make_entry_document)
+ assert_equal(ENTRY_TITLE, entry.title.content)
+ end
+
+ def test_entry_updated
+ entry = RSS::Parser.parse(make_entry_document)
+ assert_equal(Time.parse(ENTRY_UPDATED), entry.updated.content)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_parser_atom_feed.rb b/jni/ruby/test/rss/test_parser_atom_feed.rb
new file mode 100644
index 0000000..a5731b2
--- /dev/null
+++ b/jni/ruby/test/rss/test_parser_atom_feed.rb
@@ -0,0 +1,276 @@
+require_relative "rss-testcase"
+
+require "rss/atom"
+
+module RSS
+ class TestParserAtomFeed < TestCase
+ def test_feed_validation
+ assert_ns("", Atom::URI) do
+ Parser.parse(<<-EOA)
+<feed/>
+EOA
+ end
+
+ assert_ns("", Atom::URI) do
+ Parser.parse(<<-EOA)
+<feed xmlns="hoge"/>
+EOA
+ end
+
+ assert_parse(<<-EOA, :missing_tag, "id", "feed") do
+<feed xmlns="#{Atom::URI}"/>
+EOA
+ end
+
+ assert_parse(<<-EOA, :missing_tag, "title", "feed") do
+<feed xmlns="#{Atom::URI}">
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
+</feed>
+EOA
+ end
+
+ assert_parse(<<-EOA, :missing_tag, "updated", "feed") do
+<feed xmlns="#{Atom::URI}">
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
+ <title>Example Feed</title>
+</feed>
+EOA
+ end
+
+ assert_parse(<<-EOA, :missing_tag, "author", "feed") do
+<feed xmlns="#{Atom::URI}">
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
+ <title>Example Feed</title>
+ <updated>2003-12-13T18:30:02Z</updated>
+</feed>
+EOA
+ end
+
+ assert_parse(<<-EOA, :nothing_raised) do
+<feed xmlns="#{Atom::URI}">
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
+ <title>Example Feed</title>
+ <updated>2003-12-13T18:30:02Z</updated>
+ <author>
+ <name>A person</name>
+ </author>
+</feed>
+EOA
+ end
+ end
+
+ def test_lang
+ feed = RSS::Parser.parse(<<-EOA)
+<feed xmlns="#{Atom::URI}" xml:lang="ja">
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
+ <title xml:lang="en">Example Feed</title>
+ <updated>2003-12-13T18:30:02Z</updated>
+ <author xml:lang="en">
+ <name>A person</name>
+ </author>
+</feed>
+EOA
+
+ assert_equal("ja", feed.lang)
+ assert_equal("ja", feed.id.lang)
+ assert_equal("en", feed.title.lang)
+ assert_equal("ja", feed.updated.lang)
+ assert_equal("en", feed.author.lang)
+ assert_equal("en", feed.author.name.lang)
+ end
+
+ def test_base
+ feed = RSS::Parser.parse(<<-EOA)
+<feed xmlns="#{Atom::URI}" xml:base="http://example.com/">
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
+ <title xml:lang="en">Example Feed</title>
+ <updated>2003-12-13T18:30:02Z</updated>
+ <generator uri="generator">Generator</generator>
+ <link hreflang="ja" href="http://example.org/link1"/>
+ <link hreflang="en" href="link2"/>
+ <link hreflang="fr" xml:base="http://example.net/" href="link3"/>
+ <author>
+ <name>A person</name>
+ <uri>person</uri>
+ </author>
+</feed>
+EOA
+
+ assert_equal("http://example.com/", feed.base)
+ assert_equal("http://example.com/", feed.id.base)
+ assert_equal("http://example.com/", feed.title.base)
+ assert_equal("http://example.com/", feed.updated.base)
+ assert_equal("http://example.com/", feed.generator.base)
+ assert_equal("http://example.com/generator", feed.generator.uri)
+
+ assert_equal("http://example.com/", feed.links[0].base)
+ assert_equal("http://example.org/link1", feed.links[0].href)
+ assert_equal("http://example.com/", feed.links[1].base)
+ assert_equal("http://example.com/link2", feed.links[1].href)
+ assert_equal("http://example.net/", feed.links[2].base)
+ assert_equal("http://example.net/link3", feed.links[2].href)
+ assert_equal("http://example.com/person", feed.author.uri.content)
+ end
+
+ def test_feed_author
+ assert_atom_person("author", method(:make_feed)) do |feed|
+ assert_equal(2, feed.authors.size)
+ feed.authors[1]
+ end
+ end
+
+ def test_entry_author
+ generator = method(:make_feed_with_open_entry)
+ assert_atom_person("author", generator) do |feed|
+ assert_equal(1, feed.entries.size)
+ assert_equal(1, feed.entry.authors.size)
+ feed.entry.author
+ end
+ end
+
+ def test_feed_category
+ assert_atom_category(method(:make_feed)) do |feed|
+ assert_equal(1, feed.categories.size)
+ feed.category
+ end
+ end
+
+ def test_entry_category
+ assert_atom_category(method(:make_feed_with_open_entry)) do |feed|
+ assert_equal(1, feed.entries.size)
+ assert_equal(1, feed.entry.categories.size)
+ feed.entry.category
+ end
+ end
+
+ def test_entry_content
+ assert_atom_content(method(:make_feed_with_open_entry)) do |feed|
+ assert_equal(1, feed.entries.size)
+ feed.entry.content
+ end
+ end
+
+ def test_feed_contributor
+ assert_atom_person("contributor", method(:make_feed)) do |feed|
+ assert_equal(1, feed.contributors.size)
+ feed.contributor
+ end
+ end
+
+ def test_entry_contributor
+ generator = method(:make_feed_with_open_entry)
+ assert_atom_person("contributor", generator) do |feed|
+ assert_equal(1, feed.entries.size)
+ assert_equal(1, feed.entry.contributors.size)
+ feed.entry.contributor
+ end
+ end
+
+ def test_feed_generator
+ assert_atom_generator(method(:make_feed)) do |feed|
+ feed.generator
+ end
+ end
+
+ def test_feed_icon
+ assert_atom_icon(method(:make_feed)) do |feed|
+ feed.icon
+ end
+ end
+
+ def test_feed_id
+ feed = RSS::Parser.parse(make_feed(''))
+ assert_equal(FEED_ID, feed.id.content)
+ end
+
+ def test_entry_id
+ feed = RSS::Parser.parse(make_feed(''))
+ assert_equal(ENTRY_ID, feed.entry.id.content)
+ end
+
+ def test_feed_link
+ assert_atom_link(method(:make_feed)) do |feed|
+ assert_equal(1, feed.links.size)
+ feed.link
+ end
+ end
+
+ def test_entry_link
+ assert_atom_link(method(:make_feed_with_open_entry)) do |feed|
+ assert_equal(1, feed.entries.size)
+ assert_equal(1, feed.entry.links.size)
+ feed.entry.link
+ end
+ end
+
+ def test_feed_logo
+ assert_atom_logo(method(:make_feed)) do |feed|
+ feed.logo
+ end
+ end
+
+ def test_feed_rights
+ assert_atom_text_construct("rights", method(:make_feed)) do |feed|
+ feed.rights
+ end
+ end
+
+ def test_entry_rights
+ generator = method(:make_feed_with_open_entry)
+ assert_atom_text_construct("rights", generator) do |feed|
+ assert_equal(1, feed.entries.size)
+ feed.entry.rights
+ end
+ end
+
+ def test_entry_source
+ assert_atom_source(method(:make_feed_with_open_entry_source)) do |feed|
+ assert_equal(1, feed.entries.size)
+ assert_not_nil(feed.entry.source)
+ feed.entry.source
+ end
+ end
+
+ def test_feed_subtitle
+ assert_atom_text_construct("subtitle", method(:make_feed)) do |feed|
+ feed.subtitle
+ end
+ end
+
+ def test_feed_title
+ feed = RSS::Parser.parse(make_feed(''))
+ assert_equal(FEED_TITLE, feed.title.content)
+ end
+
+ def test_entry_title
+ feed = RSS::Parser.parse(make_feed(''))
+ assert_equal(ENTRY_TITLE, feed.entry.title.content)
+ end
+
+ def test_feed_updated
+ feed = RSS::Parser.parse(make_feed(''))
+ assert_equal(Time.parse(FEED_UPDATED), feed.updated.content)
+ end
+
+ def test_entry_updated
+ feed = RSS::Parser.parse(make_feed(''))
+ assert_equal(Time.parse(ENTRY_UPDATED), feed.entry.updated.content)
+ end
+
+ def test_entry_published
+ generator = method(:make_feed_with_open_entry)
+ assert_atom_date_construct("published", generator) do |feed|
+ assert_equal(1, feed.entries.size)
+ feed.entry.published
+ end
+ end
+
+ def test_entry_summary
+ generator = method(:make_feed_with_open_entry)
+ assert_atom_text_construct("summary", generator) do |feed|
+ assert_equal(1, feed.entries.size)
+ feed.entry.summary
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_setup_maker_0.9.rb b/jni/ruby/test/rss/test_setup_maker_0.9.rb
new file mode 100644
index 0000000..2714b9c
--- /dev/null
+++ b/jni/ruby/test/rss/test_setup_maker_0.9.rb
@@ -0,0 +1,246 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestSetupMaker09 < TestCase
+
+ def test_setup_maker_channel
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+ language = "ja"
+ copyright = "foo"
+ managingEditor = "bar"
+ webMaster = "web master"
+ rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
+ docs = "http://foo.com/doc"
+ skipDays = [
+ "Sunday",
+ "Monday",
+ ]
+ skipHours = [
+ "0",
+ "13",
+ ]
+ pubDate = Time.now
+ lastBuildDate = Time.now
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ maker.channel.language = language
+ maker.channel.copyright = copyright
+ maker.channel.managingEditor = managingEditor
+ maker.channel.webMaster = webMaster
+ maker.channel.rating = rating
+ maker.channel.docs = docs
+ maker.channel.pubDate = pubDate
+ maker.channel.lastBuildDate = lastBuildDate
+
+ skipDays.each do |day|
+ maker.channel.skipDays.new_day do |new_day|
+ new_day.content = day
+ end
+ end
+ skipHours.each do |hour|
+ maker.channel.skipHours.new_hour do |new_hour|
+ new_hour.content = hour
+ end
+ end
+
+ setup_dummy_image(maker)
+ end
+
+ assert_not_set_error("maker.image", %w(title url)) do
+ RSS::Maker.make("0.91") do |maker|
+ rss.channel.setup_maker(maker)
+ end
+ end
+
+ new_rss = RSS::Maker.make("0.91") do |maker|
+ rss.channel.setup_maker(maker)
+ setup_dummy_image(maker)
+ end
+ channel = new_rss.channel
+
+ assert_equal(title, channel.title)
+ assert_equal(link, channel.link)
+ assert_equal(description, channel.description)
+ assert_equal(language, channel.language)
+ assert_equal(copyright, channel.copyright)
+ assert_equal(managingEditor, channel.managingEditor)
+ assert_equal(webMaster, channel.webMaster)
+ assert_equal(rating, channel.rating)
+ assert_equal(docs, channel.docs)
+ assert_equal(pubDate, channel.pubDate)
+ assert_equal(lastBuildDate, channel.lastBuildDate)
+
+ skipDays.each_with_index do |day, i|
+ assert_equal(day, channel.skipDays.days[i].content)
+ end
+ skipHours.each_with_index do |hour, i|
+ assert_equal(hour.to_i, channel.skipHours.hours[i].content)
+ end
+
+ assert(channel.items.empty?)
+ assert_nil(channel.textInput)
+ end
+
+ def test_setup_maker_image
+ title = "fugafuga"
+ link = "http://hoge.com"
+ url = "http://hoge.com/hoge.png"
+ width = "144"
+ height = "400"
+ description = "an image"
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+
+ new_rss = RSS::Maker.make("0.91") do |maker|
+ rss.channel.setup_maker(maker)
+ rss.image.setup_maker(maker)
+ end
+
+ image = new_rss.image
+ assert_equal(title, image.title)
+ assert_equal(link, image.link)
+ assert_equal(url, image.url)
+ assert_equal(width.to_i, image.width)
+ assert_equal(height.to_i, image.height)
+ assert_equal(description, image.description)
+ end
+
+ def test_setup_maker_textinput
+ title = "fugafuga"
+ description = "text hoge fuga"
+ name = "hoge"
+ link = "http://hoge.com"
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+
+ new_rss = RSS::Maker.make("0.91") do |maker|
+ rss.channel.setup_maker(maker)
+ rss.image.setup_maker(maker)
+ rss.textinput.setup_maker(maker)
+ end
+
+ textInput = new_rss.channel.textInput
+ assert_equal(title, textInput.title)
+ assert_equal(description, textInput.description)
+ assert_equal(name, textInput.name)
+ assert_equal(link, textInput.link)
+ end
+
+ def test_setup_maker_items(for_backward_compatibility=false)
+ title = "TITLE"
+ link = "http://hoge.com/"
+ description = "text hoge fuga"
+
+ item_size = 5
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |item|
+ item.title = "#{title}#{i}"
+ item.link = "#{link}#{i}"
+ item.description = "#{description}#{i}"
+ end
+ end
+
+ setup_dummy_image(maker)
+ end
+
+ new_rss = RSS::Maker.make("0.91") do |maker|
+ rss.channel.setup_maker(maker)
+
+ rss.items.each do |item|
+ if for_backward_compatibility
+ item.setup_maker(maker)
+ else
+ item.setup_maker(maker.items)
+ end
+ end
+
+ rss.image.setup_maker(maker)
+ end
+
+ assert_equal(item_size, new_rss.items.size)
+ new_rss.items.each_with_index do |item, i|
+ assert_equal("#{title}#{i}", item.title)
+ assert_equal("#{link}#{i}", item.link)
+ assert_equal("#{description}#{i}", item.description)
+ end
+ end
+
+ def test_setup_maker_items_backward_compatibility
+ test_setup_maker_items(true)
+ end
+
+ def test_setup_maker
+ encoding = "EUC-JP"
+ standalone = true
+
+ href = 'a.xsl'
+ type = 'text/xsl'
+ title = 'sample'
+ media = 'printer'
+ charset = 'UTF-8'
+ alternate = 'yes'
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ maker.encoding = encoding
+ maker.standalone = standalone
+
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ xss.href = href
+ xss.type = type
+ xss.title = title
+ xss.media = media
+ xss.charset = charset
+ xss.alternate = alternate
+ end
+
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+ end
+
+ new_rss = RSS::Maker.make("0.91") do |maker|
+ rss.setup_maker(maker)
+ end
+
+ assert_equal("0.91", new_rss.rss_version)
+ assert_equal(encoding, new_rss.encoding)
+ assert_equal(standalone, new_rss.standalone)
+
+ xss = rss.xml_stylesheets.first
+ assert_equal(1, rss.xml_stylesheets.size)
+ assert_equal(href, xss.href)
+ assert_equal(type, xss.type)
+ assert_equal(title, xss.title)
+ assert_equal(media, xss.media)
+ assert_equal(charset, xss.charset)
+ assert_equal(alternate, xss.alternate)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_setup_maker_1.0.rb b/jni/ruby/test/rss/test_setup_maker_1.0.rb
new file mode 100644
index 0000000..0408ca9
--- /dev/null
+++ b/jni/ruby/test/rss/test_setup_maker_1.0.rb
@@ -0,0 +1,550 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestSetupMaker10 < TestCase
+
+ def setup
+ t = Time.iso8601("2000-01-01T12:00:05+00:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ @dc_elems = {
+ :title => "hoge",
+ :description =>
+ " XML is placing increasingly heavy loads on
+ the existing technical infrastructure of the Internet.",
+ :creator => "Rael Dornfest (mailto:rael@oreilly.com)",
+ :subject => "XML",
+ :publisher => "The O'Reilly Network",
+ :contributor => "hogehoge",
+ :type => "fugafuga",
+ :format => "hohoho",
+ :identifier => "fufufu",
+ :source => "barbar",
+ :language => "ja",
+ :relation => "cococo",
+ :rights => "Copyright (c) 2000 O'Reilly &amp; Associates, Inc.",
+ :date => t,
+ }
+
+ @sy_elems = {
+ :updatePeriod => "hourly",
+ :updateFrequency => "2",
+ :updateBase => t,
+ }
+
+ @content_elems = {
+ :encoded => "<em>ATTENTION</em>",
+ }
+
+ @trackback_elems = {
+ :ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
+ :about => [
+ "http://foo.com/trackback/tb.cgi?tb_id=20020923",
+ "http://foo.com/trackback/tb.cgi?tb_id=20021010",
+ ],
+ }
+
+ @taxo_topic_elems = [
+ {
+ :link => "http://meerkat.oreillynet.com/?c=cat23",
+ :title => "Data: XML",
+ :description => "A Meerkat channel",
+ },
+ {
+ :link => "http://dmoz.org/Computers/Data_Formats/Markup_Languages/XML/",
+ :title => "XML",
+ :subject => "XML",
+ :description => "DMOZ category",
+ :topics => [
+ "http://meerkat.oreillynet.com/?c=cat23",
+ "http://dmoz.org/Computers/Data_Formats/Markup_Languages/SGML/",
+ "http://dmoz.org/Computers/Programming/Internet/",
+ ]
+ },
+ ]
+ end
+
+ def test_setup_maker_channel
+ about = "http://hoge.com"
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ maker.channel.about = about
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+
+ @dc_elems.each do |var, value|
+ maker.channel.__send__("dc_#{var}=", value)
+ end
+
+ @sy_elems.each do |var, value|
+ maker.channel.__send__("sy_#{var}=", value)
+ end
+
+ setup_dummy_item(maker)
+ end
+
+ new_rss = RSS::Maker.make("1.0") do |maker|
+ rss.channel.setup_maker(maker)
+ rss.items.each do |item|
+ item.setup_maker(maker)
+ end
+ end
+ channel = new_rss.channel
+
+ assert_equal(about, channel.about)
+ assert_equal(title, channel.title)
+ assert_equal(link, channel.link)
+ assert_equal(description, channel.description)
+ assert_equal(1, channel.items.Seq.lis.size)
+ assert_nil(channel.image)
+ assert_nil(channel.textinput)
+
+ @dc_elems.each do |var, value|
+ assert_equal(value, channel.__send__("dc_#{var}"))
+ end
+
+ @sy_elems.each do |var, value|
+ value = value.to_i if var == :updateFrequency
+ assert_equal(value, channel.__send__("sy_#{var}"))
+ end
+
+ end
+
+ def test_setup_maker_image
+ title = "fugafuga"
+ link = "http://hoge.com"
+ url = "http://hoge.com/hoge.png"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ maker.image.url = url
+
+ @dc_elems.each do |var, value|
+ maker.image.__send__("dc_#{var}=", value)
+ end
+
+ setup_dummy_item(maker)
+ end
+
+ new_rss = RSS::Maker.make("1.0") do |maker|
+ rss.channel.setup_maker(maker)
+ rss.image.setup_maker(maker)
+ rss.items.each do |item|
+ item.setup_maker(maker)
+ end
+ end
+
+ image = new_rss.image
+ assert_equal(url, image.about)
+ assert_equal(url, new_rss.channel.image.resource)
+ assert_equal(title, image.title)
+ assert_equal(link, image.link)
+ assert_equal(url, image.url)
+
+ @dc_elems.each do |var, value|
+ assert_equal(image.__send__("dc_#{var}"), value)
+ end
+ end
+
+ def test_setup_maker_textinput
+ title = "fugafuga"
+ description = "text hoge fuga"
+ name = "hoge"
+ link = "http://hoge.com"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.textinput.link = link
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+
+ @dc_elems.each do |var, value|
+ maker.textinput.__send__("dc_#{var}=", value)
+ end
+
+ setup_dummy_item(maker)
+ end
+
+ new_rss = RSS::Maker.make("1.0") do |maker|
+ rss.channel.setup_maker(maker)
+ rss.textinput.setup_maker(maker)
+ rss.items.each do |item|
+ item.setup_maker(maker)
+ end
+ end
+
+ textinput = new_rss.textinput
+ assert_equal(link, textinput.about)
+ assert_equal(link, new_rss.channel.textinput.resource)
+ assert_equal(title, textinput.title)
+ assert_equal(name, textinput.name)
+ assert_equal(description, textinput.description)
+ assert_equal(link, textinput.link)
+
+ @dc_elems.each do |var, value|
+ assert_equal(textinput.__send__("dc_#{var}"), value)
+ end
+ end
+
+ def test_setup_maker_items(for_backward_compatibility=false)
+ title = "TITLE"
+ link = "http://hoge.com/"
+ description = "text hoge fuga"
+
+ item_size = 5
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |item|
+ item.title = "#{title}#{i}"
+ item.link = "#{link}#{i}"
+ item.description = "#{description}#{i}"
+
+ @dc_elems.each do |var, value|
+ item.__send__("dc_#{var}=", value)
+ end
+
+ @content_elems.each do |var, value|
+ item.__send__("content_#{var}=", value)
+ end
+
+ item.trackback_ping = @trackback_elems[:ping]
+ @trackback_elems[:about].each do |value|
+ item.trackback_abouts.new_about do |new_about|
+ new_about.value = value
+ end
+ end
+ end
+ end
+ end
+
+ new_rss = RSS::Maker.make("1.0") do |maker|
+ rss.channel.setup_maker(maker)
+
+ rss.items.each do |item|
+ if for_backward_compatibility
+ item.setup_maker(maker)
+ else
+ item.setup_maker(maker.items)
+ end
+ end
+ end
+
+ assert_equal(item_size, new_rss.items.size)
+ new_rss.items.each_with_index do |item, i|
+ assert_equal("#{link}#{i}", item.about)
+ assert_equal("#{title}#{i}", item.title)
+ assert_equal("#{link}#{i}", item.link)
+ assert_equal("#{description}#{i}", item.description)
+
+ @dc_elems.each do |var, value|
+ assert_equal(item.__send__("dc_#{var}"), value)
+ end
+
+ @content_elems.each do |var, value|
+ assert_equal(item.__send__("content_#{var}"), value)
+ end
+
+ assert_equal(@trackback_elems[:ping], item.trackback_ping)
+ assert_equal(@trackback_elems[:about].size, item.trackback_abouts.size)
+ item.trackback_abouts.each_with_index do |about, j|
+ assert_equal(@trackback_elems[:about][j], about.value)
+ end
+ end
+ end
+
+ def test_setup_maker_items_sort
+ title = "TITLE"
+ link = "http://hoge.com/"
+ description = "text hoge fuga"
+
+ item_size = 5
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ item = RSS::RDF::Item.new("#{link}#{i}")
+ item.title = "#{title}#{i}"
+ item.link = "#{link}#{i}"
+ item.description = "#{description}#{i}"
+ item.dc_date = Time.now + i * 60
+ item.setup_maker(maker.items)
+ end
+ maker.items.do_sort = false
+ end
+ assert_equal(item_size, rss.items.size)
+ rss.items.each_with_index do |item, i|
+ assert_equal("#{link}#{i}", item.about)
+ assert_equal("#{title}#{i}", item.title)
+ assert_equal("#{link}#{i}", item.link)
+ assert_equal("#{description}#{i}", item.description)
+ end
+
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ item = RSS::RDF::Item.new("#{link}#{i}")
+ item.title = "#{title}#{i}"
+ item.link = "#{link}#{i}"
+ item.description = "#{description}#{i}"
+ item.dc_date = Time.now + i * 60
+ item.setup_maker(maker.items)
+ end
+ maker.items.do_sort = true
+ end
+ assert_equal(item_size, rss.items.size)
+ rss.items.reverse.each_with_index do |item, i|
+ assert_equal("#{link}#{i}", item.about)
+ assert_equal("#{title}#{i}", item.title)
+ assert_equal("#{link}#{i}", item.link)
+ assert_equal("#{description}#{i}", item.description)
+ end
+ end
+
+ def test_setup_maker_items_backward_compatibility
+ test_setup_maker_items(true)
+ end
+
+ def test_setup_maker
+ encoding = "EUC-JP"
+ standalone = true
+
+ href = 'a.xsl'
+ type = 'text/xsl'
+ title = 'sample'
+ media = 'printer'
+ charset = 'UTF-8'
+ alternate = 'yes'
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ maker.encoding = encoding
+ maker.standalone = standalone
+
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ xss.href = href
+ xss.type = type
+ xss.title = title
+ xss.media = media
+ xss.charset = charset
+ xss.alternate = alternate
+ end
+
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+ end
+
+ new_rss = RSS::Maker.make("1.0") do |maker|
+ rss.setup_maker(maker)
+ end
+
+ assert_equal("1.0", new_rss.rss_version)
+ assert_equal(encoding, new_rss.encoding)
+ assert_equal(standalone, new_rss.standalone)
+
+ xss = new_rss.xml_stylesheets.first
+ assert_equal(1, new_rss.xml_stylesheets.size)
+ assert_equal(href, xss.href)
+ assert_equal(type, xss.type)
+ assert_equal(title, xss.title)
+ assert_equal(media, xss.media)
+ assert_equal(charset, xss.charset)
+ assert_equal(alternate, xss.alternate)
+ end
+
+ def test_setup_maker_full
+ encoding = "EUC-JP"
+ standalone = true
+
+ href = 'a.xsl'
+ type = 'text/xsl'
+ title = 'sample'
+ media = 'printer'
+ charset = 'UTF-8'
+ alternate = 'yes'
+
+ channel_about = "http://hoge.com"
+ channel_title = "fugafuga"
+ channel_link = "http://hoge.com"
+ channel_description = "fugafugafugafuga"
+
+ image_title = "fugafuga"
+ image_url = "http://hoge.com/hoge.png"
+
+ textinput_title = "fugafuga"
+ textinput_description = "text hoge fuga"
+ textinput_name = "hoge"
+ textinput_link = "http://hoge.com"
+
+ item_title = "TITLE"
+ item_link = "http://hoge.com/"
+ item_description = "text hoge fuga"
+
+ item_size = 5
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ maker.encoding = encoding
+ maker.standalone = standalone
+
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ xss.href = href
+ xss.type = type
+ xss.title = title
+ xss.media = media
+ xss.charset = charset
+ xss.alternate = alternate
+ end
+
+ maker.channel.about = channel_about
+ maker.channel.title = channel_title
+ maker.channel.link = channel_link
+ maker.channel.description = channel_description
+ @dc_elems.each do |var, value|
+ maker.channel.__send__("dc_#{var}=", value)
+ end
+ @sy_elems.each do |var, value|
+ maker.channel.__send__("sy_#{var}=", value)
+ end
+
+ maker.image.title = image_title
+ maker.image.url = image_url
+ @dc_elems.each do |var, value|
+ maker.image.__send__("dc_#{var}=", value)
+ end
+
+ maker.textinput.link = textinput_link
+ maker.textinput.title = textinput_title
+ maker.textinput.description = textinput_description
+ maker.textinput.name = textinput_name
+ @dc_elems.each do |var, value|
+ maker.textinput.__send__("dc_#{var}=", value)
+ end
+
+ item_size.times do |i|
+ maker.items.new_item do |item|
+ item.title = "#{item_title}#{i}"
+ item.link = "#{item_link}#{i}"
+ item.description = "#{item_description}#{i}"
+
+ @dc_elems.each do |var, value|
+ item.__send__("dc_#{var}=", value)
+ end
+
+ @content_elems.each do |var, value|
+ item.__send__("content_#{var}=", value)
+ end
+
+ item.trackback_ping = @trackback_elems[:ping]
+ @trackback_elems[:about].each do |value|
+ item.trackback_abouts.new_about do |new_about|
+ new_about.value = value
+ end
+ end
+ end
+ end
+
+ setup_taxo_topic(maker, @taxo_topic_elems)
+ end
+
+ new_rss = RSS::Maker.make("1.0") do |maker|
+ rss.setup_maker(maker)
+ end
+
+ assert_equal("1.0", new_rss.rss_version)
+ assert_equal(encoding, new_rss.encoding)
+ assert_equal(standalone, new_rss.standalone)
+
+ xss = new_rss.xml_stylesheets.first
+ assert_equal(1, new_rss.xml_stylesheets.size)
+ assert_equal(href, xss.href)
+ assert_equal(type, xss.type)
+ assert_equal(title, xss.title)
+ assert_equal(media, xss.media)
+ assert_equal(charset, xss.charset)
+ assert_equal(alternate, xss.alternate)
+
+ channel = new_rss.channel
+ assert_equal(channel_about, channel.about)
+ assert_equal(channel_title, channel.title)
+ assert_equal(channel_link, channel.link)
+ assert_equal(channel_description, channel.description)
+ item_resources = []
+ item_size.times do |i|
+ item_resources << "#{item_link}#{i}"
+ end
+ assert_equal(item_resources, channel.items.resources)
+ assert_equal(image_url, channel.image.resource)
+ assert_equal(textinput_link, channel.textinput.resource)
+ @dc_elems.each do |var, value|
+ assert_equal(value, channel.__send__("dc_#{var}"))
+ end
+ @sy_elems.each do |var, value|
+ value = value.to_i if var == :updateFrequency
+ assert_equal(value, channel.__send__("sy_#{var}"))
+ end
+
+ image = new_rss.image
+ assert_equal(image_url, image.about)
+ assert_equal(image_url, new_rss.channel.image.resource)
+ assert_equal(image_title, image.title)
+ assert_equal(channel_link, image.link)
+ assert_equal(image_url, image.url)
+ @dc_elems.each do |var, value|
+ assert_equal(image.__send__("dc_#{var}"), value)
+ end
+
+ textinput = new_rss.textinput
+ assert_equal(textinput_link, textinput.about)
+ assert_equal(textinput_link, new_rss.channel.textinput.resource)
+ assert_equal(textinput_title, textinput.title)
+ assert_equal(textinput_name, textinput.name)
+ assert_equal(textinput_description, textinput.description)
+ assert_equal(textinput_link, textinput.link)
+ @dc_elems.each do |var, value|
+ assert_equal(textinput.__send__("dc_#{var}"), value)
+ end
+
+ assert_equal(item_size, new_rss.items.size)
+ new_rss.items.each_with_index do |item, i|
+ assert_equal("#{item_link}#{i}", item.about)
+ assert_equal("#{item_title}#{i}", item.title)
+ assert_equal("#{item_link}#{i}", item.link)
+ assert_equal("#{item_description}#{i}", item.description)
+
+ @dc_elems.each do |var, value|
+ assert_equal(item.__send__("dc_#{var}"), value)
+ end
+
+ @content_elems.each do |var, value|
+ assert_equal(item.__send__("content_#{var}"), value)
+ end
+
+ assert_equal(@trackback_elems[:ping], item.trackback_ping)
+ assert_equal(@trackback_elems[:about].size, item.trackback_abouts.size)
+ item.trackback_abouts.each_with_index do |about, j|
+ assert_equal(@trackback_elems[:about][j], about.value)
+ end
+ end
+
+ assert_taxo_topic(@taxo_topic_elems, new_rss)
+ end
+
+ end
+end
diff --git a/jni/ruby/test/rss/test_setup_maker_2.0.rb b/jni/ruby/test/rss/test_setup_maker_2.0.rb
new file mode 100644
index 0000000..fcf1f57
--- /dev/null
+++ b/jni/ruby/test/rss/test_setup_maker_2.0.rb
@@ -0,0 +1,308 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestSetupMaker20 < TestCase
+
+ def test_setup_maker_channel
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+ language = "ja"
+ copyright = "foo"
+ managingEditor = "bar"
+ webMaster = "web master"
+ rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
+ docs = "http://foo.com/doc"
+ skipDays = [
+ "Sunday",
+ "Monday",
+ ]
+ skipHours = [
+ "0",
+ "13",
+ ]
+ pubDate = Time.now
+ lastBuildDate = Time.now
+ categories = [
+ "Nespapers",
+ "misc",
+ ]
+ generator = "RSS Maker"
+ ttl = "60"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ maker.channel.title = title
+ maker.channel.link = link
+ maker.channel.description = description
+ maker.channel.language = language
+ maker.channel.copyright = copyright
+ maker.channel.managingEditor = managingEditor
+ maker.channel.webMaster = webMaster
+ maker.channel.rating = rating
+ maker.channel.docs = docs
+ maker.channel.pubDate = pubDate
+ maker.channel.lastBuildDate = lastBuildDate
+
+ skipDays.each do |day|
+ maker.channel.skipDays.new_day do |new_day|
+ new_day.content = day
+ end
+ end
+ skipHours.each do |hour|
+ maker.channel.skipHours.new_hour do |new_hour|
+ new_hour.content = hour
+ end
+ end
+
+
+ categories.each do |category|
+ maker.channel.categories.new_category do |new_category|
+ new_category.content = category
+ end
+ end
+
+ maker.channel.generator = generator
+ maker.channel.ttl = ttl
+ end
+
+ new_rss = RSS::Maker.make("2.0") do |maker|
+ rss.channel.setup_maker(maker)
+ end
+ channel = new_rss.channel
+
+ assert_equal(title, channel.title)
+ assert_equal(link, channel.link)
+ assert_equal(description, channel.description)
+ assert_equal(language, channel.language)
+ assert_equal(copyright, channel.copyright)
+ assert_equal(managingEditor, channel.managingEditor)
+ assert_equal(webMaster, channel.webMaster)
+ assert_equal(rating, channel.rating)
+ assert_equal(docs, channel.docs)
+ assert_equal(pubDate, channel.pubDate)
+ assert_equal(lastBuildDate, channel.lastBuildDate)
+
+ skipDays.each_with_index do |day, i|
+ assert_equal(day, channel.skipDays.days[i].content)
+ end
+ skipHours.each_with_index do |hour, i|
+ assert_equal(hour.to_i, channel.skipHours.hours[i].content)
+ end
+
+
+ channel.categories.each_with_index do |category, i|
+ assert_equal(categories[i], category.content)
+ end
+
+ assert_equal(generator, channel.generator)
+ assert_equal(ttl.to_i, channel.ttl)
+
+
+ assert(channel.items.empty?)
+ assert_nil(channel.image)
+ assert_nil(channel.textInput)
+ end
+
+ def test_setup_maker_image
+ title = "fugafuga"
+ link = "http://hoge.com"
+ url = "http://hoge.com/hoge.png"
+ width = "144"
+ height = "400"
+ description = "an image"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+ maker.channel.link = link
+
+ maker.image.title = title
+ maker.image.url = url
+ maker.image.width = width
+ maker.image.height = height
+ maker.image.description = description
+ end
+
+ new_rss = RSS::Maker.make("2.0") do |maker|
+ rss.channel.setup_maker(maker)
+ rss.image.setup_maker(maker)
+ end
+
+ image = new_rss.image
+ assert_equal(title, image.title)
+ assert_equal(link, image.link)
+ assert_equal(url, image.url)
+ assert_equal(width.to_i, image.width)
+ assert_equal(height.to_i, image.height)
+ assert_equal(description, image.description)
+ end
+
+ def test_setup_maker_textinput
+ title = "fugafuga"
+ description = "text hoge fuga"
+ name = "hoge"
+ link = "http://hoge.com"
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ maker.textinput.title = title
+ maker.textinput.description = description
+ maker.textinput.name = name
+ maker.textinput.link = link
+ end
+
+ new_rss = RSS::Maker.make("2.0") do |maker|
+ rss.channel.setup_maker(maker)
+ rss.textinput.setup_maker(maker)
+ end
+
+ textInput = new_rss.channel.textInput
+ assert_equal(title, textInput.title)
+ assert_equal(description, textInput.description)
+ assert_equal(name, textInput.name)
+ assert_equal(link, textInput.link)
+ end
+
+ def test_setup_maker_items(for_backward_compatibility=false)
+ title = "TITLE"
+ link = "http://hoge.com/"
+ description = "text hoge fuga"
+ author = "oprah@oxygen.net"
+ comments = "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290"
+ pubDate = Time.now
+
+ guid_isPermaLink = "true"
+ guid_content = "http://inessential.com/2002/09/01.php#a2"
+
+ enclosure_url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
+ enclosure_length = "12216320"
+ enclosure_type = "audio/mpeg"
+
+ source_url = "http://static.userland.com/tomalak/links2.xml"
+ source_content = "Tomalak's Realm"
+
+ category_domain = "http://www.fool.com/cusips"
+ category_content = "MSFT"
+
+ item_size = 5
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_dummy_channel(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |item|
+ item.title = "#{title}#{i}"
+ item.link = "#{link}#{i}"
+ item.description = "#{description}#{i}"
+ item.author = "#{author}#{i}"
+ item.comments = "#{comments}#{i}"
+ item.date = pubDate
+
+ item.guid.isPermaLink = guid_isPermaLink
+ item.guid.content = guid_content
+
+ item.enclosure.url = enclosure_url
+ item.enclosure.length = enclosure_length
+ item.enclosure.type = enclosure_type
+
+ item.source.url = source_url
+ item.source.content = source_content
+
+ category = item.categories.new_category
+ category.domain = category_domain
+ category.content = category_content
+ end
+ end
+ end
+
+ new_rss = RSS::Maker.make("2.0") do |maker|
+ rss.channel.setup_maker(maker)
+
+ rss.items.each do |item|
+ if for_backward_compatibility
+ item.setup_maker(maker)
+ else
+ item.setup_maker(maker.items)
+ end
+ end
+ end
+
+ assert_equal(item_size, new_rss.items.size)
+ new_rss.items.each_with_index do |item, i|
+ assert_equal("#{title}#{i}", item.title)
+ assert_equal("#{link}#{i}", item.link)
+ assert_equal("#{description}#{i}", item.description)
+ assert_equal("#{author}#{i}", item.author)
+ assert_equal("#{comments}#{i}", item.comments)
+ assert_equal(pubDate, item.pubDate)
+
+ assert_equal(guid_isPermaLink == "true", item.guid.isPermaLink)
+ assert_equal(guid_content, item.guid.content)
+
+ assert_equal(enclosure_url, item.enclosure.url)
+ assert_equal(enclosure_length.to_i, item.enclosure.length)
+ assert_equal(enclosure_type, item.enclosure.type)
+
+ assert_equal(source_url, item.source.url)
+ assert_equal(source_content, item.source.content)
+
+ assert_equal(1, item.categories.size)
+ assert_equal(category_domain, item.category.domain)
+ assert_equal(category_content, item.category.content)
+ end
+
+ end
+
+ def test_setup_maker_items_backward_compatibility
+ test_setup_maker_items(true)
+ end
+
+ def test_setup_maker
+ encoding = "EUC-JP"
+ standalone = true
+
+ href = 'a.xsl'
+ type = 'text/xsl'
+ title = 'sample'
+ media = 'printer'
+ charset = 'UTF-8'
+ alternate = 'yes'
+
+ rss = RSS::Maker.make("2.0") do |maker|
+ maker.encoding = encoding
+ maker.standalone = standalone
+
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ xss.href = href
+ xss.type = type
+ xss.title = title
+ xss.media = media
+ xss.charset = charset
+ xss.alternate = alternate
+ end
+
+ setup_dummy_channel(maker)
+ end
+
+ new_rss = RSS::Maker.make("2.0") do |maker|
+ rss.setup_maker(maker)
+ end
+
+ assert_equal("2.0", new_rss.rss_version)
+ assert_equal(encoding, new_rss.encoding)
+ assert_equal(standalone, new_rss.standalone)
+
+ xss = rss.xml_stylesheets.first
+ assert_equal(1, rss.xml_stylesheets.size)
+ assert_equal(href, xss.href)
+ assert_equal(type, xss.type)
+ assert_equal(title, xss.title)
+ assert_equal(media, xss.media)
+ assert_equal(charset, xss.charset)
+ assert_equal(alternate, xss.alternate)
+ end
+
+ end
+end
diff --git a/jni/ruby/test/rss/test_setup_maker_atom_entry.rb b/jni/ruby/test/rss/test_setup_maker_atom_entry.rb
new file mode 100644
index 0000000..ec9df5e
--- /dev/null
+++ b/jni/ruby/test/rss/test_setup_maker_atom_entry.rb
@@ -0,0 +1,409 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestSetupMakerAtomEntry < TestCase
+ def setup
+ t = Time.iso8601("2000-01-01T12:00:05+00:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ @dc_elems = {
+ :title => "hoge",
+ :description =>
+ " XML is placing increasingly heavy loads on
+ the existing technical infrastructure of the Internet.",
+ :creator => "Rael Dornfest (mailto:rael@oreilly.com)",
+ :subject => "XML",
+ :publisher => "The O'Reilly Network",
+ :contributor => "hogehoge",
+ :type => "fugafuga",
+ :format => "hohoho",
+ :identifier => "fufufu",
+ :source => "barbar",
+ :language => "ja",
+ :relation => "cococo",
+ :rights => "Copyright (c) 2000 O'Reilly &amp; Associates, Inc.",
+ :date => t,
+ }
+ end
+
+ def test_setup_maker_entry(with_dc=true)
+ authors = [
+ {
+ :name => "Bob",
+ :uri => "http://example.com/~bob/",
+ :email => "bob@example.com",
+ },
+ {
+ :name => "Alice",
+ :uri => "http://example.com/~alice/",
+ :email => "alice@example.com",
+ },
+ ]
+ categories = [
+ {
+ :term => "music",
+ :label => "Music",
+ },
+ {
+ :term => "book",
+ :scheme => "http://example.com/category/book/",
+ :label => "Book",
+ },
+ ]
+ contributors = [
+ {
+ :name => "Chris",
+ :email => "chris@example.com",
+ },
+ {
+ :name => "Eva",
+ :uri => "http://example.com/~eva/",
+ },
+ ]
+ id = "urn:uuid:8b105336-7e20-45fc-bb78-37fb3e1db25a"
+ link = "http://hoge.com"
+ published = Time.now - 60 * 3600
+ rights = "Copyrights (c) 2007 Alice and Bob"
+ description = "fugafugafugafuga"
+ title = "fugafuga"
+ updated = Time.now
+
+ feed = RSS::Maker.make("atom:entry") do |maker|
+ maker.items.new_item do |item|
+ authors.each do |author_info|
+ item.authors.new_author do |author|
+ author_info.each do |key, value|
+ author.__send__("#{key}=", value)
+ end
+ end
+ end
+
+ categories.each do |category_info|
+ item.categories.new_category do |category|
+ category_info.each do |key, value|
+ category.__send__("#{key}=", value)
+ end
+ end
+ end
+
+ contributors.each do |contributor_info|
+ item.contributors.new_contributor do |contributor|
+ contributor_info.each do |key, value|
+ contributor.__send__("#{key}=", value)
+ end
+ end
+ end
+
+ item.id = id
+ item.link = link
+ item.published = published
+ item.rights = rights
+ item.description = description
+ item.title = title
+ item.updated = updated
+
+ if with_dc
+ @dc_elems.each do |var, value|
+ if var == :date
+ item.new_dc_date(value)
+ else
+ item.__send__("dc_#{var}=", value)
+ end
+ end
+ end
+ end
+ end
+ assert_not_nil(feed)
+
+ new_feed = RSS::Maker.make("atom:entry") do |maker|
+ feed.setup_maker(maker)
+ end
+ assert_not_nil(new_feed)
+
+ new_authors = new_feed.authors.collect do |author|
+ {
+ :name => author.name.content,
+ :uri => author.uri.content,
+ :email => author.email.content,
+ }
+ end
+ assert_equal(authors, new_authors)
+
+ new_categories = new_feed.categories.collect do |category|
+ {
+ :term => category.term,
+ :scheme => category.scheme,
+ :label => category.label,
+ }.reject {|key, value| value.nil?}
+ end
+ assert_equal(categories, new_categories)
+
+ new_contributors = new_feed.contributors.collect do |contributor|
+ info = {}
+ info[:name] = contributor.name.content
+ info[:uri] = contributor.uri.content if contributor.uri
+ info[:email] = contributor.email.content if contributor.email
+ info
+ end
+ assert_equal(contributors, new_contributors)
+
+ assert_equal(id, new_feed.id.content)
+ assert_equal(link, new_feed.link.href)
+ assert_equal(published, new_feed.published.content)
+ assert_equal(rights, new_feed.rights.content)
+ assert_equal(description, new_feed.summary.content)
+ assert_equal(title, new_feed.title.content)
+ assert_equal(updated, new_feed.updated.content)
+
+ if with_dc
+ @dc_elems.each do |var, value|
+ if var == :date
+ assert_equal([updated, value],
+ new_feed.dc_dates.collect {|date| date.value})
+ else
+ assert_equal(value, new_feed.__send__("dc_#{var}"))
+ end
+ end
+ end
+
+ assert_equal(1, new_feed.items.size)
+ end
+
+ def test_setup_maker_entry_without_dc
+ test_setup_maker_entry(false)
+ end
+
+ def test_setup_maker_items(for_backward_compatibility=false)
+ title = "TITLE"
+ link = "http://hoge.com/"
+ description = "text hoge fuga"
+ updated = Time.now
+
+ item_size = 5
+ feed = RSS::Maker.make("atom:entry") do |maker|
+ setup_dummy_channel_atom(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |item|
+ item.title = "#{title}#{i}"
+ item.link = "#{link}#{i}"
+ item.description = "#{description}#{i}"
+ item.updated = updated + i * 60
+ end
+ end
+ end
+
+ new_feed = RSS::Maker.make("atom:entry") do |maker|
+ feed.items.each do |item|
+ if for_backward_compatibility
+ item.setup_maker(maker)
+ else
+ item.setup_maker(maker.items)
+ end
+ end
+
+ feed.items.clear
+ feed.setup_maker(maker)
+ end
+
+ assert_equal(1, new_feed.items.size)
+ new_feed.items[0..1].each_with_index do |item, i|
+ assert_equal("#{title}#{i}", item.title.content)
+ assert_equal("#{link}#{i}", item.link.href)
+ assert_equal("#{description}#{i}", item.summary.content)
+ assert_equal(updated + i * 60, item.updated.content)
+ end
+ end
+
+ def test_setup_maker_items_sort
+ title = "TITLE"
+ link = "http://hoge.com/"
+ summary = "text hoge fuga"
+ updated = Time.now
+
+ feed_size = 5
+ feed = RSS::Maker.make("atom:entry") do |maker|
+ setup_dummy_channel_atom(maker)
+
+ feed_size.times do |i|
+ entry_class = RSS::Atom::Entry
+ entry = entry_class.new
+ entry.title = entry_class::Title.new(:content => "#{title}#{i}")
+ entry.links << entry_class::Link.new(:href => "#{link}#{i}")
+ entry.summary = entry_class::Summary.new(:content => "#{summary}#{i}")
+ entry.updated = entry_class::Updated.new(:content => updated + i * 60)
+ entry.setup_maker(maker.items)
+ end
+ maker.items.do_sort = false
+ end
+ assert_equal(1, feed.items.size)
+
+ assert_equal("#{title}0", feed.title.content)
+ assert_equal("#{link}0", feed.link.href)
+ assert_equal("#{summary}0", feed.summary.content)
+
+
+ feed = RSS::Maker.make("atom:entry") do |maker|
+ setup_dummy_channel_atom(maker)
+
+ feed_size.times do |i|
+ entry_class = RSS::Atom::Entry
+ entry = entry_class.new
+ entry.title = entry_class::Title.new(:content => "#{title}#{i}")
+ entry.links << entry_class::Link.new(:href => "#{link}#{i}")
+ entry.summary = entry_class::Summary.new(:content => "#{summary}#{i}")
+ entry.updated = entry_class::Updated.new(:content => updated + i * 60)
+ entry.setup_maker(maker.items)
+ end
+ maker.items.do_sort = true
+ end
+ assert_equal(1, feed.items.size)
+
+ assert_equal("#{title}#{feed_size - 1}", feed.title.content)
+ assert_equal("#{link}#{feed_size - 1}", feed.link.href)
+ assert_equal("#{summary}#{feed_size - 1}", feed.summary.content)
+ end
+
+ def test_setup_maker_items_backward_compatibility
+ test_setup_maker_items(true)
+ end
+
+ def test_setup_maker
+ encoding = "EUC-JP"
+ standalone = true
+
+ href = 'a.xsl'
+ type = 'text/xsl'
+ title = 'sample'
+ media = 'printer'
+ charset = 'UTF-8'
+ alternate = 'yes'
+
+ feed = RSS::Maker.make("atom:entry") do |maker|
+ maker.encoding = encoding
+ maker.standalone = standalone
+
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ xss.href = href
+ xss.type = type
+ xss.title = title
+ xss.media = media
+ xss.charset = charset
+ xss.alternate = alternate
+ end
+
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ assert_not_nil(feed)
+
+ new_feed = RSS::Maker.make("atom:entry") do |maker|
+ feed.setup_maker(maker)
+ end
+
+ assert_equal(["atom", "1.0", "entry"], new_feed.feed_info)
+ assert_equal(encoding, new_feed.encoding)
+ assert_equal(standalone, new_feed.standalone)
+
+ xss = new_feed.xml_stylesheets.first
+ assert_equal(1, new_feed.xml_stylesheets.size)
+ assert_equal(href, xss.href)
+ assert_equal(type, xss.type)
+ assert_equal(title, xss.title)
+ assert_equal(media, xss.media)
+ assert_equal(charset, xss.charset)
+ assert_equal(alternate, xss.alternate)
+ end
+
+ def test_setup_maker_full
+ encoding = "EUC-JP"
+ standalone = true
+
+ href = 'a.xsl'
+ type = 'text/xsl'
+ title = 'sample'
+ media = 'printer'
+ charset = 'UTF-8'
+ alternate = 'yes'
+
+ channel_about = "http://hoge.com"
+ channel_title = "fugafuga"
+ channel_link = "http://hoge.com"
+ channel_description = "fugafugafugafuga"
+ channel_author = "Bob"
+
+ image_url = "http://hoge.com/hoge.png"
+
+ item_title = "TITLE"
+ item_link = "http://hoge.com/"
+ item_description = "text hoge fuga"
+
+ entry_size = 5
+ feed = RSS::Maker.make("atom:entry") do |maker|
+ maker.encoding = encoding
+ maker.standalone = standalone
+
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ xss.href = href
+ xss.type = type
+ xss.title = title
+ xss.media = media
+ xss.charset = charset
+ xss.alternate = alternate
+ end
+
+ maker.channel.about = channel_about
+ maker.channel.title = channel_title
+ maker.channel.link = channel_link
+ maker.channel.description = channel_description
+ maker.channel.author = channel_author
+ @dc_elems.each do |var, value|
+ maker.channel.__send__("dc_#{var}=", value)
+ end
+
+ maker.image.url = image_url
+
+ entry_size.times do |i|
+ maker.items.new_item do |item|
+ item.title = "#{item_title}#{i}"
+ item.link = "#{item_link}#{i}"
+ item.description = "#{item_description}#{i}"
+
+ @dc_elems.each do |var, value|
+ item.__send__("dc_#{var}=", value)
+ end
+ end
+ end
+ end
+
+ new_feed = RSS::Maker.make("atom:entry") do |maker|
+ feed.setup_maker(maker)
+ end
+
+ assert_equal(["atom", "1.0", "entry"], new_feed.feed_info)
+ assert_equal(encoding, new_feed.encoding)
+ assert_equal(standalone, new_feed.standalone)
+
+ xss = new_feed.xml_stylesheets.first
+ assert_equal(1, new_feed.xml_stylesheets.size)
+ assert_equal(href, xss.href)
+ assert_equal(type, xss.type)
+ assert_equal(title, xss.title)
+ assert_equal(media, xss.media)
+ assert_equal(charset, xss.charset)
+ assert_equal(alternate, xss.alternate)
+
+ assert_equal("#{item_title}0", new_feed.title.content)
+ assert_equal("#{item_link}0", new_feed.link.href)
+ assert_equal("#{item_description}0", new_feed.summary.content)
+ @dc_elems.each do |var, value|
+ assert_equal(value, new_feed.__send__("dc_#{var}"))
+ end
+ assert_equal(1, new_feed.items.size)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_setup_maker_atom_feed.rb b/jni/ruby/test/rss/test_setup_maker_atom_feed.rb
new file mode 100644
index 0000000..ad2c693
--- /dev/null
+++ b/jni/ruby/test/rss/test_setup_maker_atom_feed.rb
@@ -0,0 +1,445 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestSetupMakerAtomFeed < TestCase
+ def setup
+ t = Time.iso8601("2000-01-01T12:00:05+00:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ @dc_elems = {
+ :title => "hoge",
+ :description =>
+ " XML is placing increasingly heavy loads on
+ the existing technical infrastructure of the Internet.",
+ :creator => "Rael Dornfest (mailto:rael@oreilly.com)",
+ :subject => "XML",
+ :publisher => "The O'Reilly Network",
+ :contributor => "hogehoge",
+ :type => "fugafuga",
+ :format => "hohoho",
+ :identifier => "fufufu",
+ :source => "barbar",
+ :language => "ja",
+ :relation => "cococo",
+ :rights => "Copyright (c) 2000 O'Reilly &amp; Associates, Inc.",
+ :date => t,
+ }
+ end
+
+ def test_setup_maker_feed(with_dc=true)
+ authors = [
+ {
+ :name => "Bob",
+ :uri => "http://example.com/~bob/",
+ :email => "bob@example.com",
+ },
+ {
+ :name => "Alice",
+ :uri => "http://example.com/~alice/",
+ :email => "alice@example.com",
+ },
+ ]
+ categories = [
+ {
+ :term => "music",
+ :label => "Music",
+ },
+ {
+ :term => "book",
+ :scheme => "http://example.com/category/book/",
+ :label => "Book",
+ },
+ ]
+ contributors = [
+ {
+ :name => "Chris",
+ :email => "chris@example.com",
+ },
+ {
+ :name => "Eva",
+ :uri => "http://example.com/~eva/",
+ },
+ ]
+ generator = {
+ :uri => "http://example.com/generator/",
+ :version => "0.0.1",
+ :content => "Feed Generator",
+ }
+ icon = "http://example.com/icon.png"
+ about = "http://hoge.com"
+ title = "fugafuga"
+ link = "http://hoge.com"
+ logo = "http://example.com/logo.png"
+ rights = "Copyrights (c) 2007 Alice and Bob"
+ description = "fugafugafugafuga"
+ updated = Time.now
+
+ feed = RSS::Maker.make("atom") do |maker|
+ authors.each do |author_info|
+ maker.channel.authors.new_author do |author|
+ author_info.each do |key, value|
+ author.__send__("#{key}=", value)
+ end
+ end
+ end
+
+ categories.each do |category_info|
+ maker.channel.categories.new_category do |category|
+ category_info.each do |key, value|
+ category.__send__("#{key}=", value)
+ end
+ end
+ end
+
+ contributors.each do |contributor_info|
+ maker.channel.contributors.new_contributor do |contributor|
+ contributor_info.each do |key, value|
+ contributor.__send__("#{key}=", value)
+ end
+ end
+ end
+
+ generator.each do |key, value|
+ maker.channel.generator do |g|
+ g.__send__("#{key}=", value)
+ end
+ end
+
+ maker.channel.icon = icon
+
+ maker.channel.about = about
+ maker.channel.link = link
+ maker.channel.logo = logo
+ maker.channel.rights = rights
+ maker.channel.title = title
+ maker.channel.description = description
+ maker.channel.updated = updated
+
+ if with_dc
+ @dc_elems.each do |var, value|
+ if var == :date
+ maker.channel.new_dc_date(value)
+ else
+ maker.channel.__send__("dc_#{var}=", value)
+ end
+ end
+ end
+
+ setup_dummy_item_atom(maker)
+ end
+ assert_not_nil(feed)
+
+ new_feed = RSS::Maker.make("atom") do |maker|
+ feed.setup_maker(maker)
+ end
+ assert_not_nil(new_feed)
+
+ new_authors = new_feed.authors.collect do |author|
+ {
+ :name => author.name.content,
+ :uri => author.uri.content,
+ :email => author.email.content,
+ }
+ end
+ assert_equal(authors, new_authors)
+
+ new_categories = new_feed.categories.collect do |category|
+ {
+ :term => category.term,
+ :scheme => category.scheme,
+ :label => category.label,
+ }.reject {|key, value| value.nil?}
+ end
+ assert_equal(categories, new_categories)
+
+ new_contributors = new_feed.contributors.collect do |contributor|
+ info = {}
+ info[:name] = contributor.name.content
+ info[:uri] = contributor.uri.content if contributor.uri
+ info[:email] = contributor.email.content if contributor.email
+ info
+ end
+ assert_equal(contributors, new_contributors)
+
+ new_generator = {
+ :uri => new_feed.generator.uri,
+ :version => new_feed.generator.version,
+ :content => new_feed.generator.content,
+ }
+ assert_equal(generator, new_generator)
+
+ assert_equal(icon, new_feed.icon.content)
+ assert_equal(about, new_feed.id.content)
+ assert_equal(link, new_feed.link.href)
+ assert_equal(logo, new_feed.logo.content)
+ assert_equal(rights, new_feed.rights.content)
+ assert_equal(description, new_feed.subtitle.content)
+ assert_equal(title, new_feed.title.content)
+ assert_equal(updated, new_feed.updated.content)
+
+ if with_dc
+ @dc_elems.each do |var, value|
+ if var == :date
+ assert_equal([updated, value],
+ new_feed.dc_dates.collect {|date| date.value})
+ else
+ assert_equal(value, new_feed.__send__("dc_#{var}"))
+ end
+ end
+ end
+
+ assert_equal(1, new_feed.items.size)
+ end
+
+ def test_setup_maker_feed_without_dc
+ test_setup_maker_feed(false)
+ end
+
+ def test_setup_maker_items(for_backward_compatibility=false)
+ title = "TITLE"
+ link = "http://hoge.com/"
+ description = "text hoge fuga"
+ updated = Time.now
+
+ item_size = 5
+ feed = RSS::Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+
+ item_size.times do |i|
+ maker.items.new_item do |item|
+ item.title = "#{title}#{i}"
+ item.link = "#{link}#{i}"
+ item.description = "#{description}#{i}"
+ item.updated = updated + i * 60
+ end
+ end
+ end
+
+ new_feed = RSS::Maker.make("atom") do |maker|
+ feed.items.each do |item|
+ if for_backward_compatibility
+ item.setup_maker(maker)
+ else
+ item.setup_maker(maker.items)
+ end
+ end
+
+ feed.items.clear
+ feed.setup_maker(maker)
+ end
+
+ assert_equal(item_size, new_feed.items.size)
+ new_feed.items.each_with_index do |item, i|
+ assert_equal("#{title}#{i}", item.title.content)
+ assert_equal("#{link}#{i}", item.link.href)
+ assert_equal("#{description}#{i}", item.summary.content)
+ assert_equal(updated + i * 60, item.updated.content)
+ end
+ end
+
+ def test_setup_maker_items_sort
+ title = "TITLE"
+ link = "http://hoge.com/"
+ summary = "text hoge fuga"
+ updated = Time.now
+
+ feed_size = 5
+ feed = RSS::Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+
+ feed_size.times do |i|
+ entry_class = RSS::Atom::Feed::Entry
+ entry = entry_class.new
+ entry.title = entry_class::Title.new(:content => "#{title}#{i}")
+ entry.links << entry_class::Link.new(:href => "#{link}#{i}")
+ entry.summary = entry_class::Summary.new(:content => "#{summary}#{i}")
+ entry.updated = entry_class::Updated.new(:content => updated + i * 60)
+ entry.setup_maker(maker.items)
+ end
+ maker.items.do_sort = false
+ end
+ assert_equal(feed_size, feed.entries.size)
+ feed.entries.each_with_index do |entry, i|
+ assert_equal("#{title}#{i}", entry.title.content)
+ assert_equal("#{link}#{i}", entry.link.href)
+ assert_equal("#{summary}#{i}", entry.summary.content)
+ end
+
+
+ feed = RSS::Maker.make("atom") do |maker|
+ setup_dummy_channel_atom(maker)
+
+ feed_size.times do |i|
+ entry_class = RSS::Atom::Feed::Entry
+ entry = entry_class.new
+ entry.title = entry_class::Title.new(:content => "#{title}#{i}")
+ entry.links << entry_class::Link.new(:href => "#{link}#{i}")
+ entry.summary = entry_class::Summary.new(:content => "#{summary}#{i}")
+ entry.updated = entry_class::Updated.new(:content => updated + i * 60)
+ entry.setup_maker(maker.items)
+ end
+ maker.items.do_sort = true
+ end
+ assert_equal(feed_size, feed.entries.size)
+ feed.entries.reverse.each_with_index do |entry, i|
+ assert_equal("#{title}#{i}", entry.title.content)
+ assert_equal("#{link}#{i}", entry.link.href)
+ assert_equal("#{summary}#{i}", entry.summary.content)
+ end
+ end
+
+ def test_setup_maker_items_backward_compatibility
+ test_setup_maker_items(true)
+ end
+
+ def test_setup_maker
+ encoding = "EUC-JP"
+ standalone = true
+
+ href = 'a.xsl'
+ type = 'text/xsl'
+ title = 'sample'
+ media = 'printer'
+ charset = 'UTF-8'
+ alternate = 'yes'
+
+ feed = RSS::Maker.make("atom") do |maker|
+ maker.encoding = encoding
+ maker.standalone = standalone
+
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ xss.href = href
+ xss.type = type
+ xss.title = title
+ xss.media = media
+ xss.charset = charset
+ xss.alternate = alternate
+ end
+
+ setup_dummy_channel_atom(maker)
+ setup_dummy_item_atom(maker)
+ end
+ assert_not_nil(feed)
+
+ new_feed = RSS::Maker.make("atom") do |maker|
+ feed.setup_maker(maker)
+ end
+
+ assert_equal(["atom", "1.0", "feed"], new_feed.feed_info)
+ assert_equal(encoding, new_feed.encoding)
+ assert_equal(standalone, new_feed.standalone)
+
+ xss = new_feed.xml_stylesheets.first
+ assert_equal(1, new_feed.xml_stylesheets.size)
+ assert_equal(href, xss.href)
+ assert_equal(type, xss.type)
+ assert_equal(title, xss.title)
+ assert_equal(media, xss.media)
+ assert_equal(charset, xss.charset)
+ assert_equal(alternate, xss.alternate)
+ end
+
+ def test_setup_maker_full
+ encoding = "EUC-JP"
+ standalone = true
+
+ href = 'a.xsl'
+ type = 'text/xsl'
+ title = 'sample'
+ media = 'printer'
+ charset = 'UTF-8'
+ alternate = 'yes'
+
+ channel_about = "http://hoge.com"
+ channel_title = "fugafuga"
+ channel_link = "http://hoge.com"
+ channel_description = "fugafugafugafuga"
+ channel_author = "Bob"
+
+ image_url = "http://hoge.com/hoge.png"
+
+ item_title = "TITLE"
+ item_link = "http://hoge.com/"
+ item_description = "text hoge fuga"
+
+ entry_size = 5
+ feed = RSS::Maker.make("atom") do |maker|
+ maker.encoding = encoding
+ maker.standalone = standalone
+
+ maker.xml_stylesheets.new_xml_stylesheet do |xss|
+ xss.href = href
+ xss.type = type
+ xss.title = title
+ xss.media = media
+ xss.charset = charset
+ xss.alternate = alternate
+ end
+
+ maker.channel.about = channel_about
+ maker.channel.title = channel_title
+ maker.channel.link = channel_link
+ maker.channel.description = channel_description
+ maker.channel.author = channel_author
+ @dc_elems.each do |var, value|
+ maker.channel.__send__("dc_#{var}=", value)
+ end
+
+ maker.image.url = image_url
+
+ entry_size.times do |i|
+ maker.items.new_item do |item|
+ item.title = "#{item_title}#{i}"
+ item.link = "#{item_link}#{i}"
+ item.description = "#{item_description}#{i}"
+
+ @dc_elems.each do |var, value|
+ item.__send__("dc_#{var}=", value)
+ end
+ end
+ end
+ end
+
+ new_feed = RSS::Maker.make("atom") do |maker|
+ feed.setup_maker(maker)
+ end
+
+ assert_equal(["atom", "1.0", "feed"], new_feed.feed_info)
+ assert_equal(encoding, new_feed.encoding)
+ assert_equal(standalone, new_feed.standalone)
+
+ xss = new_feed.xml_stylesheets.first
+ assert_equal(1, new_feed.xml_stylesheets.size)
+ assert_equal(href, xss.href)
+ assert_equal(type, xss.type)
+ assert_equal(title, xss.title)
+ assert_equal(media, xss.media)
+ assert_equal(charset, xss.charset)
+ assert_equal(alternate, xss.alternate)
+
+ assert_equal(channel_title, new_feed.title.content)
+ assert_equal(channel_link, new_feed.link.href)
+ assert_equal(channel_description, new_feed.subtitle.content)
+ assert_equal(channel_author, new_feed.author.name.content)
+ assert_equal(image_url, new_feed.logo.content)
+ @dc_elems.each do |var, value|
+ assert_equal(value, new_feed.__send__("dc_#{var}"))
+ end
+
+ assert_equal(entry_size, new_feed.entries.size)
+ new_feed.entries.each_with_index do |entry, i|
+ assert_equal("#{item_title}#{i}", entry.title.content)
+ assert_equal("#{item_link}#{i}", entry.link.href)
+ assert_equal("#{item_description}#{i}", entry.summary.content)
+
+ @dc_elems.each do |var, value|
+ assert_equal(value, entry.__send__("dc_#{var}"))
+ end
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_setup_maker_itunes.rb b/jni/ruby/test/rss/test_setup_maker_itunes.rb
new file mode 100644
index 0000000..246fecf
--- /dev/null
+++ b/jni/ruby/test/rss/test_setup_maker_itunes.rb
@@ -0,0 +1,143 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestSetupMakerITunes < TestCase
+ def test_setup_maker_simple
+ author = "John Doe"
+ block = true
+ categories = ["Audio Blogs"]
+ image = "http://example.com/podcasts/everything/AllAboutEverything.jpg"
+ duration = "4:05"
+ duration_components = [0, 4, 5]
+ explicit = true
+ keywords = ["salt", "pepper", "shaker", "exciting"]
+ owner = {:name => "John Doe", :email => "john.doe@example.com"}
+ subtitle = "A show about everything"
+ summary = "All About Everything is a show about " +
+ "everything. Each week we dive into any " +
+ "subject known to man and talk about it " +
+ "as much as we can. Look for our Podcast " +
+ "in the iTunes Music Store"
+
+ feed = RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ channel = maker.channel
+ channel.itunes_author = author
+ channel.itunes_block = block
+ categories.each do |category|
+ channel.itunes_categories.new_category.text = category
+ end
+ channel.itunes_image = image
+ channel.itunes_explicit = explicit
+ channel.itunes_keywords = keywords
+ channel.itunes_owner.itunes_name = owner[:name]
+ channel.itunes_owner.itunes_email = owner[:email]
+ channel.itunes_subtitle = subtitle
+ channel.itunes_summary = summary
+
+ item = maker.items.last
+ item.itunes_author = author
+ item.itunes_block = block
+ item.itunes_duration = duration
+ item.itunes_explicit = explicit
+ item.itunes_keywords = keywords
+ item.itunes_subtitle = subtitle
+ item.itunes_summary = summary
+ end
+ assert_not_nil(feed)
+
+ new_feed = RSS::Maker.make("rss2.0") do |maker|
+ feed.setup_maker(maker)
+ end
+ assert_not_nil(new_feed)
+
+ channel = new_feed.channel
+ item = new_feed.items.last
+
+ assert_equal(author, channel.itunes_author)
+ assert_equal(author, item.itunes_author)
+
+ assert_equal(block, channel.itunes_block?)
+ assert_equal(block, item.itunes_block?)
+
+ assert_equal(categories,
+ collect_itunes_categories(channel.itunes_categories))
+
+ assert_equal(image, channel.itunes_image.href)
+
+ assert_equal(duration_components,
+ [item.itunes_duration.hour,
+ item.itunes_duration.minute,
+ item.itunes_duration.second])
+
+ assert_equal(explicit, channel.itunes_explicit?)
+ assert_equal(explicit, item.itunes_explicit?)
+
+ assert_equal(keywords, channel.itunes_keywords)
+ assert_equal(keywords, item.itunes_keywords)
+
+ assert_equal(owner,
+ {
+ :name => channel.itunes_owner.itunes_name,
+ :email => channel.itunes_owner.itunes_email
+ })
+
+ assert_equal(subtitle, channel.itunes_subtitle)
+ assert_equal(subtitle, item.itunes_subtitle)
+
+ assert_equal(summary, channel.itunes_summary)
+ assert_equal(summary, item.itunes_summary)
+ end
+
+ def test_setup_maker_with_nested_categories
+ categories = [["Arts & Entertainment", "Games"],
+ ["Technology", "Computers"],
+ "Audio Blogs"]
+
+ feed = RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ channel = maker.channel
+ categories.each do |category|
+ target = channel.itunes_categories
+ if category.is_a?(Array)
+ category.each do |sub_category|
+ target = target.new_category
+ target.text = sub_category
+ end
+ else
+ target.new_category.text = category
+ end
+ end
+ end
+ assert_not_nil(feed)
+
+ new_feed = RSS::Maker.make("rss2.0") do |maker|
+ feed.setup_maker(maker)
+ end
+ assert_not_nil(new_feed)
+
+ channel = new_feed.channel
+
+ assert_equal(categories,
+ collect_itunes_categories(channel.itunes_categories))
+ end
+
+ private
+ def collect_itunes_categories(categories)
+ categories.collect do |c|
+ rest = collect_itunes_categories(c.itunes_categories)
+ if rest.empty?
+ c.text
+ else
+ [c.text, *rest]
+ end
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_setup_maker_slash.rb b/jni/ruby/test/rss/test_setup_maker_slash.rb
new file mode 100644
index 0000000..cd12db9
--- /dev/null
+++ b/jni/ruby/test/rss/test_setup_maker_slash.rb
@@ -0,0 +1,38 @@
+require_relative "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestSetupMakerSlash < TestCase
+ def test_setup_maker
+ elements = {
+ "section" => "articles",
+ "department" => "not-an-ocean-unless-there-are-lobsters",
+ "comments" => 177,
+ "hit_parades" => [177, 155, 105, 33, 6, 3, 0],
+ }
+
+ rss = RSS::Maker.make("rss1.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ item = maker.items.last
+ item.slash_section = elements["section"]
+ item.slash_department = elements["department"]
+ item.slash_comments = elements["comments"]
+ item.slash_hit_parade = elements["hit_parades"].join(",")
+ end
+ assert_not_nil(rss)
+
+ new_rss = RSS::Maker.make("rss1.0") do |maker|
+ rss.setup_maker(maker)
+ end
+ assert_not_nil(new_rss)
+
+ item = new_rss.items.last
+ assert_not_nil(item)
+
+ assert_slash_elements(elements, item)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_slash.rb b/jni/ruby/test/rss/test_slash.rb
new file mode 100644
index 0000000..757e787
--- /dev/null
+++ b/jni/ruby/test/rss/test_slash.rb
@@ -0,0 +1,64 @@
+require "cgi"
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/1.0"
+require "rss/slash"
+
+module RSS
+ class TestSlash < TestCase
+ def setup
+ @elements = {
+ "section" => "articles",
+ "department" => "not-an-ocean-unless-there-are-lobsters",
+ "comments" => 177,
+ "hit_parades" => [177, 155, 105, 33, 6, 3, 0],
+ }
+
+ slash_nodes = @elements.collect do |name, value|
+ if name == "hit_parades"
+ name = "hit_parade"
+ value = value.join(",")
+ end
+ "<slash:#{name}>#{value}</slash:#{name}>"
+ end.join("\n")
+
+ slash_ns = {"slash" => "http://purl.org/rss/1.0/modules/slash/"}
+ @source = make_RDF(<<-EOR, slash_ns)
+#{make_channel}
+#{make_image}
+#{make_item(slash_nodes)}
+#{make_textinput}
+EOR
+ end
+
+ def test_parser
+ rss = RSS::Parser.parse(@source)
+
+ assert_not_nil(rss)
+
+ item = rss.items[0]
+ assert_not_nil(item)
+
+ assert_slash_elements(item)
+ end
+
+ def test_to_s
+ rss = RSS::Parser.parse(@source)
+ rss = RSS::Parser.parse(rss.to_s)
+
+ assert_not_nil(rss)
+
+ item = rss.items[0]
+ assert_not_nil(item)
+
+ assert_slash_elements(item)
+ end
+
+ private
+ def assert_slash_elements(target)
+ super(@elements, target)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_syndication.rb b/jni/ruby/test/rss/test_syndication.rb
new file mode 100644
index 0000000..17875f1
--- /dev/null
+++ b/jni/ruby/test/rss/test_syndication.rb
@@ -0,0 +1,125 @@
+require "cgi"
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/1.0"
+require "rss/syndication"
+
+module RSS
+ class TestSyndication < TestCase
+
+ def setup
+ @prefix = "sy"
+ @uri = "http://purl.org/rss/1.0/modules/syndication/"
+
+ @parents = %w(channel)
+
+ t = Time.iso8601("2000-01-01T12:00:05+00:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ @elems = {
+ :updatePeriod => "hourly",
+ :updateFrequency => "2",
+ :updateBase => t,
+ }
+
+ @sy_nodes = @elems.collect do |name, value|
+ "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
+ end.join("\n")
+
+ @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
+#{make_channel(@sy_nodes)}
+#{make_image()}
+#{make_item()}
+#{make_textinput()}
+EOR
+
+ @rss = Parser.parse(@rss_source)
+ end
+
+ def test_parser
+
+ assert_nothing_raised do
+ Parser.parse(@rss_source)
+ end
+
+ @elems.each do |tag, value|
+ assert_too_much_tag(tag.to_s, "channel") do
+ Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
+#{make_channel(("<" + @prefix + ":" + tag.to_s + ">" +
+ CGI.escapeHTML(value.to_s) +
+ "</" + @prefix + ":" + tag.to_s + ">") * 2)}
+#{make_item}
+EOR
+ end
+ end
+
+ end
+
+ def test_accessor
+
+ t = Time.iso8601("2003-01-01T12:00:23+09:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ new_value = {
+ :updatePeriod => "daily",
+ :updateFrequency => "11",
+ :updateBase => t,
+ }
+
+ @elems.each do |name, value|
+ value = value.to_i if name == :updateFrequency
+ @parents.each do |parent|
+ assert_equal(value, @rss.__send__(parent).__send__("sy_#{name}"))
+ @rss.__send__(parent).__send__("sy_#{name}=", new_value[name])
+ new_val = new_value[name]
+ new_val = new_val.to_i if name == :updateFrequency
+ assert_equal(new_val, @rss.__send__(parent).__send__("sy_#{name}"))
+ end
+ end
+
+ %w(hourly daily weekly monthly yearly).each do |x|
+ @parents.each do |parent|
+ assert_nothing_raised do
+ @rss.__send__(parent).sy_updatePeriod = x
+ end
+ end
+ end
+
+ %w(-2 0.3 -0.4).each do |x|
+ @parents.each do |parent|
+ assert_not_available_value("sy:updateBase", x) do
+ @rss.__send__(parent).sy_updateBase = x
+ end
+ end
+ end
+
+ end
+
+ def test_to_s
+
+ @elems.each do |name, value|
+ excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
+ @parents.each do |parent|
+ assert_equal(excepted,
+ @rss.__send__(parent).__send__("sy_#{name}_element"))
+ end
+ end
+
+ REXML::Document.new(@rss_source).root.each_element do |parent|
+ if @parents.include?(parent.name)
+ parent.each_element do |elem|
+ if elem.namespace == @uri
+ assert_equal(elem.text, @elems[elem.name.intern].to_s)
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_taxonomy.rb b/jni/ruby/test/rss/test_taxonomy.rb
new file mode 100644
index 0000000..34937e4
--- /dev/null
+++ b/jni/ruby/test/rss/test_taxonomy.rb
@@ -0,0 +1,172 @@
+require "cgi"
+
+require_relative "rss-testcase"
+
+require "rss/1.0"
+require "rss/2.0"
+require "rss/taxonomy"
+
+module RSS
+ class TestTaxonomy < TestCase
+
+ def setup
+ @prefix = "taxo"
+ @uri = "http://purl.org/rss/1.0/modules/taxonomy/"
+ @dc_prefix = "dc"
+ @dc_uri = "http://purl.org/dc/elements/1.1/"
+
+ @ns = {
+ @prefix => @uri,
+ @dc_prefix => @dc_uri,
+ }
+
+ @topics_parents = %w(channel item)
+
+ @topics_lis = [
+ "http://meerkat.oreillynet.com/?c=cat23",
+ "http://meerkat.oreillynet.com/?c=47",
+ "http://dmoz.org/Computers/Data_Formats/Markup_Languages/XML/",
+ ]
+
+ @topics_node = "<#{@prefix}:topics>\n"
+ @topics_node << " <rdf:Bag>\n"
+ @topics_lis.each do |value|
+ resource = CGI.escapeHTML(value)
+ @topics_node << " <rdf:li resource=\"#{resource}\"/>\n"
+ end
+ @topics_node << " </rdf:Bag>\n"
+ @topics_node << "</#{@prefix}:topics>"
+
+ @topic_topics_lis = \
+ [
+ "http://meerkat.oreillynet.com/?c=cat23",
+ "http://dmoz.org/Computers/Data_Formats/Markup_Languages/SGML/",
+ "http://dmoz.org/Computers/Programming/Internet/",
+ ]
+
+ @topic_contents = \
+ [
+ {
+ :link => "http://meerkat.oreillynet.com/?c=cat23",
+ :title => "Data: XML",
+ :description => "A Meerkat channel",
+ },
+ {
+ :link => "http://dmoz.org/Computers/Data_Formats/Markup_Languages/XML/",
+ :title => "XML",
+ :subject => "XML",
+ :description => "DMOZ category",
+ :topics => @topic_topics_lis,
+ }
+ ]
+
+ @topic_nodes = @topic_contents.collect do |info|
+ link = info[:link]
+ rv = "<#{@prefix}:topic rdf:about=\"#{link}\">\n"
+ info.each do |name, value|
+ case name
+ when :topics
+ rv << " <#{@prefix}:topics>\n"
+ rv << " <rdf:Bag>\n"
+ value.each do |li|
+ resource = CGI.escapeHTML(li)
+ rv << " <rdf:li resource=\"#{resource}\"/>\n"
+ end
+ rv << " </rdf:Bag>\n"
+ rv << " </#{@prefix}:topics>\n"
+ else
+ prefix = (name == :link ? @prefix : @dc_prefix)
+ rv << " <#{prefix}:#{name}>#{value}</#{prefix}:#{name}>\n"
+ end
+ end
+ rv << "</#{@prefix}:topic>"
+ end
+
+ @rss_source = make_RDF(<<-EOR, @ns)
+#{make_channel(@topics_node)}
+#{make_image()}
+#{make_item(@topics_node)}
+#{make_textinput()}
+#{@topic_nodes.join("\n")}
+EOR
+
+ @rss = Parser.parse(@rss_source)
+ end
+
+ def test_parser
+ assert_nothing_raised do
+ Parser.parse(@rss_source)
+ end
+
+ assert_too_much_tag("topics", "channel") do
+ Parser.parse(make_RDF(<<-EOR, @ns))
+#{make_channel(@topics_node * 2)}
+#{make_item()}
+EOR
+ end
+
+ assert_too_much_tag("topics", "item") do
+ Parser.parse(make_RDF(<<-EOR, @ns))
+#{make_channel()}
+#{make_item(@topics_node * 2)}
+EOR
+ end
+ end
+
+ def test_accessor
+ topics = @rss.channel.taxo_topics
+ assert_equal(@topics_lis.sort,
+ topics.Bag.lis.collect {|li| li.resource}.sort)
+ assert_equal(@topics_lis.sort, topics.resources.sort)
+
+ assert_equal(@rss.taxo_topics.first, @rss.taxo_topic)
+
+ @topic_contents.each_with_index do |info, i|
+ topic = @rss.taxo_topics[i]
+ info.each do |name, value|
+ case name
+ when :link
+ assert_equal(value, topic.about)
+ assert_equal(value, topic.taxo_link)
+ when :topics
+ assert_equal(value.sort, topic.taxo_topics.resources.sort)
+ else
+ assert_equal(value, topic.__send__("dc_#{name}"))
+ end
+ end
+ end
+ end
+
+ def test_to_s
+ @topics_parents.each do |parent|
+ meth = "taxo_topics_element"
+ assert_equal(@topics_node, @rss.__send__(parent).__send__(meth))
+ end
+
+ @topic_nodes.each_with_index do |node, i|
+ expected_xml = taxo_xmlns_container(node)
+ expected = REXML::Document.new(expected_xml).root.elements[1]
+ actual_xml = taxo_xmlns_container(@rss.taxo_topics[i].to_s(true, ""))
+ actual = REXML::Document.new(actual_xml).root.elements[1]
+ expected_elems = expected.reject {|x| x.is_a?(REXML::Text)}
+ actual_elems = actual.reject {|x| x.is_a?(REXML::Text)}
+ expected_elems.sort! {|x, y| x.name <=> y.name}
+ actual_elems.sort! {|x, y| x.name <=> y.name}
+ assert_equal(expected_elems.collect {|x| x.to_s},
+ actual_elems.collect {|x| x.to_s})
+ assert_equal(expected.attributes.sort, actual.attributes.sort)
+ end
+ end
+
+ private
+ def taxo_xmlns_container(content)
+ xmlns_container({
+ @prefix => @uri,
+ "dc" => "http://purl.org/dc/elements/1.1/",
+ "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ },
+ content)
+ end
+ end
+end
+
diff --git a/jni/ruby/test/rss/test_to_s.rb b/jni/ruby/test/rss/test_to_s.rb
new file mode 100644
index 0000000..4ef83ce
--- /dev/null
+++ b/jni/ruby/test/rss/test_to_s.rb
@@ -0,0 +1,670 @@
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/maker"
+require "rss/1.0"
+require "rss/2.0"
+require "rss/content"
+require "rss/dublincore"
+require "rss/syndication"
+require "rss/trackback"
+
+module RSS
+ class TestToS < TestCase
+ def setup
+ @image_url = "http://example.com/foo.png"
+ @textinput_link = "http://example.com/search.cgi"
+ @item_links = [
+ "http://example.com/1",
+ "http://example.com/2",
+ ]
+
+ setup_xml_declaration_info
+ setup_xml_stylesheet_infos
+ setup_channel_info
+ setup_item_infos
+ setup_image_info
+ setup_textinput_info
+
+ setup_dublin_core_info
+ setup_syndication_info
+ setup_content_info
+ setup_trackback_info
+ end
+
+ def test_to_s_10
+ rss = RSS::Maker.make("1.0") do |maker|
+ setup_full(maker)
+ end
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel10(@channel_info, rss.channel)
+ assert_items10(@item_infos, rss.items)
+ rss.items.each do |item|
+ assert_trackback(@trackback_info, item)
+ end
+ assert_image10(@image_info, rss.image)
+ assert_textinput10(@textinput_info, rss.textinput)
+
+ rss = RSS::Parser.parse(rss.to_s)
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel10(@channel_info, rss.channel)
+ assert_items10(@item_infos, rss.items)
+ assert_image10(@image_info, rss.image)
+ assert_textinput10(@textinput_info, rss.textinput)
+ end
+
+ def test_to_s_09
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_full(maker)
+ end
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel09(@channel_info, rss.channel)
+ assert_items09(@item_infos, rss.items)
+ assert_image09(@image_info, rss.image)
+ assert_textinput09(@textinput_info, rss.textinput)
+
+ rss = RSS::Parser.parse(rss.to_s)
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel09(@channel_info, rss.channel)
+ assert_items09(@item_infos, rss.items)
+ assert_image09(@image_info, rss.image)
+ assert_textinput09(@textinput_info, rss.textinput)
+ end
+
+ def test_to_s_20
+ rss = RSS::Maker.make("2.0") do |maker|
+ setup_full(maker)
+ end
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel20(@channel_info, rss.channel)
+ assert_items20(@item_infos, rss.items)
+ assert_image20(@image_info, rss.image)
+ assert_textinput20(@textinput_info, rss.textinput)
+
+ rss = RSS::Parser.parse(rss.to_s)
+
+ assert_xml_declaration(@version, @encoding, @standalone, rss)
+ assert_xml_stylesheets(@xs_infos, rss.xml_stylesheets)
+ assert_channel20(@channel_info, rss.channel)
+ assert_items20(@item_infos, rss.items)
+ assert_image20(@image_info, rss.image)
+ assert_textinput20(@textinput_info, rss.textinput)
+ end
+
+ private
+ def setup_xml_declaration_info
+ @version = "1.0"
+ @encoding = "UTF-8"
+ @standalone = false
+ end
+
+ def setup_xml_stylesheet_infos
+ @xs_infos = [
+ {
+ "href" => "XXX.xsl",
+ "type" => "text/xsl",
+ "title" => "XXX",
+ "media" => "print",
+ "alternate" => "no",
+ },
+ {
+ "href" => "YYY.css",
+ "type" => "text/css",
+ "title" => "YYY",
+ "media" => "all",
+ "alternate" => "no",
+ },
+ ]
+ end
+
+ def setup_channel_info
+ @channel_info = {
+ "about" => "http://example.com/index.rdf",
+ "title" => "Sample RSS",
+ "link" => "http://example.com/",
+ "description" => "Sample\n\n\n\n\nSite",
+ "language" => "en",
+ "copyright" => "FDL",
+ "managingEditor" => "foo@example.com",
+ "webMaster" => "webmaster@example.com",
+ "rating" => '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))',
+ "docs" => "http://backend.userland.com/rss091",
+ "skipDays" => [
+ "Monday",
+ "Friday",
+ ],
+ "skipHours" => [
+ "12",
+ "23",
+ ],
+ "date" => Time.now,
+ "lastBuildDate" => Time.now - 3600,
+ "generator" => "RSS Maker",
+ "ttl" => "60",
+ "cloud" => {
+ "domain" => "rpc.sys.com",
+ "port" => "80",
+ "path" => "/RPC2",
+ "registerProcedure" => "myCloud.rssPleaseNotify",
+ "protocol" => "xml-rpc",
+ },
+ "category" => {
+ "domain" => "http://example.com/misc/",
+ "content" => "misc",
+ },
+
+ "image" => {
+ "resource" => @image_url,
+ },
+
+ "textinput" => {
+ "resource" => @textinput_link,
+ },
+
+ "items" => @item_links.collect{|link| {"resource" => link}},
+ }
+ end
+
+ def setup_item_infos
+ @item_infos = [
+ {
+ "title" => "Sample item1",
+ "link" => @item_links[0],
+ "description" => "Sample description1",
+ "date" => Time.now - 3600,
+ "author" => "foo@example.com",
+ "comments" => "http://example.com/1/comments",
+ "guid" => {
+ "isPermaLink" => "true",
+ "content" => "http://example.com/1",
+ },
+ "enclosure" => {
+ "url" => "http://example.com/1.mp3",
+ "length" => "100",
+ "type" => "audio/mpeg",
+ },
+ "source" => {
+ "url" => "http:/example.com/",
+ "content" => "Sample site",
+ },
+ "category" => {
+ "domain" => "http://example.com/misc/",
+ "content" => "misc",
+ },
+ },
+
+ {
+ "title" => "Sample item2",
+ "link" => @item_links[1],
+ "description" => "Sample description2",
+ "date" => Time.now - 7200,
+ "author" => "foo@example.com",
+ "comments" => "http://example.com/2/comments",
+ "guid" => {
+ "isPermaLink" => "false",
+ "content" => "http://example.com/2",
+ },
+ "enclosure" => {
+ "url" => "http://example.com/2.mp3",
+ "length" => "200",
+ "type" => "audio/mpeg",
+ },
+ "source" => {
+ "url" => "http:/example.com/",
+ "content" => "Sample site",
+ },
+ "category" => {
+ "domain" => "http://example.com/misc/",
+ "content" => "misc",
+ },
+ },
+ ]
+ end
+
+ def setup_image_info
+ @image_info = {
+ "title" => "Sample image",
+ "url" => @image_url,
+ "width" => "88",
+ "height" => "31",
+ "description" => "Sample",
+ }
+ end
+
+ def setup_textinput_info
+ @textinput_info = {
+ "title" => "Sample textinput",
+ "description" => "Search",
+ "name" => "key",
+ "link" => @textinput_link,
+ }
+ end
+
+ def setup_dublin_core_info
+ @dc_info = {
+ "title" => "DC title",
+ "description" => "DC desc",
+ "creator" => "DC creator",
+ "subject" => "DC subject",
+ "publisher" => "DC publisher",
+ "contributor" => "DC contributor",
+ "type" => "DC type",
+ "format" => "DC format",
+ "identifier" => "DC identifier",
+ "source" => "DC source",
+ "language" => "ja",
+ "relation" => "DC relation",
+ "coverage" => "DC coverage",
+ "rights" => "DC rights",
+ "date" => Time.now - 60,
+ }
+ end
+
+ def setup_syndication_info
+ @sy_info = {
+ "updatePeriod" => "hourly",
+ "updateFrequency" => "2",
+ "updateBase" => Time.now - 3600,
+ }
+ end
+
+ def setup_content_info
+ @content_info = {
+ "encoded" => "<p>p</p>",
+ }
+ end
+
+ def setup_trackback_info
+ @trackback_info = {
+ "ping" => "http://example.com/tb.cgi?tb_id=XXX",
+ "abouts" => [
+ "http://example.net/tb.cgi?tb_id=YYY",
+ "http://example.org/tb.cgi?tb_id=ZZZ",
+ ]
+ }
+ end
+
+
+ def setup_full(maker)
+ setup_xml_declaration(maker)
+ setup_xml_stylesheets(maker)
+ setup_channel(maker)
+ setup_image(maker)
+ setup_items(maker)
+ setup_textinput(maker)
+ end
+
+ def setup_xml_declaration(maker)
+ %w(version encoding standalone).each do |name|
+ maker.__send__("#{name}=", instance_eval("@#{name}"))
+ end
+ end
+
+ def setup_xml_stylesheets(maker)
+ @xs_infos.each do |info|
+ xs = maker.xml_stylesheets.new_xml_stylesheet
+ info.each do |name, value|
+ xs.__send__("#{name}=", value)
+ end
+ end
+ end
+
+ def setup_channel(maker)
+ channel = maker.channel
+ info = @channel_info
+
+ %w(about title link description language copyright
+ managingEditor webMaster rating docs date
+ lastBuildDate generator ttl).each do |name|
+ channel.__send__("#{name}=", info[name])
+ end
+
+ skipDays = channel.skipDays
+ info["skipDays"].each do |day|
+ new_day = skipDays.new_day
+ new_day.content = day
+ end
+
+ skipHours = channel.skipHours
+ info["skipHours"].each do |hour|
+ new_hour = skipHours.new_hour
+ new_hour.content = hour
+ end
+
+ cloud = channel.cloud
+ %w(domain port path registerProcedure protocol).each do |name|
+ cloud.__send__("#{name}=", info["cloud"][name])
+ end
+
+ category = channel.categories.new_category
+ %w(domain content).each do |name|
+ category.__send__("#{name}=", info["category"][name])
+ end
+ end
+
+ def setup_image(maker)
+ image = maker.image
+ info = @image_info
+
+ %w(title url width height description).each do |name|
+ image.__send__("#{name}=", info[name])
+ end
+ end
+
+ def setup_items(maker)
+ items = maker.items
+
+ @item_infos.each do |info|
+ item = items.new_item
+ %w(title link description date author comments).each do |name|
+ item.__send__("#{name}=", info[name])
+ end
+
+ guid = item.guid
+ %w(isPermaLink content).each do |name|
+ guid.__send__("#{name}=", info["guid"][name])
+ end
+
+ enclosure = item.enclosure
+ %w(url length type).each do |name|
+ enclosure.__send__("#{name}=", info["enclosure"][name])
+ end
+
+ source = item.source
+ %w(url content).each do |name|
+ source.__send__("#{name}=", info["source"][name])
+ end
+
+ category = item.categories.new_category
+ %w(domain content).each do |name|
+ category.__send__("#{name}=", info["category"][name])
+ end
+
+ setup_trackback(item)
+ end
+ end
+
+ def setup_textinput(maker)
+ textinput = maker.textinput
+ info = @textinput_info
+
+ %w(title description name link).each do |name|
+ textinput.__send__("#{name}=", info[name])
+ end
+ end
+
+ def setup_content(target)
+ prefix = "content"
+ %w(encoded).each do |name|
+ target.__send__("#{prefix}_#{name}=", @content_info[name])
+ end
+ end
+
+ def setup_dublin_core(target)
+ prefix = "dc"
+ %w(title description creator subject publisher
+ contributor type format identifier source language
+ relation coverage rights).each do |name|
+ target.__send__("#{prefix}_#{name}=", @dc_info[name])
+ end
+ end
+
+ def setup_syndicate(target)
+ prefix = "sy"
+ %w(updatePeriod updateFrequency updateBase).each do |name|
+ target.__send__("#{prefix}_#{name}=", @sy_info[name])
+ end
+ end
+
+ def setup_trackback(target)
+ target.trackback_ping = @trackback_info["ping"]
+ @trackback_info["abouts"].each do |about|
+ new_about = target.trackback_abouts.new_about
+ new_about.value = about
+ end
+ end
+
+
+ def assert_channel10(attrs, channel)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+
+ names = %w(about title link description)
+ assert_attributes(attrs, names, channel)
+
+ %w(image items textinput).each do |name|
+ value = n_attrs[name]
+ if value
+ target = channel.__send__(name)
+ __send__("assert_channel10_#{name}", value, target)
+ end
+ end
+ end
+ end
+
+ def assert_channel10_image(attrs, image)
+ _wrap_assertion do
+ assert_attributes(attrs, %w(resource), image)
+ end
+ end
+
+ def assert_channel10_textinput(attrs, textinput)
+ _wrap_assertion do
+ assert_attributes(attrs, %w(resource), textinput)
+ end
+ end
+
+ def assert_channel10_items(attrs, items)
+ _wrap_assertion do
+ assert_equal(items.resources, items.Seq.lis.collect {|x| x.resource})
+ items.Seq.lis.each_with_index do |li, i|
+ assert_attributes(attrs[i], %w(resource), li)
+ end
+ end
+ end
+
+ def assert_image10(attrs, image)
+ _wrap_assertion do
+ names = %w(about title url link)
+ assert_attributes(attrs, names, image)
+ end
+ end
+
+ def assert_items10(attrs, items)
+ _wrap_assertion do
+ names = %w(about title link description)
+ items.each_with_index do |item, i|
+ assert_attributes(attrs[i], names, item)
+ end
+ end
+ end
+
+ def assert_textinput10(attrs, textinput)
+ _wrap_assertion do
+ names = %w(about title description name link)
+ assert_attributes(attrs, names, textinput)
+ end
+ end
+
+
+ def assert_channel09(attrs, channel)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+
+ names = %w(title description link language rating
+ copyright pubDate lastBuildDate docs
+ managingEditor webMaster)
+ assert_attributes(attrs, names, channel)
+
+ %w(skipHours skipDays).each do |name|
+ value = n_attrs[name]
+ if value
+ target = channel.__send__(name)
+ __send__("assert_channel09_#{name}", value, target)
+ end
+ end
+ end
+ end
+
+ def assert_channel09_skipDays(contents, skipDays)
+ _wrap_assertion do
+ days = skipDays.days
+ contents.each_with_index do |content, i|
+ assert_equal(content, days[i].content)
+ end
+ end
+ end
+
+ def assert_channel09_skipHours(contents, skipHours)
+ _wrap_assertion do
+ hours = skipHours.hours
+ contents.each_with_index do |content, i|
+ assert_equal(content.to_i, hours[i].content)
+ end
+ end
+ end
+
+ def assert_image09(attrs, image)
+ _wrap_assertion do
+ names = %w(url link title description)
+ names << ["width", :integer]
+ names << ["height", :integer]
+ assert_attributes(attrs, names, image)
+ end
+ end
+
+ def assert_items09(attrs, items)
+ _wrap_assertion do
+ names = %w(title link description)
+ items.each_with_index do |item, i|
+ assert_attributes(attrs[i], names, item)
+ end
+ end
+ end
+
+ def assert_textinput09(attrs, textinput)
+ _wrap_assertion do
+ names = %w(title description name link)
+ assert_attributes(attrs, names, textinput)
+ end
+ end
+
+
+ def assert_channel20(attrs, channel)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+
+ names = %w(title link description language copyright
+ managingEditor webMaster pubDate
+ lastBuildDate generator docs rating)
+ names << ["ttl", :integer]
+ assert_attributes(attrs, names, channel)
+
+ %w(cloud categories skipHours skipDays).each do |name|
+ value = n_attrs[name]
+ if value
+ target = channel.__send__(name)
+ __send__("assert_channel20_#{name}", value, target)
+ end
+ end
+ end
+ end
+
+ def assert_channel20_skipDays(contents, skipDays)
+ assert_channel09_skipDays(contents, skipDays)
+ end
+
+ def assert_channel20_skipHours(contents, skipHours)
+ assert_channel09_skipHours(contents, skipHours)
+ end
+
+ def assert_channel20_cloud(attrs, cloud)
+ _wrap_assertion do
+ names = %w(domain path registerProcedure protocol)
+ names << ["port", :integer]
+ assert_attributes(attrs, names, cloud)
+ end
+ end
+
+ def assert_channel20_categories(attrs, categories)
+ _wrap_assertion do
+ names = %w(domain content)
+ categories.each_with_index do |category, i|
+ assert_attributes(attrs[i], names, category)
+ end
+ end
+ end
+
+ def assert_image20(attrs, image)
+ _wrap_assertion do
+ names = %w(url link title description)
+ names << ["width", :integer]
+ names << ["height", :integer]
+ assert_attributes(attrs, names, image)
+ end
+ end
+
+ def assert_items20(attrs, items)
+ _wrap_assertion do
+ names = %w(about title link description)
+ items.each_with_index do |item, i|
+ assert_attributes(attrs[i], names, item)
+
+ n_attrs = normalized_attrs(attrs[i])
+
+ %w(source enclosure categories guid).each do |name|
+ value = n_attrs[name]
+ if value
+ target = item.__send__(name)
+ __send__("assert_items20_#{name}", value, target)
+ end
+ end
+ end
+ end
+ end
+
+ def assert_items20_source(attrs, source)
+ _wrap_assertion do
+ assert_attributes(attrs, %w(url content), source)
+ end
+ end
+
+ def assert_items20_enclosure(attrs, enclosure)
+ _wrap_assertion do
+ names = ["url", ["length", :integer], "type"]
+ assert_attributes(attrs, names, enclosure)
+ end
+ end
+
+ def assert_items20_categories(attrs, categories)
+ _wrap_assertion do
+ assert_channel20_categories(attrs, categories)
+ end
+ end
+
+ def assert_items20_guid(attrs, guid)
+ _wrap_assertion do
+ names = [["isPermaLink", :boolean], ["content"]]
+ assert_attributes(attrs, names, guid)
+ end
+ end
+
+ def assert_textinput20(attrs, textinput)
+ _wrap_assertion do
+ names = %w(title description name link)
+ assert_attributes(attrs, names, textinput)
+ end
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_trackback.rb b/jni/ruby/test/rss/test_trackback.rb
new file mode 100644
index 0000000..8560c25
--- /dev/null
+++ b/jni/ruby/test/rss/test_trackback.rb
@@ -0,0 +1,135 @@
+require "cgi"
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/1.0"
+require "rss/2.0"
+require "rss/trackback"
+
+module RSS
+ class TestTrackBack < TestCase
+
+ def setup
+ @prefix = "trackback"
+ @uri = "http://madskills.com/public/xml/rss/module/trackback/"
+
+ @parents = %w(item)
+
+ @elems = {
+ :ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
+ :about => "http://foo.com/trackback/tb.cgi?tb_id=20020923",
+ }
+
+ @content_nodes = @elems.collect do |name, value|
+ "<#{@prefix}:#{name} rdf:resource=\"#{CGI.escapeHTML(value.to_s)}\"/>"
+ end.join("\n")
+
+ @content_nodes2 = @elems.collect do |name, value|
+ "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
+ end.join("\n")
+
+ @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
+#{make_channel()}
+#{make_image()}
+#{make_item(@content_nodes)}
+#{make_textinput()}
+EOR
+
+ @rss = Parser.parse(@rss_source)
+
+ @rss20_source = make_rss20(nil, {@prefix => @uri}) do
+ make_channel20(nil) do
+ make_item20(@content_nodes2)
+ end
+ end
+
+ @rss20 = Parser.parse(@rss20_source, false)
+ end
+
+ def test_parser
+
+ assert_nothing_raised do
+ Parser.parse(@rss_source)
+ end
+
+ @elems.find_all{|k, v| k == :ping}.each do |tag, value|
+ assert_too_much_tag(tag.to_s, "item") do
+ Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
+#{make_channel()}
+#{make_item(("<" + @prefix + ":" + tag.to_s + " rdf:resource=\"" +
+ CGI.escapeHTML(value.to_s) +
+ "\"/>") * 2)}
+EOR
+ end
+ end
+
+ @elems.find_all{|k, v| k == :about}.each do |tag, value|
+ assert_missing_tag("trackback:ping", "item") do
+ Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
+#{make_channel()}
+#{make_item(("<" + @prefix + ":" + tag.to_s + " rdf:resource=\"" +
+ CGI.escapeHTML(value.to_s) +
+ "\"/>") * 2)}
+EOR
+ end
+
+ end
+
+ end
+
+ def test_accessor
+
+ new_value = {
+ :ping => "http://baz.com/trackback/tb.cgi?tb_id=20030808",
+ :about => "http://hoge.com/trackback/tb.cgi?tb_id=90030808",
+ }
+
+ @elems.each do |name, value|
+ @parents.each do |parent|
+ accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}"
+ target = @rss.__send__(parent)
+ target20 = @rss20.channel.__send__(parent, -1)
+ assert_equal(value, target.__send__(accessor))
+ assert_equal(value, target20.__send__(accessor))
+ if name == :about
+ # abount is zero or more
+ target.__send__("#{accessor}=", 0, new_value[name].to_s)
+ target20.__send__("#{accessor}=", 0, new_value[name].to_s)
+ else
+ target.__send__("#{accessor}=", new_value[name].to_s)
+ target20.__send__("#{accessor}=", new_value[name].to_s)
+ end
+ assert_equal(new_value[name], target.__send__(accessor))
+ assert_equal(new_value[name], target20.__send__(accessor))
+ end
+ end
+
+ end
+
+ def test_to_s
+
+ @elems.each do |name, value|
+ excepted = %Q!<#{@prefix}:#{name} rdf:resource="#{CGI.escapeHTML(value)}"/>!
+ @parents.each do |parent|
+ meth = "#{RSS::TRACKBACK_PREFIX}_#{name}_element"
+ meth << "s" if name == :about
+ assert_equal(excepted, @rss.__send__(parent).__send__(meth))
+ end
+ end
+
+ REXML::Document.new(@rss_source).root.each_element do |parent|
+ if @parents.include?(parent.name)
+ parent.each_element do |elem|
+ if elem.namespace == @uri
+ assert_equal(elem.attributes["resource"], @elems[elem.name.intern])
+ end
+ end
+ end
+ end
+
+ end
+
+ end
+end
+
diff --git a/jni/ruby/test/rss/test_version.rb b/jni/ruby/test/rss/test_version.rb
new file mode 100644
index 0000000..d2175ab
--- /dev/null
+++ b/jni/ruby/test/rss/test_version.rb
@@ -0,0 +1,9 @@
+require_relative "rss-testcase"
+
+module RSS
+ class TestVersion < TestCase
+ def test_version
+ assert_equal("0.2.7", ::RSS::VERSION)
+ end
+ end
+end
diff --git a/jni/ruby/test/rss/test_xml-stylesheet.rb b/jni/ruby/test/rss/test_xml-stylesheet.rb
new file mode 100644
index 0000000..c67922f
--- /dev/null
+++ b/jni/ruby/test/rss/test_xml-stylesheet.rb
@@ -0,0 +1,108 @@
+require "rexml/document"
+
+require_relative "rss-testcase"
+
+require "rss/1.0"
+require "rss/xml-stylesheet"
+
+module RSS
+ class TestXMLStyleSheet < TestCase
+
+ def test_accessor
+ [
+ {:href => "a.xsl", :type => "text/xsl"},
+ {:media => "print", :title => "FOO"},
+ {:charset => "UTF-8", :alternate => "yes"},
+ ].each do |attrs|
+ assert_xml_stylesheet_attrs(attrs, XMLStyleSheet.new(attrs))
+ end
+ end
+
+ def test_to_s
+ [
+ {:href => "a.xsl", :type => "text/xsl"},
+ {:type => "text/xsl"},
+ {:href => "a.xsl", :guess_type => "text/xsl"},
+ {:href => "a.css", :type => "text/css"},
+ {:href => "a.css", :type => "text/xsl",
+ :guess_type => "text/css"},
+ {:href => "a.xsl", :type => "text/xsl",
+ :title => "sample", :media => "printer",
+ :charset => "UTF-8", :alternate => "yes"},
+ {:href => "a.css", :guess_type => "text/css",
+ :alternate => "no"},
+ {:type => "text/xsl", :title => "sample",
+ :media => "printer", :charset => "UTF-8",
+ :alternate => "yes"},
+ ].each do |attrs|
+ target, contents = parse_pi(XMLStyleSheet.new(attrs).to_s)
+ assert_xml_stylesheet(target, attrs, XMLStyleSheet.new(contents))
+ end
+ end
+
+ def test_bad_alternate
+ %w(a ___ ??? BAD_ALTERNATE).each do |value|
+ xss = XMLStyleSheet.new
+ assert_raise(NotAvailableValueError) do
+ xss.alternate = value
+ end
+ xss.do_validate = false
+ assert_nothing_raised do
+ xss.alternate = value
+ end
+ assert_nil(xss.alternate)
+ end
+ end
+
+ def test_parse
+ [
+ [{:href => "a.xsl", :type => "text/xsl"},],
+ [{:media => "print", :title => "FOO"},],
+ [{:charset => "UTF-8", :alternate => "yes"},],
+ [{:href => "a.xsl", :type => "text/xsl"},
+ {:type => "text/xsl"},
+ {:href => "a.xsl", :guess_type => "text/xsl"},
+ {:href => "a.css", :type => "text/css"},
+ {:href => "a.css", :type => "text/xsl",
+ :guess_type => "text/css"},
+ {:href => "a.xsl", :type => "text/xsl",
+ :title => "sample", :media => "printer",
+ :charset => "UTF-8", :alternate => "yes"},
+ {:href => "a.css", :guess_type => "text/css",
+ :alternate => "no"},
+ {:type => "text/xsl", :title => "sample",
+ :media => "printer", :charset => "UTF-8",
+ :alternate => "yes"},],
+ ].each do |xsss|
+ doc = REXML::Document.new(make_sample_RDF)
+ root = doc.root
+ xsss.each do |xss|
+ content = xss.collect do |key, name|
+ %Q[#{key}="#{name}"]
+ end.join(" ")
+ pi = REXML::Instruction.new("xml-stylesheet", content)
+ root.previous_sibling = pi
+ end
+ rss = Parser.parse(doc.to_s)
+ have_href_xsss = xsss.find_all {|xss| xss.has_key?(:href)}
+ assert_equal(have_href_xsss.size, rss.xml_stylesheets.size)
+ rss.xml_stylesheets.each_with_index do |stylesheet, i|
+ target, = parse_pi(stylesheet.to_s)
+ assert_xml_stylesheet(target, have_href_xsss[i], stylesheet)
+ end
+ end
+ end
+
+ def parse_pi(pi)
+ /\A\s*<\?(\S+)([^?]*\?+(?:[^?>][^?]*\?+)*)>\s*\z/ =~ pi
+ target = $1
+ dummy = REXML::Document.new("<dummy #{$2.to_s.chop}/>").root
+ contents = {}
+ dummy.attributes.each do |name, value|
+ contents[name] = value
+ end
+ [target, contents]
+ end
+
+ end
+end