3 # Copyright 2004 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio 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)
12 # GNU Radio 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.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
23 from gnuradio import gr, gr_unittest
27 return (gr.block_ncurrently_allocated (),
28 gr.block_detail_ncurrently_allocated (),
29 gr.buffer_ncurrently_allocated (),
30 gr.buffer_reader_ncurrently_allocated (),
31 gr.message_ncurrently_allocated ())
34 class test_message (gr_unittest.TestCase):
37 self.msgq = gr.msg_queue ()
42 def leak_check (self, fct):
45 # tear down early so we can check for leaks
48 self.assertEqual (begin, end)
51 msg = gr.message (0, 1.5, 2.3)
52 self.assertEquals (0, msg.type())
53 self.assertAlmostEqual (1.5, msg.arg1())
54 self.assertAlmostEqual (2.3, msg.arg2())
55 self.assertEquals (0, msg.length())
59 msg = gr.message_from_string(s)
60 self.assertEquals(s, msg.to_string())
63 self.leak_check (self.body_200)
66 self.msgq.insert_tail (gr.message (0))
67 self.assertEquals (1, self.msgq.count())
68 self.msgq.insert_tail (gr.message (1))
69 self.assertEquals (2, self.msgq.count())
70 msg0 = self.msgq.delete_head ()
71 self.assertEquals (0, msg0.type())
72 msg1 = self.msgq.delete_head ()
73 self.assertEquals (1, msg1.type())
74 self.assertEquals (0, self.msgq.count())
77 self.leak_check (self.body_201)
80 self.msgq.insert_tail (gr.message (0))
81 self.assertEquals (1, self.msgq.count())
82 self.msgq.insert_tail (gr.message (1))
83 self.assertEquals (2, self.msgq.count())
86 self.leak_check (self.body_202)
90 msg = gr.message (666)
93 input_data = (0,1,2,3,4,5,6,7,8,9)
94 src = gr.vector_source_b(input_data)
95 dst = gr.vector_sink_b()
99 self.assertEquals(input_data, dst.data())
102 # Use itemsize, limit constructor
103 src = gr.message_source(gr.sizeof_char)
104 dst = gr.vector_sink_b()
107 src.msgq().insert_tail(gr.message_from_string('01234'))
108 src.msgq().insert_tail(gr.message_from_string('5'))
109 src.msgq().insert_tail(gr.message_from_string(''))
110 src.msgq().insert_tail(gr.message_from_string('6789'))
111 src.msgq().insert_tail(gr.message(1)) # send EOF
113 self.assertEquals(tuple(map(ord, '0123456789')), dst.data())
116 # Use itemsize, msgq constructor
117 msgq = gr.msg_queue()
118 src = gr.message_source(gr.sizeof_char, msgq)
119 dst = gr.vector_sink_b()
122 src.msgq().insert_tail(gr.message_from_string('01234'))
123 src.msgq().insert_tail(gr.message_from_string('5'))
124 src.msgq().insert_tail(gr.message_from_string(''))
125 src.msgq().insert_tail(gr.message_from_string('6789'))
126 src.msgq().insert_tail(gr.message(1)) # send EOF
128 self.assertEquals(tuple(map(ord, '0123456789')), dst.data())
130 if __name__ == '__main__':