spec/dde/client_spec.rb in dde-0.2.8 vs spec/dde/client_spec.rb in dde-0.2.9
- old
+ new
@@ -1,36 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/app_shared')
module DDETest
- def start_callback_recorder
- @client_calls = []
- @server_calls = []
- @client = DDE::Client.new {|*args| @client_calls << extract_values(*args); 1}
- @server = DDE::Server.new do |*args|
- @server_calls << extract_values(*args)
- #puts "#{Time.now.strftime('%T.%6N')} #{extract_values(*args)}"
- DDE_FACK
- end
- @server.start_service('service')
- end
-
- def stop_callback_recorder
- @client.stop_conversation if @client.conversation_active?
- #@client.stop_dde if @client.dde_active?
- @server.stop_service if @server.service_active?
- @server.stop_dde if @server.dde_active?
- end
-
- def extract_values(type, format, conv, hsz1, hsz2, data, data1, data2)
- [Win::DDE::TYPES[type], format, conv,
- dde_query_string(@client.id, hsz1),
- dde_query_string(@client.id, hsz2),
- data, data1, data2]
- end
-
describe DDE::Client do
before(:each){ @client = DDE::Client.new }
after(:each){ @client.stop_dde if @client.dde_active?}
it_should_behave_like "DDE App"
@@ -101,20 +75,20 @@
end
it 'initiates XTYP_CONNECT transaction to service`s callback' do
@client.start_conversation 'service', 'topic'
- @server_calls.first[0].should == 'XTYP_CONNECT'
+ @server_calls.first[0].should == :XTYP_CONNECT
@server_calls.first[3].should == @client.topic
@server_calls.first[4].should == @client.service
end
it 'if server confirms connect, XTYP_CONNECT_CONFIRM transaction to service`s callback follows' do
@client.start_conversation 'service', 'topic'
# p @server_calls, @client_calls # ?????????? No XTYP_DISCONNECT ? Why ?
- @server_calls[1][0].should == 'XTYP_CONNECT_CONFIRM'
+ @server_calls[1][0].should == :XTYP_CONNECT_CONFIRM
@server_calls[1][3].should == @client.topic
@server_calls[1][4].should == @client.service
end
it 'client`s callback receives no transactions' do
@@ -155,13 +129,11 @@
end # context 'with inactive (uninitialized) DDE:'
context 'with active (initialized) DDE AND existing DDE server supporting "service" topic' do
before(:each ){start_callback_recorder}
- after(:each )do
- stop_callback_recorder
- end
+ after(:each ){stop_callback_recorder}
it 'fails to stop conversation' do
lambda{@client.stop_conversation}.
should raise_error /Conversation not started/
@client.conversation_active?.should == false
@@ -191,14 +163,38 @@
it 'initiates XTYP_DISCONNECT transaction to service`s callback' do
pending
@client.stop_conversation
p @server_calls, @client_calls # ?????????? No XTYP_DISCONNECT ? Why ?
- @server_calls.last[0].should == 'XTYP_DISCONNECT'
+ @server_calls.last[0].should == :XTYP_DISCONNECT
end
end # context 'conversation already started'
end # context 'with active (initialized) DDE AND existing DDE server supporting "service" topic'
end # describe '#stop_conversation'
+
+ describe '#send_data' do
+ context 'with active (initialized) DDE AND existing DDE server supporting "service" topic' do
+ before(:each )do
+ start_callback_recorder do |*args|
+ @server_calls << extract_values(*args)
+ if args[0] == XTYP_POKE
+ @data, @size = dde_get_data(args[5])
+ end
+ DDE_FACK
+ end
+ @client.start_conversation 'service', 'topic'
+ end
+ after(:each ){stop_callback_recorder}
+
+ it 'sends data to server' do
+ @client.send_data TEST_STRING, CF_TEXT, "item"
+ @server_calls.last[0].should == :XTYP_POKE
+ @data.get_bytes(0, @size).rstrip.should == TEST_STRING
+ end
+
+ end # context 'with active (initialized) DDE'
+ end # describe #send_data
+
end # describe DDE::Client
end
\ No newline at end of file