ruddy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5472f2049ff6bfd144aeea055ab4e7bf2f28c2a
4
- data.tar.gz: b631945110c72dbddb97b16f53a96b4aace394a9
3
+ metadata.gz: f0b6e57ede4cc6d661e6e1072970ac932815895a
4
+ data.tar.gz: b22188ffb539b4d7874132da1d133cbd1f44b236
5
5
  SHA512:
6
- metadata.gz: a48d3d9eb7bb0a5baa0c263675f629af983d940ad2322e6bf34035ad112ebecf1bf96d3901c73358d45494aa6f0eb359fb5a3656b54968b648282972b4a6cc86
7
- data.tar.gz: 2cdb71ff621c0cdb7849428ce1d786569764d6542a62e42957df51e881f1f65b977f1a2cb4ea9f9a566654c1133654d03bc1ee7a4b5ed9179704f3631527d271
6
+ metadata.gz: 9b0286e719425ee74a8dd6c9454dcfeb9a7d3b65b66cb0929af3c540e0e032d3dfc326799444f341676c2c4ae7cca1cc91d5d660cc1ab7da2e4c0be1a83aa1da
7
+ data.tar.gz: e8021df09d1fac855c30389722a1599f61c7bdef4a6a772dce7f69866cd86102b3a7faa05c2378ed8ff8b7141f405c93747fe9f7964e7eb40ee024d9c640be42
data/lib/ruddy.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  require "ruddy/version"
2
2
  require "dde"
3
+ require "ruddy/error"
4
+ require "ruddy/errors"
3
5
  require "ruddy/connection"
@@ -29,7 +29,7 @@ module Ruddy
29
29
  result = FFI::MemoryPointer.new(:uint)
30
30
 
31
31
  data = DDE.client_transaction(buffer, buffer.size, conversation, nil, 0, DDE::XTYP_EXECUTE, timeout, result)
32
- raise SystemCallError.new("command execution failed", DDE.last_error(instance)) if data.null?
32
+ raise Error.new("command execution failed", DDE.last_error(instance)) if data.null?
33
33
  DDE.free_data_handle(data)
34
34
 
35
35
  return result.read_uint
@@ -55,7 +55,7 @@ module Ruddy
55
55
  def start
56
56
  instance = FFI::MemoryPointer.new(:uint)
57
57
  error = DDE.start(instance, CALLBACK, DDE::APPCLASS_STANDARD | DDE::APPCMD_CLIENTONLY, 0)
58
- raise SystemCallError.new("DDE management library initialization failed", error) if error != DDE::DMLERR_NO_ERROR
58
+ raise Error.new("DDE management library initialization failed", error) if error != DDE::DMLERR_NO_ERROR
59
59
  @instance = instance.read_uint
60
60
  end
61
61
 
@@ -68,7 +68,7 @@ module Ruddy
68
68
  free_string_handle service_handle
69
69
  free_string_handle topic_handle
70
70
 
71
- raise SystemCallError.new(%{could not connect to DDE service "#{service}"}) if conversation.null?
71
+ raise Error.new(%{could not connect to DDE service "#{service}"}, DDE.last_error(instance)) if conversation.null?
72
72
  end
73
73
 
74
74
  def create_string_handle(string)
@@ -0,0 +1,31 @@
1
+ module Ruddy
2
+ class Error < StandardError
3
+ def initialize(message, errno)
4
+ super("#{message} - #{description}")
5
+ @errno = errno
6
+ end
7
+
8
+ attr_reader :errno
9
+
10
+ def self.errnos
11
+ @errnos ||= Hash.new(self)
12
+ end
13
+
14
+ def self.define(errno, description)
15
+ errnos[errno] = Class.new(self) do
16
+ define_method(:description) { description }
17
+ private :description
18
+ end
19
+ end
20
+
21
+ def self.new(message, errno)
22
+ errnos[errno].allocate.tap{|instance| instance.send :initialize, message, errno }
23
+ end
24
+
25
+ private
26
+
27
+ def description
28
+ "Unknown error"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,42 @@
1
+ module Ruddy
2
+ AdviseTimeoutError = Error.define(0x4000, "A request for a synchronous advise transaction has timed out.")
3
+
4
+ BusyError = Error.define(0x4001, "The response to the transaction caused the DDE_FBUSY flag to be set.")
5
+
6
+ DataTimeoutError = Error.define(0x4002, "A request for a synchronous data transaction has timed out.")
7
+
8
+ DLLNotInitializedError = Error.define(0x4003, "A DDEML function was called without first calling the DdeInitialize function, or an invalid instance identifier was passed to a DDEML function.")
9
+
10
+ DLLUsageError = Error.define(0x4004, "An application initialized as APPCLASS_MONITOR has attempted to perform a DDE transaction, or an application initialized as APPCMD_CLIENTONLY has attempted to perform server transactions.")
11
+
12
+ ExecutionTimeoutError = Error.define(0x4005, "A request for a synchronous execute transaction has timed out.")
13
+
14
+ InvalidParameterError = Error.define(0x4006, "A parameter failed to be validated by the DDEML. Some of the possible causes follow:
15
+ The application used a data handle initialized with a different item name handle than was required by the transaction.
16
+ The application used a data handle that was initialized with a different clipboard data format than was required by the transaction.
17
+ The application used a client-side conversation handle with a server-side function or vice versa.
18
+ The application used a freed data handle or string handle.
19
+ More than one instance of the application used the same object.")
20
+
21
+ LowMemoryError = Error.define(0x4007, "A DDEML application has created a prolonged race condition (in which the server application outruns the client), causing large amounts of memory to be consumed.")
22
+
23
+ MemoryError = Error.define(0x4008, "A memory allocation has failed.")
24
+
25
+ NoConversationEstablishedError = Error.define(0x400A, "A client's attempt to establish a conversation has failed.")
26
+
27
+ NotProcessedError = Error.define(0x4009, "A transaction has failed.")
28
+
29
+ PokeTimeoutError = Error.define(0x400B, "A request for a synchronous poke transaction has timed out.")
30
+
31
+ PostMessageFailedError = Error.define(0x400C, "An internal call to the PostMessage function has failed.")
32
+
33
+ ReentrancyError = Error.define(0x400D, "An application instance with a synchronous transaction already in progress attempted to initiate another synchronous transaction, or the DdeEnableCallback function was called from within a DDEML callback function.")
34
+
35
+ ServerDiedError = Error.define(0x400E, "A server-side transaction was attempted on a conversation terminated by the client, or the server terminated before completing a transaction.")
36
+
37
+ SystemError = Error.define(0x400F, "An internal error has occurred in the DDEML.")
38
+
39
+ UnadviseTimeoutError = Error.define(0x4010, "A request to end an advise transaction has timed out.")
40
+
41
+ QueueNotFoundError = Error.define(0x4011, "An invalid transaction identifier was passed to a DDEML function. Once the application has returned from an XTYP_XACT_COMPLETE callback, the transaction identifier for that callback function is no longer valid.")
42
+ end
data/lib/ruddy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ruddy
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "ruddy/connection"
2
+ require "ruddy/error"
2
3
  require "ffi"
3
4
 
4
5
  require "support/fake_dde"
@@ -49,14 +50,14 @@ module Ruddy
49
50
  context "when initializing the DDE management library fails" do
50
51
  it "raises an error" do
51
52
  DDE.stub start: 0x4006
52
- expect{Connection.new("MY_SERVICE", "my_topic")}.to raise_error SystemCallError, /DDE management library initialization failed/
53
+ expect{Connection.new("MY_SERVICE", "my_topic")}.to raise_error Error, /DDE management library initialization failed/
53
54
  end
54
55
 
55
56
  it "sets the error code" do
56
57
  DDE.stub start: 0x4006
57
58
  begin
58
59
  Connection.new("MY_SERVICE", "my_topic")
59
- rescue SystemCallError => error
60
+ rescue Error => error
60
61
  expect(error.errno).to eq 0x4006
61
62
  end
62
63
  end
@@ -65,7 +66,19 @@ module Ruddy
65
66
  context "when the connection fails" do
66
67
  it "raises an error" do
67
68
  DDE.stub connect: null_pointer
68
- expect{Connection.new("MY_SERVICE", "my_topic")}.to raise_error SystemCallError, /could not connect to DDE service "MY_SERVICE"/
69
+ expect{Connection.new("MY_SERVICE", "my_topic")}.to raise_error Error, /could not connect to DDE service "MY_SERVICE"/
70
+ end
71
+
72
+ it "sets the error code" do
73
+ stub_instance 42
74
+ DDE.stub connect: null_pointer
75
+ DDE.stub(:last_error).with(42).and_return(0x4009)
76
+
77
+ begin
78
+ Connection.new("MY_SERVICE", "my_topic")
79
+ rescue Error => error
80
+ expect(error.errno).to eq 0x4009
81
+ end
69
82
  end
70
83
  end
71
84
  end
@@ -128,20 +141,21 @@ module Ruddy
128
141
  it "raises an error" do
129
142
  connection = Connection.new("MY_SERVICE", "my_topic")
130
143
  DDE.stub client_transaction: null_pointer
144
+ DDE.stub last_error: 0x4009
131
145
 
132
- expect{connection.execute("[Foo(bar)]")}.to raise_error SystemCallError, /command execution failed/
146
+ expect{connection.execute("[Foo(bar)]")}.to raise_error Error, /command execution failed/
133
147
  end
134
148
 
135
149
  it "sets the error code" do
136
150
  stub_instance 42
137
151
  connection = Connection.new("MY_SERVICE", "my_topic")
138
- DDE.stub(:last_error).with(42).and_return(0x4000)
152
+ DDE.stub(:last_error).with(42).and_return(0x4009)
139
153
  DDE.stub client_transaction: null_pointer
140
154
 
141
155
  begin
142
156
  connection.execute("[Foo(bar)]")
143
- rescue SystemCallError => error
144
- expect(error.errno).to eq 0x4000
157
+ rescue Error => error
158
+ expect(error.errno).to eq 0x4009
145
159
  end
146
160
  end
147
161
  end
@@ -0,0 +1,52 @@
1
+ require "ruddy/error"
2
+
3
+ module Ruddy
4
+ describe Error do
5
+ describe ".new" do
6
+ after { Error.errnos.clear }
7
+
8
+ context "with a known error code" do
9
+ it "returns an instance of a subclass" do
10
+ subclass = Error.define(42, "")
11
+ instance = Error.new("", 42)
12
+
13
+ expect(instance).to be_an_instance_of subclass
14
+ end
15
+
16
+ it "sets the error number" do
17
+ Error.define 42, ""
18
+ instance = Error.new("", 42)
19
+
20
+ expect(instance.errno).to eq 42
21
+ end
22
+
23
+ it "sets the message" do
24
+ Error.define 42, "bar"
25
+ instance = Error.new("foo", 42)
26
+
27
+ expect(instance.message).to eq "foo - bar"
28
+ end
29
+ end
30
+
31
+ context "with an unknown error code" do
32
+ it "returns an instance of itself" do
33
+ instance = Error.new("", 42)
34
+
35
+ expect(instance).to be_an_instance_of Error
36
+ end
37
+
38
+ it "sets the error number" do
39
+ instance = Error.new("", 42)
40
+
41
+ expect(instance.errno).to eq 42
42
+ end
43
+
44
+ it "sets the message" do
45
+ instance = Error.new("foo", 42)
46
+
47
+ expect(instance.message).to eq "foo - Unknown error"
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Haines
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-21 00:00:00.000000000 Z
11
+ date: 2013-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -82,9 +82,12 @@ files:
82
82
  - lib/dde/constants.rb
83
83
  - lib/ruddy.rb
84
84
  - lib/ruddy/connection.rb
85
+ - lib/ruddy/error.rb
86
+ - lib/ruddy/errors.rb
85
87
  - lib/ruddy/version.rb
86
88
  - ruddy.gemspec
87
89
  - spec/ruddy/connection_spec.rb
90
+ - spec/ruddy/error_spec.rb
88
91
  - spec/support/fake_dde.rb
89
92
  - spec/support/string_pointer_matcher.rb
90
93
  homepage: https://github.com/haines/ruddy
@@ -107,11 +110,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
110
  version: '0'
108
111
  requirements: []
109
112
  rubyforge_project:
110
- rubygems_version: 2.0.0
113
+ rubygems_version: 2.0.3
111
114
  signing_key:
112
115
  specification_version: 4
113
116
  summary: Basic Win32 DDE client in Ruby
114
117
  test_files:
115
118
  - spec/ruddy/connection_spec.rb
119
+ - spec/ruddy/error_spec.rb
116
120
  - spec/support/fake_dde.rb
117
121
  - spec/support/string_pointer_matcher.rb