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
24 import qa_basic_flow_graph
28 return (gr.block_ncurrently_allocated (),
29 gr.block_detail_ncurrently_allocated (),
30 gr.buffer_ncurrently_allocated (),
31 gr.buffer_reader_ncurrently_allocated (),
32 gr.message_ncurrently_allocated ())
35 class test_message (gr_unittest.TestCase):
38 self.fg = gr.flow_graph()
39 self.msgq = gr.msg_queue ()
45 def leak_check (self, fct):
48 # tear down early so we can check for leaks
51 self.assertEqual (begin, end)
54 msg = gr.message (0, 1.5, 2.3)
55 self.assertEquals (0, msg.type())
56 self.assertAlmostEqual (1.5, msg.arg1())
57 self.assertAlmostEqual (2.3, msg.arg2())
58 self.assertEquals (0, msg.length())
62 msg = gr.message_from_string(s)
63 self.assertEquals(s, msg.to_string())
66 self.leak_check (self.body_200)
69 self.msgq.insert_tail (gr.message (0))
70 self.assertEquals (1, self.msgq.count())
71 self.msgq.insert_tail (gr.message (1))
72 self.assertEquals (2, self.msgq.count())
73 msg0 = self.msgq.delete_head ()
74 self.assertEquals (0, msg0.type())
75 msg1 = self.msgq.delete_head ()
76 self.assertEquals (1, msg1.type())
77 self.assertEquals (0, self.msgq.count())
80 self.leak_check (self.body_201)
83 self.msgq.insert_tail (gr.message (0))
84 self.assertEquals (1, self.msgq.count())
85 self.msgq.insert_tail (gr.message (1))
86 self.assertEquals (2, self.msgq.count())
89 self.leak_check (self.body_202)
93 msg = gr.message (666)
96 input_data = (0,1,2,3,4,5,6,7,8,9)
97 src = gr.vector_source_b(input_data)
98 dst = gr.vector_sink_b()
99 self.fg.connect(src, dst)
101 self.assertEquals(input_data, dst.data())
104 src = gr.message_source(gr.sizeof_char)
105 dst = gr.vector_sink_b()
106 self.fg.connect(src, dst)
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 if __name__ == '__main__':