anthill_smpp_ruby 0.5.1

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.
Files changed (154) hide show
  1. data/MIT-LICENSE +21 -0
  2. data/README +30 -0
  3. data/anthill_smpp_ruby.gemspec +18 -0
  4. data/changelog +43 -0
  5. data/data/dumps/random_command.dump +1 -0
  6. data/data/dumps/smpp_alert_notification.dump +1 -0
  7. data/data/dumps/smpp_bind_receiver.dump +1 -0
  8. data/data/dumps/smpp_bind_receiver_resp.dump +1 -0
  9. data/data/dumps/smpp_bind_transceiver.dump +1 -0
  10. data/data/dumps/smpp_bind_transceiver_1.dump +2 -0
  11. data/data/dumps/smpp_bind_transceiver_resp.dump +1 -0
  12. data/data/dumps/smpp_bind_transmitter.dump +1 -0
  13. data/data/dumps/smpp_bind_transmitter_resp.dump +1 -0
  14. data/data/dumps/smpp_broadcast_sm.dump +1 -0
  15. data/data/dumps/smpp_broadcast_sm_resp.dump +1 -0
  16. data/data/dumps/smpp_cancel_broadcast_sm.dump +1 -0
  17. data/data/dumps/smpp_cancel_broadcast_sm_resp.dump +1 -0
  18. data/data/dumps/smpp_cancel_sm.dump +1 -0
  19. data/data/dumps/smpp_cancel_sm_resp.dump +1 -0
  20. data/data/dumps/smpp_data_sm.dump +1 -0
  21. data/data/dumps/smpp_data_sm_resp.dump +1 -0
  22. data/data/dumps/smpp_deliver_sm.dump +1 -0
  23. data/data/dumps/smpp_deliver_sm_resp.dump +1 -0
  24. data/data/dumps/smpp_enquire_link.dump +1 -0
  25. data/data/dumps/smpp_enquire_link_resp.dump +1 -0
  26. data/data/dumps/smpp_generic_nack.dump +1 -0
  27. data/data/dumps/smpp_outbind.dump +1 -0
  28. data/data/dumps/smpp_query_broadcast_sm.dump +1 -0
  29. data/data/dumps/smpp_query_broadcast_sm_resp.dump +1 -0
  30. data/data/dumps/smpp_query_broadcast_sm_resp_1.dump +1 -0
  31. data/data/dumps/smpp_query_sm.dump +1 -0
  32. data/data/dumps/smpp_query_sm_resp.dump +1 -0
  33. data/data/dumps/smpp_replace_sm.dump +1 -0
  34. data/data/dumps/smpp_replace_sm_resp.dump +1 -0
  35. data/data/dumps/smpp_submit_multi.dump +1 -0
  36. data/data/dumps/smpp_submit_multi_resp.dump +1 -0
  37. data/data/dumps/smpp_submit_sm.dump +1 -0
  38. data/data/dumps/smpp_submit_sm_resp.dump +1 -0
  39. data/data/dumps/smpp_unbind.dump +1 -0
  40. data/data/dumps/smpp_unbind_resp.dump +1 -0
  41. data/data/pdus/random_command.xml +35 -0
  42. data/data/pdus/smpp_alert_notification.xml +14 -0
  43. data/data/pdus/smpp_alert_notification_no_optional.xml +13 -0
  44. data/data/pdus/smpp_bind_receiver.xml +17 -0
  45. data/data/pdus/smpp_bind_receiver_resp.xml +12 -0
  46. data/data/pdus/smpp_bind_receiver_resp_no_optional.xml +11 -0
  47. data/data/pdus/smpp_bind_transceiver.xml +17 -0
  48. data/data/pdus/smpp_bind_transceiver_resp.xml +12 -0
  49. data/data/pdus/smpp_bind_transceiver_resp_no_optional.xml +11 -0
  50. data/data/pdus/smpp_bind_transmitter.xml +17 -0
  51. data/data/pdus/smpp_bind_transmitter_resp.xml +12 -0
  52. data/data/pdus/smpp_bind_transmitter_resp_no_optional.xml +11 -0
  53. data/data/pdus/smpp_broadcast_sm.xml +47 -0
  54. data/data/pdus/smpp_broadcast_sm_no_optional.xml +26 -0
  55. data/data/pdus/smpp_broadcast_sm_resp.xml +14 -0
  56. data/data/pdus/smpp_broadcast_sm_resp_no_optional.xml +8 -0
  57. data/data/pdus/smpp_cancel_broadcast_sm.xml +17 -0
  58. data/data/pdus/smpp_cancel_broadcast_sm_no_optional.xml +15 -0
  59. data/data/pdus/smpp_cancel_broadcast_sm_resp.xml +7 -0
  60. data/data/pdus/smpp_cancel_sm.xml +18 -0
  61. data/data/pdus/smpp_cancel_sm_resp.xml +10 -0
  62. data/data/pdus/smpp_commands.xsd +914 -0
  63. data/data/pdus/smpp_data_sm.xml +58 -0
  64. data/data/pdus/smpp_data_sm_no_optional.xml +17 -0
  65. data/data/pdus/smpp_data_sm_resp.xml +15 -0
  66. data/data/pdus/smpp_data_sm_resp_no_optional.xml +8 -0
  67. data/data/pdus/smpp_deliver_sm.xml +46 -0
  68. data/data/pdus/smpp_deliver_sm_no_optional.xml +25 -0
  69. data/data/pdus/smpp_deliver_sm_resp.xml +14 -0
  70. data/data/pdus/smpp_deliver_sm_resp_no_optional.xml +8 -0
  71. data/data/pdus/smpp_enquire_link.xml +10 -0
  72. data/data/pdus/smpp_enquire_link_resp.xml +10 -0
  73. data/data/pdus/smpp_generic_nack.xml +10 -0
  74. data/data/pdus/smpp_outbind.xml +12 -0
  75. data/data/pdus/smpp_query_broadcast_sm.xml +12 -0
  76. data/data/pdus/smpp_query_broadcast_sm_no_optional.xml +11 -0
  77. data/data/pdus/smpp_query_broadcast_sm_resp.xml +17 -0
  78. data/data/pdus/smpp_query_broadcast_sm_resp_no_optional.xml +15 -0
  79. data/data/pdus/smpp_query_sm.xml +11 -0
  80. data/data/pdus/smpp_query_sm_resp.xml +11 -0
  81. data/data/pdus/smpp_replace_sm.xml +18 -0
  82. data/data/pdus/smpp_replace_sm_no_optional.xml +17 -0
  83. data/data/pdus/smpp_replace_sm_resp.xml +7 -0
  84. data/data/pdus/smpp_submit_multi.xml +73 -0
  85. data/data/pdus/smpp_submit_multi_no_optional.xml +51 -0
  86. data/data/pdus/smpp_submit_multi_resp.xml +35 -0
  87. data/data/pdus/smpp_submit_sm.xml +57 -0
  88. data/data/pdus/smpp_submit_sm_no_optional.xml +28 -0
  89. data/data/pdus/smpp_submit_sm_resp.xml +8 -0
  90. data/data/pdus/smpp_unbind.xml +10 -0
  91. data/data/pdus/smpp_unbind_resp.xml +10 -0
  92. data/examples/dump_viewer.rb +298 -0
  93. data/examples/pdu_composer.rb +1331 -0
  94. data/knownbugs +24 -0
  95. data/lib/anthill_smpp_ruby.rb +83 -0
  96. data/lib/i_smpp_outputter.rb +425 -0
  97. data/lib/pdu/smpp_alert_notification.rb +132 -0
  98. data/lib/pdu/smpp_bind.rb +102 -0
  99. data/lib/pdu/smpp_bind_receiver.rb +29 -0
  100. data/lib/pdu/smpp_bind_receiver_resp.rb +30 -0
  101. data/lib/pdu/smpp_bind_resp.rb +100 -0
  102. data/lib/pdu/smpp_bind_transceiver.rb +29 -0
  103. data/lib/pdu/smpp_bind_transceiver_resp.rb +31 -0
  104. data/lib/pdu/smpp_bind_transmitter.rb +29 -0
  105. data/lib/pdu/smpp_bind_transmitter_resp.rb +30 -0
  106. data/lib/pdu/smpp_broadcast_sm.rb +566 -0
  107. data/lib/pdu/smpp_broadcast_sm_resp.rb +130 -0
  108. data/lib/pdu/smpp_cancel_broadcast_sm.rb +143 -0
  109. data/lib/pdu/smpp_cancel_broadcast_sm_resp.rb +60 -0
  110. data/lib/pdu/smpp_cancel_sm.rb +110 -0
  111. data/lib/pdu/smpp_cancel_sm_resp.rb +60 -0
  112. data/lib/pdu/smpp_data_sm.rb +679 -0
  113. data/lib/pdu/smpp_data_sm_resp.rb +148 -0
  114. data/lib/pdu/smpp_deliver_sm.rb +458 -0
  115. data/lib/pdu/smpp_deliver_sm_resp.rb +137 -0
  116. data/lib/pdu/smpp_enquire_link.rb +59 -0
  117. data/lib/pdu/smpp_enquire_link_resp.rb +61 -0
  118. data/lib/pdu/smpp_generic_nack.rb +61 -0
  119. data/lib/pdu/smpp_outbind.rb +71 -0
  120. data/lib/pdu/smpp_pdu.rb +90 -0
  121. data/lib/pdu/smpp_query_broadcast_sm.rb +120 -0
  122. data/lib/pdu/smpp_query_broadcast_sm_resp.rb +192 -0
  123. data/lib/pdu/smpp_query_sm.rb +92 -0
  124. data/lib/pdu/smpp_query_sm_resp.rb +92 -0
  125. data/lib/pdu/smpp_replace_sm.rb +172 -0
  126. data/lib/pdu/smpp_replace_sm_resp.rb +61 -0
  127. data/lib/pdu/smpp_resp.rb +40 -0
  128. data/lib/pdu/smpp_submit_multi.rb +517 -0
  129. data/lib/pdu/smpp_submit_multi_resp.rb +90 -0
  130. data/lib/pdu/smpp_submit_sm.rb +591 -0
  131. data/lib/pdu/smpp_submit_sm_resp.rb +72 -0
  132. data/lib/pdu/smpp_unbind.rb +60 -0
  133. data/lib/pdu/smpp_unbind_resp.rb +61 -0
  134. data/lib/smpp_constants.rb +917 -0
  135. data/lib/smpp_csv_outputter.rb +1601 -0
  136. data/lib/smpp_datatypes.rb +89 -0
  137. data/lib/smpp_decoder.rb +627 -0
  138. data/lib/smpp_encoder.rb +495 -0
  139. data/lib/smpp_hex_outputter.rb +36 -0
  140. data/lib/smpp_outputter_base.rb +315 -0
  141. data/lib/smpp_structures.rb +98 -0
  142. data/lib/smpp_txt_outputter.rb +1895 -0
  143. data/lib/smpp_validator.rb +373 -0
  144. data/lib/smpp_xml_outputter.rb +34 -0
  145. data/roadmap +18 -0
  146. data/setup.rb +1585 -0
  147. data/test/anthill_smpp_test.rb +29 -0
  148. data/test/smpp_codec_test.rb +30 -0
  149. data/test/smpp_datatypes_test.rb +69 -0
  150. data/test/smpp_outputter_test.rb +1261 -0
  151. data/test/smpp_parsing_test.rb +1758 -0
  152. data/test/smpp_rawdump_test.rb +2095 -0
  153. data/test/smpp_validator_test.rb +441 -0
  154. metadata +206 -0
@@ -0,0 +1,1758 @@
1
+ #
2
+ # Copyright 2007 Majoron.com (developers@majoron.com)
3
+ # Original sources are available at www.majoron.com
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ $:.unshift File.dirname(__FILE__) + '/../lib/'
19
+ $:.unshift File.dirname(__FILE__) + '/../lib/' + '/../../../AntHill/0.5/lib/'
20
+
21
+ require "csv"
22
+ require "test/unit"
23
+ require "anthill"
24
+ require "anthill_smpp"
25
+
26
+
27
+ class SMPPParsingTest < Test::Unit::TestCase
28
+ # Module contains error messages
29
+ module Errors
30
+ INVALID_COMMAND_ID = "Unknown PDU command id."
31
+ MORE_THAN_ONE_PACKAGE = "Dump contains a valid SMPP package and extra dump information."
32
+ end
33
+
34
+ # Class describe smpp decoded fields
35
+ class SMPPDecodedField
36
+ attr_accessor :field_type
37
+ attr_accessor :field_length
38
+ attr_accessor :field_name
39
+ attr_accessor :field_value
40
+ attr_accessor :field_hexdump
41
+
42
+ def initialize(fldtype, fldlen, fldname, fldval, flddump)
43
+ @field_type = fldtype
44
+ @field_length = fldlen
45
+ @field_name = fldname
46
+ @field_value = fldval
47
+ @field_hexdump = flddump
48
+ end
49
+ end
50
+
51
+
52
+ def test_smpp_bind_transceiver
53
+ dump = String.new()
54
+ # read and decode package based on hex dump
55
+ dump << "00 00 00 2E 00 00 00 09 00 00 00 00 00 00 00 0B 53 79 73 74 65 6D 49 "
56
+ dump << "64 00 70 61 73 73 77 6F 72 64 00 53 4D 53 43 00 50 01 01 31 32 33 00 "
57
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
58
+
59
+
60
+ message = ""
61
+ result = []
62
+ begin
63
+ # Get SMPP command
64
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
65
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
66
+ decoder.append_buffer(buffer)
67
+ pdu = decoder.get_packet()
68
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
69
+
70
+ # Validate SMPP package
71
+ pdu.decode_packet(decoder)
72
+ decoder.validate_offset(pdu.command_length)
73
+ pdu.validate_packet(validator)
74
+ if pdu.command_length != buffer.size()
75
+ message = Errors::MORE_THAN_ONE_PACKAGE
76
+ end
77
+
78
+ # Check txt outputter
79
+ ostreamcsv = String.new()
80
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
81
+ assert_not_equal 0, ostreamcsv.size()
82
+
83
+ if RUBY_VERSION >= "1.9.0"
84
+ # Iterate line by line
85
+ ostreamcsv.each_line do |line|
86
+ continue if line.nil? || line.empty?
87
+ fields = CSV.parse_line(line, {:col_sep => "|"})
88
+ assert_equal 5, fields.size()
89
+ continue if fields.size() != 5
90
+ result << SMPPDecodedField.new(fields[0],
91
+ fields[1], fields[2], fields[3],
92
+ fields[4])
93
+ end
94
+ else
95
+ # Iterate line by line
96
+ ostreamcsv.each do |line|
97
+ continue if line.nil? || line.empty?
98
+ fields = CSV.parse_line(line, "|")
99
+ assert_equal 5, fields.size()
100
+ continue if fields.size() != 5
101
+ result << SMPPDecodedField.new(fields[0],
102
+ fields[1], fields[2], fields[3],
103
+ fields[4])
104
+ end
105
+ end
106
+
107
+ rescue RuntimeError => e
108
+ message = e
109
+ assert false
110
+ end
111
+ end
112
+
113
+ def test_smpp_unbind
114
+ dump = String.new()
115
+ # read and decode package based on hex dump
116
+ dump << "00 00 00 10 00 00 00 06 00 00 00 00 00 00 00 0C"
117
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
118
+
119
+
120
+ message = ""
121
+ result = []
122
+ begin
123
+ # Get SMPP command
124
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
125
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
126
+ decoder.append_buffer(buffer)
127
+ pdu = decoder.get_packet()
128
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
129
+
130
+ # Validate SMPP package
131
+ pdu.decode_packet(decoder)
132
+ decoder.validate_offset(pdu.command_length)
133
+ pdu.validate_packet(validator)
134
+ if pdu.command_length != buffer.size()
135
+ message = Errors::MORE_THAN_ONE_PACKAGE
136
+ end
137
+
138
+ # Check txt outputter
139
+ ostreamcsv = String.new()
140
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
141
+ assert_not_equal 0, ostreamcsv.size()
142
+
143
+ if RUBY_VERSION >= "1.9.0"
144
+ # Iterate line by line
145
+ ostreamcsv.each_line do |line|
146
+ continue if line.nil? || line.empty?
147
+ fields = CSV.parse_line(line, {:col_sep => "|"})
148
+ assert_equal 5, fields.size()
149
+ continue if fields.size() != 5
150
+ result << SMPPDecodedField.new(fields[0],
151
+ fields[1], fields[2], fields[3],
152
+ fields[4])
153
+ end
154
+ else
155
+ # Iterate line by line
156
+ ostreamcsv.each do |line|
157
+ continue if line.nil? || line.empty?
158
+ fields = CSV.parse_line(line, "|")
159
+ assert_equal 5, fields.size()
160
+ continue if fields.size() != 5
161
+ result << SMPPDecodedField.new(fields[0],
162
+ fields[1], fields[2], fields[3],
163
+ fields[4])
164
+ end
165
+ end
166
+ rescue RuntimeError => e
167
+ message = e
168
+ assert false
169
+ end
170
+ end
171
+
172
+ def test_smpp_unbind_resp
173
+ dump = String.new()
174
+ # read and decode package based on hex dump
175
+ dump << "00 00 00 10 80 00 00 06 00 00 00 00 00 00 00 0C"
176
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
177
+
178
+
179
+ message = ""
180
+ result = []
181
+ begin
182
+ # Get SMPP command
183
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
184
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
185
+ decoder.append_buffer(buffer)
186
+ pdu = decoder.get_packet()
187
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
188
+
189
+ # Validate SMPP package
190
+ pdu.decode_packet(decoder)
191
+ decoder.validate_offset(pdu.command_length)
192
+ pdu.validate_packet(validator)
193
+ if pdu.command_length != buffer.size()
194
+ message = Errors::MORE_THAN_ONE_PACKAGE
195
+ end
196
+
197
+ # Check txt outputter
198
+ ostreamcsv = String.new()
199
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
200
+ assert_not_equal 0, ostreamcsv.size()
201
+
202
+ if RUBY_VERSION >= "1.9.0"
203
+ # Iterate line by line
204
+ ostreamcsv.each_line do |line|
205
+ continue if line.nil? || line.empty?
206
+ fields = CSV.parse_line(line, {:col_sep => "|"})
207
+ assert_equal 5, fields.size()
208
+ continue if fields.size() != 5
209
+ result << SMPPDecodedField.new(fields[0],
210
+ fields[1], fields[2], fields[3],
211
+ fields[4])
212
+ end
213
+ else
214
+ # Iterate line by line
215
+ lines.each do |line|
216
+ continue if line.nil? || line.empty?
217
+ fields = CSV.parse_line(line, "|")
218
+ assert_equal 5, fields.size()
219
+ continue if fields.size() != 5
220
+ result << SMPPDecodedField.new(fields[0],
221
+ fields[1], fields[2], fields[3],
222
+ fields[4])
223
+ end
224
+ end
225
+
226
+ rescue RuntimeError => e
227
+ message = e
228
+ assert false
229
+ end
230
+ end
231
+
232
+ def test_smpp_outbind
233
+ dump = String.new()
234
+ # read and decode package based on hex dump
235
+ dump << "00 00 00 19 00 00 00 0B 00 00 00 00 00 00 00 0C 73 74 6D 31 00 70 77 64 00"
236
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
237
+
238
+ message = ""
239
+ result = []
240
+ begin
241
+ # Get SMPP command
242
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
243
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
244
+ decoder.append_buffer(buffer)
245
+ pdu = decoder.get_packet()
246
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
247
+
248
+ # Validate SMPP package
249
+ pdu.decode_packet(decoder)
250
+ decoder.validate_offset(pdu.command_length)
251
+ pdu.validate_packet(validator)
252
+ if pdu.command_length != buffer.size()
253
+ message = Errors::MORE_THAN_ONE_PACKAGE
254
+ end
255
+
256
+ # Check txt outputter
257
+ ostreamcsv = String.new()
258
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
259
+ assert_not_equal 0, ostreamcsv.size()
260
+
261
+ if RUBY_VERSION >= "1.9.0"
262
+ # Iterate line by line
263
+ ostreamcsv.each_line do |line|
264
+ continue if line.nil? || line.empty?
265
+ fields = CSV.parse_line(line, {:col_sep => "|"})
266
+ assert_equal 5, fields.size()
267
+ continue if fields.size() != 5
268
+ result << SMPPDecodedField.new(fields[0],
269
+ fields[1], fields[2], fields[3],
270
+ fields[4])
271
+ end
272
+ else
273
+ # Iterate line by line
274
+ lines.each do |line|
275
+ continue if line.nil? || line.empty?
276
+ fields = CSV.parse_line(line, "|")
277
+ assert_equal 5, fields.size()
278
+ continue if fields.size() != 5
279
+ result << SMPPDecodedField.new(fields[0],
280
+ fields[1], fields[2], fields[3],
281
+ fields[4])
282
+ end
283
+ end
284
+ rescue RuntimeError => e
285
+ message = e
286
+ assert false
287
+ end
288
+ end
289
+
290
+
291
+
292
+ def test_smpp_alert_notification
293
+ dump = String.new()
294
+ # read and decode package based on hex dump
295
+ dump << "00 00 00 21 00 00 01 02 00 00 00 00 00 00 00 0C 01 01 31 32 33 00 02 "
296
+ dump << "02 33 32 31 00 04 22 00 01 01"
297
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
298
+
299
+
300
+ message = ""
301
+ result = []
302
+ begin
303
+ # Get SMPP command
304
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
305
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
306
+ decoder.append_buffer(buffer)
307
+ pdu = decoder.get_packet()
308
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
309
+
310
+ # Validate SMPP package
311
+ pdu.decode_packet(decoder)
312
+ decoder.validate_offset(pdu.command_length)
313
+ pdu.validate_packet(validator)
314
+ if pdu.command_length != buffer.size()
315
+ message = Errors::MORE_THAN_ONE_PACKAGE
316
+ end
317
+
318
+ # Check txt outputter
319
+ ostreamcsv = String.new()
320
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
321
+ assert_not_equal 0, ostreamcsv.size()
322
+
323
+ if RUBY_VERSION >= "1.9.0"
324
+ # Iterate line by line
325
+ ostreamcsv.each_line do |line|
326
+ continue if line.nil? || line.empty?
327
+ fields = CSV.parse_line(line, {:col_sep => "|"})
328
+ assert_equal 5, fields.size()
329
+ continue if fields.size() != 5
330
+ result << SMPPDecodedField.new(fields[0],
331
+ fields[1], fields[2], fields[3],
332
+ fields[4])
333
+ end
334
+ else
335
+ # Iterate line by line
336
+ lines.each do |line|
337
+ continue if line.nil? || line.empty?
338
+ fields = CSV.parse_line(line, "|")
339
+ assert_equal 5, fields.size()
340
+ continue if fields.size() != 5
341
+ result << SMPPDecodedField.new(fields[0],
342
+ fields[1], fields[2], fields[3],
343
+ fields[4])
344
+ end
345
+ end
346
+ rescue RuntimeError => e
347
+ message = e
348
+ assert false
349
+ end
350
+ end
351
+
352
+ def test_smpp_enquire_link
353
+ dump = String.new()
354
+ # read and decode package based on hex dump
355
+ dump << "00 00 00 10 00 00 00 15 00 00 00 00 00 00 00 0C"
356
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
357
+
358
+
359
+ message = ""
360
+ result = []
361
+ begin
362
+ # Get SMPP command
363
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
364
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
365
+ decoder.append_buffer(buffer)
366
+ pdu = decoder.get_packet()
367
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
368
+
369
+ # Validate SMPP package
370
+ pdu.decode_packet(decoder)
371
+ decoder.validate_offset(pdu.command_length)
372
+ pdu.validate_packet(validator)
373
+ if pdu.command_length != buffer.size()
374
+ message = Errors::MORE_THAN_ONE_PACKAGE
375
+ end
376
+
377
+ # Check txt outputter
378
+ ostreamcsv = String.new()
379
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
380
+ assert_not_equal 0, ostreamcsv.size()
381
+
382
+ if RUBY_VERSION >= "1.9.0"
383
+ # Iterate line by line
384
+ ostreamcsv.each_line do |line|
385
+ continue if line.nil? || line.empty?
386
+ fields = CSV.parse_line(line, {:col_sep => "|"})
387
+ assert_equal 5, fields.size()
388
+ continue if fields.size() != 5
389
+ result << SMPPDecodedField.new(fields[0],
390
+ fields[1], fields[2], fields[3],
391
+ fields[4])
392
+ end
393
+ else
394
+ # Iterate line by line
395
+ lines.each do |line|
396
+ continue if line.nil? || line.empty?
397
+ fields = CSV.parse_line(line, "|")
398
+ assert_equal 5, fields.size()
399
+ continue if fields.size() != 5
400
+ result << SMPPDecodedField.new(fields[0],
401
+ fields[1], fields[2], fields[3],
402
+ fields[4])
403
+ end
404
+ end
405
+
406
+ rescue RuntimeError => e
407
+ message = e
408
+ assert false
409
+ end
410
+ end
411
+
412
+ def test_smpp_enquire_link_resp
413
+ dump = String.new()
414
+ # read and decode package based on hex dump
415
+ dump << "00 00 00 10 80 00 00 15 00 00 00 00 00 00 00 0C"
416
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
417
+
418
+
419
+ message = ""
420
+ result = []
421
+ begin
422
+ # Get SMPP command
423
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
424
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
425
+ decoder.append_buffer(buffer)
426
+ pdu = decoder.get_packet()
427
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
428
+
429
+ # Validate SMPP package
430
+ pdu.decode_packet(decoder)
431
+ decoder.validate_offset(pdu.command_length)
432
+ pdu.validate_packet(validator)
433
+ if pdu.command_length != buffer.size()
434
+ message = Errors::MORE_THAN_ONE_PACKAGE
435
+ end
436
+
437
+ # Check txt outputter
438
+ ostreamcsv = String.new()
439
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
440
+ assert_not_equal 0, ostreamcsv.size()
441
+
442
+ if RUBY_VERSION >= "1.9.0"
443
+ # Iterate line by line
444
+ ostreamcsv.each_line do |line|
445
+ continue if line.nil? || line.empty?
446
+ fields = CSV.parse_line(line, {:col_sep => "|"})
447
+ assert_equal 5, fields.size()
448
+ continue if fields.size() != 5
449
+ result << SMPPDecodedField.new(fields[0],
450
+ fields[1], fields[2], fields[3],
451
+ fields[4])
452
+ end
453
+ else
454
+ # Iterate line by line
455
+ lines.each do |line|
456
+ continue if line.nil? || line.empty?
457
+ fields = CSV.parse_line(line, "|")
458
+ assert_equal 5, fields.size()
459
+ continue if fields.size() != 5
460
+ result << SMPPDecodedField.new(fields[0],
461
+ fields[1], fields[2], fields[3],
462
+ fields[4])
463
+ end
464
+ end
465
+
466
+ rescue RuntimeError => e
467
+ message = e
468
+ assert false
469
+ end
470
+ end
471
+
472
+ def test_smpp_generic_nack
473
+ dump = String.new()
474
+ # read and decode package based on hex dump
475
+ dump << "00 00 00 10 80 00 00 00 00 00 00 00 00 00 00 0C"
476
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
477
+ message = ""
478
+ result = []
479
+ begin
480
+ # Get SMPP command
481
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
482
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
483
+ decoder.append_buffer(buffer)
484
+ pdu = decoder.get_packet()
485
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
486
+
487
+ # Validate SMPP package
488
+ pdu.decode_packet(decoder)
489
+ decoder.validate_offset(pdu.command_length)
490
+ pdu.validate_packet(validator)
491
+ if pdu.command_length != buffer.size()
492
+ message = Errors::MORE_THAN_ONE_PACKAGE
493
+ end
494
+
495
+ # Check txt outputter
496
+ ostreamcsv = String.new()
497
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
498
+ assert_not_equal 0, ostreamcsv.size()
499
+
500
+ if RUBY_VERSION >= "1.9.0"
501
+ # Iterate line by line
502
+ ostreamcsv.each_line do |line|
503
+ continue if line.nil? || line.empty?
504
+ fields = CSV.parse_line(line, {:col_sep => "|"})
505
+ assert_equal 5, fields.size()
506
+ continue if fields.size() != 5
507
+ result << SMPPDecodedField.new(fields[0],
508
+ fields[1], fields[2], fields[3],
509
+ fields[4])
510
+ end
511
+ else
512
+ # Iterate line by line
513
+ lines.each do |line|
514
+ continue if line.nil? || line.empty?
515
+ fields = CSV.parse_line(line, "|")
516
+ assert_equal 5, fields.size()
517
+ continue if fields.size() != 5
518
+ result << SMPPDecodedField.new(fields[0],
519
+ fields[1], fields[2], fields[3],
520
+ fields[4])
521
+ end
522
+ end
523
+
524
+ rescue RuntimeError => e
525
+ message = e
526
+ assert false
527
+ end
528
+ end
529
+
530
+
531
+ def test_smpp_submit_sm
532
+ dump = String.new()
533
+ # read and decode package based on hex dump
534
+ dump << "00 00 00 E2 00 00 00 21 00 00 00 00 00 00 00 0C 73 72 76 74 70 00 01 "
535
+ dump << "02 31 32 33 00 06 02 64 69 73 74 72 5F 6C 69 73 74 31 00 02 64 69 73 "
536
+ dump << "74 72 5F 6C 69 73 74 32 00 01 31 31 31 32 33 00 01 32 32 32 32 33 00 "
537
+ dump << "02 64 69 73 74 72 5F 6C 69 73 74 31 00 02 64 69 73 74 72 5F 6C 69 73 "
538
+ dump << "74 32 00 01 02 03 00 00 04 05 06 07 00 02 0A 00 02 00 02 00 0D 00 01 "
539
+ dump << "03 02 0B 00 02 00 04 00 05 00 01 05 02 0C 00 02 00 06 02 0E 00 01 07 "
540
+ dump << "02 0F 00 01 08 00 19 00 01 09 04 24 00 01 09 02 01 00 01 0A 03 81 00 "
541
+ dump << "04 01 02 AA FF 03 02 00 01 0B 03 03 00 04 01 02 AA FF 02 02 00 04 01 "
542
+ dump << "02 AA FF 02 03 00 04 01 02 AA FF 12 01 00 01 0C 12 03 00 02 00 0D 12 "
543
+ dump << "04 00 01 0E 00 30 00 01 0F 13 0C 00 01 10 02 0D 00 01 11"
544
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
545
+ message = ""
546
+ result = []
547
+ begin
548
+ # Get SMPP command
549
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
550
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
551
+ decoder.append_buffer(buffer)
552
+ pdu = decoder.get_packet()
553
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
554
+
555
+ # Validate SMPP package
556
+ pdu.decode_packet(decoder)
557
+ decoder.validate_offset(pdu.command_length)
558
+ pdu.validate_packet(validator)
559
+ if pdu.command_length != buffer.size()
560
+ message = Errors::MORE_THAN_ONE_PACKAGE
561
+ end
562
+
563
+ # Check txt outputter
564
+ ostreamcsv = String.new()
565
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
566
+ assert_not_equal 0, ostreamcsv.size()
567
+
568
+ if RUBY_VERSION >= "1.9.0"
569
+ # Iterate line by line
570
+ ostreamcsv.each_line do |line|
571
+ continue if line.nil? || line.empty?
572
+ fields = CSV.parse_line(line, {:col_sep => "|"})
573
+ assert_equal 5, fields.size()
574
+ continue if fields.size() != 5
575
+ result << SMPPDecodedField.new(fields[0],
576
+ fields[1], fields[2], fields[3],
577
+ fields[4])
578
+ end
579
+ else
580
+ # Iterate line by line
581
+ lines.each do |line|
582
+ continue if line.nil? || line.empty?
583
+ fields = CSV.parse_line(line, "|")
584
+ assert_equal 5, fields.size()
585
+ continue if fields.size() != 5
586
+ result << SMPPDecodedField.new(fields[0],
587
+ fields[1], fields[2], fields[3],
588
+ fields[4])
589
+ end
590
+ end
591
+
592
+ rescue RuntimeError => e
593
+ message = e
594
+ assert false
595
+ end
596
+
597
+ end
598
+
599
+ def test_smpp_submit_sm_resp
600
+ dump = String.new()
601
+ # read and decode package based on hex dump
602
+ dump << "00 00 00 14 80 00 00 04 00 00 00 00 00 00 00 0C 31 32 33 00"
603
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
604
+ message = ""
605
+ result = []
606
+ begin
607
+ # Get SMPP command
608
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
609
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
610
+ decoder.append_buffer(buffer)
611
+ pdu = decoder.get_packet()
612
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
613
+
614
+ # Validate SMPP package
615
+ pdu.decode_packet(decoder)
616
+ decoder.validate_offset(pdu.command_length)
617
+ pdu.validate_packet(validator)
618
+ if pdu.command_length != buffer.size()
619
+ message = Errors::MORE_THAN_ONE_PACKAGE
620
+ end
621
+
622
+ # Check txt outputter
623
+ ostreamcsv = String.new()
624
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
625
+ assert_not_equal 0, ostreamcsv.size()
626
+
627
+ if RUBY_VERSION >= "1.9.0"
628
+ # Iterate line by line
629
+ ostreamcsv.each_line do |line|
630
+ continue if line.nil? || line.empty?
631
+ fields = CSV.parse_line(line, {:col_sep => "|"})
632
+ assert_equal 5, fields.size()
633
+ continue if fields.size() != 5
634
+ result << SMPPDecodedField.new(fields[0],
635
+ fields[1], fields[2], fields[3],
636
+ fields[4])
637
+ end
638
+ else
639
+ # Iterate line by line
640
+ lines.each do |line|
641
+ continue if line.nil? || line.empty?
642
+ fields = CSV.parse_line(line, "|")
643
+ assert_equal 5, fields.size()
644
+ continue if fields.size() != 5
645
+ result << SMPPDecodedField.new(fields[0],
646
+ fields[1], fields[2], fields[3],
647
+ fields[4])
648
+ end
649
+ end
650
+
651
+ rescue RuntimeError => e
652
+ message = e
653
+ assert false
654
+ end
655
+
656
+ end
657
+
658
+ def test_smpp_submit_multi_resp
659
+ dump = String.new()
660
+ # read and decode package based on hex dump
661
+ dump << "00 00 00 33 80 00 00 21 00 00 00 00 00 00 00 0C 31 32 33 00 03 01 02 "
662
+ dump << "31 32 33 00 00 00 00 01 03 04 33 32 31 00 00 00 00 03 05 06 32 31 33 "
663
+ dump << "00 00 00 00 03"
664
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
665
+ message = ""
666
+ result = []
667
+ begin
668
+ # Get SMPP command
669
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
670
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
671
+ decoder.append_buffer(buffer)
672
+ pdu = decoder.get_packet()
673
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
674
+
675
+ # Validate SMPP package
676
+ pdu.decode_packet(decoder)
677
+ decoder.validate_offset(pdu.command_length)
678
+ pdu.validate_packet(validator)
679
+ if pdu.command_length != buffer.size()
680
+ message = Errors::MORE_THAN_ONE_PACKAGE
681
+ end
682
+
683
+ # Check txt outputter
684
+ ostreamcsv = String.new()
685
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
686
+ assert_not_equal 0, ostreamcsv.size()
687
+
688
+ if RUBY_VERSION >= "1.9.0"
689
+ # Iterate line by line
690
+ ostreamcsv.each_line do |line|
691
+ continue if line.nil? || line.empty?
692
+ fields = CSV.parse_line(line, {:col_sep => "|"})
693
+ assert_equal 5, fields.size()
694
+ continue if fields.size() != 5
695
+ result << SMPPDecodedField.new(fields[0],
696
+ fields[1], fields[2], fields[3],
697
+ fields[4])
698
+ end
699
+ else
700
+ # Iterate line by line
701
+ lines.each do |line|
702
+ continue if line.nil? || line.empty?
703
+ fields = CSV.parse_line(line, "|")
704
+ assert_equal 5, fields.size()
705
+ continue if fields.size() != 5
706
+ result << SMPPDecodedField.new(fields[0],
707
+ fields[1], fields[2], fields[3],
708
+ fields[4])
709
+ end
710
+ end
711
+
712
+ rescue RuntimeError => e
713
+ message = e
714
+ assert false
715
+ end
716
+
717
+ end
718
+
719
+
720
+ def test_smpp_cancel_sm
721
+ dump = String.new()
722
+ # read and decode package based on hex dump
723
+ dump << "00 00 00 26 00 00 00 08 00 00 00 00 00 00 00 0C 73 72 76 74 70 00 "
724
+ dump << "31 32 33 00 01 02 31 32 33 00 04 05 33 32 31 00"
725
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
726
+ message = ""
727
+ result = []
728
+ begin
729
+ # Get SMPP command
730
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
731
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
732
+ decoder.append_buffer(buffer)
733
+ pdu = decoder.get_packet()
734
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
735
+
736
+ # Validate SMPP package
737
+ pdu.decode_packet(decoder)
738
+ decoder.validate_offset(pdu.command_length)
739
+ pdu.validate_packet(validator)
740
+ if pdu.command_length != buffer.size()
741
+ message = Errors::MORE_THAN_ONE_PACKAGE
742
+ end
743
+
744
+ # Check txt outputter
745
+ ostreamcsv = String.new()
746
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
747
+ assert_not_equal 0, ostreamcsv.size()
748
+
749
+ if RUBY_VERSION >= "1.9.0"
750
+ # Iterate line by line
751
+ ostreamcsv.each_line do |line|
752
+ continue if line.nil? || line.empty?
753
+ fields = CSV.parse_line(line, {:col_sep => "|"})
754
+ assert_equal 5, fields.size()
755
+ continue if fields.size() != 5
756
+ result << SMPPDecodedField.new(fields[0],
757
+ fields[1], fields[2], fields[3],
758
+ fields[4])
759
+ end
760
+ else
761
+ # Iterate line by line
762
+ lines.each do |line|
763
+ continue if line.nil? || line.empty?
764
+ fields = CSV.parse_line(line, "|")
765
+ assert_equal 5, fields.size()
766
+ continue if fields.size() != 5
767
+ result << SMPPDecodedField.new(fields[0],
768
+ fields[1], fields[2], fields[3],
769
+ fields[4])
770
+ end
771
+ end
772
+
773
+ rescue RuntimeError => e
774
+ message = e
775
+ assert false
776
+ end
777
+
778
+ end
779
+
780
+
781
+ def test_smpp_cancel_sm_resp
782
+ dump = String.new()
783
+ # read and decode package based on hex dump
784
+ dump << "00 00 00 10 80 00 00 08 00 00 00 00 00 00 00 0C"
785
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
786
+ message = ""
787
+ result = []
788
+ begin
789
+ # Get SMPP command
790
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
791
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
792
+ decoder.append_buffer(buffer)
793
+ pdu = decoder.get_packet()
794
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
795
+
796
+ # Validate SMPP package
797
+ pdu.decode_packet(decoder)
798
+ decoder.validate_offset(pdu.command_length)
799
+ pdu.validate_packet(validator)
800
+ if pdu.command_length != buffer.size()
801
+ message = Errors::MORE_THAN_ONE_PACKAGE
802
+ end
803
+
804
+ # Check txt outputter
805
+ ostreamcsv = String.new()
806
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
807
+ assert_not_equal 0, ostreamcsv.size()
808
+
809
+ if RUBY_VERSION >= "1.9.0"
810
+ # Iterate line by line
811
+ ostreamcsv.each_line do |line|
812
+ continue if line.nil? || line.empty?
813
+ fields = CSV.parse_line(line, {:col_sep => "|"})
814
+ assert_equal 5, fields.size()
815
+ continue if fields.size() != 5
816
+ result << SMPPDecodedField.new(fields[0],
817
+ fields[1], fields[2], fields[3],
818
+ fields[4])
819
+ end
820
+ else
821
+ # Iterate line by line
822
+ lines.each do |line|
823
+ continue if line.nil? || line.empty?
824
+ fields = CSV.parse_line(line, "|")
825
+ assert_equal 5, fields.size()
826
+ continue if fields.size() != 5
827
+ result << SMPPDecodedField.new(fields[0],
828
+ fields[1], fields[2], fields[3],
829
+ fields[4])
830
+ end
831
+ end
832
+
833
+ rescue RuntimeError => e
834
+ message = e
835
+ assert false
836
+ end
837
+
838
+ end
839
+
840
+ def test_smpp_query_sm
841
+ dump = String.new()
842
+ # read and decode package based on hex dump
843
+ dump << "00 00 00 1A 00 00 00 03 00 00 00 00 00 00 00 0C 31 32 33 00 01 02 33 32 31 00"
844
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
845
+ message = ""
846
+ result = []
847
+ begin
848
+ # Get SMPP command
849
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
850
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
851
+ decoder.append_buffer(buffer)
852
+ pdu = decoder.get_packet()
853
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
854
+
855
+ # Validate SMPP package
856
+ pdu.decode_packet(decoder)
857
+ decoder.validate_offset(pdu.command_length)
858
+ pdu.validate_packet(validator)
859
+ if pdu.command_length != buffer.size()
860
+ message = Errors::MORE_THAN_ONE_PACKAGE
861
+ end
862
+
863
+ # Check txt outputter
864
+ ostreamcsv = String.new()
865
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
866
+ assert_not_equal 0, ostreamcsv.size()
867
+
868
+ if RUBY_VERSION >= "1.9.0"
869
+ # Iterate line by line
870
+ ostreamcsv.each_line do |line|
871
+ continue if line.nil? || line.empty?
872
+ fields = CSV.parse_line(line, {:col_sep => "|"})
873
+ assert_equal 5, fields.size()
874
+ continue if fields.size() != 5
875
+ result << SMPPDecodedField.new(fields[0],
876
+ fields[1], fields[2], fields[3],
877
+ fields[4])
878
+ end
879
+ else
880
+ # Iterate line by line
881
+ lines.each do |line|
882
+ continue if line.nil? || line.empty?
883
+ fields = CSV.parse_line(line, "|")
884
+ assert_equal 5, fields.size()
885
+ continue if fields.size() != 5
886
+ result << SMPPDecodedField.new(fields[0],
887
+ fields[1], fields[2], fields[3],
888
+ fields[4])
889
+ end
890
+ end
891
+
892
+ rescue RuntimeError => e
893
+ message = e
894
+ assert false
895
+ end
896
+
897
+ end
898
+
899
+ def test_smpp_query_sm_resp
900
+ dump = String.new()
901
+ # read and decode package based on hex dump
902
+ dump << "00 00 00 17 80 00 00 03 00 00 00 00 00 00 00 0C 31 32 33 00 00 01 02"
903
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
904
+ message = ""
905
+ result = []
906
+ begin
907
+ # Get SMPP command
908
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
909
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
910
+ decoder.append_buffer(buffer)
911
+ pdu = decoder.get_packet()
912
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
913
+
914
+ # Validate SMPP package
915
+ pdu.decode_packet(decoder)
916
+ decoder.validate_offset(pdu.command_length)
917
+ pdu.validate_packet(validator)
918
+ if pdu.command_length != buffer.size()
919
+ message = Errors::MORE_THAN_ONE_PACKAGE
920
+ end
921
+
922
+ # Check txt outputter
923
+ ostreamcsv = String.new()
924
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
925
+ assert_not_equal 0, ostreamcsv.size()
926
+
927
+ if RUBY_VERSION >= "1.9.0"
928
+ # Iterate line by line
929
+ ostreamcsv.each_line do |line|
930
+ continue if line.nil? || line.empty?
931
+ fields = CSV.parse_line(line, {:col_sep => "|"})
932
+ assert_equal 5, fields.size()
933
+ continue if fields.size() != 5
934
+ result << SMPPDecodedField.new(fields[0],
935
+ fields[1], fields[2], fields[3],
936
+ fields[4])
937
+ end
938
+ else
939
+ # Iterate line by line
940
+ lines.each do |line|
941
+ continue if line.nil? || line.empty?
942
+ fields = CSV.parse_line(line, "|")
943
+ assert_equal 5, fields.size()
944
+ continue if fields.size() != 5
945
+ result << SMPPDecodedField.new(fields[0],
946
+ fields[1], fields[2], fields[3],
947
+ fields[4])
948
+ end
949
+ end
950
+
951
+ rescue RuntimeError => e
952
+ message = e
953
+ assert false
954
+ end
955
+
956
+ end
957
+
958
+ def test_smpp_replace_sm
959
+ dump = String.new()
960
+ # read and decode package based on hex dump
961
+ dump << "00 00 00 26 00 00 00 07 00 00 00 00 00 00 00 0C 33 34 35 00 01 02 "
962
+ dump << "31 32 33 00 00 00 01 07 00 04 24 00 03 01 FF AA"
963
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
964
+ message = ""
965
+ result = []
966
+ begin
967
+ # Get SMPP command
968
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
969
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
970
+ decoder.append_buffer(buffer)
971
+ pdu = decoder.get_packet()
972
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
973
+
974
+ # Validate SMPP package
975
+ pdu.decode_packet(decoder)
976
+ decoder.validate_offset(pdu.command_length)
977
+ pdu.validate_packet(validator)
978
+ if pdu.command_length != buffer.size()
979
+ message = Errors::MORE_THAN_ONE_PACKAGE
980
+ end
981
+
982
+ # Check txt outputter
983
+ ostreamcsv = String.new()
984
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
985
+ assert_not_equal 0, ostreamcsv.size()
986
+
987
+ if RUBY_VERSION >= "1.9.0"
988
+ # Iterate line by line
989
+ ostreamcsv.each_line do |line|
990
+ continue if line.nil? || line.empty?
991
+ fields = CSV.parse_line(line, {:col_sep => "|"})
992
+ assert_equal 5, fields.size()
993
+ continue if fields.size() != 5
994
+ result << SMPPDecodedField.new(fields[0],
995
+ fields[1], fields[2], fields[3],
996
+ fields[4])
997
+ end
998
+ else
999
+ # Iterate line by line
1000
+ lines.each do |line|
1001
+ continue if line.nil? || line.empty?
1002
+ fields = CSV.parse_line(line, "|")
1003
+ assert_equal 5, fields.size()
1004
+ continue if fields.size() != 5
1005
+ result << SMPPDecodedField.new(fields[0],
1006
+ fields[1], fields[2], fields[3],
1007
+ fields[4])
1008
+ end
1009
+ end
1010
+ rescue RuntimeError => e
1011
+ message = e
1012
+ assert false
1013
+ end
1014
+
1015
+ end
1016
+
1017
+
1018
+
1019
+ def test_smpp_replace_sm_resp
1020
+ dump = String.new()
1021
+ # read and decode package based on hex dump
1022
+ dump << "00 00 00 10 80 00 00 07 00 00 00 00 00 00 00 0C"
1023
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1024
+ message = ""
1025
+ result = []
1026
+ begin
1027
+ # Get SMPP command
1028
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1029
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1030
+ decoder.append_buffer(buffer)
1031
+ pdu = decoder.get_packet()
1032
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1033
+
1034
+ # Validate SMPP package
1035
+ pdu.decode_packet(decoder)
1036
+ decoder.validate_offset(pdu.command_length)
1037
+ pdu.validate_packet(validator)
1038
+ if pdu.command_length != buffer.size()
1039
+ message = Errors::MORE_THAN_ONE_PACKAGE
1040
+ end
1041
+
1042
+ # Check txt outputter
1043
+ ostreamcsv = String.new()
1044
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1045
+ assert_not_equal 0, ostreamcsv.size()
1046
+
1047
+ if RUBY_VERSION >= "1.9.0"
1048
+ # Iterate line by line
1049
+ ostreamcsv.each_line do |line|
1050
+ continue if line.nil? || line.empty?
1051
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1052
+ assert_equal 5, fields.size()
1053
+ continue if fields.size() != 5
1054
+ result << SMPPDecodedField.new(fields[0],
1055
+ fields[1], fields[2], fields[3],
1056
+ fields[4])
1057
+ end
1058
+ else
1059
+ # Iterate line by line
1060
+ lines.each do |line|
1061
+ continue if line.nil? || line.empty?
1062
+ fields = CSV.parse_line(line, "|")
1063
+ assert_equal 5, fields.size()
1064
+ continue if fields.size() != 5
1065
+ result << SMPPDecodedField.new(fields[0],
1066
+ fields[1], fields[2], fields[3],
1067
+ fields[4])
1068
+ end
1069
+ end
1070
+
1071
+ rescue RuntimeError => e
1072
+ message = e
1073
+ assert false
1074
+ end
1075
+
1076
+ end
1077
+
1078
+
1079
+ def test_smpp_data_sm
1080
+ dump = String.new()
1081
+ # read and decode package based on hex dump
1082
+ dump << "00 00 00 FF 00 00 01 03 00 00 00 00 00 00 00 0C 73 72 76 74 70 00 01 "
1083
+ dump << "02 31 32 33 00 03 04 33 32 31 00 00 01 08 02 0A 00 02 00 01 00 0D 00 "
1084
+ dump << "01 02 00 0E 00 01 03 00 0F 00 01 04 00 10 00 01 05 02 0B 00 02 00 06 "
1085
+ dump << "00 05 00 01 07 00 06 00 01 08 00 07 00 01 09 00 08 00 01 0A 02 0C 00 "
1086
+ dump << "02 00 0B 02 0E 00 01 0C 02 0F 00 01 0D 04 26 00 01 01 00 17 00 04 00 "
1087
+ dump << "00 00 0E 00 19 00 01 0F 04 24 00 05 01 02 03 AF FF 04 21 00 01 10 00 "
1088
+ dump << "1E 00 06 31 32 33 32 31 00 04 27 00 01 01 04 23 00 03 01 00 01 02 04 "
1089
+ dump << "00 02 00 7B 02 01 00 01 01 03 81 00 01 01 03 02 00 01 01 03 03 00 02 "
1090
+ dump << "AA FF 02 02 00 02 AA FF 02 03 00 02 AA FF 02 05 00 01 01 12 01 00 01 "
1091
+ dump << "02 12 03 00 02 00 03 12 04 00 01 04 00 30 00 01 05 03 04 00 01 06 03 "
1092
+ dump << "04 00 01 06 13 0C 00 01 07 02 0D 00 01 08 13 80 00 01 09 13 83 00 02 "
1093
+ dump << "00 0A"
1094
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1095
+ message = ""
1096
+ result = []
1097
+ begin
1098
+ # Get SMPP command
1099
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1100
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1101
+ decoder.append_buffer(buffer)
1102
+ pdu = decoder.get_packet()
1103
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1104
+
1105
+ # Validate SMPP package
1106
+ pdu.decode_packet(decoder)
1107
+ decoder.validate_offset(pdu.command_length)
1108
+ pdu.validate_packet(validator)
1109
+ if pdu.command_length != buffer.size()
1110
+ message = Errors::MORE_THAN_ONE_PACKAGE
1111
+ end
1112
+
1113
+ # Check txt outputter
1114
+ ostreamcsv = String.new()
1115
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1116
+ assert_not_equal 0, ostreamcsv.size()
1117
+
1118
+ if RUBY_VERSION >= "1.9.0"
1119
+ # Iterate line by line
1120
+ ostreamcsv.each_line do |line|
1121
+ continue if line.nil? || line.empty?
1122
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1123
+ assert_equal 5, fields.size()
1124
+ continue if fields.size() != 5
1125
+ result << SMPPDecodedField.new(fields[0],
1126
+ fields[1], fields[2], fields[3],
1127
+ fields[4])
1128
+ end
1129
+ else
1130
+ # Iterate line by line
1131
+ lines.each do |line|
1132
+ continue if line.nil? || line.empty?
1133
+ fields = CSV.parse_line(line, "|")
1134
+ assert_equal 5, fields.size()
1135
+ continue if fields.size() != 5
1136
+ result << SMPPDecodedField.new(fields[0],
1137
+ fields[1], fields[2], fields[3],
1138
+ fields[4])
1139
+ end
1140
+ end
1141
+
1142
+ rescue RuntimeError => e
1143
+ message = e
1144
+ assert false
1145
+ end
1146
+ end
1147
+
1148
+
1149
+ def test_smpp_data_sm_resp
1150
+ dump = String.new()
1151
+ # read and decode package based on hex dump
1152
+ dump << "00 00 00 29 80 00 01 03 00 00 00 00 00 00 00 0C 00 04 25 00 01 01 04 "
1153
+ dump << "23 00 03 03 00 01 00 1D 00 03 01 FF AA 04 20 00 01 17 "
1154
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1155
+ message = ""
1156
+ result = []
1157
+ begin
1158
+ # Get SMPP command
1159
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1160
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1161
+ decoder.append_buffer(buffer)
1162
+ pdu = decoder.get_packet()
1163
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1164
+
1165
+ # Validate SMPP package
1166
+ pdu.decode_packet(decoder)
1167
+ decoder.validate_offset(pdu.command_length)
1168
+ pdu.validate_packet(validator)
1169
+ if pdu.command_length != buffer.size()
1170
+ message = Errors::MORE_THAN_ONE_PACKAGE
1171
+ end
1172
+
1173
+ # Check txt outputter
1174
+ ostreamcsv = String.new()
1175
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1176
+ assert_not_equal 0, ostreamcsv.size()
1177
+
1178
+ if RUBY_VERSION >= "1.9.0"
1179
+ # Iterate line by line
1180
+ ostreamcsv.each_line do |line|
1181
+ continue if line.nil? || line.empty?
1182
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1183
+ assert_equal 5, fields.size()
1184
+ continue if fields.size() != 5
1185
+ result << SMPPDecodedField.new(fields[0],
1186
+ fields[1], fields[2], fields[3],
1187
+ fields[4])
1188
+ end
1189
+ else
1190
+ # Iterate line by line
1191
+ lines.each do |line|
1192
+ continue if line.nil? || line.empty?
1193
+ fields = CSV.parse_line(line, "|")
1194
+ assert_equal 5, fields.size()
1195
+ continue if fields.size() != 5
1196
+ result << SMPPDecodedField.new(fields[0],
1197
+ fields[1], fields[2], fields[3],
1198
+ fields[4])
1199
+ end
1200
+ end
1201
+
1202
+ rescue RuntimeError => e
1203
+ message = e
1204
+ assert false
1205
+ end
1206
+ end
1207
+
1208
+ def test_smpp_deliver_sm
1209
+ dump = String.new()
1210
+ # read and decode package based on hex dump
1211
+ dump << "00 00 00 96 00 00 00 05 00 00 00 00 00 00 00 0C 53 4D 53 00 01 02 31 "
1212
+ dump << "32 33 00 04 05 33 32 31 00 06 07 08 00 00 09 0A 0B 0C 00 02 04 00 02 "
1213
+ dump << "00 01 02 0A 00 02 00 02 02 0B 00 02 00 03 02 0C 00 02 00 04 02 0E 00 "
1214
+ dump << "01 05 02 0F 00 01 06 02 05 00 01 07 02 01 00 01 08 00 19 00 01 09 04 "
1215
+ dump << "24 00 03 01 FF AA 03 81 00 03 01 FF AA 02 02 00 03 01 FF AA 02 03 00 "
1216
+ dump << "03 01 FF AA 02 0D 00 01 0A 13 83 00 02 00 0A 04 23 00 03 03 00 0C 04 "
1217
+ dump << "27 00 01 03 00 1E 00 04 31 32 33 00"
1218
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1219
+ message = ""
1220
+ result = []
1221
+ begin
1222
+ # Get SMPP command
1223
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1224
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1225
+ decoder.append_buffer(buffer)
1226
+ pdu = decoder.get_packet()
1227
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1228
+
1229
+ # Validate SMPP package
1230
+ pdu.decode_packet(decoder)
1231
+ decoder.validate_offset(pdu.command_length)
1232
+ pdu.validate_packet(validator)
1233
+ if pdu.command_length != buffer.size()
1234
+ message = Errors::MORE_THAN_ONE_PACKAGE
1235
+ end
1236
+
1237
+ # Check txt outputter
1238
+ ostreamcsv = String.new()
1239
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1240
+ assert_not_equal 0, ostreamcsv.size()
1241
+
1242
+ if RUBY_VERSION >= "1.9.0"
1243
+ # Iterate line by line
1244
+ ostreamcsv.each_line do |line|
1245
+ continue if line.nil? || line.empty?
1246
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1247
+ assert_equal 5, fields.size()
1248
+ continue if fields.size() != 5
1249
+ result << SMPPDecodedField.new(fields[0],
1250
+ fields[1], fields[2], fields[3],
1251
+ fields[4])
1252
+ end
1253
+ else
1254
+ # Iterate line by line
1255
+ lines.each do |line|
1256
+ continue if line.nil? || line.empty?
1257
+ fields = CSV.parse_line(line, "|")
1258
+ assert_equal 5, fields.size()
1259
+ continue if fields.size() != 5
1260
+ result << SMPPDecodedField.new(fields[0],
1261
+ fields[1], fields[2], fields[3],
1262
+ fields[4])
1263
+ end
1264
+ end
1265
+
1266
+ rescue RuntimeError => e
1267
+ message = e
1268
+ assert false
1269
+ end
1270
+ end
1271
+
1272
+
1273
+ def test_smpp_deliver_sm_resp
1274
+ dump = String.new()
1275
+ # read and decode package based on hex dump
1276
+ dump << "00 00 00 24 80 00 00 05 00 00 00 00 00 00 00 0C 00 00 1D 00 03 01 FF "
1277
+ dump << "AA 04 25 00 01 01 04 23 00 03 01 00 02"
1278
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1279
+ message = ""
1280
+ result = []
1281
+ begin
1282
+ # Get SMPP command
1283
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1284
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1285
+ decoder.append_buffer(buffer)
1286
+ pdu = decoder.get_packet()
1287
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1288
+
1289
+ # Validate SMPP package
1290
+ pdu.decode_packet(decoder)
1291
+ decoder.validate_offset(pdu.command_length)
1292
+ pdu.validate_packet(validator)
1293
+ if pdu.command_length != buffer.size()
1294
+ message = Errors::MORE_THAN_ONE_PACKAGE
1295
+ end
1296
+
1297
+ # Check txt outputter
1298
+ ostreamcsv = String.new()
1299
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1300
+ assert_not_equal 0, ostreamcsv.size()
1301
+
1302
+ if RUBY_VERSION >= "1.9.0"
1303
+ # Iterate line by line
1304
+ ostreamcsv.each_line do |line|
1305
+ continue if line.nil? || line.empty?
1306
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1307
+ assert_equal 5, fields.size()
1308
+ continue if fields.size() != 5
1309
+ result << SMPPDecodedField.new(fields[0],
1310
+ fields[1], fields[2], fields[3],
1311
+ fields[4])
1312
+ end
1313
+ else
1314
+ # Iterate line by line
1315
+ lines.each do |line|
1316
+ continue if line.nil? || line.empty?
1317
+ fields = CSV.parse_line(line, "|")
1318
+ assert_equal 5, fields.size()
1319
+ continue if fields.size() != 5
1320
+ result << SMPPDecodedField.new(fields[0],
1321
+ fields[1], fields[2], fields[3],
1322
+ fields[4])
1323
+ end
1324
+ end
1325
+
1326
+ rescue RuntimeError => e
1327
+ message = e
1328
+ assert false
1329
+ end
1330
+ end
1331
+
1332
+
1333
+
1334
+ def test_smpp_broadcast_sm
1335
+ dump = String.new()
1336
+ # read and decode package based on hex dump
1337
+ dump << "00 00 00 C5 00 00 01 11 00 00 00 00 00 00 00 0C 73 72 76 74 70 00 01 "
1338
+ dump << "02 31 32 33 00 33 34 35 00 01 00 00 03 04 05 06 06 00 02 01 FF 06 06 "
1339
+ dump << "00 02 01 AF 06 06 00 02 01 DF 06 01 00 03 01 02 FF 06 04 00 02 00 0A "
1340
+ dump << "06 05 00 03 01 02 FF 13 0C 00 01 01 06 00 00 01 02 06 02 00 03 01 FF "
1341
+ dump << "AA 06 03 00 01 03 06 0A 00 03 01 FF AA 03 81 00 01 10 03 03 00 03 01 "
1342
+ dump << "FF AA 03 02 00 01 04 02 03 00 03 01 FF AA 02 0B 00 02 00 05 12 01 00 "
1343
+ dump << "01 06 02 0D 00 01 07 04 24 00 03 01 FF AA 12 04 00 01 08 00 19 00 01 "
1344
+ dump << "09 02 01 00 01 0A 12 03 00 02 00 0B 00 0D 00 01 0C 02 0A 00 02 00 0D "
1345
+ dump << "02 02 00 03 01 FF AA 02 04 00 02 00 16"
1346
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1347
+ message = ""
1348
+ result = []
1349
+ begin
1350
+ # Get SMPP command
1351
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1352
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1353
+ decoder.append_buffer(buffer)
1354
+ pdu = decoder.get_packet()
1355
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1356
+
1357
+ # Validate SMPP package
1358
+ pdu.decode_packet(decoder)
1359
+ decoder.validate_offset(pdu.command_length)
1360
+ pdu.validate_packet(validator)
1361
+ if pdu.command_length != buffer.size()
1362
+ message = Errors::MORE_THAN_ONE_PACKAGE
1363
+ end
1364
+
1365
+ # Check txt outputter
1366
+ ostreamcsv = String.new()
1367
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1368
+ assert_not_equal 0, ostreamcsv.size()
1369
+
1370
+ if RUBY_VERSION >= "1.9.0"
1371
+ # Iterate line by line
1372
+ ostreamcsv.each_line do |line|
1373
+ continue if line.nil? || line.empty?
1374
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1375
+ assert_equal 5, fields.size()
1376
+ continue if fields.size() != 5
1377
+ result << SMPPDecodedField.new(fields[0],
1378
+ fields[1], fields[2], fields[3],
1379
+ fields[4])
1380
+ end
1381
+ else
1382
+ # Iterate line by line
1383
+ lines.each do |line|
1384
+ continue if line.nil? || line.empty?
1385
+ fields = CSV.parse_line(line, "|")
1386
+ assert_equal 5, fields.size()
1387
+ continue if fields.size() != 5
1388
+ result << SMPPDecodedField.new(fields[0],
1389
+ fields[1], fields[2], fields[3],
1390
+ fields[4])
1391
+ end
1392
+ end
1393
+
1394
+ rescue RuntimeError => e
1395
+ message = e
1396
+ assert false
1397
+ end
1398
+ end
1399
+
1400
+ def test_smpp_broadcast_sm_resp
1401
+ dump = String.new()
1402
+ # read and decode package based on hex dump
1403
+ dump << "00 00 00 2E 80 00 01 11 00 00 00 00 00 00 00 0C 31 32 33 00 06 07 00 "
1404
+ dump << "04 00 00 00 01 06 06 00 02 01 FF 06 06 00 02 01 AF 06 06 00 02 01 DF"
1405
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1406
+ message = ""
1407
+ result = []
1408
+ begin
1409
+ # Get SMPP command
1410
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1411
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1412
+ decoder.append_buffer(buffer)
1413
+ pdu = decoder.get_packet()
1414
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1415
+
1416
+ # Validate SMPP package
1417
+ pdu.decode_packet(decoder)
1418
+ decoder.validate_offset(pdu.command_length)
1419
+ pdu.validate_packet(validator)
1420
+ if pdu.command_length != buffer.size()
1421
+ message = Errors::MORE_THAN_ONE_PACKAGE
1422
+ end
1423
+
1424
+ # Check txt outputter
1425
+ ostreamcsv = String.new()
1426
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1427
+ assert_not_equal 0, ostreamcsv.size()
1428
+
1429
+ if RUBY_VERSION >= "1.9.0"
1430
+ # Iterate line by line
1431
+ ostreamcsv.each_line do |line|
1432
+ continue if line.nil? || line.empty?
1433
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1434
+ assert_equal 5, fields.size()
1435
+ continue if fields.size() != 5
1436
+ result << SMPPDecodedField.new(fields[0],
1437
+ fields[1], fields[2], fields[3],
1438
+ fields[4])
1439
+ end
1440
+ else
1441
+ # Iterate line by line
1442
+ lines.each do |line|
1443
+ continue if line.nil? || line.empty?
1444
+ fields = CSV.parse_line(line, "|")
1445
+ assert_equal 5, fields.size()
1446
+ continue if fields.size() != 5
1447
+ result << SMPPDecodedField.new(fields[0],
1448
+ fields[1], fields[2], fields[3],
1449
+ fields[4])
1450
+ end
1451
+ end
1452
+
1453
+ rescue RuntimeError => e
1454
+ message = e
1455
+ assert false
1456
+ end
1457
+ end
1458
+
1459
+ def test_smpp_cancel_broadcast_sm
1460
+ dump = String.new()
1461
+ # read and decode package based on hex dump
1462
+ dump << "00 00 00 2C 00 00 01 13 00 00 00 00 00 00 00 0C 73 72 76 74 70 00 31 "
1463
+ dump << "32 33 00 01 01 31 32 33 00 06 01 00 02 01 FF 02 04 00 02 00 0A"
1464
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1465
+ message = ""
1466
+ result = []
1467
+ begin
1468
+ # Get SMPP command
1469
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1470
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1471
+ decoder.append_buffer(buffer)
1472
+ pdu = decoder.get_packet()
1473
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1474
+
1475
+ # Validate SMPP package
1476
+ pdu.decode_packet(decoder)
1477
+ decoder.validate_offset(pdu.command_length)
1478
+ pdu.validate_packet(validator)
1479
+ if pdu.command_length != buffer.size()
1480
+ message = Errors::MORE_THAN_ONE_PACKAGE
1481
+ end
1482
+
1483
+ # Check txt outputter
1484
+ ostreamcsv = String.new()
1485
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1486
+ assert_not_equal 0, ostreamcsv.size()
1487
+
1488
+ if RUBY_VERSION >= "1.9.0"
1489
+ # Iterate line by line
1490
+ ostreamcsv.each_line do |line|
1491
+ continue if line.nil? || line.empty?
1492
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1493
+ assert_equal 5, fields.size()
1494
+ continue if fields.size() != 5
1495
+ result << SMPPDecodedField.new(fields[0],
1496
+ fields[1], fields[2], fields[3],
1497
+ fields[4])
1498
+ end
1499
+ else
1500
+ # Iterate line by line
1501
+ lines.each do |line|
1502
+ continue if line.nil? || line.empty?
1503
+ fields = CSV.parse_line(line, "|")
1504
+ assert_equal 5, fields.size()
1505
+ continue if fields.size() != 5
1506
+ result << SMPPDecodedField.new(fields[0],
1507
+ fields[1], fields[2], fields[3],
1508
+ fields[4])
1509
+ end
1510
+ end
1511
+
1512
+ rescue RuntimeError => e
1513
+ message = e
1514
+ assert false
1515
+ end
1516
+ end
1517
+
1518
+ def test_smpp_cancel_broadcast_sm_resp
1519
+ dump = String.new()
1520
+ # read and decode package based on hex dump
1521
+ dump << "00 00 00 10 80 00 01 13 00 00 00 00 00 00 00 0C"
1522
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1523
+ message = ""
1524
+ result = []
1525
+ begin
1526
+ # Get SMPP command
1527
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1528
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1529
+ decoder.append_buffer(buffer)
1530
+ pdu = decoder.get_packet()
1531
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1532
+
1533
+ # Validate SMPP package
1534
+ pdu.decode_packet(decoder)
1535
+ decoder.validate_offset(pdu.command_length)
1536
+ pdu.validate_packet(validator)
1537
+ if pdu.command_length != buffer.size()
1538
+ message = Errors::MORE_THAN_ONE_PACKAGE
1539
+ end
1540
+
1541
+ # Check txt outputter
1542
+ ostreamcsv = String.new()
1543
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1544
+ assert_not_equal 0, ostreamcsv.size()
1545
+
1546
+ if RUBY_VERSION >= "1.9.0"
1547
+ # Iterate line by line
1548
+ ostreamcsv.each_line do |line|
1549
+ continue if line.nil? || line.empty?
1550
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1551
+ assert_equal 5, fields.size()
1552
+ continue if fields.size() != 5
1553
+ result << SMPPDecodedField.new(fields[0],
1554
+ fields[1], fields[2], fields[3],
1555
+ fields[4])
1556
+ end
1557
+ else
1558
+ # Iterate line by line
1559
+ lines.each do |line|
1560
+ continue if line.nil? || line.empty?
1561
+ fields = CSV.parse_line(line, "|")
1562
+ assert_equal 5, fields.size()
1563
+ continue if fields.size() != 5
1564
+ result << SMPPDecodedField.new(fields[0],
1565
+ fields[1], fields[2], fields[3],
1566
+ fields[4])
1567
+ end
1568
+ end
1569
+
1570
+ rescue RuntimeError => e
1571
+ message = e
1572
+ assert false
1573
+ end
1574
+ end
1575
+
1576
+ def test_smpp_query_broadcast_sm
1577
+ dump = String.new()
1578
+ # read and decode package based on hex dump
1579
+ dump << "00 00 00 20 00 00 01 12 00 00 00 00 00 00 00 0C 31 32 33 00 01 02 33 34 35 00 02 04 00 02 00 02"
1580
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1581
+ message = ""
1582
+ result = []
1583
+ begin
1584
+ # Get SMPP command
1585
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1586
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1587
+ decoder.append_buffer(buffer)
1588
+ pdu = decoder.get_packet()
1589
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1590
+
1591
+ # Validate SMPP package
1592
+ pdu.decode_packet(decoder)
1593
+ decoder.validate_offset(pdu.command_length)
1594
+ pdu.validate_packet(validator)
1595
+ if pdu.command_length != buffer.size()
1596
+ message = Errors::MORE_THAN_ONE_PACKAGE
1597
+ end
1598
+
1599
+ # Check txt outputter
1600
+ ostreamcsv = String.new()
1601
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1602
+ assert_not_equal 0, ostreamcsv.size()
1603
+
1604
+ if RUBY_VERSION >= "1.9.0"
1605
+ # Iterate line by line
1606
+ ostreamcsv.each_line do |line|
1607
+ continue if line.nil? || line.empty?
1608
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1609
+ assert_equal 5, fields.size()
1610
+ continue if fields.size() != 5
1611
+ result << SMPPDecodedField.new(fields[0],
1612
+ fields[1], fields[2], fields[3],
1613
+ fields[4])
1614
+ end
1615
+ else
1616
+ # Iterate line by line
1617
+ lines.each do |line|
1618
+ continue if line.nil? || line.empty?
1619
+ fields = CSV.parse_line(line, "|")
1620
+ assert_equal 5, fields.size()
1621
+ continue if fields.size() != 5
1622
+ result << SMPPDecodedField.new(fields[0],
1623
+ fields[1], fields[2], fields[3],
1624
+ fields[4])
1625
+ end
1626
+ end
1627
+
1628
+ rescue RuntimeError => e
1629
+ message = e
1630
+ assert false
1631
+ end
1632
+ end
1633
+
1634
+ def test_smpp_query_broadcast_sm_resp
1635
+ dump = String.new()
1636
+ # read and decode package based on hex dump
1637
+ dump << "00 00 00 36 80 00 01 12 00 00 00 00 00 00 00 0C 31 32 33 00 04 27 00 01 02 "
1638
+ dump << "06 06 00 02 01 FF 06 06 00 02 01 AF 06 06 00 02 01 DF 06 08 00 01 66 02 04 "
1639
+ dump << "00 02 00 7B"
1640
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1641
+ message = ""
1642
+ result = []
1643
+ begin
1644
+ # Get SMPP command
1645
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1646
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1647
+ decoder.append_buffer(buffer)
1648
+ pdu = decoder.get_packet()
1649
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1650
+
1651
+ # Validate SMPP package
1652
+ pdu.decode_packet(decoder)
1653
+ decoder.validate_offset(pdu.command_length)
1654
+ pdu.validate_packet(validator)
1655
+ if pdu.command_length != buffer.size()
1656
+ message = Errors::MORE_THAN_ONE_PACKAGE
1657
+ end
1658
+
1659
+ # Check txt outputter
1660
+ ostreamcsv = String.new()
1661
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1662
+ assert_not_equal 0, ostreamcsv.size()
1663
+
1664
+ if RUBY_VERSION >= "1.9.0"
1665
+ # Iterate line by line
1666
+ ostreamcsv.each_line do |line|
1667
+ continue if line.nil? || line.empty?
1668
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1669
+ assert_equal 5, fields.size()
1670
+ continue if fields.size() != 5
1671
+ result << SMPPDecodedField.new(fields[0],
1672
+ fields[1], fields[2], fields[3],
1673
+ fields[4])
1674
+ end
1675
+ else
1676
+ # Iterate line by line
1677
+ lines.each do |line|
1678
+ continue if line.nil? || line.empty?
1679
+ fields = CSV.parse_line(line, "|")
1680
+ assert_equal 5, fields.size()
1681
+ continue if fields.size() != 5
1682
+ result << SMPPDecodedField.new(fields[0],
1683
+ fields[1], fields[2], fields[3],
1684
+ fields[4])
1685
+ end
1686
+ end
1687
+
1688
+ rescue RuntimeError => e
1689
+ message = e
1690
+ assert false
1691
+ end
1692
+ end
1693
+
1694
+
1695
+ def test_smpp_query_broadcast_sm_resp_1
1696
+ dump = String.new()
1697
+ # read and decode package based on hex dump
1698
+ dump << "00 00 00 3B 80 00 01 12 00 00 00 00 00 00 00 0C 31 32 33 00 04 27 00 01 02 "
1699
+ dump << "06 06 00 02 01 FF 06 06 00 02 01 AF 06 06 00 02 01 DF 06 08 00 01 66 02 04 "
1700
+ dump << "00 02 00 7B 06 09 00 01 00"
1701
+ buffer = Majoron::AntHill::ByteBuffer.decode_hex(dump)
1702
+ message = ""
1703
+ result = []
1704
+ begin
1705
+ # Get SMPP command
1706
+ decoder = Majoron::AntHill::SMPP::SMPPDecoder.new()
1707
+ validator = Majoron::AntHill::SMPP::SMPPValidator.new()
1708
+ decoder.append_buffer(buffer)
1709
+ pdu = decoder.get_packet()
1710
+ raise Errors::INVALID_COMMAND_ID if pdu.nil?
1711
+
1712
+ # Validate SMPP package
1713
+ pdu.decode_packet(decoder)
1714
+ decoder.validate_offset(pdu.command_length)
1715
+ pdu.validate_packet(validator)
1716
+ if pdu.command_length != buffer.size()
1717
+ message = Errors::MORE_THAN_ONE_PACKAGE
1718
+ end
1719
+
1720
+ # Check txt outputter
1721
+ ostreamcsv = String.new()
1722
+ pdu.output_packet(Majoron::AntHill::SMPP::SMPPCSVOutputter.new(ostreamcsv))
1723
+ assert_not_equal 0, ostreamcsv.size()
1724
+
1725
+ if RUBY_VERSION >= "1.9.0"
1726
+ # Iterate line by line
1727
+ ostreamcsv.each_line do |line|
1728
+ continue if line.nil? || line.empty?
1729
+ fields = CSV.parse_line(line, {:col_sep => "|"})
1730
+ assert_equal 5, fields.size()
1731
+ continue if fields.size() != 5
1732
+ result << SMPPDecodedField.new(fields[0],
1733
+ fields[1], fields[2], fields[3],
1734
+ fields[4])
1735
+ end
1736
+ else
1737
+ # Iterate line by line
1738
+ lines.each do |line|
1739
+ continue if line.nil? || line.empty?
1740
+ fields = CSV.parse_line(line, "|")
1741
+ assert_equal 5, fields.size()
1742
+ continue if fields.size() != 5
1743
+ result << SMPPDecodedField.new(fields[0],
1744
+ fields[1], fields[2], fields[3],
1745
+ fields[4])
1746
+ end
1747
+ end
1748
+
1749
+ rescue RuntimeError => e
1750
+ message = e
1751
+ assert false
1752
+ end
1753
+ end
1754
+
1755
+
1756
+
1757
+
1758
+ end