diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-04-24 21:58:10 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-05-12 10:03:23 +0200 |
commit | a2a6bbc690e087dfe1ee8070307084076ad1c8e2 (patch) | |
tree | 1d44bad2b0c27107186ddb7bac231b01798ecea8 | |
parent | fea5159aa72b020339aab35ca1cecf5cab8eae90 (diff) |
msg: Introduce a message class that contains header and body
-rw-r--r-- | codec/SMPPMessage.st | 54 | ||||
-rw-r--r-- | package.xml | 3 | ||||
-rw-r--r-- | test/SMPPMessageTest.st | 52 |
3 files changed, 109 insertions, 0 deletions
diff --git a/codec/SMPPMessage.st b/codec/SMPPMessage.st new file mode 100644 index 0000000..5a8f8e4 --- /dev/null +++ b/codec/SMPPMessage.st @@ -0,0 +1,54 @@ +" + (C) 2014 by Holger Hans Peter Freyther + All Rights Reserved + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +" + +Object subclass: SMPPMessage [ + | header body | + + SMPPMessage class >> readFrom: aStream [ + | len data stream | + len := ((aStream next: 4) uintAt: 1) swap32. + data := aStream next: len - 4. + stream := data readStream. + ^SMPPMessage new + header: (SMPPPDUHeader readFrom: stream); + yourself. + ] + + header: aHeader [ + header := aHeader + ] + + header [ + ^header + ] + + body: aBody [ + body := aBody + ] + + writeOn: aMsg [ + | hdrData bodyData | + hdrData := header toMessageOrByteArray. + bodyData := body toMessageOrByteArray. + + aMsg + putLen32: (hdrData size + bodyData size + 4); + putByteArray: hdrData; + putByteArray: bodyData. + ] +] diff --git a/package.xml b/package.xml index 771a444..3c9a7be 100644 --- a/package.xml +++ b/package.xml @@ -4,9 +4,12 @@ <prereq>OsmoNetwork</prereq> <filein>codec/SMPPPDUHeader.st</filein> + <filein>codec/SMPPMessage.st</filein> <test> <sunit>Osmo.SMPPPDUHeaderTest</sunit> + <sunit>Osmo.SMPPMessageTest</sunit> <filein>test/SMPPPDUHeaderTest.st</filein> + <filein>test/SMPPMessageTest.st</filein> </test> </package> diff --git a/test/SMPPMessageTest.st b/test/SMPPMessageTest.st new file mode 100644 index 0000000..8eb6d9c --- /dev/null +++ b/test/SMPPMessageTest.st @@ -0,0 +1,52 @@ +" + (C) 2014 by Holger Hans Peter Freyther + All Rights Reserved + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +" + +TestCase subclass: SMPPMessageTest [ + <category: 'OsmoSMPP-Test'> + <comment: 'I test reading and writing most of the SMPP header and body'> + + examplePdu [ + ^#[16r00 16r00 16r00 16r2F 16r00 16r00 16r00 16r02 + 16r00 16r00 16r00 16r00 16r00 16r00 16r00 16r01 + 16r53 16r4D 16r50 16r50 16r33 16r54 16r45 16r53 + 16r54 16r00 16r73 16r65 16r63 16r72 16r65 16r74 + 16r30 16r38 16r00 16r53 16r55 16r42 16r4D 16r49 + 16r54 16r31 16r00 16r00 16r01 16r01 16r00] + ] + + testReadMessage [ + | msg | + msg := SMPPMessage readFrom: self examplePdu readStream. + self assert: msg header commandId equals: 2. + self assert: msg header commandStatus equals: 0. + self assert: msg header sequenceNumber equals: 1. + ] + + testWriteMessage [ + | data | + data := (SMPPMessage new + header: (SMPPPDUHeader new + commandId: 2; + commandStatus: 0; + sequenceNumber: 1; + yourself); + body: (self examplePdu copyFrom: 17); + toMessage) asByteArray. + self assert: data equals: self examplePdu. + ] +] |