3 # Copyright 2006 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
28 class test_kludge_copy(gr_unittest.TestCase):
31 self.fg = gr.flow_graph()
32 self.rng = random.Random()
39 def make_random_int_tuple(self, L):
42 result.append(self.rng.randint(int(-1e9), int(+1e9)))
47 # 1 input stream; 1 output stream
48 src0_data = self.make_random_int_tuple(16000)
49 src0 = gr.vector_source_i(src0_data)
50 op = gr.kludge_copy(gr.sizeof_int)
51 dst0 = gr.vector_sink_i()
52 self.fg.connect(src0, op, dst0)
54 dst0_data = dst0.data()
55 self.assertEqual(src0_data, dst0_data)
58 # 2 input streams; 2 output streams
59 src0_data = self.make_random_int_tuple(16000)
60 src1_data = self.make_random_int_tuple(16000)
61 src0 = gr.vector_source_i(src0_data)
62 src1 = gr.vector_source_i(src1_data)
63 op = gr.kludge_copy(gr.sizeof_int)
64 dst0 = gr.vector_sink_i()
65 dst1 = gr.vector_sink_i()
66 self.fg.connect(src0, (op, 0), dst0)
67 self.fg.connect(src1, (op, 1), dst1)
69 dst0_data = dst0.data()
70 dst1_data = dst1.data()
71 self.assertEqual(src0_data, dst0_data)
72 self.assertEqual(src1_data, dst1_data)
75 # number of input streams != number of output streams
76 src0_data = self.make_random_int_tuple(16000)
77 src1_data = self.make_random_int_tuple(16000)
78 src0 = gr.vector_source_i(src0_data)
79 src1 = gr.vector_source_i(src1_data)
80 op = gr.kludge_copy(gr.sizeof_int)
81 dst0 = gr.vector_sink_i()
82 dst1 = gr.vector_sink_i()
83 self.fg.connect(src0, (op, 0), dst0)
84 self.fg.connect(src1, (op, 1))
85 self.assertRaises(ValueError, self.fg.run)
87 if __name__ == '__main__':