# coding: utf-8
#
# 画像関連テスト
#

describe "画像関連" do
  before do
    a = [ # 10x10のPNGデータ
      137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0,
      0, 0, 10, 0, 0, 0, 10, 8, 6, 0, 0, 0, 141, 50, 207, 189, 0, 0,
      0, 4, 103, 65, 77, 65, 0, 0, 177, 143, 11, 252, 97, 5, 0, 0, 0,
      32, 99, 72, 82, 77, 0, 0, 122, 38, 0, 0, 128, 132, 0, 0, 250, 0,
      0, 0, 128, 232, 0, 0, 117, 48, 0, 0, 234, 96, 0, 0, 58, 152, 0,
      0, 23, 112, 156, 186, 81, 60, 0, 0, 0, 9, 112, 72, 89, 115, 0,
      0, 11, 19, 0, 0, 11, 19, 1, 0, 154, 156, 24, 0, 0, 1, 213, 105,
      84, 88, 116, 88, 77, 76, 58, 99, 111, 109, 46, 97, 100, 111, 98,
      101, 46, 120, 109, 112, 0, 0, 0, 0, 0, 60, 120, 58, 120, 109,
      112, 109, 101, 116, 97, 32, 120, 109, 108, 110, 115, 58, 120,
      61, 34, 97, 100, 111, 98, 101, 58, 110, 115, 58, 109, 101, 116,
      97, 47, 34, 32, 120, 58, 120, 109, 112, 116, 107, 61, 34, 88,
      77, 80, 32, 67, 111, 114, 101, 32, 53, 46, 52, 46, 48, 34, 62,
      10, 32, 32, 32, 60, 114, 100, 102, 58, 82, 68, 70, 32, 120, 109,
      108, 110, 115, 58, 114, 100, 102, 61, 34, 104, 116, 116, 112,
      58, 47, 47, 119, 119, 119, 46, 119, 51, 46, 111, 114, 103, 47,
      49, 57, 57, 57, 47, 48, 50, 47, 50, 50, 45, 114, 100, 102, 45,
      115, 121, 110, 116, 97, 120, 45, 110, 115, 35, 34, 62, 10, 32,
      32, 32, 32, 32, 32, 60, 114, 100, 102, 58, 68, 101, 115, 99,
      114, 105, 112, 116, 105, 111, 110, 32, 114, 100, 102, 58, 97,
      98, 111, 117, 116, 61, 34, 34, 10, 32, 32, 32, 32, 32, 32, 32,
      32, 32, 32, 32, 32, 120, 109, 108, 110, 115, 58, 116, 105, 102,
      102, 61, 34, 104, 116, 116, 112, 58, 47, 47, 110, 115, 46, 97,
      100, 111, 98, 101, 46, 99, 111, 109, 47, 116, 105, 102, 102, 47,
      49, 46, 48, 47, 34, 62, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32,
      60, 116, 105, 102, 102, 58, 67, 111, 109, 112, 114, 101, 115,
      115, 105, 111, 110, 62, 53, 60, 47, 116, 105, 102, 102, 58, 67,
      111, 109, 112, 114, 101, 115, 115, 105, 111, 110, 62, 10, 32,
      32, 32, 32, 32, 32, 32, 32, 32, 60, 116, 105, 102, 102, 58, 80,
      104, 111, 116, 111, 109, 101, 116, 114, 105, 99, 73, 110, 116,
      101, 114, 112, 114, 101, 116, 97, 116, 105, 111, 110, 62, 50,
      60, 47, 116, 105, 102, 102, 58, 80, 104, 111, 116, 111, 109,
      101, 116, 114, 105, 99, 73, 110, 116, 101, 114, 112, 114, 101,
      116, 97, 116, 105, 111, 110, 62, 10, 32, 32, 32, 32, 32, 32, 32,
      32, 32, 60, 116, 105, 102, 102, 58, 79, 114, 105, 101, 110, 116,
      97, 116, 105, 111, 110, 62, 49, 60, 47, 116, 105, 102, 102, 58,
      79, 114, 105, 101, 110, 116, 97, 116, 105, 111, 110, 62, 10, 32,
      32, 32, 32, 32, 32, 60, 47, 114, 100, 102, 58, 68, 101, 115, 99,
      114, 105, 112, 116, 105, 111, 110, 62, 10, 32, 32, 32, 60, 47,
      114, 100, 102, 58, 82, 68, 70, 62, 10, 60, 47, 120, 58, 120,
      109, 112, 109, 101, 116, 97, 62, 10, 176, 227, 50, 221, 0, 0, 0,
      29, 73, 68, 65, 84, 24, 25, 99, 156, 252, 203, 227, 63, 3, 17,
      128, 137, 8, 53, 96, 37, 163, 10, 241, 134, 20, 209, 193, 3, 0,
      146, 7, 2, 232, 221, 185, 27, 24, 0, 0, 0, 0, 73, 69, 78, 68,
      174, 66, 96, 130
    ]
    @png10 = a.pack("C#{a.length}") # 10x10のPNGバイナリ
  end

  it "イメージリサイズ" do
    File.open("/tmp/10x10.png","w"){ |f|
      f.print @png10
    }
    file = `file /tmp/10x10.png`
    file.should.match /10 x 10/
    Files.copy "/tmp/10x10.png", "/tmp/100x100.png"
    Image.resize 100, "/tmp/100x100.png"
    file = `file /tmp/100x100.png`
    file.should.match /100 x 100/
    File.unlink  "/tmp/100x100.png", "/tmp/10x10.png"
  end

  it "PNGイメージ生成" do
    Image.generatePNG("/tmp/junk.png","yellow",10,20)
    file = `file /tmp/junk.png`
    file.should.match /10 x 20/
  end
end
