test/test_growl_gntp.rb in ruby-growl-4.0 vs test/test_growl_gntp.rb in ruby-growl-4.1

- old
+ new

@@ -1,12 +1,13 @@ # coding: UTF-8 require 'minitest/autorun' require 'ruby-growl' +require 'ruby-growl/ruby_logo' require 'stringio' -class TestGrowlGNTP < MiniTest::Unit::TestCase +class TestGrowlGNTP < Minitest::Test class Socket attr_reader :_input, :_output def initialize *a @@ -37,16 +38,22 @@ end def setup @gntp = Growl::GNTP.new 'localhost', 'test-app' @gntp.uuid = UUID.new + + rocket_path = File.join 'test', 'rocketAlpha.jpg' + rocket_path = File.expand_path rocket_path + + @jpg_data = File.read rocket_path, mode: 'rb' + @jpg_url = "file://#{rocket_path}" end def test_add_notification - @gntp.add_notification 'test', 'Test Notification', 'PNG', true + @gntp.add_notification 'test', 'Test Notification', @jpg_url, true - expected = { 'test' => ['Test Notification', 'PNG', true] } + expected = { 'test' => ['Test Notification', @jpg_url, true] } assert_equal expected, @gntp.notifications end def test_cipher_des @@ -443,11 +450,11 @@ def test_packet_encrypt_aes_icon @gntp.encrypt = 'AES' @gntp.password = 'password' - packet = @gntp.packet 'REGISTER', ["Foo: bar"], { 'icon' => 'PNG' } + packet = @gntp.packet 'REGISTER', ["Foo: bar"], { 'icon' => @jpg_data } info, body = packet.split "\r\n", 2 _, _, algorithm_info, key_info = info.split ' ' @@ -493,11 +500,11 @@ data = body[data_offset, data_length] decrypted = decrypt cipher, key, iv, data - assert_equal 'PNG', decrypted + assert_equal @jpg_data, decrypted end def test_packet_hash @gntp.password = 'password' @@ -509,11 +516,10 @@ assert_equal 'NONE', algorithm_info key_info =~ /:(.*)\./ - digest = $` key_hash = $1 salt = $' salt = [salt].pack 'H*' @@ -535,10 +541,16 @@ EXPECTED assert_equal expected, body end + def test_packet_icon_utf_8 + packet = @gntp.packet 'REGISTER', ['Foo: π'], 1 => Growl::RUBY_LOGO_PNG + + assert_equal Encoding::BINARY, packet.encoding + end + def test_packet_notify expected = <<-EXPECTED GNTP/1.0 NOTIFY NONE\r Application-Name: test-app\r Origin-Software-Name: ruby-growl\r @@ -645,11 +657,11 @@ assert_equal expected, @gntp.packet_notify('test-note', 'title', 'message', 0, false, nil, nil) end def test_packet_notify_icon - @gntp.add_notification 'test-note', nil, 'PNG' + @gntp.add_notification 'test-note', nil, @jpg_url expected = <<-EXPECTED GNTP/1.0 NOTIFY NONE\r Application-Name: test-app\r Origin-Software-Name: ruby-growl\r @@ -661,13 +673,13 @@ Notification-Name: test-note\r Notification-Title: title\r Notification-Icon: x-growl-resource://4\r \r Identifier: 4\r -Length: 3\r +Length: #{@jpg_url.size}\r \r -PNG\r +#{@jpg_url}\r \r \r EXPECTED assert_equal expected, @gntp.packet_notify('test-note', 'title', @@ -794,11 +806,11 @@ assert_equal expected, @gntp.packet_register end def test_packet_register_application_icon @gntp.add_notification 'test-note' - @gntp.icon = 'PNG' + @gntp.icon = @jpg_url expected = <<-EXPECTED GNTP/1.0 REGISTER NONE\r Application-Name: test-app\r Origin-Software-Name: ruby-growl\r @@ -811,13 +823,13 @@ \r Notification-Name: test-note\r Notification-Enabled: true\r \r Identifier: 4\r -Length: 3\r +Length: #{@jpg_url.size}\r \r -PNG\r +#{@jpg_url}\r \r \r EXPECTED assert_equal expected, @gntp.packet_register @@ -890,11 +902,11 @@ assert_equal expected, @gntp.packet_register end def test_packet_register_notification_icon - @gntp.add_notification 'test-note', nil, 'PNG' + @gntp.add_notification 'test-note', nil, @jpg_url expected = <<-EXPECTED GNTP/1.0 REGISTER NONE\r Application-Name: test-app\r Origin-Software-Name: ruby-growl\r @@ -907,13 +919,13 @@ Notification-Name: test-note\r Notification-Enabled: true\r Notification-Icon: x-growl-resource://4\r \r Identifier: 4\r -Length: 3\r +Length: #{@jpg_url.size}\r \r -PNG\r +#{@jpg_url}\r \r \r EXPECTED assert_equal expected, @gntp.packet_register @@ -975,10 +987,10 @@ end def test_parse_header_string value = 'test' value.encode! Encoding::BINARY - + header = @gntp.parse_header('Application-Name', value) assert_equal ['Application-Name', 'test'], header assert_equal Encoding::UTF_8, header.last.encoding header = @gntp.parse_header('Application-Name', '(null)')