dde 0.2.9 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/app_shared')
3
-
4
- module DDETest
5
- describe DDE::App do
6
- it_should_behave_like "DDE App"
7
- end
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/app_shared')
3
+
4
+ module DdeTest
5
+ describe Dde::App do
6
+ it_should_behave_like "DDE App"
7
+ end
8
8
  end
@@ -1,200 +1,200 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/app_shared')
3
-
4
- module DDETest
5
-
6
- describe DDE::Client do
7
- before(:each){ @client = DDE::Client.new }
8
- after(:each){ @client.stop_dde if @client.dde_active?}
9
-
10
- it_should_behave_like "DDE App"
11
-
12
- it 'new without parameters creates Client but does not activate DDEML' do
13
- @client.id.should == nil
14
- @client.conversation.should == nil
15
- @client.service.should == nil
16
- @client.topic.should == nil
17
- @client.dde_active?.should == false
18
- @client.conversation_active?.should == false
19
- end
20
-
21
- it 'new with attached callback block creates Client and activates DDEML' do
22
- @client = DDE::Client.new {|*args|}
23
- @client.id.should be_an Integer
24
- @client.id.should_not == 0
25
- @client.dde_active?.should == true
26
- @client.conversation.should == nil
27
- @client.conversation_active?.should == false
28
- @client.service.should == nil
29
- @client.topic.should == nil
30
- end
31
-
32
- describe '#start_conversation' do
33
-
34
- context 'with inactive (uninitialized) DDE:' do
35
- it 'fails to starts new conversation' do
36
- lambda{@client.start_conversation('service', 'topic')}.
37
- should raise_error /DDE is not initialized/
38
- @client.conversation_active?.should == false
39
- lambda{@client.start_conversation(nil, nil)}.
40
- should raise_error /DDE is not initialized/
41
- @client.conversation_active?.should == false
42
- lambda{@client.start_conversation}.
43
- should raise_error /DDE is not initialized/
44
- @client.conversation_active?.should == false
45
- end
46
- end # context 'with inactive (uninitialized) DDE:'
47
-
48
- context 'with active (initialized) DDE AND existing DDE server supporting "service" topic' do
49
- before(:each ){start_callback_recorder}
50
- after(:each )do
51
- stop_callback_recorder
52
- #p @server_calls, @client_calls # ?????????? No XTYP_DISCONNECT ? Why ?
53
- end
54
-
55
- it 'starts new conversation if DDE is already activated' do
56
- res = @client.start_conversation 'service', 'topic'
57
- res.should be_true
58
- @client.conversation_active?.should == true
59
- end
60
-
61
- it 'returns self if success (allows method chain)' do
62
- @client.start_conversation('service', 'topic').should == @client
63
- end
64
-
65
- it 'sets @conversation, @service and @topic attributes' do
66
- @client.start_conversation 'service', 'topic'
67
-
68
- @client.conversation.should be_an Integer
69
- @client.conversation.should_not == 0
70
- @client.service.should be_a DDE::DdeString
71
- @client.service.should == 'service'
72
- @client.service.name.should == 'service'
73
- @client.conversation.should be_an Integer
74
- @client.conversation.should_not == 0
75
- end
76
-
77
- it 'initiates XTYP_CONNECT transaction to service`s callback' do
78
- @client.start_conversation 'service', 'topic'
79
-
80
- @server_calls.first[0].should == :XTYP_CONNECT
81
- @server_calls.first[3].should == @client.topic
82
- @server_calls.first[4].should == @client.service
83
- end
84
-
85
- it 'if server confirms connect, XTYP_CONNECT_CONFIRM transaction to service`s callback follows' do
86
- @client.start_conversation 'service', 'topic'
87
-
88
- # p @server_calls, @client_calls # ?????????? No XTYP_DISCONNECT ? Why ?
89
- @server_calls[1][0].should == :XTYP_CONNECT_CONFIRM
90
- @server_calls[1][3].should == @client.topic
91
- @server_calls[1][4].should == @client.service
92
- end
93
-
94
- it 'client`s callback receives no transactions' do
95
- @client.start_conversation 'service', 'topic'
96
-
97
- #p @server_calls, @client.service.handle, @client.topic.handle, @client.conversation
98
- @client_calls.should == []
99
- end
100
-
101
- it 'fails if another conversation is already in progress' do
102
- @client.start_conversation 'service', 'topic'
103
-
104
- lambda{@client.start_conversation 'service1', 'topic1'}.
105
- should raise_error /Another conversation already established/
106
- end
107
-
108
- it 'fails to start conversation on unsupported service' do
109
- lambda{@client.start_conversation('not_a_service', 'topic')}.
110
- should raise_error /A client`s attempt to establish a conversation has failed/
111
- @client.conversation_active?.should == false
112
-
113
- #ensure
114
- dde_free_string_handle(@client.id, @client.topic.handle)
115
- dde_free_string_handle(@client.id, @client.service.handle)
116
- end
117
-
118
- end # context 'with active (initialized) DDE AND existing DDE server supporting "service" topic' do
119
- end # describe '#start_conversation'
120
-
121
- describe '#stop_conversation' do
122
-
123
- context 'with inactive (uninitialized) DDE:' do
124
- it 'fails to stop conversation' do
125
- lambda{@client.stop_conversation}.
126
- should raise_error /DDE not started/
127
- @client.conversation_active?.should == false
128
- end
129
-
130
- end # context 'with inactive (uninitialized) DDE:'
131
-
132
- context 'with active (initialized) DDE AND existing DDE server supporting "service" topic' do
133
- before(:each ){start_callback_recorder}
134
- after(:each ){stop_callback_recorder}
135
-
136
- it 'fails to stop conversation' do
137
- lambda{@client.stop_conversation}.
138
- should raise_error /Conversation not started/
139
- @client.conversation_active?.should == false
140
- end
141
-
142
- context 'conversation already started' do
143
- before(:each){ @client.start_conversation 'service', 'topic' }
144
- after(:each){ @client.stop_conversation if @client.conversation_active?}
145
-
146
- it 'stops conversation' do
147
- res = @client.stop_conversation
148
- res.should be_true
149
- @client.conversation_active?.should == false
150
- end
151
-
152
- it 'unsets @conversation, @service and @topic attributes' do
153
- @client.stop_conversation
154
- @client.conversation.should == nil
155
- @client.service.should == nil
156
- @client.topic.should == nil
157
- end
158
-
159
- it 'does not stop DDE' do
160
- @client.stop_conversation
161
- @client.dde_active?.should == true
162
- end
163
-
164
- it 'initiates XTYP_DISCONNECT transaction to service`s callback' do
165
- pending
166
- @client.stop_conversation
167
- p @server_calls, @client_calls # ?????????? No XTYP_DISCONNECT ? Why ?
168
- @server_calls.last[0].should == :XTYP_DISCONNECT
169
- end
170
-
171
- end # context 'conversation already started'
172
-
173
- end # context 'with active (initialized) DDE AND existing DDE server supporting "service" topic'
174
- end # describe '#stop_conversation'
175
-
176
- describe '#send_data' do
177
- context 'with active (initialized) DDE AND existing DDE server supporting "service" topic' do
178
- before(:each )do
179
- start_callback_recorder do |*args|
180
- @server_calls << extract_values(*args)
181
- if args[0] == XTYP_POKE
182
- @data, @size = dde_get_data(args[5])
183
- end
184
- DDE_FACK
185
- end
186
- @client.start_conversation 'service', 'topic'
187
- end
188
- after(:each ){stop_callback_recorder}
189
-
190
- it 'sends data to server' do
191
- @client.send_data TEST_STRING, CF_TEXT, "item"
192
- @server_calls.last[0].should == :XTYP_POKE
193
- @data.get_bytes(0, @size).rstrip.should == TEST_STRING
194
- end
195
-
196
- end # context 'with active (initialized) DDE'
197
- end # describe #send_data
198
-
199
- end # describe DDE::Client
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/app_shared')
3
+
4
+ module DdeTest
5
+
6
+ describe Dde::Client do
7
+ before(:each){ @client = Dde::Client.new }
8
+ after(:each){ @client.stop_dde if @client.dde_active?}
9
+
10
+ it_should_behave_like "DDE App"
11
+
12
+ it 'new without parameters creates Client but does not activate DDEML' do
13
+ @client.id.should == nil
14
+ @client.conversation.should == nil
15
+ @client.service.should == nil
16
+ @client.topic.should == nil
17
+ @client.dde_active?.should == false
18
+ @client.conversation_active?.should == false
19
+ end
20
+
21
+ it 'new with attached callback block creates Client and activates DDEML' do
22
+ @client = Dde::Client.new {|*args|}
23
+ @client.id.should be_an Integer
24
+ @client.id.should_not == 0
25
+ @client.dde_active?.should == true
26
+ @client.conversation.should == nil
27
+ @client.conversation_active?.should == false
28
+ @client.service.should == nil
29
+ @client.topic.should == nil
30
+ end
31
+
32
+ describe '#start_conversation' do
33
+
34
+ context 'with inactive (uninitialized) DDE:' do
35
+ it 'fails to starts new conversation' do
36
+ lambda{@client.start_conversation('service', 'topic')}.
37
+ should raise_error /DDE is not initialized/
38
+ @client.conversation_active?.should == false
39
+ lambda{@client.start_conversation(nil, nil)}.
40
+ should raise_error /DDE is not initialized/
41
+ @client.conversation_active?.should == false
42
+ lambda{@client.start_conversation}.
43
+ should raise_error /DDE is not initialized/
44
+ @client.conversation_active?.should == false
45
+ end
46
+ end # context 'with inactive (uninitialized) DDE:'
47
+
48
+ context 'with active (initialized) DDE AND existing DDE server supporting "service" topic' do
49
+ before(:each ){start_callback_recorder}
50
+ after(:each )do
51
+ stop_callback_recorder
52
+ #p @server_calls, @client_calls # ?????????? No XTYP_DISCONNECT ? Why ?
53
+ end
54
+
55
+ it 'starts new conversation if DDE is already activated' do
56
+ res = @client.start_conversation 'service', 'topic'
57
+ res.should be_true
58
+ @client.conversation_active?.should == true
59
+ end
60
+
61
+ it 'returns self if success (allows method chain)' do
62
+ @client.start_conversation('service', 'topic').should == @client
63
+ end
64
+
65
+ it 'sets @conversation, @service and @topic attributes' do
66
+ @client.start_conversation 'service', 'topic'
67
+
68
+ @client.conversation.should be_an Integer
69
+ @client.conversation.should_not == 0
70
+ @client.service.should be_a Dde::DdeString
71
+ @client.service.should == 'service'
72
+ @client.service.name.should == 'service'
73
+ @client.conversation.should be_an Integer
74
+ @client.conversation.should_not == 0
75
+ end
76
+
77
+ it 'initiates XTYP_CONNECT transaction to service`s callback' do
78
+ @client.start_conversation 'service', 'topic'
79
+
80
+ @server_calls.first[0].should == :XTYP_CONNECT
81
+ @server_calls.first[3].should == @client.topic
82
+ @server_calls.first[4].should == @client.service
83
+ end
84
+
85
+ it 'if server confirms connect, XTYP_CONNECT_CONFIRM transaction to service`s callback follows' do
86
+ @client.start_conversation 'service', 'topic'
87
+
88
+ # p @server_calls, @client_calls # ?????????? No XTYP_DISCONNECT ? Why ?
89
+ @server_calls[1][0].should == :XTYP_CONNECT_CONFIRM
90
+ @server_calls[1][3].should == @client.topic
91
+ @server_calls[1][4].should == @client.service
92
+ end
93
+
94
+ it 'client`s callback receives no transactions' do
95
+ @client.start_conversation 'service', 'topic'
96
+
97
+ #p @server_calls, @client.service.handle, @client.topic.handle, @client.conversation
98
+ @client_calls.should == []
99
+ end
100
+
101
+ it 'fails if another conversation is already in progress' do
102
+ @client.start_conversation 'service', 'topic'
103
+
104
+ lambda{@client.start_conversation 'service1', 'topic1'}.
105
+ should raise_error /Another conversation already established/
106
+ end
107
+
108
+ it 'fails to start conversation on unsupported service' do
109
+ lambda{@client.start_conversation('not_a_service', 'topic')}.
110
+ should raise_error /A client`s attempt to establish a conversation has failed/
111
+ @client.conversation_active?.should == false
112
+
113
+ #ensure
114
+ dde_free_string_handle(@client.id, @client.topic.handle)
115
+ dde_free_string_handle(@client.id, @client.service.handle)
116
+ end
117
+
118
+ end # context 'with active (initialized) DDE AND existing DDE server supporting "service" topic' do
119
+ end # describe '#start_conversation'
120
+
121
+ describe '#stop_conversation' do
122
+
123
+ context 'with inactive (uninitialized) DDE:' do
124
+ it 'fails to stop conversation' do
125
+ lambda{@client.stop_conversation}.
126
+ should raise_error /DDE not started/
127
+ @client.conversation_active?.should == false
128
+ end
129
+
130
+ end # context 'with inactive (uninitialized) DDE:'
131
+
132
+ context 'with active (initialized) DDE AND existing DDE server supporting "service" topic' do
133
+ before(:each ){start_callback_recorder}
134
+ after(:each ){stop_callback_recorder}
135
+
136
+ it 'fails to stop conversation' do
137
+ lambda{@client.stop_conversation}.
138
+ should raise_error /Conversation not started/
139
+ @client.conversation_active?.should == false
140
+ end
141
+
142
+ context 'conversation already started' do
143
+ before(:each){ @client.start_conversation 'service', 'topic' }
144
+ after(:each){ @client.stop_conversation if @client.conversation_active?}
145
+
146
+ it 'stops conversation' do
147
+ res = @client.stop_conversation
148
+ res.should be_true
149
+ @client.conversation_active?.should == false
150
+ end
151
+
152
+ it 'unsets @conversation, @service and @topic attributes' do
153
+ @client.stop_conversation
154
+ @client.conversation.should == nil
155
+ @client.service.should == nil
156
+ @client.topic.should == nil
157
+ end
158
+
159
+ it 'does not stop DDE' do
160
+ @client.stop_conversation
161
+ @client.dde_active?.should == true
162
+ end
163
+
164
+ it 'initiates XTYP_DISCONNECT transaction to service`s callback' do
165
+ pending
166
+ @client.stop_conversation
167
+ p @server_calls, @client_calls # ?????????? No XTYP_DISCONNECT ? Why ?
168
+ @server_calls.last[0].should == :XTYP_DISCONNECT
169
+ end
170
+
171
+ end # context 'conversation already started'
172
+
173
+ end # context 'with active (initialized) DDE AND existing DDE server supporting "service" topic'
174
+ end # describe '#stop_conversation'
175
+
176
+ describe '#send_data' do
177
+ context 'with active (initialized) DDE AND existing DDE server supporting "service" topic' do
178
+ before(:each )do
179
+ start_callback_recorder do |*args|
180
+ @server_calls << extract_values(*args)
181
+ if args[0] == XTYP_POKE
182
+ @data, @size = dde_get_data(args[5])
183
+ end
184
+ DDE_FACK
185
+ end
186
+ @client.start_conversation 'service', 'topic'
187
+ end
188
+ after(:each ){stop_callback_recorder}
189
+
190
+ it 'sends data to server' do
191
+ @client.send_data TEST_STRING, CF_TEXT, "item"
192
+ @server_calls.last[0].should == :XTYP_POKE
193
+ @data.get_bytes(0, @size).rstrip.should == TEST_STRING
194
+ end
195
+
196
+ end # context 'with active (initialized) DDE'
197
+ end # describe #send_data
198
+
199
+ end # describe DDE::Client
200
200
  end
@@ -1,40 +1,40 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- module DDETest
4
- describe DDE::DdeString do
5
- before(:each ){ @app = DDE::App.new {|*args|}}
6
-
7
- context ' with valid instance id of active DDE application' do
8
- it 'can be created from normal string' do
9
- dde_string = DDE::DdeString.new(@app.id, "My_String")
10
- dde_string == "My_String"
11
- dde_string.handle.should be_an Integer
12
- dde_string.handle.should_not == 0
13
- end
14
-
15
- it 'can be created from valid DDE string handle' do
16
- string_handle = dde_create_string_handle(@app.id, 'My String')
17
- dde_string = DDE::DdeString.new(@app.id, string_handle)
18
- dde_string == "My_String"
19
- dde_string.handle.should be_an Integer
20
- dde_string.handle.should_not == 0
21
- end
22
- end
23
-
24
- context ' without instance id of active DDE application' do
25
- it 'cannot be created from String' do
26
- lambda{DDE::DdeString.new(nil, "My_String")}.should raise_error DDE::Errors::StringError
27
- lambda{DDE::DdeString.new(12345, "My_String")}.should raise_error DDE::Errors::StringError
28
- lambda{DDE::DdeString.new(0, "My_String")}.should raise_error DDE::Errors::StringError
29
- end
30
-
31
- it 'cannot be created from valid string handle' do
32
- string_handle = dde_create_string_handle(@app.id, 'My String')
33
- lambda{DDE::DdeString.new(nil, string_handle)}.should raise_error DDE::Errors::StringError
34
- lambda{DDE::DdeString.new(12345, string_handle)}.should raise_error DDE::Errors::StringError
35
- lambda{DDE::DdeString.new(0, string_handle)}.should raise_error DDE::Errors::StringError
36
- end
37
- end
38
-
39
- end
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ module DdeTest
4
+ describe Dde::DdeString do
5
+ before(:each ){ @app = Dde::App.new {|*args|}}
6
+
7
+ context ' with valid instance id of active DDE application' do
8
+ it 'can be created from normal string' do
9
+ dde_string = Dde::DdeString.new(@app.id, "My_String")
10
+ dde_string == "My_String"
11
+ dde_string.handle.should be_an Integer
12
+ dde_string.handle.should_not == 0
13
+ end
14
+
15
+ it 'can be created from valid DDE string handle' do
16
+ string_handle = dde_create_string_handle(@app.id, 'My String')
17
+ dde_string = Dde::DdeString.new(@app.id, string_handle)
18
+ dde_string == "My_String"
19
+ dde_string.handle.should be_an Integer
20
+ dde_string.handle.should_not == 0
21
+ end
22
+ end
23
+
24
+ context ' without instance id of active DDE application' do
25
+ it 'cannot be created from String' do
26
+ lambda{Dde::DdeString.new(nil, "My_String")}.should raise_error Dde::Errors::StringError
27
+ lambda{Dde::DdeString.new(12345, "My_String")}.should raise_error Dde::Errors::StringError
28
+ lambda{Dde::DdeString.new(0, "My_String")}.should raise_error Dde::Errors::StringError
29
+ end
30
+
31
+ it 'cannot be created from valid string handle' do
32
+ string_handle = dde_create_string_handle(@app.id, 'My String')
33
+ lambda{Dde::DdeString.new(nil, string_handle)}.should raise_error Dde::Errors::StringError
34
+ lambda{Dde::DdeString.new(12345, string_handle)}.should raise_error Dde::Errors::StringError
35
+ lambda{Dde::DdeString.new(0, string_handle)}.should raise_error Dde::Errors::StringError
36
+ end
37
+ end
38
+
39
+ end
40
40
  end