test/test-pdf.rb in chupa-text-decomposer-pdf-1.0.4 vs test/test-pdf.rb in chupa-text-decomposer-pdf-1.0.5
- old
+ new
@@ -13,10 +13,11 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
require "pathname"
+require "gdk_pixbuf2"
class TestPDF < Test::Unit::TestCase
def setup
@options = {}
end
@@ -108,12 +109,17 @@
def test_producer
assert_equal(["LibreOffice 4.1"], decompose("producer"))
end
def test_created_time
- assert_equal([Time.parse("2014-01-05T06:52:45Z")],
- decompose("created_time"))
+ if ENV["TRAVIS"] # TODO: Why? We set TZ=JST in run-test.rb
+ assert_equal([Time.parse("2014-01-05T15:52:45Z")],
+ decompose("created_time"))
+ else
+ assert_equal([Time.parse("2014-01-05T06:52:45Z")],
+ decompose("created_time"))
+ end
end
private
def decompose(attribute_name)
super(fixture_path("attributes.pdf")).collect do |data|
@@ -164,9 +170,47 @@
end
private
def decompose
super(fixture_path("encrypted.pdf"))
+ end
+ end
+
+ sub_test_case("screenshot") do
+ def test_with_password
+ assert_equal([
+ {
+ "mime-type" => "image/png",
+ "pixels" => load_image_fixture("screenshot.png"),
+ "encoding" => "base64",
+ },
+ ],
+ decompose("screenshot.pdf"))
+ end
+
+ private
+ def decompose(fixture_name)
+ super(fixture_path(fixture_name)).collect do |decompose|
+ screenshot = decompose.screenshot
+ {
+ "mime-type" => screenshot.mime_type,
+ "pixels" => load_image_data(screenshot.decoded_data),
+ "encoding" => screenshot.encoding,
+ }
+ end
+ end
+
+ def load_image_data(data)
+ loader = GdkPixbuf::PixbufLoader.new
+ loader.write(data)
+ loader.close
+ loader.pixbuf.pixels
+ end
+
+ def load_image_fixture(fixture_name)
+ File.open(fixture_path(fixture_name), "rb") do |file|
+ load_image_data(file.read)
+ end
end
end
end
end