-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathpdu_parsing_test.rb
More file actions
112 lines (95 loc) · 3.66 KB
/
Copy pathpdu_parsing_test.rb
File metadata and controls
112 lines (95 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- encoding : utf-8 -*-
require 'rubygems'
require 'test/unit'
require File.expand_path(File.dirname(__FILE__) + "../../lib/smpp")
class PduParsingTest < Test::Unit::TestCase
def test_recieve_single_message
raw_data = <<-EOF
0000 003d 0000 0005 0000 0000 0000 0002
0001 0134 3437 3830 3330 3239 3833 3700
0101 3434 3738 3033 3032 3938 3337 0000
0000 0000 0000 0000 0454 6573 74
EOF
pdu = create_pdu(raw_data)
assert_equal Smpp::Pdu::DeliverSm, pdu.class
assert_equal "447803029837", pdu.source_addr
assert_equal "447803029837", pdu.destination_addr
assert_nil pdu.udh
assert_equal "Test", pdu.short_message
end
def test_recieve_part_one_of_multi_part_message
part_one_message = <<-EOF
0000 00d8 0000 0005 0000 0000 0000 0001
0001 0134 3437 3937 3334 3238 3634 3400
0101 3434 3739 3736 3232 3430 3137 0000
0000 0000 0000 0000 9f05 0003 b402 0154
6869 7320 6973 2061 206c 6f6e 6720 6d65
7373 6167 6520 746f 2074 6573 7420 7768
6574 6865 7220 6f72 206e 6f74 2077 6520
6765 7420 7468 6520 6865 6164 6572 2069
6e66 6f20 7669 6120 7468 6520 534d 5343
2074 6861 7420 7765 2077 6f75 6c64 2072
6571 7569 7265 2074 6f20 6265 2061 626c
6520 746f 2072 6563 6f6d 706f 7365 206c
6f6e 6720 6d65 7373 6167 6573 2069 6e20
6861 7368 626c 7565
EOF
pdu = create_pdu(part_one_message)
assert_equal Smpp::Pdu::DeliverSm, pdu.class
assert_equal "447973428644", pdu.source_addr
assert_equal "447976224017", pdu.destination_addr
assert_equal [5, 0, 3, 180, 2, 1], pdu.udh
assert_equal 2, pdu.total_parts, "Have total parts of the message"
assert_equal 1, pdu.part, "Correctly show the part"
assert_equal 180, pdu.message_id
assert_equal "This is a long message to test whether or not we get the header info via the SMSC that we would require to be able to recompose long messages in hashblue", pdu.short_message
end
def test_recieve_part_two_of_multi_part_message
part_one_message = <<-EOF
0000 0062 0000 0005 0000 0000 0000 0002
0001 0134 3437 3937 3334 3238 3634 3400
0101 3434 3739 3736 3232 3430 3137 0000
0000 0000 0000 0000 2905 0003 b402 0220
616e 6420 7072 6f76 6964 6520 6120 676f
6f64 2075 7365 7220 6578 7065 7269 656e
6365
EOF
pdu = create_pdu(part_one_message)
assert_equal Smpp::Pdu::DeliverSm, pdu.class
assert_equal "447973428644", pdu.source_addr
assert_equal "447976224017", pdu.destination_addr
assert_equal [5, 0, 3, 180, 2, 2], pdu.udh
assert_equal 2, pdu.total_parts, "Have total parts of the message"
assert_equal 2, pdu.part, "Correctly show the part"
assert_equal 180, pdu.message_id
assert_equal " and provide a good user experience", pdu.short_message
end
def test_submit_sm_response_clean
data = <<-EOF
0000 0028 8000 0004 0000 0000 4da8 ebed
3534 3131 342d 3034 3135 562d 3231 3230
452d 3039 4831 5100
EOF
pdu = create_pdu(data)
assert_equal Smpp::Pdu::SubmitSmResponse, pdu.class
assert_equal "54114-0415V-2120E-09H1Q", pdu.message_id
end
def test_submit_sm_response_with_optional_params
data = <<-EOF
0000 0031 8000 0004 0000 042e 4da8 e9a1
0021 5300 0201 7721 6700 1653 6f75 7263
6520 6164 6472 6573 7320 6465 6e69 6564
2e
EOF
pdu = create_pdu(data)
assert_equal Smpp::Pdu::SubmitSmResponse, pdu.class
assert_equal "", pdu.message_id
assert pdu.optional_parameters
assert_equal "Source address denied.", pdu.optional_parameter(0x2167)
end
protected
def create_pdu(raw_data)
hex_data = [raw_data.chomp.gsub(/\s/,"")].pack("H*")
Smpp::Pdu::Base.create(hex_data)
end
end