| 1 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "helper"))
|
|---|
| 2 | require "ruwin/progress_bar"
|
|---|
| 3 |
|
|---|
| 4 | class TestRuwinProgressBar < Test::Unit::TestCase
|
|---|
| 5 | include Ruwin::Const::ProgressBar
|
|---|
| 6 | TARGET_CLASS = Ruwin::ProgressBar
|
|---|
| 7 |
|
|---|
| 8 | def setup
|
|---|
| 9 | @control = self.class::TARGET_CLASS.new(HiddenWindow.new)
|
|---|
| 10 | end
|
|---|
| 11 |
|
|---|
| 12 | def test_classname
|
|---|
| 13 | assert_equal "msctls_progress32", @control.classname
|
|---|
| 14 | end
|
|---|
| 15 |
|
|---|
| 16 | def test_style
|
|---|
| 17 | assert_equal PBS_SMOOTH, (@control.style&(PBS_SMOOTH|PBS_VERTICAL))
|
|---|
| 18 | end
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | def test_set_range
|
|---|
| 23 | @control.set_range 100, 200
|
|---|
| 24 | assert_equal 100, @control.sendMessage(PBM_GETRANGE, 1, 0)
|
|---|
| 25 | assert_equal 200, @control.sendMessage(PBM_GETRANGE, 0, 0)
|
|---|
| 26 | end
|
|---|
| 27 |
|
|---|
| 28 | def test_set_range_minus_range_error
|
|---|
| 29 | assert_raise(RangeError){ @control.set_range -1, 100 }
|
|---|
| 30 | end
|
|---|
| 31 |
|
|---|
| 32 | def test_set_range_reverse_range_error
|
|---|
| 33 | assert_raise(ArgumentError){ @control.set_range 100, 0 }
|
|---|
| 34 | end
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | def test_first_getter
|
|---|
| 38 | @control.sendMessage PBM_SETRANGE, 0, 100|200<<16
|
|---|
| 39 | assert_equal 100, @control.first
|
|---|
| 40 | end
|
|---|
| 41 |
|
|---|
| 42 | def test_first_setter
|
|---|
| 43 | @control.sendMessage PBM_SETRANGE, 0, 100|200<<16
|
|---|
| 44 | @control.first = 101
|
|---|
| 45 | assert_equal 101..200, @control.range
|
|---|
| 46 | end
|
|---|
| 47 |
|
|---|
| 48 | def test_last_getter
|
|---|
| 49 | @control.sendMessage PBM_SETRANGE, 0, 100|200<<16
|
|---|
| 50 | assert_equal 200, @control.last
|
|---|
| 51 | end
|
|---|
| 52 |
|
|---|
| 53 | def test_last_setter
|
|---|
| 54 | @control.sendMessage PBM_SETRANGE, 0, 100|200<<16
|
|---|
| 55 | @control.last = 199
|
|---|
| 56 | assert_equal 100..199, @control.range
|
|---|
| 57 | end
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | def test_range_getter
|
|---|
| 61 | @control.sendMessage PBM_SETRANGE, 0, 100|200<<16
|
|---|
| 62 | assert_equal 100..200, @control.range
|
|---|
| 63 | end
|
|---|
| 64 |
|
|---|
| 65 | def test_range_setter
|
|---|
| 66 | @control.range = 100..200
|
|---|
| 67 | assert_equal 100, @control.sendMessage(PBM_GETRANGE, 1, 0)
|
|---|
| 68 | assert_equal 200, @control.sendMessage(PBM_GETRANGE, 0, 0)
|
|---|
| 69 | end
|
|---|
| 70 |
|
|---|
| 71 | def test_range_setter_exclude_end
|
|---|
| 72 | @control.range = 100...200
|
|---|
| 73 | assert_equal 100, @control.sendMessage(PBM_GETRANGE, 1, 0)
|
|---|
| 74 | assert_equal 199, @control.sendMessage(PBM_GETRANGE, 0, 0)
|
|---|
| 75 | end
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | def test_position_getter
|
|---|
| 79 | @control.sendMessage PBM_SETRANGE, 0, 0|100<<16
|
|---|
| 80 | @control.sendMessage PBM_SETPOS, 50, 0
|
|---|
| 81 | assert_equal 50, @control.position
|
|---|
| 82 | end
|
|---|
| 83 |
|
|---|
| 84 | def test_position_setter
|
|---|
| 85 | @control.sendMessage PBM_SETRANGE, 0, 0|100<<16
|
|---|
| 86 | @control.position = 50
|
|---|
| 87 | assert_equal 50, @control.sendMessage(PBM_GETPOS, 0, 0)
|
|---|
| 88 | end
|
|---|
| 89 |
|
|---|
| 90 | def test_position_setter_over_last
|
|---|
| 91 | @control.sendMessage PBM_SETRANGE, 0, 100|200<<16
|
|---|
| 92 | @control.position = 250
|
|---|
| 93 | assert_equal 200, @control.sendMessage(PBM_GETPOS, 0, 0)
|
|---|
| 94 | end
|
|---|
| 95 |
|
|---|
| 96 | def test_position_setter_under_first
|
|---|
| 97 | @control.sendMessage PBM_SETRANGE, 0, 100|200<<16
|
|---|
| 98 | @control.position = 50
|
|---|
| 99 | assert_equal 100, @control.sendMessage(PBM_GETPOS, 0, 0)
|
|---|
| 100 | end
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 | def test_append_plus
|
|---|
| 104 | @control.sendMessage PBM_SETRANGE, 0, 0|100<<16
|
|---|
| 105 | @control.append 50
|
|---|
| 106 | assert_equal 50, @control.sendMessage(PBM_GETPOS, 0, 0)
|
|---|
| 107 | end
|
|---|
| 108 |
|
|---|
| 109 | def test_append_plus_over_last
|
|---|
| 110 | @control.sendMessage PBM_SETRANGE, 0, 0|100<<16
|
|---|
| 111 | @control.append 150
|
|---|
| 112 | assert_equal 100, @control.sendMessage(PBM_GETPOS, 0, 0)
|
|---|
| 113 | end
|
|---|
| 114 |
|
|---|
| 115 | def test_append_minus
|
|---|
| 116 | @control.sendMessage PBM_SETRANGE, 0, 0|100<<16
|
|---|
| 117 | @control.sendMessage PBM_SETPOS, 100, 0
|
|---|
| 118 | @control.append -50
|
|---|
| 119 | assert_equal 50, @control.sendMessage(PBM_GETPOS, 0, 0)
|
|---|
| 120 | end
|
|---|
| 121 |
|
|---|
| 122 | def test_append_minus_under_first
|
|---|
| 123 | @control.sendMessage PBM_SETRANGE, 0, 0|100<<16
|
|---|
| 124 | @control.sendMessage PBM_SETPOS, 100, 0
|
|---|
| 125 | @control.append -150
|
|---|
| 126 | assert_equal 0, @control.sendMessage(PBM_GETPOS, 0, 0)
|
|---|
| 127 | end
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 | def test_step_setter
|
|---|
| 131 | @control.sendMessage PBM_SETRANGE, 0, 0|100<<16
|
|---|
| 132 | @control.step = 20
|
|---|
| 133 | @control.sendMessage PBM_STEPIT, 0, 0
|
|---|
| 134 | assert_equal 20, @control.sendMessage(PBM_GETPOS, 0, 0)
|
|---|
| 135 | end
|
|---|
| 136 |
|
|---|
| 137 | def test_step_getter
|
|---|
| 138 | @control.sendMessage PBM_SETRANGE, 0, 0|100<<16
|
|---|
| 139 | @control.step = 20
|
|---|
| 140 | assert_equal 20, @control.step
|
|---|
| 141 | end
|
|---|
| 142 |
|
|---|
| 143 | def test_astep_up_should_use_step
|
|---|
| 144 | @control.sendMessage PBM_SETRANGE, 0, 0|100<<16
|
|---|
| 145 | @control.sendMessage PBM_SETSTEP, 20, 0
|
|---|
| 146 | @control.step_up
|
|---|
| 147 | assert_equal 20, @control.sendMessage(PBM_GETPOS, 0, 0)
|
|---|
| 148 | end
|
|---|
| 149 | end
|
|---|