📄 qa_message.py
字号:
#!/usr/bin/env python## Copyright 2004 Free Software Foundation, Inc.# # This file is part of GNU Radio# # GNU Radio is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2, or (at your option)# any later version.# # GNU Radio 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 General Public License for more details.# # You should have received a copy of the GNU General Public License# along with GNU Radio; see the file COPYING. If not, write to# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,# Boston, MA 02111-1307, USA.# from gnuradio import gr, gr_unittestimport qa_basic_flow_graphdef all_counts (): return (gr.block_ncurrently_allocated (), gr.block_detail_ncurrently_allocated (), gr.buffer_ncurrently_allocated (), gr.buffer_reader_ncurrently_allocated (), gr.message_ncurrently_allocated ())class test_message (gr_unittest.TestCase): def setUp (self): self.msgq = gr.msg_queue () def tearDown (self): self.msgq = None def leak_check (self, fct): begin = all_counts () fct () # tear down early so we can check for leaks self.tearDown () end = all_counts () self.assertEqual (begin, end) def test_100 (self): msg = gr.message (0, 1.5, 2.3) self.assertEquals (0, msg.type()) self.assertAlmostEqual (1.5, msg.arg1()) self.assertAlmostEqual (2.3, msg.arg2()) self.assertEquals (0, msg.length()) self.assertEquals (0, msg.buffer_length()) def test_101 (self): msg = gr.message (0, 0, 0, 100) self.assertEquals (100, msg.length()) self.assertEquals (100, msg.buffer_length()) msg.take(10) self.assertEquals (90, msg.length()) self.assertEquals (100, msg.buffer_length()) msg.pull(5) self.assertEquals (85, msg.length()) self.assertEquals (100, msg.buffer_length()) def test_200 (self): self.leak_check (self.body_200) def body_200 (self): self.msgq.insert_tail (gr.message (0)) self.assertEquals (1, self.msgq.count()) self.msgq.insert_tail (gr.message (1)) self.assertEquals (2, self.msgq.count()) msg0 = self.msgq.delete_head () self.assertEquals (0, msg0.type()) msg1 = self.msgq.delete_head () self.assertEquals (1, msg1.type()) self.assertEquals (0, self.msgq.count()) def test_201 (self): self.leak_check (self.body_201) def body_201 (self): self.msgq.insert_tail (gr.message (0)) self.assertEquals (1, self.msgq.count()) self.msgq.insert_tail (gr.message (1)) self.assertEquals (2, self.msgq.count()) def test_202 (self): self.leak_check (self.body_202) def body_202 (self): # global msg msg = gr.message (666)if __name__ == '__main__': gr_unittest.main ()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -