Roman Khassraf | c323454 | 2015-08-03 16:17:46 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 4 | # @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com> |
Roman Khassraf | c323454 | 2015-08-03 16:17:46 +0200 | [diff] [blame] | 5 | # @section LICENSE |
| 6 | # |
| 7 | # Gr-gsm is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; either version 3, or (at your option) |
| 10 | # any later version. |
| 11 | # |
| 12 | # Gr-gsm is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with gr-gsm; see the file COPYING. If not, write to |
| 19 | # the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | # Boston, MA 02110-1301, USA. |
| 21 | # |
| 22 | # |
| 23 | |
| 24 | from gnuradio import gr, gr_unittest, blocks |
Piotr Krysik | 5c7b374 | 2016-06-21 07:12:32 +0200 | [diff] [blame] | 25 | import grgsm_swig as grgsm |
Roman Khassraf | c323454 | 2015-08-03 16:17:46 +0200 | [diff] [blame] | 26 | import os |
| 27 | import pmt |
| 28 | import sys |
| 29 | import tempfile |
| 30 | |
| 31 | class qa_message_source_sink (gr_unittest.TestCase): |
| 32 | |
| 33 | def setUp (self): |
| 34 | self.tb = gr.top_block() |
| 35 | self.tmpfile = tempfile.NamedTemporaryFile() |
| 36 | |
| 37 | def tearDown (self): |
| 38 | self.tmpfile.close() |
| 39 | |
| 40 | #def getOutput(self): |
| 41 | #self.tmpfile.seek(0) |
| 42 | #return self.tmpfile.read() |
| 43 | |
| 44 | #def getOutputExpected(self, expected_lines): |
| 45 | #out = "" |
| 46 | #for l in expected_lines: |
| 47 | #out = out + l + "\n" |
| 48 | #return out |
| 49 | |
| 50 | def test_001_no_prefix_no_header (self): |
| 51 | """ |
| 52 | Four messages, without any prefix, no gsmtap header |
| 53 | """ |
| 54 | msgs_input = [ |
| 55 | "02 04 01 00 00 00 c9 00 00 1d 3c e5 02 00 01 00 15 06 21 00 01 f0 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b", |
| 56 | #"02 04 01 00 00 00 ca 00 00 1d 3c e9 02 00 02 00 15 06 21 00 01 f0 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b", |
| 57 | #"02 04 01 00 00 00 cb 00 00 1d 3d 0e 01 00 00 00 59 06 1a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff e5 04 00", |
| 58 | #"02 04 01 00 00 00 cb 00 00 1d 3d 12 02 00 00 00 15 06 21 00 01 f0 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b" |
| 59 | ] |
| 60 | |
| 61 | # there is a whitespace at the beginning of message_printer output |
| 62 | msgs_expected = [ |
| 63 | "02 04 01 00 00 00 c9 00 00 1d 3c e5 02 00 01 00 15 06 21 00 01 f0 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b", |
| 64 | #"02 04 01 00 00 00 ca 00 00 1d 3c e9 02 00 02 00 15 06 21 00 01 f0 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b", |
| 65 | #" 59 06 1a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff e5 04 00", |
| 66 | #" 15 06 21 00 01 f0 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b" |
| 67 | ] |
| 68 | |
| 69 | src = grgsm.message_source(msgs_input) |
| 70 | file_sink = grgsm.message_file_sink(self.tmpfile.name) |
| 71 | |
| 72 | #printer = grgsm.message_printer(pmt.intern(""), False) |
| 73 | #self.tb.msg_connect(src, "msgs", printer, "msgs") |
| 74 | self.tb.run() |
| 75 | |
| 76 | #self.assertEqual(self.getOutput(), self.getOutputExpected(msgs_expected)) |
| 77 | |
| 78 | |
| 79 | if __name__ == '__main__': |
| 80 | gr_unittest.run(qa_message_source_sink, "qa_message_source_sink.xml") |