ruby-smpp 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/smpp_test.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  $:.unshift File.dirname(__FILE__) + '/../lib/'
2
2
 
3
+ require 'rubygems'
3
4
  require 'test/unit'
4
5
  require 'stringio'
5
6
  require 'smpp'
6
7
 
7
- module Server1
8
- def receive_data(data)
8
+ # a server which immediately requests the client to unbind
9
+ module Server1
10
+ def receive_data(data)
9
11
  send_data Smpp::Pdu::Unbind.new.data
10
12
  end
11
13
  end
@@ -18,6 +20,30 @@ module Server2
18
20
  end
19
21
  end
20
22
 
23
+ # the delagate receives callbacks when interesting things happen on the connection
24
+ class Delegate
25
+ def mo_received(transceiver, source_addr, destination_addr, short_message)
26
+ puts "** mo_received"
27
+ end
28
+
29
+ def delivery_report_received(transceiver, msg_reference, stat, pdu)
30
+ puts "** delivery_report_received"
31
+ end
32
+
33
+ def message_accepted(transceiver, mt_message_id, smsc_message_id)
34
+ puts "** message_sent"
35
+ end
36
+
37
+ def bound(transceiver)
38
+ puts "** bound"
39
+ end
40
+
41
+ def unbound(transceiver)
42
+ puts "** unbound"
43
+ EventMachine::stop_event_loop
44
+ end
45
+ end
46
+
21
47
  class SmppTest < Test::Unit::TestCase
22
48
 
23
49
  def config
@@ -26,6 +52,7 @@ class SmppTest < Test::Unit::TestCase
26
52
  :port => 2775,
27
53
  :system_id => 'foo',
28
54
  :password => 'bar',
55
+ :system_type => '',
29
56
  :source_ton => 0,
30
57
  :source_npi => 1,
31
58
  :destination_ton => 1,
@@ -35,20 +62,199 @@ class SmppTest < Test::Unit::TestCase
35
62
  }
36
63
  end
37
64
 
38
- def test_transceiver_should_bind_and_unbind_and_stop
65
+ def test_transceiver_should_bind_and_unbind_then_stop
39
66
  EventMachine.run {
40
67
  EventMachine.start_server "localhost", 9000, Server1
41
- EventMachine.connect "localhost", 9000, Smpp::Transceiver, config, nil, nil
68
+ EventMachine.connect "localhost", 9000, Smpp::Transceiver, config, Delegate.new
42
69
  }
43
70
  # should not hang here: the server's response should have caused the client to terminate
44
71
  end
45
-
46
- def ____test_transceiver_should_send_mt
47
- EventMachine.run {
48
- EventMachine.start_server "localhost", 9000, Server2
49
- EventMachine.connect "localhost", 9000, Smpp::Transceiver, config, nil, nil
50
- }
51
- # should not hang here: the server's response should have caused the client to terminate
72
+
73
+ def test_bind_transceiver
74
+ pdu1 = Smpp::Pdu::BindTransceiver.new(
75
+ config[:system_id],
76
+ config[:password],
77
+ config[:system_type],
78
+ config[:source_ton],
79
+ config[:source_npi],
80
+ config[:source_address_range]
81
+ )
82
+
83
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
84
+
85
+ assert_instance_of(Smpp::Pdu::BindTransceiver, pdu2)
86
+ assert_equal(pdu1.system_id, pdu2.system_id)
87
+ assert_equal(pdu1.password, pdu2.password)
88
+ assert_equal(pdu1.system_type, pdu2.system_type)
89
+ assert_equal(pdu1.addr_ton, pdu2.addr_ton)
90
+ assert_equal(pdu1.addr_npi, pdu2.addr_npi)
91
+ assert_equal(pdu1.address_range, pdu2.address_range)
92
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
93
+ assert_equal(pdu1.command_status, pdu2.command_status)
52
94
  end
53
-
95
+
96
+ def test_bind_transceiver_response
97
+ pdu1 = Smpp::Pdu::BindTransceiverResponse.new(nil, Smpp::Pdu::Base::ESME_ROK, config[:system_id])
98
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
99
+ assert_instance_of(Smpp::Pdu::BindTransceiverResponse, pdu2)
100
+ assert_equal(pdu1.system_id, pdu2.system_id)
101
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
102
+ assert_equal(pdu1.command_status, pdu2.command_status)
103
+ end
104
+
105
+ def test_deliver_sm
106
+ pdu1 = Smpp::Pdu::DeliverSm.new( '11111', '1111111111', "This is a test" )
107
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
108
+ assert_instance_of(Smpp::Pdu::DeliverSm, pdu2)
109
+ assert_equal(pdu1.udh, pdu2.udh)
110
+ assert_equal(pdu1.short_message, pdu2.short_message)
111
+ assert_equal(pdu1.service_type, pdu2.service_type)
112
+ assert_equal(pdu1.source_addr_ton, pdu2.source_addr_ton)
113
+ assert_equal(pdu1.source_addr_npi, pdu2.source_addr_npi)
114
+ assert_equal(pdu1.source_addr, pdu2.source_addr)
115
+ assert_equal(pdu1.dest_addr_ton, pdu2.dest_addr_ton)
116
+ assert_equal(pdu1.dest_addr_npi, pdu2.dest_addr_npi)
117
+ assert_equal(pdu1.destination_addr, pdu2.destination_addr)
118
+ assert_equal(pdu1.esm_class, pdu2.esm_class)
119
+ assert_equal(pdu1.protocol_id, pdu2.protocol_id)
120
+ assert_equal(pdu1.priority_flag, pdu2.priority_flag)
121
+ assert_equal(pdu1.schedule_delivery_time, pdu2.schedule_delivery_time)
122
+ assert_equal(pdu1.validity_period, pdu2.validity_period)
123
+ assert_equal(pdu1.registered_delivery, pdu2.registered_delivery)
124
+ assert_equal(pdu1.replace_if_present_flag, pdu2.replace_if_present_flag)
125
+ assert_equal(pdu1.data_coding, pdu2.data_coding)
126
+ assert_equal(pdu1.sm_default_msg_id, pdu2.sm_default_msg_id)
127
+ assert_equal(pdu1.sm_length, pdu2.sm_length)
128
+ assert_equal(pdu1.stat, pdu2.stat)
129
+ assert_equal(pdu1.msg_reference, pdu2.msg_reference)
130
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
131
+ assert_equal(pdu1.command_status, pdu2.command_status)
132
+ end
133
+
134
+ def test_submit_sm
135
+ pdu1 = Smpp::Pdu::SubmitSm.new( '11111', '1111111111', "This is a test" )
136
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
137
+ assert_instance_of(Smpp::Pdu::SubmitSm, pdu2)
138
+ assert_equal(pdu1.udh, pdu2.udh)
139
+ assert_equal(pdu1.short_message, pdu2.short_message)
140
+ assert_equal(pdu1.service_type, pdu2.service_type)
141
+ assert_equal(pdu1.source_addr_ton, pdu2.source_addr_ton)
142
+ assert_equal(pdu1.source_addr_npi, pdu2.source_addr_npi)
143
+ assert_equal(pdu1.source_addr, pdu2.source_addr)
144
+ assert_equal(pdu1.dest_addr_ton, pdu2.dest_addr_ton)
145
+ assert_equal(pdu1.dest_addr_npi, pdu2.dest_addr_npi)
146
+ assert_equal(pdu1.destination_addr, pdu2.destination_addr)
147
+ assert_equal(pdu1.esm_class, pdu2.esm_class)
148
+ assert_equal(pdu1.protocol_id, pdu2.protocol_id)
149
+ assert_equal(pdu1.priority_flag, pdu2.priority_flag)
150
+ assert_equal(pdu1.schedule_delivery_time, pdu2.schedule_delivery_time)
151
+ assert_equal(pdu1.validity_period, pdu2.validity_period)
152
+ assert_equal(pdu1.registered_delivery, pdu2.registered_delivery)
153
+ assert_equal(pdu1.replace_if_present_flag, pdu2.replace_if_present_flag)
154
+ assert_equal(pdu1.data_coding, pdu2.data_coding)
155
+ assert_equal(pdu1.sm_default_msg_id, pdu2.sm_default_msg_id)
156
+ assert_equal(pdu1.sm_length, pdu2.sm_length)
157
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
158
+ assert_equal(pdu1.command_status, pdu2.command_status)
159
+ end
160
+
161
+ def test_deliver_sm_response
162
+ pdu1 = Smpp::Pdu::DeliverSmResponse.new( nil )
163
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
164
+ assert_instance_of(Smpp::Pdu::DeliverSmResponse, pdu2)
165
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
166
+ assert_equal(pdu1.command_status, pdu2.command_status)
167
+ end
168
+
169
+ def test_submit_sm_response
170
+ pdu1 = Smpp::Pdu::SubmitSmResponse.new( nil, Smpp::Pdu::Base::ESME_ROK, 3 )
171
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
172
+ assert_instance_of(Smpp::Pdu::SubmitSmResponse, pdu2)
173
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
174
+ assert_equal(pdu1.command_status, pdu2.command_status)
175
+ end
176
+
177
+ def test_enquire_link
178
+ pdu1 = Smpp::Pdu::EnquireLink.new( )
179
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
180
+ assert_instance_of(Smpp::Pdu::EnquireLink, pdu2)
181
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
182
+ assert_equal(pdu1.command_status, pdu2.command_status)
183
+ end
184
+
185
+ def test_enquire_link_resp
186
+ pdu1 = Smpp::Pdu::EnquireLinkResponse.new( )
187
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
188
+ assert_instance_of(Smpp::Pdu::EnquireLinkResponse, pdu2)
189
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
190
+ assert_equal(pdu1.command_status, pdu2.command_status)
191
+ end
192
+
193
+ def test_generic_nack
194
+ pdu1 = Smpp::Pdu::GenericNack.new(nil, Smpp::Pdu::Base::ESME_RTHROTTLED )
195
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
196
+ assert_instance_of(Smpp::Pdu::GenericNack, pdu2)
197
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
198
+ assert_equal(pdu1.command_status, pdu2.command_status)
199
+ end
200
+
201
+ def test_unbind
202
+ pdu1 = Smpp::Pdu::Unbind.new()
203
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
204
+ assert_instance_of(Smpp::Pdu::Unbind, pdu2)
205
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
206
+ assert_equal(pdu1.command_status, pdu2.command_status)
207
+ end
208
+
209
+ def test_unbind_response
210
+ pdu1 = Smpp::Pdu::UnbindResponse.new(nil, Smpp::Pdu::Base::ESME_ROK)
211
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
212
+ assert_instance_of(Smpp::Pdu::UnbindResponse, pdu2)
213
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
214
+ assert_equal(pdu1.command_status, pdu2.command_status)
215
+ end
216
+
217
+ #TODO: This test is known to fail since this portion of the library is incomplete.
218
+ def _todo_test_submit_multi
219
+ pdu1 = Smpp::Pdu::SubmitMulti.new( '11111', ['1111111111','1111111112','1111111113'], "This is a test" )
220
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
221
+ assert_instance_of(Smpp::Pdu::SubmitMulti, pdu2)
222
+ assert_equal(pdu1.udh, pdu2.udh)
223
+ assert_equal(pdu1.short_message, pdu2.short_message)
224
+ assert_equal(pdu1.service_type, pdu2.service_type)
225
+ assert_equal(pdu1.source_addr_ton, pdu2.source_addr_ton)
226
+ assert_equal(pdu1.source_addr_npi, pdu2.source_addr_npi)
227
+ assert_equal(pdu1.source_addr, pdu2.source_addr)
228
+ assert_equal(pdu1.dest_addr_ton, pdu2.dest_addr_ton)
229
+ assert_equal(pdu1.dest_addr_npi, pdu2.dest_addr_npi)
230
+ assert_equal(pdu1.destination_addr_array, pdu2.destination_addr_array)
231
+ assert_equal(pdu1.esm_class, pdu2.esm_class)
232
+ assert_equal(pdu1.protocol_id, pdu2.protocol_id)
233
+ assert_equal(pdu1.priority_flag, pdu2.priority_flag)
234
+ assert_equal(pdu1.schedule_delivery_time, pdu2.schedule_delivery_time)
235
+ assert_equal(pdu1.validity_period, pdu2.validity_period)
236
+ assert_equal(pdu1.registered_delivery, pdu2.registered_delivery)
237
+ assert_equal(pdu1.replace_if_present_flag, pdu2.replace_if_present_flag)
238
+ assert_equal(pdu1.data_coding, pdu2.data_coding)
239
+ assert_equal(pdu1.sm_default_msg_id, pdu2.sm_default_msg_id)
240
+ assert_equal(pdu1.sm_length, pdu2.sm_length)
241
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
242
+ assert_equal(pdu1.command_status, pdu2.command_status)
243
+ end
244
+
245
+ def _test_submit_multi_response
246
+ smes = [
247
+ Smpp::Pdu::SubmitMultiResponse::UnsuccessfulSme.new(1,1,'1111111111', Smpp::Pdu::Base::ESME_RINVDSTADR),
248
+ Smpp::Pdu::SubmitMultiResponse::UnsuccessfulSme.new(1,1,'1111111112', Smpp::Pdu::Base::ESME_RINVDSTADR),
249
+ Smpp::Pdu::SubmitMultiResponse::UnsuccessfulSme.new(1,1,'1111111113', Smpp::Pdu::Base::ESME_RINVDSTADR),
250
+ ]
251
+ pdu1 = Smpp::Pdu::SubmitMultiResponse.new( nil, Smpp::Pdu::Base::ESME_ROK, '3', smes )
252
+ pdu2 = Smpp::Pdu::Base.create(pdu1.data)
253
+
254
+ assert_instance_of(Smpp::Pdu::SubmitMultiResponse, pdu2)
255
+ assert_equal(pdu1.unsuccess_smes, pdu2.unsuccess_smes)
256
+ assert_equal(pdu1.sequence_number, pdu2.sequence_number)
257
+ assert_equal(pdu1.command_status, pdu2.command_status)
258
+ end
259
+
54
260
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-smpp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - August Z. Flatby
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-20 00:00:00 +02:00
12
+ date: 2009-01-22 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,23 +40,31 @@ executables: []
40
40
  extensions: []
41
41
 
42
42
  extra_rdoc_files:
43
+ - CONTRIBUTORS.txt
43
44
  - History.txt
44
45
  - License.txt
45
46
  - Manifest.txt
47
+ - NEWS.txt
46
48
  - README.txt
47
49
  files:
50
+ - CONTRIBUTORS.txt
48
51
  - History.txt
49
52
  - License.txt
50
53
  - Manifest.txt
54
+ - NEWS.txt
51
55
  - README.txt
52
56
  - Rakefile
53
- - examples/sample_gateway.rb
54
57
  - config/hoe.rb
55
58
  - config/requirements.rb
59
+ - examples/PDU1.example
60
+ - examples/PDU2.example
61
+ - examples/sample_gateway.rb
62
+ - examples/sample_smsc.rb
56
63
  - lib/smpp.rb
57
- - lib/smpp/version.rb
58
64
  - lib/smpp/base.rb
59
65
  - lib/smpp/pdu/base.rb
66
+ - lib/smpp/pdu/bind_base.rb
67
+ - lib/smpp/pdu/bind_resp_base.rb
60
68
  - lib/smpp/pdu/bind_transceiver.rb
61
69
  - lib/smpp/pdu/bind_transceiver_response.rb
62
70
  - lib/smpp/pdu/deliver_sm.rb
@@ -70,8 +78,11 @@ files:
70
78
  - lib/smpp/pdu/submit_sm_response.rb
71
79
  - lib/smpp/pdu/unbind.rb
72
80
  - lib/smpp/pdu/unbind_response.rb
81
+ - lib/smpp/server.rb
73
82
  - lib/smpp/transceiver.rb
83
+ - lib/smpp/version.rb
74
84
  - lib/sms.rb
85
+ - ruby-smpp.gemspec
75
86
  - script/console
76
87
  - script/destroy
77
88
  - script/generate
@@ -104,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
115
  requirements: []
105
116
 
106
117
  rubyforge_project: ruby-smpp
107
- rubygems_version: 1.3.0
118
+ rubygems_version: 1.3.1
108
119
  signing_key:
109
120
  specification_version: 2
110
121
  summary: Ruby-implementation of the SMPP protocol, based on EventMachine. SMPP is a protocol that allows ordinary people outside the mobile network to exchange SMS messages directly with mobile operators.