Implement ActionList::Entry#clear.
[kaya.git] / test / test_utils.rb
blobcef153d701a700524b0da0bae217c1fbde8ceb7f
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'test/unit'
9 require 'rubygems'
10 require 'mocha'
11 require 'toolkits/qt'
13 class TestQtUtils < Test::Unit::TestCase
14   class Foo
15     attr_reader :bar
17     def initialize(bar)
18       @bar = bar
19     end
21     def ==(other)
22       self.bar == other.bar
23     end
24   end
26   def test_painter_bracket
27     p = Qt::Painter.new
28     p.expects(:fill_rect).once
29     p.expects(:end).once
30     
31     p.paint do |painter|
32       painter.fill_rect
33     end
34   end
35   
36   def test_detect_index
37     alphabet = ('a'..'z')
38     h = alphabet.detect_index {|l| "hello"[0, 1] == l }
39     
40     assert_equal 7, h
41     
42     result = alphabet.detect_index {|l| 0 == 1 }
43     assert_nil result
44   end
46   def test_qvariant_from_to_ruby
47     hash = { :foo => ["bar", 4] }
48     var = Qt::Variant.from_ruby(hash)
49     assert_equal hash, var.to_ruby
51     assert_equal Foo, Qt::Variant.from_ruby(Foo).to_ruby
53     foo = Foo.new("bar")
54     assert_equal foo, Qt::Variant.from_ruby(foo).to_ruby
55   end
56 end