diff options
-rw-r--r-- | core/lib/test_unit_extensions.rb | 1 | ||||
-rw-r--r-- | core/mui/gtk_web_image_loader.rb | 3 | ||||
-rw-r--r-- | core/test/test_web_image_loader.rb | 21 | ||||
-rw-r--r-- | core/utils.rb | 17 | ||||
-rw-r--r-- | mikutter.rb | 5 |
5 files changed, 44 insertions, 3 deletions
diff --git a/core/lib/test_unit_extensions.rb b/core/lib/test_unit_extensions.rb index 9656dc54..ee0485b9 100644 --- a/core/lib/test_unit_extensions.rb +++ b/core/lib/test_unit_extensions.rb @@ -27,6 +27,7 @@ module Mopt @opts = { debug: true, + testing: true, error_level: 3 } def method_missing(key) diff --git a/core/mui/gtk_web_image_loader.rb b/core/mui/gtk_web_image_loader.rb index 58ea1c3c..9f107a3c 100644 --- a/core/mui/gtk_web_image_loader.rb +++ b/core/mui/gtk_web_image_loader.rb @@ -42,6 +42,9 @@ module Gdk::WebImageLoader else via_internet(url, rect, &load_callback) end end rescue Gdk::PixbufError + notfound_pixbuf(rect) + rescue => e + into_debug_mode(e) notfound_pixbuf(rect) end # _url_ が指している画像を任意のサイズにリサイズして、その画像のパスを返す。 diff --git a/core/test/test_web_image_loader.rb b/core/test/test_web_image_loader.rb index 463d8260..0abcbf63 100644 --- a/core/test/test_web_image_loader.rb +++ b/core/test/test_web_image_loader.rb @@ -18,7 +18,10 @@ Plugin = Class.new class TC_GtkWebImageLoader < Test::Unit::TestCase def setup Gdk::WebImageLoader::ImageCache.clear - urls = ['http://a0.twimg.com/profile_images/1522298893/itiiti_hitono_icon_no_file_mei_mirutoka_teokure_desune.png', 'http://internal.server.error/', 'http://notfound/'] + urls = ['http://a0.twimg.com/profile_images/1522298893/itiiti_hitono_icon_no_file_mei_mirutoka_teokure_desune.png', + 'http://a0.twimg.com/profile_images/1522298893/みくかわいい.png', + 'http://internal.server.error/', + 'http://notfound/'] urls.each{ |u| Plugin.stubs(:filtering).with(:image_cache, u, nil).returns([u, nil]) } end @@ -69,6 +72,22 @@ class TC_GtkWebImageLoader < Test::Unit::TestCase assert_equal(response[0], pb) end + must "load by url included japanese" do + # URI::InvalidURIError + # url = 'http://a1.twimg.com/profile_images/80925056/クリップボード01_normal.jpg' + url = 'http://a0.twimg.com/profile_images/1522298893/みくかわいい.png' + WebMock.stub_request(:get, url).to_return(File.open('test/icon_test.png'){ |io| io.read }) + response = nil + Gdk::WebImageLoader.pixbuf(url, 48, 48){ |pixbuf, success, url| + response = [pixbuf, success] + } + (Thread.list - [Thread.current]).each &:join + while not Delayer.empty? do Delayer.run end + assert_equal(true, Delayer.empty?) + assert_equal(0, Delayer.size) + assert_equal(nil, response[1]) + end + must "successfully load local image" do url = 'test/result.png' response = Gdk::WebImageLoader.pixbuf(url, 48, 48) diff --git a/core/utils.rb b/core/utils.rb index 12afca23..5089be5a 100644 --- a/core/utils.rb +++ b/core/utils.rb @@ -181,6 +181,23 @@ def error(msg) abort if Mopt.error_level >= 4 end +# --debug オプション付きで起動されている場合、インタプリタに入る。 +# ==== Args +# [exception] 原因となった例外 +# ==== Return +# インタプリタから復帰したら(インタプリタが起動されたら)true、 +# デバッグモードではない、pryがインストールされていない等、起動に失敗したらfalse +# ==== Exception +# インタプリタの起動に失敗し、かつ _exception_ が渡されていたらそれを raise する。 +def into_debug_mode(exception = nil) + if Mopt.debug and not Mopt.testing + require_if_exist 'pry' + if binding.respond_to?(:pry) + log "error", exception if exception + binding.pry + return true end end + raise exception if exception end + # 引数のチェックをすべてパスした場合のみブロックを実行する # チェックに引っかかった項目があればwarnを出力してブロックは実行せずにnilを返す。 # チェックはassocできる配列か、Hashで定義する。 diff --git a/mikutter.rb b/mikutter.rb index c8960108..5e3fe84b 100644 --- a/mikutter.rb +++ b/mikutter.rb @@ -53,8 +53,9 @@ def boot!(profile) notice "profile: done." end else - Gtk.main end end - + Gtk.main end +rescue => e + into_debug_mode(e) end begin errfile = File.join(File.expand_path(Environment::TMPDIR), 'mikutter_dump') |