| 1 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "helper"))
|
|---|
| 2 | require "ruwin/component"
|
|---|
| 3 |
|
|---|
| 4 | class TestRuwinComponent < Test::Unit::TestCase
|
|---|
| 5 | include Ruwin::Const::Window
|
|---|
| 6 |
|
|---|
| 7 | def test_component_property_accessor
|
|---|
| 8 | klass = Class.new(Ruwin::Component)
|
|---|
| 9 | klass.class_eval "property_accessor :test_pro => 1"
|
|---|
| 10 |
|
|---|
| 11 | assert_equal 1, klass.instance_variable_get(:@proparty)[:test_pro]
|
|---|
| 12 | assert_respond_to klass, :test_pro
|
|---|
| 13 | assert_equal 1, klass.test_pro
|
|---|
| 14 | klass.test_pro 2
|
|---|
| 15 | assert_equal 2, klass.test_pro
|
|---|
| 16 |
|
|---|
| 17 | instance = klass.new
|
|---|
| 18 | assert_equal 2, instance.instance_variable_get(:@proparty)[:test_pro]
|
|---|
| 19 | assert_respond_to instance, :test_pro
|
|---|
| 20 | assert_respond_to instance, :test_pro=
|
|---|
| 21 | assert_equal 2, instance.test_pro
|
|---|
| 22 | instance.test_pro = 3
|
|---|
| 23 | assert_equal 3, instance.test_pro
|
|---|
| 24 | end
|
|---|
| 25 |
|
|---|
| 26 | def test_copy_property
|
|---|
| 27 | klass = Class.new(Ruwin::Component)
|
|---|
| 28 | klass.instance_variable_get(:@proparty).replace :caption => "caption", :style => 0
|
|---|
| 29 |
|
|---|
| 30 | copied_proparty = klass.copy_proparty
|
|---|
| 31 | assert_not_same klass.instance_variable_get(:@proparty), copied_proparty
|
|---|
| 32 | assert_equal klass.instance_variable_get(:@proparty), copied_proparty
|
|---|
| 33 |
|
|---|
| 34 | assert_not_same klass.instance_variable_get(:@proparty)[:caption], copied_proparty[:caption]
|
|---|
| 35 | assert_equal klass.instance_variable_get(:@proparty)[:caption], copied_proparty[:caption]
|
|---|
| 36 |
|
|---|
| 37 | assert_same klass.instance_variable_get(:@proparty)[:style], copied_proparty[:style]
|
|---|
| 38 | assert_equal klass.instance_variable_get(:@proparty)[:style], copied_proparty[:style]
|
|---|
| 39 | end
|
|---|
| 40 |
|
|---|
| 41 | def test_component_should_have_proparty
|
|---|
| 42 | assert Ruwin::Component.instance_variable_get(:@proparty)
|
|---|
| 43 | end
|
|---|
| 44 |
|
|---|
| 45 | def test_component_subclass_should_have_proparty
|
|---|
| 46 | klass = Class.new(Ruwin::Component)
|
|---|
| 47 | assert klass.instance_variable_get(:@proparty)
|
|---|
| 48 | end
|
|---|
| 49 |
|
|---|
| 50 | def test_component_subclass_proparty_should_have_unduplicated_immutable_value
|
|---|
| 51 | symbol = :test
|
|---|
| 52 | baseklass = Class.new(Ruwin::Component)
|
|---|
| 53 | baseklass.instance_variable_get(:@proparty)[:test] = symbol
|
|---|
| 54 | klass = Class.new(baseklass)
|
|---|
| 55 | assert_equal symbol, klass.instance_variable_get(:@proparty)[:test]
|
|---|
| 56 | assert_same symbol, klass.instance_variable_get(:@proparty)[:test]
|
|---|
| 57 | end
|
|---|
| 58 |
|
|---|
| 59 | def test_component_subclass_proparty_should_have_duplicated_mutable_value
|
|---|
| 60 | string = "test"
|
|---|
| 61 | baseklass = Class.new(Ruwin::Component)
|
|---|
| 62 | baseklass.instance_variable_get(:@proparty)[:test] = string
|
|---|
| 63 | klass = Class.new(baseklass)
|
|---|
| 64 | assert_equal string, klass.instance_variable_get(:@proparty)[:test]
|
|---|
| 65 | assert_not_same string, klass.instance_variable_get(:@proparty)[:test]
|
|---|
| 66 | end
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | %w{style exstyle caption}.each do |name|
|
|---|
| 70 | class_eval <<-"END"
|
|---|
| 71 | def test_proparty_#{name}_setter
|
|---|
| 72 | klass = Class.new(Ruwin::Component)
|
|---|
| 73 | klass.class_eval do
|
|---|
| 74 | #{name} 1
|
|---|
| 75 | end
|
|---|
| 76 | assert_equal 1, klass.instance_variable_get(:@proparty)[:#{name}]
|
|---|
| 77 | end
|
|---|
| 78 |
|
|---|
| 79 | def test_proparty_#{name}_getter
|
|---|
| 80 | klass = Class.new(Ruwin::Component)
|
|---|
| 81 | klass.class_eval do
|
|---|
| 82 | #{name} 1
|
|---|
| 83 | end
|
|---|
| 84 | assert_equal 1, klass.#{name}
|
|---|
| 85 | end
|
|---|
| 86 | END
|
|---|
| 87 | end
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 | def test_new
|
|---|
| 91 | klass = Class.new(Ruwin::Component)
|
|---|
| 92 | instance = klass.new
|
|---|
| 93 | assert_equal WS_CLIPSIBLINGS, instance.style&WS_CLIPSIBLINGS
|
|---|
| 94 | assert_equal WS_OVERLAPPEDWINDOW, instance.style&WS_OVERLAPPEDWINDOW
|
|---|
| 95 | end
|
|---|
| 96 |
|
|---|
| 97 | def test_new_defined_const
|
|---|
| 98 | klass = Class.new(Ruwin::Component)
|
|---|
| 99 | klass.class_eval <<-'END'
|
|---|
| 100 | CLASS_NAME = "BUTTON"
|
|---|
| 101 | STYLE = 1
|
|---|
| 102 | EXSTYLE = 2
|
|---|
| 103 | END
|
|---|
| 104 | instance = klass.new
|
|---|
| 105 | assert_equal "BUTTON", instance.classname
|
|---|
| 106 | assert_equal 1, instance.style&1
|
|---|
| 107 | assert_equal 2, instance.exstyle&2
|
|---|
| 108 | end
|
|---|
| 109 |
|
|---|
| 110 | def test_factoy_defined_proparties
|
|---|
| 111 | klass = Class.new(Ruwin::Component)
|
|---|
| 112 | klass.class_eval <<-'END'
|
|---|
| 113 | STYLE = 1
|
|---|
| 114 | EXSTYLE = 2
|
|---|
| 115 | caption "caption"
|
|---|
| 116 | style 4
|
|---|
| 117 | exstyle 8
|
|---|
| 118 | END
|
|---|
| 119 | instance = klass.new
|
|---|
| 120 | assert_equal "caption", instance.caption
|
|---|
| 121 | assert_equal 4, instance.style&4
|
|---|
| 122 | assert_equal 8, instance.exstyle&8
|
|---|
| 123 | end
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | def test_send_message_with_error_code
|
|---|
| 128 | instance = Ruwin::Component.new
|
|---|
| 129 | def instance.sendMessage *args
|
|---|
| 130 | :returned
|
|---|
| 131 | end
|
|---|
| 132 | assert_equal :returned, instance.__send__(:send_message_with_error_code, 0, 1, 2, :error_code)
|
|---|
| 133 | end
|
|---|
| 134 |
|
|---|
| 135 | def test_send_message_with_error_code_returned_error_code
|
|---|
| 136 | instance = Ruwin::Component.new
|
|---|
| 137 | def instance.sendMessage *args
|
|---|
| 138 | :error_code
|
|---|
| 139 | end
|
|---|
| 140 | assert_equal :alternate, instance.__send__(:send_message_with_error_code, 0, 1, 2, :error_code){ :alternate }
|
|---|
| 141 | end
|
|---|
| 142 |
|
|---|
| 143 | def test_draw_bundling
|
|---|
| 144 | instance = Ruwin::Component.new
|
|---|
| 145 | instance.instance_variable_set :@messages, []
|
|---|
| 146 | class << instance
|
|---|
| 147 | attr_reader :messages
|
|---|
| 148 | def sendMessage *args
|
|---|
| 149 | @messages << args
|
|---|
| 150 | end
|
|---|
| 151 | end
|
|---|
| 152 | instance.__send__ :draw_bundling do
|
|---|
| 153 | instance.sendMessage :inter
|
|---|
| 154 | end
|
|---|
| 155 | assert_equal [[WM_SETREDRAW, 0, 0], [:inter], [WM_SETREDRAW, 1, 0]], instance.messages
|
|---|
| 156 | end
|
|---|
| 157 | end
|
|---|