From 1909f5f1b14167bc24bcccd1500a27a42551fa95 Mon Sep 17 00:00:00 2001 From: kou Date: Thu, 8 Jul 2004 13:54:07 +0000 Subject: * lib/rss/{rss,parser,0.9,1.0,2.0}.rb: supported RSS 0.9x/2.0 validation and validation which disregard order of elements. * test/rss/test_parser.rb: added tests for RSS 0.9x/2.0 validation. * test/rss/{test_trackback,rss-testcase}.rb: fixed no good method name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rss/rss-testcase.rb | 35 +++++++++- test/rss/test_parser.rb | 171 +++++++++++++++++++++++++++++++++++++++++---- test/rss/test_trackback.rb | 18 ++--- 3 files changed, 198 insertions(+), 26 deletions(-) (limited to 'test') diff --git a/test/rss/rss-testcase.rb b/test/rss/rss-testcase.rb index 349e3d4dc1..e7195f41be 100644 --- a/test/rss/rss-testcase.rb +++ b/test/rss/rss-testcase.rb @@ -19,6 +19,7 @@ module RSS 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. @@ -28,6 +29,18 @@ module RSS "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/" + def default_test # This class isn't tested end @@ -116,7 +129,7 @@ EOT EOR end - def make_Rss2(content=nil, xmlns=[]) + def make_rss20(content=nil, xmlns=[]) <<-EORSS #{make_xmldecl} #{TITLE_VALUE} #{LINK_VALUE} #{DESCRIPTION_VALUE} + #{LANGUAGE_VALUE} #{RDF_RESOURCE} @@ -142,6 +156,9 @@ EORSS #{RESOURCES.collect do |res| '' + res + '' end.join("\n")} + #{TITLE_VALUE} + #{DESCRIPTION_VALUE} + #{NAME_VALUE} #{RDF_RESOURCE} @@ -150,7 +167,7 @@ EORSS EOC end - def make_item2(content=nil) + def make_item20(content=nil) <<-EOI #{TITLE_VALUE} @@ -160,5 +177,17 @@ EOC EOI end + + def make_cloud20 + <<-EOC + +EOC + end + end end diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb index 05ff9748ad..5b15ccb908 100644 --- a/test/rss/test_parser.rb +++ b/test/rss/test_parser.rb @@ -3,6 +3,8 @@ require "rss-testcase" require "rss/1.0" +require "rss/2.0" +require "rss/dublincore" module RSS class TestParser < TestCase @@ -76,14 +78,19 @@ EOR EOR end - assert_not_excepted_tag("image", "RDF") do - Parser.parse(make_RDF(<<-EOR)) + assert_parse(make_RDF(<<-EOR), :nothing_raised) #{make_channel} #{make_item} #{make_image} #{make_textinput} EOR - end + + 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} @@ -279,16 +286,25 @@ EOR EOR - rss = make_RDF(<<-EOR) + assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") #{make_channel} hoge + http://example.com/hoge.png + http://example.com/ + +EOR + + rss = make_RDF(<<-EOR) +#{make_channel} + http://example.com/ http://example.com/hoge.png + hoge EOR - assert_missing_tag("url", "image") do + assert_missing_tag("item", "RDF") do Parser.parse(rss) end @@ -296,15 +312,6 @@ EOR Parser.parse(rss, false).validate end - assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF") -#{make_channel} - - hoge - http://example.com/hoge.png - http://example.com/ - -EOR - end def test_item @@ -439,6 +446,142 @@ EOR end + 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[])} +EOR + + end + + end + + def test_source20 + + assert_parse(make_rss20(<<-EOR), :missing_attribute, "source", "url") +#{make_channel20(make_item20(%Q[Example]))} +EOR + + assert_parse(make_rss20(<<-EOR), :nothing_raised) +#{make_channel20(make_item20(%Q[]))} +EOR + + assert_parse(make_rss20(<<-EOR), :nothing_raised) +#{make_channel20(make_item20(%Q[Example]))} +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[ + + ])} + ])} +EOR + + end + + end + + def test_category20 + + attrs = [ + ["domain", CATEGORY_DOMAIN], + ] + + (attrs.size + 1).times do |i| + missing_attr = attrs[i] + if missing_attr + meth = :missing_attribute + args = ["category", missing_attr[0]] + else + meth = :nothing_raised + args = [] + end + + category_attrs = [] + attrs.each_with_index do |attr, j| + unless i == j + category_attrs << %Q[#{attr[0]}="#{attr[1]}"] + end + end + + ["", "Example Text"].each do |text| + assert_parse(make_rss20(<<-EOR), meth, *args) +#{make_channel20(%Q[ +#{make_item20(%Q[ +#{text} + ])} + ])} +EOR + end + end + + end + def test_ignore rss = make_RDF(<<-EOR) diff --git a/test/rss/test_trackback.rb b/test/rss/test_trackback.rb index 141ef50779..ab77cf3fb8 100644 --- a/test/rss/test_trackback.rb +++ b/test/rss/test_trackback.rb @@ -40,13 +40,13 @@ EOR @rss = Parser.parse(@rss_source) - @rss2_source = make_Rss2(nil, {@prefix => @uri}) do - make_channel2(nil) do - make_item2(@content_nodes2) + @rss20_source = make_rss20(nil, {@prefix => @uri}) do + make_channel20(nil) do + make_item20(@content_nodes2) end end - @rss2 = Parser.parse(@rss2_source, false) + @rss20 = Parser.parse(@rss20_source, false) end def test_parser @@ -92,18 +92,18 @@ EOR accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}" target_accessor = "resource" target = @rss.send(parent).send(accessor) - target2 = @rss2.channel.send(parent, -1) + target20 = @rss20.channel.send(parent, -1) assert_equal(value, target.send(target_accessor)) - assert_equal(value, target2.send(accessor)) + assert_equal(value, target20.send(accessor)) target.send("#{target_accessor}=", new_value[name].to_s) if name == :about # abount is zero or more - target2.send("#{accessor}=", 0, new_value[name].to_s) + target20.send("#{accessor}=", 0, new_value[name].to_s) else - target2.send("#{accessor}=", new_value[name].to_s) + target20.send("#{accessor}=", new_value[name].to_s) end assert_equal(new_value[name], target.send(target_accessor)) - assert_equal(new_value[name], target2.send(accessor)) + assert_equal(new_value[name], target20.send(accessor)) end end -- cgit v1.2.3