dde 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ module DDETest
4
+
5
+ describe DDE::Monitor do
6
+ after(:each){@monitor.stop_dde}
7
+
8
+ it 'starts without constructor parameters' do
9
+ @monitor = DDE::Monitor.new
10
+
11
+ @monitor.id.should be_an Integer
12
+ @monitor.id.should_not == 0
13
+ @monitor.dde_active?.should == true
14
+ end
15
+
16
+ # context 'with existing DDE clients and server supporting "service" topic' do
17
+ # before(:each )do
18
+ # @client_calls = []
19
+ # @server_calls = []
20
+ # @client = DDE::Client.new {|*args| @client_calls << args; 1}
21
+ # @server = DDE::Server.new {|*args| @server_calls << args; 1}
22
+ # @server.start_service('service')
23
+ # end
24
+ #
25
+ # it 'starts new conversation if DDE is already activated' do
26
+ # res = @client.start_conversation 'service', 'topic'
27
+ # res.should == true
28
+ # @client.conversation_active?.should == true
29
+ # end
30
+ #
31
+ # it 'sets @conversation, @service and @topic attributes' do
32
+ # @client.start_conversation 'service', 'topic'
33
+ #
34
+ # @client.conversation.should be_an Integer
35
+ # @client.conversation.should_not == 0
36
+ # @client.service.should be_a DDE::DdeString
37
+ # @client.service.should == 'service'
38
+ # @client.service.name.should == 'service'
39
+ # @client.conversation.should be_an Integer
40
+ # @client.conversation.should_not == 0
41
+ # end
42
+ #
43
+ # it 'initiates XTYP_CONNECT transaction to service`s callback' do
44
+ # @client.start_conversation 'service', 'topic'
45
+ #
46
+ # @server_calls.first[0].should == XTYP_CONNECT
47
+ # @server_calls.first[3].should == @client.topic.handle
48
+ # @server_calls.first[4].should == @client.service.handle
49
+ # end
50
+ #
51
+ # it 'if server confirms connect, XTYP_CONNECT_CONFIRM transaction to service`s callback follows' do
52
+ # @client.start_conversation 'service', 'topic'
53
+ #
54
+ # @server_calls[1][0].should == XTYP_CONNECT_CONFIRM
55
+ # @server_calls[1][3].should == @client.topic.handle
56
+ # @server_calls[1][4].should == @client.service.handle
57
+ # end
58
+ #
59
+ # it 'client`s callback receives no transactions' do
60
+ # @client.start_conversation 'service', 'topic'
61
+ #
62
+ # p @server_calls, @client.service.handle, @client.topic.handle, @client.conversation
63
+ # @client_calls.should == []
64
+ # end
65
+ #
66
+ # it 'fails if another conversation is already in progress' do
67
+ # @client.start_conversation 'service', 'topic'
68
+ #
69
+ # lambda{@client.start_conversation 'service1', 'topic1'}.
70
+ # should raise_error /Another conversation already established/
71
+ # end
72
+ #
73
+ # it 'fails to start conversation on unsupported service' do
74
+ # lambda{@client.start_conversation('not_a_service', 'topic')}.
75
+ # should raise_error /A client`s attempt to establish a conversation has failed/
76
+ # @client.conversation_active?.should == false
77
+ # end
78
+ #
79
+ # end
80
+ end
81
+ end
@@ -0,0 +1,103 @@
1
+ module DDETest
2
+ shared_examples_for "DDE Server" do
3
+ it 'new without parameters creates Server but does not activate DDEML or start service' do
4
+ @server.id.should == nil
5
+ @server.service.should == nil
6
+ @server.dde_active?.should == false
7
+ @server.service_active?.should == false
8
+ end
9
+
10
+ it 'new with attached callback block creates Server and activates DDEML, but does not start service' do
11
+ server = described_class.new {|*args|}
12
+ server.id.should be_an Integer
13
+ server.id.should_not == 0
14
+ server.dde_active?.should == true
15
+ server.service.should == nil
16
+ server.service_active?.should == false
17
+ end
18
+
19
+ describe '#start_service' do
20
+
21
+ context 'with inactive (uninitialized) DDE:' do
22
+ it 'with attached block, initializes DDE and starts new service' do
23
+ @server.start_service('myservice') {|*args|}.should be_true
24
+
25
+ @server.service.should be_a DDE::DdeString
26
+ @server.service.should == 'myservice'
27
+ @server.service.name.should == 'myservice'
28
+ @server.service.handle.should be_an Integer
29
+ @server.service.handle.should_not == 0
30
+ @server.service_active?.should == true
31
+ end
32
+
33
+ it 'returns self if success (allows method chain)' do
34
+ res = @server.start_service('myservice') {|*args|}
35
+ res.should == @server
36
+ end
37
+
38
+ it 'fails to start new service without callback block' do
39
+ lambda{@server.start_service('myservice')}.should raise_error DDE::Errors::ServiceError
40
+ @server.service_active?.should == false
41
+ end
42
+
43
+ end
44
+
45
+ context 'with active (initialized) DDE:' do
46
+ before(:each ){ @server = described_class.new {|*args|}}
47
+
48
+ it 'starts new service with given name' do
49
+ res = @server.start_service 'myservice'
50
+ res.should be_true
51
+
52
+ @server.service.should be_a DDE::DdeString
53
+ @server.service.should == 'myservice'
54
+ @server.service.name.should == 'myservice'
55
+ @server.service.handle.should be_an Integer
56
+ @server.service.handle.should_not == 0
57
+ end
58
+
59
+ it 'fails to starts new service if name is not a String' do
60
+ lambda{@server.start_service(11)}.should raise_error DDE::Errors::ServiceError
61
+ @server.service_active?.should == false
62
+ end
63
+
64
+ end
65
+ end
66
+
67
+ describe '#stop_service' do
68
+
69
+ context 'with inactive (uninitialized) DDE:' do
70
+ it 'fails to stop service' do
71
+ lambda{@server.stop_service}.should raise_error DDE::Errors::ServiceError
72
+ end
73
+ end
74
+
75
+ context 'with active (initialized) DDE:' do
76
+ before(:each){ @server = described_class.new {|*args|}}
77
+
78
+ context 'with already registered DDE service: "myservice"' do
79
+ before(:each){ @server.start_service('myservice')}
80
+
81
+ it 'stops previously registered service' do
82
+ @server.stop_service.should be_true
83
+
84
+ @server.service.should == nil
85
+ @server.service_active?.should == false
86
+ end
87
+
88
+ it 'does not stop DDE instance' do
89
+ @server.stop_service
90
+ @server.id.should_not == nil
91
+ @server.dde_active?.should == true
92
+ end
93
+
94
+ it 'returns self if success (allows method chain)' do
95
+ @server.stop_service.should == @server
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/server_shared')
3
+
4
+ module DDETest
5
+
6
+ describe DDE::Server do
7
+ before(:each ){ @server = DDE::Server.new }
8
+
9
+ it_should_behave_like "DDE Server"
10
+
11
+ describe '#start_service' do
12
+
13
+ it 'service name should be given explicitly' do
14
+ expect{@server.start_dde{|*args|}.start_service}.to raise_error ArgumentError, /0 for 1/
15
+ expect{@server.start_service {|*args|}}.to raise_error ArgumentError, /0 for 1/
16
+ end
17
+ end
18
+
19
+
20
+ end
21
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/server_shared')
3
+
4
+ module DDETest
5
+
6
+ describe DDE::XlServer do
7
+ before(:each ){ @server = DDE::XlServer.new }
8
+
9
+ it_should_behave_like "DDE Server"
10
+
11
+ it 'new without parameters creates empty table attribute' do
12
+ @server.table.should be_an DDE::XlTable
13
+ @server.table.should be_empty
14
+ end
15
+
16
+ it 'new with attached callback block creates empty table attribute' do
17
+ server = DDE::XlServer.new {|*args|}
18
+ @server.table.should be_an DDE::XlTable
19
+ @server.table.should be_empty
20
+ end
21
+
22
+ describe '#start_service' do
23
+ context 'with inactive (uninitialized) DDE:' do
24
+ it 'service name defaults to "excel" if not given explicitly' do
25
+ @server.start_service {|*args|}.should be_true
26
+
27
+ @server.service.should be_a DDE::DdeString
28
+ @server.service.should == 'excel'
29
+ @server.service.name.should == 'excel'
30
+ @server.service.handle.should be_an Integer
31
+ @server.service.handle.should_not == 0
32
+ @server.service_active?.should == true
33
+ end
34
+ end
35
+ context 'with active (initialized) DDE:' do
36
+ before(:each ){ @server = DDE::XlServer.new {|*args|}}
37
+
38
+ it 'service name defaults to "excel" if not given explicitly' do
39
+ @server.start_service.should be_true
40
+
41
+ @server.service.should be_a DDE::DdeString
42
+ @server.service.should == 'excel'
43
+ @server.service.name.should == 'excel'
44
+ @server.service.handle.should be_an Integer
45
+ @server.service.handle.should_not == 0
46
+ end
47
+ end
48
+ end # describe '#start_service'
49
+
50
+ end
51
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ module DDETest
4
+ describe DDE::XlTable do
5
+
6
+ it 'starts out empty and without item/topic' do
7
+ table = DDE::XlTable.new
8
+ table.should be_empty
9
+ table.buf.should == nil
10
+ end
11
+ end
12
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
@@ -0,0 +1,49 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'spec'
4
+ require 'spec/autorun'
5
+ require 'dde'
6
+
7
+ # Customize RSpec with my own extensions
8
+ module SpecMacros
9
+
10
+ # wrapper for it method that extracts description from example source code, such as:
11
+ # spec { use{ function(arg1 = 4, arg2 = 'string') }}
12
+ def spec &block
13
+ it description_from(caller[0]), &block # it description_from(*block.source_location), &block
14
+ #do lambda(&block).should_not raise_error end
15
+ end
16
+
17
+ # reads description line from source file and drops external brackets like its{}, use{}
18
+ # accepts as arguments either file name and line or call stack member (caller[0])
19
+ def description_from(*args)
20
+ case args.size
21
+ when 1
22
+ file, line = args.first.scan(/\A(.*?):(\d+)/).first
23
+ when 2
24
+ file, line = args
25
+ end
26
+ File.open(file) do |f|
27
+ f.lines.to_a[line.to_i-1].gsub( /(spec.*?{)|(use.*?{)|}/, '' ).strip
28
+ end
29
+ end
30
+ end
31
+
32
+ Spec::Runner.configure { |config| config.extend(SpecMacros) }
33
+
34
+ module DDETest
35
+
36
+ include Win::DDE
37
+ # @@monitor = DDE::Monitor.new
38
+
39
+ TEST_IMPOSSIBLE = 'Impossible'
40
+
41
+ def use
42
+ lambda {yield}.should_not raise_error
43
+ end
44
+
45
+ def any_block
46
+ lambda {|*args| args}
47
+ end
48
+
49
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dde
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - arvicco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-26 00:00:00 +03:00
13
+ default_executable: dde_main
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: win_gui
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.9
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: cucumber
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Server that mimics Excel receiving XLTable data via DDE protocol
46
+ email: arvitallian@gmail.com
47
+ executables:
48
+ - dde_main
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - bin/dde_main
62
+ - dde.gemspec
63
+ - doc/XLTable_format.doc
64
+ - doc/dde_formats.doc
65
+ - doc/ddeml.d.txt
66
+ - doc/types.txt
67
+ - doc/~$Table_format.doc
68
+ - doc/~$e_formats.doc
69
+ - features/dde.feature
70
+ - features/step_definitions/dde_steps.rb
71
+ - features/support/env.rb
72
+ - lib/dde.rb
73
+ - lib/dde/app.rb
74
+ - lib/dde/client.rb
75
+ - lib/dde/dde_string.rb
76
+ - lib/dde/monitor.rb
77
+ - lib/dde/server.rb
78
+ - lib/dde/xl_server.rb
79
+ - lib/dde/xl_table.rb
80
+ - spec/dde/app_spec.rb
81
+ - spec/dde/client_spec.rb
82
+ - spec/dde/dde_string_spec.rb
83
+ - spec/dde/monitor_spec.rb
84
+ - spec/dde/server_shared.rb
85
+ - spec/dde/server_spec.rb
86
+ - spec/dde/xl_server_spec.rb
87
+ - spec/dde/xl_table_spec.rb
88
+ - spec/spec.opts
89
+ - spec/spec_helper.rb
90
+ has_rdoc: true
91
+ homepage: http://github.com/arvicco/dde
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --charset=UTF-8
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: "0"
110
+ version:
111
+ requirements: []
112
+
113
+ rubyforge_project:
114
+ rubygems_version: 1.3.5
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: DDE server for Ruby
118
+ test_files:
119
+ - spec/dde/app_spec.rb
120
+ - spec/dde/client_spec.rb
121
+ - spec/dde/dde_string_spec.rb
122
+ - spec/dde/monitor_spec.rb
123
+ - spec/dde/server_shared.rb
124
+ - spec/dde/server_spec.rb
125
+ - spec/dde/xl_server_spec.rb
126
+ - spec/dde/xl_table_spec.rb
127
+ - spec/spec_helper.rb