1770d5471bb54d3891d18ad51c6e5386bd05fc0a
[zxing.git] / jruby / test / zxing / decodable_test.rb
1 #!/usr/bin/env jruby --headless -rubygems
2
3 require File.expand_path( File.dirname(__FILE__) + '/../test_helper')
4 require 'zxing/decodable'
5
6 class DecodableTest < Test::Unit::TestCase
7
8   class Object::File
9     include Decodable
10   end
11
12   class URL
13     include Decodable
14     def initialize(path)
15       @path = path
16     end
17     def path; @path end
18   end
19
20   context "A Decodable module" do
21     setup do
22       @file = File.open( File.expand_path( File.dirname(__FILE__) + '/../qrcode.png' ))
23       @uri = URL.new "http://2d-code.co.uk/images/bbc-logo-in-qr-code.gif"
24       @bad_uri = URL.new "http://google.com"
25     end
26
27     should "provide #decode to decode the return value of #path" do
28       assert_equal @file.decode, ZXing.decode(@file.path)
29       assert_equal @uri.decode, ZXing.decode(@uri.path)
30       assert_nil @bad_uri.decode
31     end
32
33     should "provide #decode! as well" do
34       assert_equal @file.decode!, ZXing.decode(@file.path)
35       assert_equal @uri.decode!, ZXing.decode(@uri.path)
36       assert_raise(NativeException) { @bad_uri.decode! }
37     end
38   end
39
40 end