te3270 0.5.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,179 @@
1
+ require 'spec_helper'
2
+
3
+ describe TE3270::Emulators::X3270 do
4
+
5
+ let(:x3270) { TE3270::Emulators::X3270.new }
6
+
7
+ before(:each) do
8
+ @x3270_io = double('x3270_io')
9
+ Open3.stub(:popen2e).and_return [@x3270_io,@x3270_io,nil]
10
+ x3270.instance_variable_set(:@executable_command, "the_command")
11
+ x3270.instance_variable_set(:@host, "the_host")
12
+ @x3270_io.stub(:print)
13
+ @x3270_io.stub(:flush)
14
+ @x3270_io.stub(:gets).and_return('goo','ok')
15
+ end
16
+
17
+ describe "global behaviors" do
18
+ it 'should open pipe to x3270' do
19
+ Open3.should_receive(:popen2e).and_return(x3270_system)
20
+ x3270.connect
21
+ end
22
+
23
+ it 'should take the timeout value from a block' do
24
+ x3270.should_receive(:executable_command=).with('path to the x3270 executable')
25
+ x3270.connect do |platform|
26
+ platform.executable_command = 'path to the x3270 executable'
27
+ end
28
+ end
29
+
30
+ it 'should take the host to connect to from a block' do
31
+ x3270.should_receive(:host=).with('name of host to connect to')
32
+ x3270.connect do |platform|
33
+ platform.host = 'name of host to connect to'
34
+ end
35
+ end
36
+
37
+ it 'should take the max timeout value from a block' do
38
+ x3270.should_receive(:max_wait_time=).with(42)
39
+ x3270.connect do |platform|
40
+ platform.max_wait_time = 42
41
+ end
42
+ end
43
+
44
+ it 'should display an error when the path to the executable is not set' do
45
+ x3270.instance_variable_set(:@executable_command, nil)
46
+ expect { x3270.connect }.to raise_error('The executable command must be set in a block when calling connect with the X3270 emulator.')
47
+ end
48
+
49
+ it 'should display an error when the host is not set' do
50
+ x3270.instance_variable_set(:@host, nil)
51
+ expect { x3270.connect }.to raise_error('The host must be set in a block when calling connect with the X3270 emulator.')
52
+ end
53
+
54
+ it 'should default to max_wait_time being 10 when not provided' do
55
+ #x3270.should_receive(:max_wait_time=).with(10)
56
+ x3270.connect
57
+ x3270.instance_variable_get(:@max_wait_time).should eq(10)
58
+ end
59
+
60
+ it 'should display an error when cannot popen supplied x3270 program' do
61
+ Open3.stub(:popen2e).and_raise('darn it, popen failed')
62
+ expect { x3270.connect }.to raise_error( "Could not start x3270 'the_command': darn it, popen failed")
63
+ end
64
+
65
+ it 'should close input and output on pipe when disconnect called' do
66
+ io = double('IO')
67
+ Open3.stub(:popen2e).and_return([io,io,io])
68
+ io.should_receive(:close).twice
69
+ x3270.connect
70
+ x3270.disconnect
71
+ end
72
+ end
73
+
74
+ describe "interacting with text fields" do
75
+ it 'should get the value from the screen' do
76
+ @x3270_io.should_receive(:print).with("ascii(0,1,7)\n")
77
+ @x3270_io.stub(:gets).and_return('data: blah','goo','ok')
78
+ #@x3270_io.stub(:gets).and_return('ok')
79
+ x3270.connect
80
+ x3270.get_string(1, 2, 7).should == 'blah'
81
+ end
82
+
83
+ it 'should put a value on the screen' do
84
+ @x3270_io.should_receive(:print).with("MoveCursor(14,55)\n")
85
+ @x3270_io.should_receive(:print).with('string "blah"'+"\n")
86
+ x3270.connect
87
+ x3270.put_string('blah', 15, 56)
88
+ end
89
+
90
+ it 'should put proper escape value on the screen' do
91
+ @x3270_io.should_receive(:print).with("MoveCursor(14,55)\n")
92
+ @x3270_io.should_receive(:print).with('string "ab\"cd"'+"\n")
93
+ x3270.connect
94
+ x3270.put_string('ab"cd', 15, 56)
95
+ end
96
+ end
97
+
98
+ describe "interacting with the screen" do
99
+ it 'should know how to send function keys' do
100
+ @x3270_io.should_receive(:print).with("Home\n")
101
+ @x3270_io.should_receive(:print).with("wait(output)\n")
102
+ x3270.connect
103
+ x3270.send_keys(TE3270.Home)
104
+ end
105
+
106
+ it 'should know how to send program function keys ' do
107
+ @x3270_io.should_receive(:print).with("Pf(13)\n")
108
+ @x3270_io.should_receive(:print).with("wait(output)\n")
109
+ x3270.connect
110
+ x3270.send_keys(TE3270.Pf13)
111
+ end
112
+
113
+ it 'should know how to send program attention keys ' do
114
+ @x3270_io.should_receive(:print).with("Pa(2)\n")
115
+ @x3270_io.should_receive(:print).with("wait(output)\n")
116
+ x3270.connect
117
+ x3270.send_keys(TE3270.Pa2)
118
+ end
119
+
120
+ it 'should wait for a string to appear' do
121
+ @x3270_io.should_receive(:print).with("ascii(2,9,6)\n")
122
+ @x3270_io.should_receive(:gets).and_return('data: string','goo','ok')
123
+ x3270.should_not_receive(:sleep)
124
+ x3270.connect
125
+ x3270.wait_for_string('string', 3, 10)
126
+ end
127
+
128
+ it 'should timeout when wait for a string does not appear' do
129
+ @x3270_io.should_receive(:print).with("ascii(2,9,6)\n").exactly(20).times
130
+ @x3270_io.should_receive(:gets).and_return('data: stuff','goo','ok')
131
+ x3270.should_receive(:sleep).exactly(20).times
132
+ x3270.connect
133
+ x3270.wait_for_string('string', 3, 10)
134
+ end
135
+
136
+ it 'should find string after one sleep when waiting for a string to appear' do
137
+ @x3270_io.should_receive(:print).with("ascii(2,9,6)\n").twice
138
+ @x3270_io.should_receive(:gets).and_return('data: blah','goo','ok','data: string','goo','ok')
139
+ x3270.stub(:sleep).with(0.5).once
140
+ x3270.connect
141
+ x3270.wait_for_string('string', 3, 10)
142
+ end
143
+
144
+ it 'should wait for host' do
145
+ @x3270_io.should_receive(:print).with("Wait(10,Output)\n")
146
+ x3270.connect
147
+ x3270.wait_for_host(10)
148
+ end
149
+
150
+ it 'should wait until the cursor is at a position' do
151
+ @x3270_io.should_receive(:print).with("MoveCursor(5,8)\n")
152
+ x3270.connect
153
+ x3270.wait_until_cursor_at(6,9)
154
+ end
155
+
156
+ it 'should take screenshots' do
157
+ File.should_receive(:exists?).and_return(false)
158
+ File.should_not_receive(:delete)
159
+ @x3270_io.should_receive(:print).with("printtext(file,image.txt)\n")
160
+ x3270.connect
161
+ x3270.screenshot("image.txt")
162
+ end
163
+
164
+ it 'should delete existing file when taking screenshots' do
165
+ File.should_receive(:exists?).and_return(true)
166
+ File.should_receive(:delete)
167
+ @x3270_io.should_receive(:print).with("printtext(file,image.txt)\n")
168
+ x3270.connect
169
+ x3270.screenshot("image.txt")
170
+ end
171
+
172
+ it 'should get all text from screen' do
173
+ @x3270_io.should_receive(:print).with("ascii(0,0,1920)\n")
174
+ @x3270_io.should_receive(:gets).and_return('data: string','goo','ok')
175
+ x3270.connect
176
+ x3270.text.should == 'string'
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ class ScreenFactoryScreen
4
+ include TE3270
5
+ end
6
+
7
+ class WorldSuper
8
+ attr_reader :super_called
9
+ def on(screen_class, &block)
10
+ @super_called = true
11
+ end
12
+ end
13
+
14
+ class World < WorldSuper
15
+ include TE3270::ScreenFactory
16
+ end
17
+
18
+ describe TE3270::ScreenFactory do
19
+
20
+ let(:world) { World.new }
21
+
22
+ it 'should create a new screen object' do
23
+ emulator = double('platform')
24
+ world.instance_variable_set('@emulator', emulator)
25
+ world.on(ScreenFactoryScreen).should be_instance_of ScreenFactoryScreen
26
+ end
27
+
28
+ it 'should create a new screen object and execute a block' do
29
+ emulator = double('platform')
30
+ world.instance_variable_set('@emulator', emulator)
31
+ world.on(ScreenFactoryScreen) do |page|
32
+ page.should be_instance_of ScreenFactoryScreen
33
+ end
34
+ end
35
+
36
+ it 'should raise an error when an @emulator instance variable does not exist' do
37
+ expect { world.on(ScreenFactoryScreen) }.to raise_error("@emulator instance variable must be available to use the ScreenFactory methods")
38
+ end
39
+
40
+ it 'should pass control to super if passed a class that does not include TE3270' do
41
+ class NoTE
42
+ end
43
+ emulator = double('platform')
44
+ world.instance_variable_set('@emulator', emulator)
45
+ world.on(NoTE)
46
+ world.super_called.should be true
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ class ScreenPopulatorScreen
4
+ include TE3270
5
+
6
+ text_field(:editable, 1, 2, 10, true)
7
+ text_field(:read_only, 2, 3, 12, false)
8
+ end
9
+
10
+ describe TE3270::ScreenPopulator do
11
+
12
+ let(:platform) { double('platform') }
13
+ let(:screen_object) { ScreenPopulatorScreen.new platform }
14
+
15
+ it 'should set a value in a text field' do
16
+ platform.should_receive(:put_string).with('the_value', 1, 2)
17
+ screen_object.populate_screen_with editable: 'the_value'
18
+ end
19
+
20
+ it 'should not set a value when a text field is read only' do
21
+ platform.should_not_receive(:put_string)
22
+ screen_object.populate_screen_with read_only: 'the_value'
23
+ end
24
+
25
+ it 'should attempt to set all values from the provided Hash' do
26
+ platform.should_receive(:put_string).with('the_value', 1, 2)
27
+ platform.should_not_receive(:put_string).with('read_only', 2, 3)
28
+ screen_object.populate_screen_with(editable: 'the_value', read_only: 'read_only')
29
+ end
30
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ class TEScreenObject
4
+ include TE3270
5
+
6
+ attr_reader :initialize_screen
7
+
8
+ def initialize_screen
9
+ @initialize_screen = true
10
+ end
11
+ end
12
+
13
+ describe TE3270 do
14
+ let(:platform) { double('platform') }
15
+ let(:screen_object) { TEScreenObject.new platform }
16
+
17
+ before(:each) do
18
+ screen_object.stub(:platform).and_return platform
19
+ end
20
+
21
+ describe "interacting with the platform" do
22
+ it 'should use the platform to connect to an emulator' do
23
+ platform.should_receive(:connect)
24
+ screen_object.connect
25
+ end
26
+
27
+ it 'should use the platform to disconnect from an emulator' do
28
+ platform.should_receive(:disconnect)
29
+ screen_object.disconnect
30
+ end
31
+
32
+ it 'should use the platform to send keys to the screen' do
33
+ platform.should_receive(:send_keys).with('<Clear>')
34
+ screen_object.send_keys(TE3270.Clear)
35
+ end
36
+
37
+ it 'should use the platform to wait for a string to appear on the screen' do
38
+ platform.should_receive(:wait_for_string).with('The String', 2, 4)
39
+ screen_object.wait_for_string('The String', 2, 4)
40
+ end
41
+
42
+ it 'should use the platform to wait for the host to be quiet' do
43
+ platform.should_receive(:wait_for_host).with(4)
44
+ screen_object.wait_for_host(4)
45
+ end
46
+
47
+ it 'should default to five seconds when waiting for the host' do
48
+ platform.should_receive(:wait_for_host).with(5)
49
+ screen_object.wait_for_host
50
+ end
51
+
52
+ it 'should use the platform to wait until the cursor at a specific position' do
53
+ platform.should_receive(:wait_until_cursor_at).with(10, 10)
54
+ screen_object.wait_until_cursor_at(10, 10)
55
+ end
56
+
57
+ it 'should use the platform to take a screenshot of the screen' do
58
+ platform.should_receive(:screenshot).with('image.png')
59
+ screen_object.screenshot('image.png')
60
+ end
61
+
62
+ it 'should use the platform to get the text for the entire screen' do
63
+ platform.should_receive(:text).and_return('123abc')
64
+ screen_object.text.should == '123abc'
65
+ end
66
+ end
67
+
68
+ describe "module functionality" do
69
+ it 'should know the function keys' do
70
+ TE3270.Clear.should == '<Clear>'
71
+ TE3270.Pf24.should == '<Pf24>'
72
+ end
73
+
74
+ it 'should call initialize_screen if it exists' do
75
+ screen_object.initialize_screen.should be true
76
+ end
77
+
78
+ it 'should create an emulator and connect to terminal' do
79
+ TE3270::Emulators::Extra.should_receive(:new).and_return(platform)
80
+ platform.should_receive(:connect)
81
+ TE3270.emulator_for :extra
82
+ end
83
+
84
+ it 'should accept a block when creating an emulator' do
85
+ WIN32OLE.stub(:new).and_return extra_system
86
+ extra_sessions.should_receive(:Open).with('blah.edp').and_return(extra_session)
87
+ TE3270.emulator_for :extra do |emulator|
88
+ emulator.session_file = 'blah.edp'
89
+ end
90
+ end
91
+
92
+ it 'should allow one to disconnect using the module' do
93
+ platform.should_receive(:disconnect)
94
+ TE3270.disconnect(platform)
95
+ end
96
+ end
97
+
98
+ end
@@ -0,0 +1,71 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'te3270'
4
+ require 'win32ole'
5
+ require 'win32/screenshot'
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.syntax = :should
10
+ end
11
+ end
12
+
13
+ def extra_system
14
+ @extra_system ||= double('system')
15
+ @extra_system.stub(:Sessions).and_return extra_sessions
16
+ @extra_system.stub(:Version).and_return("0")
17
+ @extra_system
18
+ end
19
+
20
+ def extra_sessions
21
+ @extra_sessions ||= double('sessions')
22
+ @extra_sessions.stub(:Count).and_return 0
23
+ @extra_sessions.stub(:Open).and_return extra_session
24
+ @extra_sessions
25
+ end
26
+
27
+ def extra_session
28
+ @extra_session ||= double('session')
29
+ @extra_session.stub(:Screen).and_return extra_screen
30
+ @extra_session.stub(:WindowState=)
31
+ @extra_session.stub(:Visible=)
32
+ @extra_session
33
+ end
34
+
35
+ def extra_screen
36
+ @extra_screen ||= double('screen')
37
+ @extra_screen.stub(:SelectAll).and_return extra_area
38
+ @extra_screen
39
+ end
40
+
41
+ def extra_area
42
+ @extra_area ||= double('area')
43
+ @extra_area
44
+ end
45
+
46
+ def quick_system
47
+ @quick_system ||= double('quick_system')
48
+ @quick_system.stub(:ActiveSession).and_return quick_session
49
+ @quick_system.stub(:Visible=)
50
+ @quick_system
51
+ end
52
+
53
+ def quick_session
54
+ @quick_session ||= double('quick_session')
55
+ @quick_session.stub(:Screen).and_return quick_screen
56
+ @quick_session.stub(:Open)
57
+ @quick_session.stub(:Connect)
58
+ @quick_session.stub(:Server_Name=)
59
+ @quick_session.stub(:Connected).and_return true
60
+ @quick_session
61
+ end
62
+
63
+ def quick_screen
64
+ @quick_screen ||= double('screen')
65
+ @quick_screen
66
+ end
67
+
68
+ def x3270_system
69
+ @x3270_system ||= double('x3270_system')
70
+ @x3270_system
71
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'te3270/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "te3270"
8
+ spec.version = TE3270::VERSION
9
+ spec.platform = Gem::Platform::CURRENT
10
+ spec.authors = ["Jeffrey S. Morgan", "Nithin C. Reddy", "Glenn W. Waters"]
11
+ spec.email = ["jeff.morgan@leandog.com","nithinreddyc@gmail.com", "gwwaters@gmail.com"]
12
+ spec.description = %q{Automates a 3270 Terminal Emulator}
13
+ spec.summary = %q{Automates a 3270 Terminal Emulator}
14
+ spec.homepage = "http://github.com/cheezy/te3270"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+ spec.extensions = ["ext/mkrf_conf.rb"]
22
+
23
+ spec.add_dependency 'page_navigation', '>= 0.9'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ end
29
+