shoes-swt 4.0.0.pre2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG +84 -0
- data/Gemfile +24 -0
- data/Guardfile +11 -0
- data/LICENSE +31 -0
- data/README.md +201 -0
- data/lib/shoes/swt.rb +118 -0
- data/lib/shoes/swt/animation.rb +46 -0
- data/lib/shoes/swt/app.rb +314 -0
- data/lib/shoes/swt/arc.rb +71 -0
- data/lib/shoes/swt/background.rb +41 -0
- data/lib/shoes/swt/border.rb +41 -0
- data/lib/shoes/swt/button.rb +18 -0
- data/lib/shoes/swt/check.rb +14 -0
- data/lib/shoes/swt/check_button.rb +19 -0
- data/lib/shoes/swt/color.rb +49 -0
- data/lib/shoes/swt/color_factory.rb +32 -0
- data/lib/shoes/swt/common/child.rb +16 -0
- data/lib/shoes/swt/common/clickable.rb +68 -0
- data/lib/shoes/swt/common/container.rb +28 -0
- data/lib/shoes/swt/common/fill.rb +38 -0
- data/lib/shoes/swt/common/painter.rb +92 -0
- data/lib/shoes/swt/common/painter_updates_position.rb +12 -0
- data/lib/shoes/swt/common/remove.rb +30 -0
- data/lib/shoes/swt/common/resource.rb +29 -0
- data/lib/shoes/swt/common/selection_listener.rb +14 -0
- data/lib/shoes/swt/common/stroke.rb +42 -0
- data/lib/shoes/swt/common/update_position.rb +15 -0
- data/lib/shoes/swt/common/visibility.rb +13 -0
- data/lib/shoes/swt/dialog.rb +90 -0
- data/lib/shoes/swt/disposed_protection.rb +23 -0
- data/lib/shoes/swt/download.rb +24 -0
- data/lib/shoes/swt/font.rb +32 -0
- data/lib/shoes/swt/gradient.rb +92 -0
- data/lib/shoes/swt/image.rb +128 -0
- data/lib/shoes/swt/image_pattern.rb +31 -0
- data/lib/shoes/swt/input_box.rb +73 -0
- data/lib/shoes/swt/key_listener.rb +145 -0
- data/lib/shoes/swt/line.rb +60 -0
- data/lib/shoes/swt/link.rb +31 -0
- data/lib/shoes/swt/link_segment.rb +111 -0
- data/lib/shoes/swt/list_box.rb +48 -0
- data/lib/shoes/swt/mouse_move_listener.rb +67 -0
- data/lib/shoes/swt/oval.rb +52 -0
- data/lib/shoes/swt/progress.rb +35 -0
- data/lib/shoes/swt/radio.rb +29 -0
- data/lib/shoes/swt/radio_group.rb +54 -0
- data/lib/shoes/swt/rect.rb +30 -0
- data/lib/shoes/swt/rect_painter.rb +23 -0
- data/lib/shoes/swt/redrawing_aspect.rb +123 -0
- data/lib/shoes/swt/shape.rb +133 -0
- data/lib/shoes/swt/shoes_layout.rb +43 -0
- data/lib/shoes/swt/slot.rb +39 -0
- data/lib/shoes/swt/sound.rb +119 -0
- data/lib/shoes/swt/star.rb +50 -0
- data/lib/shoes/swt/support/jl1.0.1.jar +0 -0
- data/lib/shoes/swt/support/jogg-0.0.7.jar +0 -0
- data/lib/shoes/swt/support/jorbis-0.0.15.jar +0 -0
- data/lib/shoes/swt/support/log4j-1.2.16.jar +0 -0
- data/lib/shoes/swt/support/mp3spi1.9.5.jar +0 -0
- data/lib/shoes/swt/support/tritonus_share.jar +0 -0
- data/lib/shoes/swt/support/vorbisspi1.0.3.jar +0 -0
- data/lib/shoes/swt/swt_button.rb +56 -0
- data/lib/shoes/swt/text_block.rb +124 -0
- data/lib/shoes/swt/text_block/centered_text_segment.rb +22 -0
- data/lib/shoes/swt/text_block/cursor_painter.rb +53 -0
- data/lib/shoes/swt/text_block/fitter.rb +212 -0
- data/lib/shoes/swt/text_block/painter.rb +47 -0
- data/lib/shoes/swt/text_block/text_font_factory.rb +50 -0
- data/lib/shoes/swt/text_block/text_segment.rb +108 -0
- data/lib/shoes/swt/text_block/text_segment_collection.rb +160 -0
- data/lib/shoes/swt/text_block/text_style_factory.rb +88 -0
- data/lib/shoes/swt/timer.rb +19 -0
- data/lib/shoes/swt/tooling/leak_hunter.rb +35 -0
- data/lib/shoes/swt/version.rb +5 -0
- data/manifests/common.rb +34 -0
- data/manifests/shoes-swt.rb +29 -0
- data/shoes-swt.gemspec +24 -0
- data/spec/code_coverage.rb +14 -0
- data/spec/shoes/animation_spec.rb +65 -0
- data/spec/shoes/app_spec.rb +484 -0
- data/spec/shoes/arc_spec.rb +51 -0
- data/spec/shoes/background_spec.rb +53 -0
- data/spec/shoes/border_spec.rb +47 -0
- data/spec/shoes/builtin_methods_spec.rb +110 -0
- data/spec/shoes/button_spec.rb +44 -0
- data/spec/shoes/check_spec.rb +35 -0
- data/spec/shoes/cli_spec.rb +15 -0
- data/spec/shoes/color_spec.rb +408 -0
- data/spec/shoes/common/inspect_spec.rb +26 -0
- data/spec/shoes/common/remove_spec.rb +38 -0
- data/spec/shoes/common/style_normalizer_spec.rb +28 -0
- data/spec/shoes/common/style_spec.rb +147 -0
- data/spec/shoes/configuration_spec.rb +36 -0
- data/spec/shoes/constants_spec.rb +38 -0
- data/spec/shoes/dialog_spec.rb +163 -0
- data/spec/shoes/dimension_spec.rb +407 -0
- data/spec/shoes/dimensions_spec.rb +837 -0
- data/spec/shoes/download_spec.rb +142 -0
- data/spec/shoes/flow_spec.rb +133 -0
- data/spec/shoes/font_spec.rb +37 -0
- data/spec/shoes/framework_learning_spec.rb +30 -0
- data/spec/shoes/gradient_spec.rb +32 -0
- data/spec/shoes/helpers/fake_element.rb +17 -0
- data/spec/shoes/helpers/inspect_helpers.rb +5 -0
- data/spec/shoes/helpers/sample17_helper.rb +66 -0
- data/spec/shoes/image_spec.rb +49 -0
- data/spec/shoes/images/shoe.jpg +0 -0
- data/spec/shoes/input_box_spec.rb +80 -0
- data/spec/shoes/integration_spec.rb +20 -0
- data/spec/shoes/internal_app_spec.rb +141 -0
- data/spec/shoes/keypress_spec.rb +11 -0
- data/spec/shoes/keyrelease_spec.rb +12 -0
- data/spec/shoes/line_spec.rb +49 -0
- data/spec/shoes/link_spec.rb +105 -0
- data/spec/shoes/list_box_spec.rb +74 -0
- data/spec/shoes/logger/ruby_spec.rb +8 -0
- data/spec/shoes/logger_spec.rb +45 -0
- data/spec/shoes/oval_spec.rb +24 -0
- data/spec/shoes/point_spec.rb +71 -0
- data/spec/shoes/progress_spec.rb +54 -0
- data/spec/shoes/radio_spec.rb +32 -0
- data/spec/shoes/rect_spec.rb +39 -0
- data/spec/shoes/renamed_delegate_spec.rb +70 -0
- data/spec/shoes/shape_spec.rb +95 -0
- data/spec/shoes/shared_examples/button.rb +6 -0
- data/spec/shoes/shared_examples/changeable.rb +26 -0
- data/spec/shoes/shared_examples/clickable.rb +5 -0
- data/spec/shoes/shared_examples/common_methods.rb +35 -0
- data/spec/shoes/shared_examples/dimensions.rb +32 -0
- data/spec/shoes/shared_examples/dsl.rb +44 -0
- data/spec/shoes/shared_examples/dsl/animate.rb +29 -0
- data/spec/shoes/shared_examples/dsl/arc.rb +45 -0
- data/spec/shoes/shared_examples/dsl/background.rb +26 -0
- data/spec/shoes/shared_examples/dsl/border.rb +10 -0
- data/spec/shoes/shared_examples/dsl/button.rb +5 -0
- data/spec/shoes/shared_examples/dsl/cap.rb +6 -0
- data/spec/shoes/shared_examples/dsl/check.rb +11 -0
- data/spec/shoes/shared_examples/dsl/edit_box.rb +8 -0
- data/spec/shoes/shared_examples/dsl/edit_line.rb +8 -0
- data/spec/shoes/shared_examples/dsl/editable_element.rb +29 -0
- data/spec/shoes/shared_examples/dsl/fill.rb +27 -0
- data/spec/shoes/shared_examples/dsl/flow.rb +15 -0
- data/spec/shoes/shared_examples/dsl/gradient.rb +62 -0
- data/spec/shoes/shared_examples/dsl/image.rb +21 -0
- data/spec/shoes/shared_examples/dsl/line.rb +9 -0
- data/spec/shoes/shared_examples/dsl/nofill.rb +6 -0
- data/spec/shoes/shared_examples/dsl/nostroke.rb +6 -0
- data/spec/shoes/shared_examples/dsl/oval.rb +88 -0
- data/spec/shoes/shared_examples/dsl/pattern.rb +34 -0
- data/spec/shoes/shared_examples/dsl/progress.rb +7 -0
- data/spec/shoes/shared_examples/dsl/rect.rb +92 -0
- data/spec/shoes/shared_examples/dsl/rgb.rb +26 -0
- data/spec/shoes/shared_examples/dsl/shape.rb +21 -0
- data/spec/shoes/shared_examples/dsl/star.rb +48 -0
- data/spec/shoes/shared_examples/dsl/stroke.rb +30 -0
- data/spec/shoes/shared_examples/dsl/strokewidth.rb +19 -0
- data/spec/shoes/shared_examples/dsl/style.rb +32 -0
- data/spec/shoes/shared_examples/dsl/text_elements.rb +81 -0
- data/spec/shoes/shared_examples/dsl/video.rb +5 -0
- data/spec/shoes/shared_examples/dsl_app_context.rb +8 -0
- data/spec/shoes/shared_examples/hover_leave.rb +11 -0
- data/spec/shoes/shared_examples/parent.rb +6 -0
- data/spec/shoes/shared_examples/scroll.rb +41 -0
- data/spec/shoes/shared_examples/shared_element_method.rb +60 -0
- data/spec/shoes/shared_examples/slot.rb +331 -0
- data/spec/shoes/shared_examples/state.rb +19 -0
- data/spec/shoes/shared_examples/style.rb +82 -0
- data/spec/shoes/slot_spec.rb +130 -0
- data/spec/shoes/sound_spec.rb +15 -0
- data/spec/shoes/span_spec.rb +112 -0
- data/spec/shoes/spec_helper.rb +24 -0
- data/spec/shoes/stack_spec.rb +79 -0
- data/spec/shoes/star_spec.rb +31 -0
- data/spec/shoes/text_block_dimensions_spec.rb +75 -0
- data/spec/shoes/text_block_spec.rb +270 -0
- data/spec/shoes/url_spec.rb +68 -0
- data/spec/shoes/widget_spec.rb +70 -0
- data/spec/shoes_spec.rb +44 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/swt_shoes/animation_spec.rb +86 -0
- data/spec/swt_shoes/app_spec.rb +84 -0
- data/spec/swt_shoes/arc_spec.rb +103 -0
- data/spec/swt_shoes/background_spec.rb +67 -0
- data/spec/swt_shoes/border_spec.rb +52 -0
- data/spec/swt_shoes/button_spec.rb +101 -0
- data/spec/swt_shoes/check_spec.rb +28 -0
- data/spec/swt_shoes/color_factory_spec.rb +49 -0
- data/spec/swt_shoes/color_spec.rb +67 -0
- data/spec/swt_shoes/common/painter_spec.rb +49 -0
- data/spec/swt_shoes/common/remove_spec.rb +53 -0
- data/spec/swt_shoes/configuration_spec.rb +12 -0
- data/spec/swt_shoes/dialog_spec.rb +106 -0
- data/spec/swt_shoes/disposed_protection_spec.rb +49 -0
- data/spec/swt_shoes/flow_spec.rb +36 -0
- data/spec/swt_shoes/font_spec.rb +33 -0
- data/spec/swt_shoes/gradient_spec.rb +31 -0
- data/spec/swt_shoes/image_pattern_spec.rb +35 -0
- data/spec/swt_shoes/image_spec.rb +100 -0
- data/spec/swt_shoes/input_box_spec.rb +116 -0
- data/spec/swt_shoes/integration_spec.rb +27 -0
- data/spec/swt_shoes/key_listener_spec.rb +325 -0
- data/spec/swt_shoes/line_spec.rb +49 -0
- data/spec/swt_shoes/link_segment_spec.rb +120 -0
- data/spec/swt_shoes/link_spec.rb +54 -0
- data/spec/swt_shoes/list_box_spec.rb +56 -0
- data/spec/swt_shoes/minimal.png +0 -0
- data/spec/swt_shoes/mouse_move_listener_spec.rb +123 -0
- data/spec/swt_shoes/oval_spec.rb +51 -0
- data/spec/swt_shoes/progress_spec.rb +44 -0
- data/spec/swt_shoes/radio_group_spec.rb +73 -0
- data/spec/swt_shoes/radio_spec.rb +56 -0
- data/spec/swt_shoes/rect_painter_spec.rb +45 -0
- data/spec/swt_shoes/rect_spec.rb +19 -0
- data/spec/swt_shoes/shape_spec.rb +84 -0
- data/spec/swt_shoes/shared_examples/button.rb +21 -0
- data/spec/swt_shoes/shared_examples/clickable.rb +85 -0
- data/spec/swt_shoes/shared_examples/movable.rb +36 -0
- data/spec/swt_shoes/shared_examples/paintable.rb +7 -0
- data/spec/swt_shoes/shared_examples/painter.rb +83 -0
- data/spec/swt_shoes/shared_examples/pattern.rb +32 -0
- data/spec/swt_shoes/shared_examples/removable.rb +41 -0
- data/spec/swt_shoes/shared_examples/swt_app_context.rb +23 -0
- data/spec/swt_shoes/shared_examples/visibility.rb +15 -0
- data/spec/swt_shoes/shell_control_listener_spec.rb +23 -0
- data/spec/swt_shoes/slot_spec.rb +24 -0
- data/spec/swt_shoes/sound.rb +10 -0
- data/spec/swt_shoes/spec_helper.rb +31 -0
- data/spec/swt_shoes/star_spec.rb +47 -0
- data/spec/swt_shoes/text_block/centered_text_segment_spec.rb +16 -0
- data/spec/swt_shoes/text_block/cursor_painter_spec.rb +120 -0
- data/spec/swt_shoes/text_block/fitter_spec.rb +213 -0
- data/spec/swt_shoes/text_block/painter_spec.rb +212 -0
- data/spec/swt_shoes/text_block/text_font_factory_spec.rb +40 -0
- data/spec/swt_shoes/text_block/text_segment_collection_spec.rb +256 -0
- data/spec/swt_shoes/text_block/text_segment_spec.rb +135 -0
- data/spec/swt_shoes/text_block_spec.rb +199 -0
- metadata +496 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
class Harness
|
|
2
|
+
include Shoes::Swt::DisposedProtection
|
|
3
|
+
|
|
4
|
+
def initialize(real)
|
|
5
|
+
@real = real
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe Shoes::Swt::DisposedProtection do
|
|
10
|
+
let(:width) { 234 }
|
|
11
|
+
let(:real_with_disposed_protection) { Harness.new(bare_real).real }
|
|
12
|
+
|
|
13
|
+
context "when real object is NOT disposed" do
|
|
14
|
+
let(:bare_real) { double("delegation object", width: width, dispose: nil, disposed?: false) }
|
|
15
|
+
|
|
16
|
+
it "delegates method" do
|
|
17
|
+
real_with_disposed_protection.width
|
|
18
|
+
expect(bare_real).to have_received(:width)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "returns the same result as the bare real object" do
|
|
22
|
+
expect(real_with_disposed_protection.width).to eq(width)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "disposes real object" do
|
|
26
|
+
real_with_disposed_protection.dispose
|
|
27
|
+
expect(bare_real).to have_received(:dispose)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "when real object IS disposed" do
|
|
32
|
+
let(:bare_real) { double("delegation object", width: width, dispose: nil, disposed?: true) }
|
|
33
|
+
|
|
34
|
+
it "does NOT delegate method" do
|
|
35
|
+
real_with_disposed_protection.width
|
|
36
|
+
expect(bare_real).not_to have_received(:width)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "returns nil" do
|
|
40
|
+
expect(real_with_disposed_protection.width).to eq(nil)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "does NOT dispose real object" do
|
|
44
|
+
real_with_disposed_protection.dispose
|
|
45
|
+
expect(bare_real).not_to have_received(:dispose)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'swt_shoes/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Shoes::Swt::Flow do
|
|
4
|
+
include_context "swt app"
|
|
5
|
+
|
|
6
|
+
let(:dsl) { double('dsl', app: shoes_app,
|
|
7
|
+
pass_coordinates?: true).as_null_object }
|
|
8
|
+
let(:real) { double('real', disposed?: false) }
|
|
9
|
+
let(:parent_real) { double('parent_real', :get_layout => "ok") }
|
|
10
|
+
|
|
11
|
+
subject { Shoes::Swt::Flow.new(dsl, parent) }
|
|
12
|
+
|
|
13
|
+
# it does not use toggle anymore and hides each element individually
|
|
14
|
+
# which means that each element takes care of what this spec specs,
|
|
15
|
+
# which we test elsewhere.
|
|
16
|
+
# Add back in when slots get an appropriate backend.
|
|
17
|
+
# #905
|
|
18
|
+
# it_behaves_like "updating visibility"
|
|
19
|
+
|
|
20
|
+
it_behaves_like "clickable backend" do
|
|
21
|
+
let(:click_block_parameters) { click_block_coordinates }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "#initialize" do
|
|
25
|
+
before do
|
|
26
|
+
allow(parent).to receive(:real) { parent_real }
|
|
27
|
+
allow(parent_real).to receive(:get_layout){double(top_slot: true)}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "sets readers" do
|
|
31
|
+
expect(subject.parent).to eq parent
|
|
32
|
+
expect(subject.dsl).to eq dsl
|
|
33
|
+
expect(subject.real).to eq parent_real
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'swt_shoes/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Shoes::Swt::Font do
|
|
4
|
+
|
|
5
|
+
subject {Shoes::Swt::Font}
|
|
6
|
+
|
|
7
|
+
describe 'Shoes::FONTS' do
|
|
8
|
+
it 'has the FONTS array initially populared' do
|
|
9
|
+
expect(Shoes::FONTS).not_to be_empty
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'loads the 2 shoes specific fonts' do
|
|
13
|
+
expect(Shoes::FONTS).to include("Coolvetica", "Lacuna")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '.add_font' do
|
|
18
|
+
it 'returns nil if no font was found' do
|
|
19
|
+
expect(subject.add_font('/non/existent/font.ttf')).to be_nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'returns the font name when the font file is present' do
|
|
23
|
+
expect(subject.add_font(Shoes::FONT_DIR + 'Coolvetica.ttf')).to eq 'Coolvetica'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'calls the Display#load_font method' do
|
|
27
|
+
font_path = Shoes::FONT_DIR + 'Coolvetica.ttf'
|
|
28
|
+
expect(::Swt.display).to receive(:load_font).with(font_path)
|
|
29
|
+
subject.add_font font_path
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'swt_shoes/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Shoes::Swt::Gradient do
|
|
4
|
+
let(:color1) { Shoes::Color.create(Shoes::COLORS[:honeydew]) }
|
|
5
|
+
let(:color2) { Shoes::Color.create(Shoes::COLORS[:salmon]) }
|
|
6
|
+
let(:dsl) { Shoes::Gradient.new(color1, color2) }
|
|
7
|
+
let(:gc) { double("gc", set_background_pattern: nil) }
|
|
8
|
+
|
|
9
|
+
subject { Shoes::Swt::Gradient.new(dsl) }
|
|
10
|
+
|
|
11
|
+
it_behaves_like "an swt pattern"
|
|
12
|
+
|
|
13
|
+
describe "#dispose" do
|
|
14
|
+
it "lets subresources do" do
|
|
15
|
+
# Prime the object's lazy colors
|
|
16
|
+
subject.apply_as_fill(gc, 10, 20, 100, 200)
|
|
17
|
+
|
|
18
|
+
expect(subject.color1).to receive(:dispose)
|
|
19
|
+
expect(subject.color2).to receive(:dispose)
|
|
20
|
+
|
|
21
|
+
subject.dispose
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#apply_as_fill" do
|
|
26
|
+
it "sets background" do
|
|
27
|
+
expect(gc).to receive(:set_background_pattern)
|
|
28
|
+
subject.apply_as_fill(gc, 10, 20, 100, 200)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'swt_shoes/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Shoes::Swt::ImagePattern do
|
|
4
|
+
let(:dsl) { Shoes::ImagePattern.new("some/path/to") }
|
|
5
|
+
let(:swt_image) { double("swt image") }
|
|
6
|
+
let(:swt_pattern) { double("swt pattern") }
|
|
7
|
+
|
|
8
|
+
subject { Shoes::Swt::ImagePattern.new(dsl) }
|
|
9
|
+
|
|
10
|
+
it_behaves_like "an swt pattern"
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
allow(::Swt::Image).to receive(:new) { swt_image }
|
|
14
|
+
allow(::Swt::Pattern).to receive(:new) { swt_pattern }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "#dispose" do
|
|
18
|
+
it "disposes of sub-resources" do
|
|
19
|
+
expect(swt_image).to receive(:dispose)
|
|
20
|
+
expect(swt_pattern).to receive(:dispose)
|
|
21
|
+
|
|
22
|
+
expect(subject.pattern).to_not be_nil
|
|
23
|
+
subject.dispose
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "#apply_as_fill" do
|
|
28
|
+
let(:gc) { double("gc") }
|
|
29
|
+
|
|
30
|
+
it "sets background" do
|
|
31
|
+
expect(gc).to receive(:set_background_pattern)
|
|
32
|
+
subject.apply_as_fill(gc, 10, 20, 100, 200)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'swt_shoes/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Shoes::Swt::Image do
|
|
4
|
+
include_context "swt app"
|
|
5
|
+
|
|
6
|
+
IMAGE_WIDTH = 3
|
|
7
|
+
IMAGE_HEIGHT = 1
|
|
8
|
+
|
|
9
|
+
let(:blk) { double("block") }
|
|
10
|
+
let(:dsl) { Shoes::Image.new shoes_app, parent_dsl, image, opts}
|
|
11
|
+
let(:opts) {{left: left, top: top, width: width, height: height}}
|
|
12
|
+
let(:left) { 100 }
|
|
13
|
+
let(:top) { 200 }
|
|
14
|
+
let(:height) { nil }
|
|
15
|
+
let(:width) {nil}
|
|
16
|
+
let(:image) { "spec/swt_shoes/minimal.png" }
|
|
17
|
+
|
|
18
|
+
subject {
|
|
19
|
+
allow(dsl).to receive(:file_path) { image }
|
|
20
|
+
Shoes::Swt::Image.new(dsl, parent)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
it_behaves_like "paintable"
|
|
24
|
+
it_behaves_like "removable"
|
|
25
|
+
it_behaves_like "clickable backend"
|
|
26
|
+
it_behaves_like "updating visibility"
|
|
27
|
+
|
|
28
|
+
describe "paint callback" do
|
|
29
|
+
let(:event) { double("event", gc: gc) }
|
|
30
|
+
let(:gc) { double("gc", drawImage: true) }
|
|
31
|
+
|
|
32
|
+
before :each do
|
|
33
|
+
expect(swt_app).to receive(:add_paint_listener)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
specify "draws image" do
|
|
37
|
+
allow(dsl).to receive_messages element_left: left, element_top: top
|
|
38
|
+
expect(gc).to receive(:drawImage).with(subject.real, 0, 0, 3, 1, left, top, 3, 1)
|
|
39
|
+
subject.painter.call(event)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "painting raw images" do
|
|
44
|
+
let(:image) { File.read("spec/swt_shoes/minimal.png", :mode => "rb") }
|
|
45
|
+
|
|
46
|
+
specify "loads image from raw data" do
|
|
47
|
+
subject.real.image_data.width = 3
|
|
48
|
+
subject.real.image_data.height = 1
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# note the image used is 3x1 pixel big
|
|
53
|
+
describe 'dimensions' do
|
|
54
|
+
|
|
55
|
+
it 'has the given width' do
|
|
56
|
+
expect(subject.width).to eq(IMAGE_WIDTH)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'has the given height' do
|
|
60
|
+
expect(subject.height).to eq(IMAGE_HEIGHT)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'can change its width' do
|
|
64
|
+
subject.width = 7
|
|
65
|
+
expect(subject.width).to eq(7)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'can change its height' do
|
|
69
|
+
subject.height = 7
|
|
70
|
+
expect(subject.height).to eq(7)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe 'with a given width' do
|
|
74
|
+
let(:width) {(IMAGE_WIDTH * 5.8).to_i}
|
|
75
|
+
it 'scales the height' do
|
|
76
|
+
expect(subject.height).to eq((IMAGE_HEIGHT * 5.8).to_i)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe 'with a given height' do
|
|
81
|
+
let(:height) {IMAGE_HEIGHT * 4}
|
|
82
|
+
|
|
83
|
+
it 'scales the width' do
|
|
84
|
+
expect(subject.width).to eq(IMAGE_WIDTH * 4)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe 'with a given width and height' do
|
|
89
|
+
let(:width) {1}
|
|
90
|
+
let(:height) {2}
|
|
91
|
+
it 'sets the given width' do
|
|
92
|
+
expect(subject.width).to eq(1)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'sets the given height' do
|
|
96
|
+
expect(subject.height).to eq(2)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
require 'swt_shoes/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Shoes::Swt::InputBox do
|
|
4
|
+
include_context "swt app"
|
|
5
|
+
|
|
6
|
+
let(:dsl) { double('dsl', app: shoes_app, visible?: true, element_width: 80,
|
|
7
|
+
element_height: 22, initial_text: 'Jay',
|
|
8
|
+
secret?: secret,
|
|
9
|
+
call_change_listeners: true).as_null_object }
|
|
10
|
+
let(:real) { double('real', disposed?: false, text: text,
|
|
11
|
+
add_modify_listener: true).as_null_object }
|
|
12
|
+
let(:styles) {::Swt::SWT::SINGLE | ::Swt::SWT::BORDER}
|
|
13
|
+
let(:secret) {false}
|
|
14
|
+
let(:text) {'Some text...'}
|
|
15
|
+
|
|
16
|
+
subject { Shoes::Swt::InputBox.new dsl, parent, styles }
|
|
17
|
+
|
|
18
|
+
before :each do
|
|
19
|
+
allow(::Swt::Widgets::Text).to receive(:new) { real }
|
|
20
|
+
allow(::Swt::Widgets::Text).to receive(:text=) { real }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it_behaves_like "movable element"
|
|
24
|
+
it_behaves_like "removable native element"
|
|
25
|
+
it_behaves_like "updating visibility"
|
|
26
|
+
|
|
27
|
+
describe "#initialize" do
|
|
28
|
+
let(:event) {double 'Event', source: source}
|
|
29
|
+
let(:source) {double 'Source'}
|
|
30
|
+
it "sets text on real element" do
|
|
31
|
+
subject.text = "some text"
|
|
32
|
+
expect(real).to have_received(:text=).with("some text")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe 'change listeners' do
|
|
36
|
+
|
|
37
|
+
it "should set up a listener that delegates change events" do
|
|
38
|
+
expect(dsl).to receive(:call_change_listeners)
|
|
39
|
+
expect(real).to receive(:add_modify_listener) do |&blk|
|
|
40
|
+
blk.call(event)
|
|
41
|
+
end
|
|
42
|
+
subject
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe 'modify block' do
|
|
46
|
+
before :each do
|
|
47
|
+
@modify_block = nil
|
|
48
|
+
expect(real).to receive(:add_modify_listener) do |&blk|
|
|
49
|
+
@modify_block = blk
|
|
50
|
+
end
|
|
51
|
+
subject
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'normally calls the dsl change listeners' do
|
|
55
|
+
@modify_block.call event
|
|
56
|
+
|
|
57
|
+
expect(dsl).to have_received :call_change_listeners
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe 'with the same text' do
|
|
61
|
+
let(:event) {double 'Bad Event', source: source}
|
|
62
|
+
let(:source) {double 'Our source', text: text}
|
|
63
|
+
let(:text) {'Double call'}
|
|
64
|
+
|
|
65
|
+
it 'does not call the change listeners' do
|
|
66
|
+
subject.text = text
|
|
67
|
+
allow(event).to receive(:instance_of?) do |klazz|
|
|
68
|
+
klazz == Java::OrgEclipseSwtEvents::ModifyEvent
|
|
69
|
+
end
|
|
70
|
+
allow(source).to receive(:instance_of?) do |klazz|
|
|
71
|
+
klazz == Java::OrgEclipseSwtWidgets::Text
|
|
72
|
+
end
|
|
73
|
+
@modify_block.call event
|
|
74
|
+
expect(dsl).to_not have_received :call_change_listeners
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe 'text selections' do
|
|
83
|
+
it 'translates the highlight_text call' do
|
|
84
|
+
subject.highlight_text 4, 20
|
|
85
|
+
expect(real).to have_received(:set_selection).with(4, 20)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'translates the caret_to call' do
|
|
89
|
+
subject.caret_to 42
|
|
90
|
+
expect(real).to have_received(:set_selection).with(42)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe Shoes::Swt::EditLine do
|
|
95
|
+
subject {Shoes::Swt::EditLine.new dsl, parent}
|
|
96
|
+
describe ":secret option" do
|
|
97
|
+
context "when NOT set" do
|
|
98
|
+
it "does NOT set PASSWORD style" do
|
|
99
|
+
options = Shoes::Swt::EditLine::DEFAULT_STYLES
|
|
100
|
+
allow(dsl).to receive(:secret?) { false }
|
|
101
|
+
expect(::Swt::Widgets::Text).to receive(:new).with(parent.real, options)
|
|
102
|
+
subject
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
context "when set" do
|
|
107
|
+
it "sets PASSWORD style" do
|
|
108
|
+
options = Shoes::Swt::EditLine::DEFAULT_STYLES | ::Swt::SWT::PASSWORD
|
|
109
|
+
allow(dsl).to receive(:secret?) { true }
|
|
110
|
+
expect(::Swt::Widgets::Text).to receive(:new).with(parent.real, options)
|
|
111
|
+
subject
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'swt_shoes/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Shoes::App do
|
|
4
|
+
before :each do
|
|
5
|
+
# The stubs that are unstubbed here occur in the spec_helper
|
|
6
|
+
# error not triggered with a stubbed flush (removing the stub overall
|
|
7
|
+
# seemed to difficult after initial try)
|
|
8
|
+
allow_any_instance_of(Shoes::Swt::App).to receive(:flush).and_call_original
|
|
9
|
+
allow(Shoes::Swt::RedrawingAspect).to receive(:new).and_call_original
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'does not fail with just a simple para #574' do
|
|
13
|
+
app = nil
|
|
14
|
+
begin
|
|
15
|
+
expect do
|
|
16
|
+
app = Shoes.app do para 'me no fail' end
|
|
17
|
+
app.quit
|
|
18
|
+
end.not_to raise_error
|
|
19
|
+
ensure
|
|
20
|
+
# Really ugly, but we have to can't let the redrawing aspect persist out
|
|
21
|
+
# of this test run, don't really want to expose it broadly, and can't
|
|
22
|
+
# clear it during `quit` like might feel natural because of #782
|
|
23
|
+
aspect = app.instance_variable_get(:@__app__).gui.instance_variable_get(:@redrawing_aspect)
|
|
24
|
+
aspect.remove_redraws
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'swt_shoes/spec_helper'
|
|
3
|
+
|
|
4
|
+
describe Shoes::Swt::Keypress do
|
|
5
|
+
let(:app) { double('app', add_key_listener: nil, remove_key_listener: nil) }
|
|
6
|
+
let(:dsl) { double('dsl') }
|
|
7
|
+
let(:block) { proc{ |key| key} }
|
|
8
|
+
let(:key_listener) {Shoes::Swt::Keypress.new(dsl, app, &block)}
|
|
9
|
+
|
|
10
|
+
describe '.get_swt_constant' do
|
|
11
|
+
it 'gets the swt constant' do
|
|
12
|
+
expect(Shoes::Swt::KeyListener.get_swt_constant("TAB")).to eq ::Swt::SWT::TAB
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "subclasses" do
|
|
17
|
+
|
|
18
|
+
describe "Subclass Keypress" do
|
|
19
|
+
it "adds key listener on creation" do
|
|
20
|
+
expect(app).to receive(:add_key_listener)
|
|
21
|
+
Shoes::Swt::Keypress.new dsl, app, &block
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "Subclass Keyrelease" do
|
|
26
|
+
it "adds key listener on creation" do
|
|
27
|
+
expect(app).to receive(:add_key_listener)
|
|
28
|
+
Shoes::Swt::Keyrelease.new dsl, app, &block
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "removes the key listener from the app on remove" do
|
|
34
|
+
key_listener.remove
|
|
35
|
+
expect(app).to have_received(:remove_key_listener).with(key_listener)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
CTRL = ::Swt::SWT::CTRL
|
|
39
|
+
ALT = ::Swt::SWT::ALT
|
|
40
|
+
SHIFT = ::Swt::SWT::SHIFT
|
|
41
|
+
|
|
42
|
+
subject {key_listener}
|
|
43
|
+
|
|
44
|
+
def test_character_press(character, state_modifier = 0, result_char = character)
|
|
45
|
+
expect(block).to receive(:call).with(result_char)
|
|
46
|
+
event = double character: character.ord,
|
|
47
|
+
stateMask: 0 | state_modifier,
|
|
48
|
+
keyCode: character.downcase.ord
|
|
49
|
+
subject.handle_key_event(event)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_alt_character_press(character, state_mask_modifier = 0)
|
|
53
|
+
state_modifier = ALT | state_mask_modifier
|
|
54
|
+
result = ('alt_' + character).to_sym
|
|
55
|
+
test_character_press(character, state_modifier, result)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
describe 'works with simple keys such as' do
|
|
60
|
+
it '"a"' do
|
|
61
|
+
test_character_press 'a'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it '"1"' do
|
|
65
|
+
test_character_press '1'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it '"$"' do
|
|
69
|
+
test_character_press '$'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'handles UTF-8 (œ)' do
|
|
73
|
+
test_character_press 'œ'
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe 'works with shift key pressed such as' do
|
|
78
|
+
def test_shift_character_press(character)
|
|
79
|
+
state_modifier = SHIFT
|
|
80
|
+
test_character_press(character, state_modifier)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it '"A"' do
|
|
84
|
+
test_shift_character_press "A"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it '"Z"' do
|
|
88
|
+
test_shift_character_press "Z"
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe 'works with alt key pressed such as' do
|
|
93
|
+
it ':alt_a' do
|
|
94
|
+
test_alt_character_press 'a'
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it ':alt_z' do
|
|
98
|
+
test_alt_character_press 'z'
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it ':alt_/' do
|
|
102
|
+
test_alt_character_press '/'
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'works with what Macs seem to produce for opt + / (should be alt_/)' do
|
|
106
|
+
expect(block).to receive(:call).with(:'alt_/')
|
|
107
|
+
event = double character: '÷'.ord,
|
|
108
|
+
stateMask: ALT,
|
|
109
|
+
keyCode: '/'.ord
|
|
110
|
+
subject.handle_key_event(event)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe 'works with the ctrl key pressed such as' do
|
|
115
|
+
def test_ctrl_character_press(character, modifier = 0)
|
|
116
|
+
result_char = ('control_' + character).to_sym
|
|
117
|
+
expect(block).to receive(:call).with(result_char)
|
|
118
|
+
event = double character: 'something weird like \x00',
|
|
119
|
+
stateMask: CTRL | modifier,
|
|
120
|
+
keyCode: character.downcase.ord
|
|
121
|
+
subject.handle_key_event(event)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it ':ctrl_a' do
|
|
125
|
+
test_ctrl_character_press 'a'
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'ctrl_z' do
|
|
129
|
+
test_ctrl_character_press 'z'
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe 'and if we add the shift key' do
|
|
133
|
+
it ':ctrl_A' do
|
|
134
|
+
test_ctrl_character_press 'A', SHIFT
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it ':ctrl_Z' do
|
|
138
|
+
test_ctrl_character_press 'Z', SHIFT
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
describe 'works with shift combined with alt yielding capital letters' do
|
|
144
|
+
def test_alt_shift_character_press(character)
|
|
145
|
+
test_alt_character_press(character, SHIFT)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it ':alt_A' do
|
|
149
|
+
test_alt_shift_character_press 'A'
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it ':alt_Z' do
|
|
153
|
+
test_alt_shift_character_press 'Z'
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe 'only modifier keys yield nothing' do
|
|
158
|
+
def test_receive_nothing_with_modifier(modifier, last_key_press = modifier)
|
|
159
|
+
expect(block).not_to receive :call
|
|
160
|
+
event = double stateMask: modifier, keyCode: last_key_press, character: 0
|
|
161
|
+
subject.handle_key_event(event)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'shift' do
|
|
165
|
+
test_receive_nothing_with_modifier SHIFT
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it 'alt' do
|
|
169
|
+
test_receive_nothing_with_modifier ALT
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it 'control' do
|
|
173
|
+
test_receive_nothing_with_modifier CTRL
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it 'shift + ctrl' do
|
|
177
|
+
test_receive_nothing_with_modifier SHIFT | CTRL, SHIFT
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'ctrl + alt' do
|
|
181
|
+
test_receive_nothing_with_modifier CTRL | ALT, CTRL
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it 'shift + ctrl + alt' do
|
|
185
|
+
test_receive_nothing_with_modifier CTRL | SHIFT | ALT, ALT
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
describe 'special keys' do
|
|
190
|
+
|
|
191
|
+
ARROW_LEFT = ::Swt::SWT::ARROW_LEFT
|
|
192
|
+
|
|
193
|
+
def special_key_test(code, expected, modifier = 0)
|
|
194
|
+
expect(block).to receive(:call).with(expected)
|
|
195
|
+
event = double stateMask: modifier,
|
|
196
|
+
keyCode: code,
|
|
197
|
+
character: 0
|
|
198
|
+
subject.handle_key_event(event)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it '"\n"' do
|
|
202
|
+
special_key_test(::Swt::SWT::CR, "\n")
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
it ':left' do
|
|
206
|
+
special_key_test ARROW_LEFT, :left
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it ':f1' do
|
|
210
|
+
special_key_test ::Swt::SWT::F1, :f1
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it ':tab' do
|
|
214
|
+
special_key_test ::Swt::SWT::TAB, :tab
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it ':delete' do
|
|
218
|
+
special_key_test ::Swt::SWT::DEL, :delete
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
describe 'with modifier' do
|
|
222
|
+
it ':alt_left' do
|
|
223
|
+
special_key_test ARROW_LEFT, :alt_left, ALT
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it ':control_left' do
|
|
227
|
+
special_key_test ARROW_LEFT, :control_left, CTRL
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it ':shift_left' do
|
|
231
|
+
special_key_test ARROW_LEFT, :shift_left, SHIFT
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
it ':control_alt_home' do
|
|
235
|
+
special_key_test ::Swt::SWT::HOME, :control_alt_home, ALT | CTRL
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it ':control_shift_home' do
|
|
239
|
+
special_key_test ::Swt::SWT::HOME,
|
|
240
|
+
:control_shift_alt_home,
|
|
241
|
+
ALT | CTRL | SHIFT
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
describe 'Mac command key' do
|
|
247
|
+
it 'fixes crash of shift option command #584' do
|
|
248
|
+
event = double 'key event', stateMask: 196608,
|
|
249
|
+
keyCode: 4194304,
|
|
250
|
+
character: "don't care atm"
|
|
251
|
+
expect {subject.handle_key_event(event)}.not_to raise_error
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
describe '#ignore_event?' do
|
|
256
|
+
|
|
257
|
+
let(:character) {'a'}
|
|
258
|
+
let(:event) {double 'key event',
|
|
259
|
+
widget: widget,
|
|
260
|
+
stateMask: 0,
|
|
261
|
+
keyCode: keyCode,
|
|
262
|
+
character: character.ord }
|
|
263
|
+
let(:shell){Java::OrgEclipseSwtWidgets::Shell.new}
|
|
264
|
+
let(:style) {0}
|
|
265
|
+
let(:keyCode) {character.downcase.ord}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
subject{key_listener.ignore_event? event}
|
|
269
|
+
|
|
270
|
+
shared_examples_for 'ignores space and enter' do
|
|
271
|
+
describe 'with a space' do
|
|
272
|
+
let(:character) {' '}
|
|
273
|
+
it {is_expected.to be_truthy}
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
describe 'with enter' do
|
|
277
|
+
let(:keyCode) {::Swt::SWT::CR}
|
|
278
|
+
it {is_expected.to be_truthy}
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
shared_examples_for 'accepts normal characters' do
|
|
283
|
+
describe 'with a normal character' do
|
|
284
|
+
let(:character) {'a'}
|
|
285
|
+
it{is_expected.to be_falsey}
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
context 'on a Shell' do
|
|
290
|
+
let(:widget){shell}
|
|
291
|
+
it {is_expected.to be_falsey}
|
|
292
|
+
|
|
293
|
+
describe 'even with enter' do
|
|
294
|
+
let(:keyCode) {::Swt::SWT::CR}
|
|
295
|
+
it {is_expected.to be_falsey}
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
context 'on a Text' do
|
|
300
|
+
let(:widget){Java::OrgEclipseSwtWidgets::Text.new(shell, style)}
|
|
301
|
+
it {is_expected.to be_truthy}
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
context 'on a button' do
|
|
305
|
+
let(:widget) {Java::OrgEclipseSwtWidgets::Button.new(shell, style)}
|
|
306
|
+
|
|
307
|
+
it_behaves_like 'ignores space and enter'
|
|
308
|
+
it_behaves_like 'accepts normal characters'
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
context 'on a Combo' do
|
|
312
|
+
let(:widget) {Java::OrgEclipseSwtWidgets::Combo.new(shell, style)}
|
|
313
|
+
|
|
314
|
+
it_behaves_like 'ignores space and enter'
|
|
315
|
+
|
|
316
|
+
describe 'with up' do
|
|
317
|
+
let(:keyCode) {::Swt::SWT::ARROW_UP}
|
|
318
|
+
it{is_expected.to be_truthy}
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
it_behaves_like 'accepts normal characters'
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
end
|