| 1 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "helper"))
|
|---|
| 2 | require "ruwin"
|
|---|
| 3 | require "ruwin/edit_field"
|
|---|
| 4 |
|
|---|
| 5 | class TestRuwinEditFieldRichCharFormat < Test::Unit::TestCase
|
|---|
| 6 | include Ruwin::Const::EditField
|
|---|
| 7 |
|
|---|
| 8 | def setup
|
|---|
| 9 | @control = Ruwin::EditField::Rich.new(HiddenWindow.new)
|
|---|
| 10 | @format = @control.default
|
|---|
| 11 | @control.message_log.clear
|
|---|
| 12 | end
|
|---|
| 13 |
|
|---|
| 14 | {
|
|---|
| 15 | :bold => %w{CFM_BOLD CFE_BOLD},
|
|---|
| 16 | :italic => %w{CFM_ITALIC CFE_ITALIC},
|
|---|
| 17 | :underline => %w{CFM_UNDERLINE CFE_UNDERLINE},
|
|---|
| 18 | :strikeout => %w{CFM_STRIKEOUT CFE_STRIKEOUT},
|
|---|
| 19 | :protected => %w{CFM_PROTECTED CFE_PROTECTED},
|
|---|
| 20 | }.each do |option, (mask, effect)|
|
|---|
| 21 | {
|
|---|
| 22 | :on => true,
|
|---|
| 23 | :off => false,
|
|---|
| 24 | }.each do |name, enable|
|
|---|
| 25 | class_eval <<-"END"
|
|---|
| 26 | def test_effects_#{option}_setter_#{name}
|
|---|
| 27 | @format.#{option} = #{enable}
|
|---|
| 28 |
|
|---|
| 29 | assert_equal 1, @control.message_log.size
|
|---|
| 30 | assert_setcharformat @control.message_log.last, 1 => #{mask}, 2 => #{name == :on ? effect : 0}
|
|---|
| 31 | end
|
|---|
| 32 |
|
|---|
| 33 | def test_effects_#{option}_getter_#{name}
|
|---|
| 34 | @format.#{option} = #{enable}
|
|---|
| 35 |
|
|---|
| 36 | assert_equal #{enable}, @format.#{option}
|
|---|
| 37 | end
|
|---|
| 38 | END
|
|---|
| 39 | end
|
|---|
| 40 | end
|
|---|
| 41 |
|
|---|
| 42 | {
|
|---|
| 43 | :height => %w{CFM_SIZE 3},
|
|---|
| 44 | :offset => %w{CFM_OFFSET 4},
|
|---|
| 45 | }.each do |option, (mask, index)|
|
|---|
| 46 | %w{20 -20}.each do |value|
|
|---|
| 47 | class_eval <<-"END"
|
|---|
| 48 | def test_#{option}_setter_#{value.gsub "-", "minus"}
|
|---|
| 49 | @format.#{option} = #{value}
|
|---|
| 50 |
|
|---|
| 51 | assert_equal 1, @control.message_log.size
|
|---|
| 52 | assert_setcharformat @control.message_log.last, 1 => #{mask}, #{index} => #{value}
|
|---|
| 53 | end
|
|---|
| 54 |
|
|---|
| 55 | def test_#{option}_getter_#{value.gsub "-", "minus"}
|
|---|
| 56 | @format.#{option} = #{value}
|
|---|
| 57 |
|
|---|
| 58 | assert_equal #{value}, @format.#{option}
|
|---|
| 59 | end
|
|---|
| 60 | END
|
|---|
| 61 | end
|
|---|
| 62 | end
|
|---|
| 63 |
|
|---|
| 64 | def test_color
|
|---|
| 65 | @format.color = 0xFF9933
|
|---|
| 66 |
|
|---|
| 67 | assert_equal 1, @control.message_log.size
|
|---|
| 68 | assert_setcharformat @control.message_log.last, 1 => CFM_COLOR, 5 => 0xFF9933
|
|---|
| 69 | end
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | def assert_setcharformat expected, options
|
|---|
| 73 | assert_equal EM_SETCHARFORMAT, expected[0]
|
|---|
| 74 | assert_equal SCF_DEFAULT, expected[1]
|
|---|
| 75 |
|
|---|
| 76 | charformat = expected[2].unpack("LLLLLLCCU")
|
|---|
| 77 | options.each do |index, value|
|
|---|
| 78 | assert_equal value, Ruwin::SIGNEDLONG(charformat[index])
|
|---|
| 79 | end
|
|---|
| 80 | end
|
|---|
| 81 | end
|
|---|