added spec for pdf2swf url conversion
[swftools.git] / spec / spec_helper.rb
index 1727b0f..876f1d4 100644 (file)
@@ -56,6 +56,10 @@ class Area
        text2 = @file.get_text(@x1,@y1,@x2,@y2) 
        text2 == text or raise AreaError.new(self, "doesn't contain text \"#{text}\" (found: \"#{text2}\")")
     end
+    def should_contain_link(url)
+       links = @file.get_links(@x1,@y1,@x2,@y2) 
+       (links & [url]) or raise AreaError.new(self, "doesn't contain url \"#{url}\")
+    end
     def to_s
        "(#{@x1},#{@y1},#{@x2},#{@y2})"
     end
@@ -134,6 +138,10 @@ class DocFile
        #puts `swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}`
        `swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}`.chomp
     end
+    def get_links(x1,y1,x2,y2)
+       self.convert()
+       `swfdump -a #{@swfname}`.scan(/GetUrl2? URL:"([^"]*)"/).inject([]) do |a,u| a + u end
+    end
     def get_area(x1,y1,x2,y2)
        self.render()
        data = @img.export_pixels(x1, y1, x2-x1, y2-y1, "RGB")