1 #!/usr/bin/env jruby --headless -rubygems
3 require File.expand_path( File.dirname(__FILE__) + '/test_helper')
6 class ZXingTest < Test::Unit::TestCase
7 context "A QR decoder singleton" do
9 class Foo < Struct.new(:v); def to_s; self.v; end; end
13 @uri = "http://2d-code.co.uk/images/bbc-logo-in-qr-code.gif"
14 @path = File.expand_path( File.dirname(__FILE__) + '/qrcode.png')
15 @file = File.new(@path)
16 @google_logo = "http://www.google.com/logos/grandparentsday10.gif"
17 @uri_result = "http://bbc.co.uk/programmes"
18 @path_result = "http://rubyflow.com"
21 should "decode a URL" do
22 assert_equal @decoder.decode(@uri), @uri_result
25 should "decode a file path" do
26 assert_equal @decoder.decode(@path), @path_result
29 should "return nil if #decode fails" do
30 assert_nil @decoder.decode(@google_logo)
33 should "raise an exception if #decode! fails" do
34 assert_raise(NativeException) { @decoder.decode!(@google_logo) }
37 should "decode objects that respond to #path" do
38 assert_equal @decoder.decode(@file), @path_result
41 should "call #to_s to argument passed in as a last resort" do
42 assert_equal @decoder.decode(Foo.new(@path)), @path_result
46 context "A QR decoder module" do
49 class SpyRing; include ZXing end
53 should "include #decode and #decode! into classes" do
54 assert_equal defined?(@ring.decode), "method"
55 assert_equal defined?(@ring.decode!), "method"