Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / runtime / qa_gr_top_block.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
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)
10  * any later version.
11  * 
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.
16  * 
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.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <qa_gr_top_block.h>
28 #include <gr_top_block.h>
29 #include <gr_head.h>
30 #include <gr_null_source.h>
31 #include <gr_null_sink.h>
32 #include <iostream>
33
34 #define VERBOSE 0
35
36 void qa_gr_top_block::t0()
37 {
38   if (VERBOSE) std::cout << "qa_gr_top_block::t0()\n";
39
40   gr_top_block_sptr tb = gr_make_top_block("top");
41
42   CPPUNIT_ASSERT(tb);
43 }
44
45 void qa_gr_top_block::t1_run()
46 {
47   if (VERBOSE) std::cout << "qa_gr_top_block::t1()\n";
48
49   gr_top_block_sptr tb = gr_make_top_block("top");
50
51   gr_block_sptr src = gr_make_null_source(sizeof(int));
52   gr_block_sptr head = gr_make_head(sizeof(int), 100000);
53   gr_block_sptr dst = gr_make_null_sink(sizeof(int));
54
55   tb->connect(src, 0, head, 0);
56   tb->connect(head, 0, dst, 0);
57   tb->run();
58 }
59
60 void qa_gr_top_block::t2_start_stop_wait()
61 {
62   if (VERBOSE) std::cout << "qa_gr_top_block::t2()\n";
63
64   gr_top_block_sptr tb = gr_make_top_block("top");
65
66   gr_block_sptr src = gr_make_null_source(sizeof(int));
67   gr_block_sptr head = gr_make_head(sizeof(int), 100000);
68   gr_block_sptr dst = gr_make_null_sink(sizeof(int));
69
70   tb->connect(src, 0, head, 0);
71   tb->connect(head, 0, dst, 0);
72
73   tb->start();
74   tb->stop();
75   tb->wait();
76 }
77
78 void qa_gr_top_block::t3_lock_unlock()
79 {
80   if (VERBOSE) std::cout << "qa_gr_top_block::t3()\n";
81
82   gr_top_block_sptr tb = gr_make_top_block("top");
83
84   gr_block_sptr src = gr_make_null_source(sizeof(int));
85   gr_block_sptr dst = gr_make_null_sink(sizeof(int));
86
87   tb->connect(src, 0, dst, 0);
88
89   tb->start();
90
91   tb->lock();
92   tb->unlock();
93
94   tb->stop();
95   tb->wait();
96 }
97
98 void qa_gr_top_block::t4_reconfigure()
99 {
100   if (VERBOSE) std::cout << "qa_gr_top_block::t4()\n";
101
102   gr_top_block_sptr tb = gr_make_top_block("top");
103
104   gr_block_sptr src = gr_make_null_source(sizeof(int));
105   gr_block_sptr head = gr_make_head(sizeof(int), 100000);
106   gr_block_sptr dst = gr_make_null_sink(sizeof(int));
107
108   // Start infinite flowgraph
109   tb->connect(src, 0, dst, 0);
110   tb->start();
111
112   // Reconfigure with gr_head in the middle
113   tb->lock();
114   tb->disconnect(src, 0, dst, 0);
115   tb->connect(src, 0, head, 0);
116   tb->connect(head, 0, dst, 0);
117   tb->unlock();
118
119   // Wait for flowgraph to end on its own
120   tb->wait();
121 }