Sha256: a3c577ca0d9c6ec0037ba82afae87b82b03f93f6c5c932570d840605998e2faa

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "helper"))

class QRCodeTestCase < QRToolsTestCase
  def setup
    @code = QRTools::Encoder.encode('http://tenderlovemaking.com/')
  end

  def test_new
    encoder = QRTools::Encoder.new
  end

  def test_version
    encoder = QRTools::Encoder.new
    assert encoder.version
  end

  def test_version=
    encoder = QRTools::Encoder.new
    encoder.version = 1
    assert_equal 1, encoder.version
  end

  def test_code_has_a_width
    assert @code.width
  end

  def test_code_has_a_version
    assert @code.version
  end

  def test_code_has_data
    assert @code.data
  end

  def test_to_matrix
    assert @code.to_matrix
  end

  def test_to_s
    assert @code.to_s
  end

  def test_roundtrip
    filename = File.join(Dir::tmpdir, 'out.png')
    File.open(filename, 'wb') { |f|
      f.write @code.to_png
    }
    img = QRTools::Image.load(filename)
    assert decoder = QRTools::Decoder.decode(img)
    assert_equal 'http://tenderlovemaking.com/', decoder.body.downcase
  end

  class Foo < Struct.new(:foo)
  end

  def test_marshal_roundtrip
    object = Foo.new("foo")
    packed = [Marshal.dump(object)].pack('m')

    # Encode packed object
    assert code = QRTools::Encoder.encode(packed,
      :case_sensitive => true,
      :error_correction => QRTools::Encoder::H
    )

    filename = File.join('/tmp', 'out.png')
    File.open(filename, 'wb') { |f| f.write code.to_png }

    img = QRTools::Image.load(filename)
    assert decoder = QRTools::Decoder.decode(img)

    # Make sure we can read the packed object
    assert_equal packed, decoder.body

    foo = Marshal.load(decoder.body.unpack('m').first)
    assert_equal object.foo, foo.foo
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qrtools-1.0.0 test/test_qrcode.rb
qrtools-1.0.1 test/test_qrcode.rb