1 /* -*- c++ -*- */
2 /*
3 * Copyright 2006,2008,2013,2018 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 <gnuradio/blocks/copy.h>
28 #include <gnuradio/blocks/head.h>
29 #include <gnuradio/blocks/null_sink.h>
30 #include <gnuradio/blocks/null_source.h>
31 #include <gnuradio/io_signature.h>
32 #include <gnuradio/top_block.h>
33 #include <boost/test/unit_test.hpp>
34
35 // Declare a test C++ hierarchical block
36
37 class gr_derived_block;
38 typedef boost::shared_ptr<gr_derived_block> gr_derived_block_sptr;
39 gr_derived_block_sptr gr_make_derived_block();
40
41 class gr_derived_block : public gr::hier_block2
42 {
43 private:
44 friend gr_derived_block_sptr gr_make_derived_block();
45 gr_derived_block();
46
47 public:
48 ~gr_derived_block();
49 };
50
51
gr_make_derived_block()52 gr_derived_block_sptr gr_make_derived_block()
53 {
54 return gnuradio::get_initial_sptr(new gr_derived_block());
55 }
56
gr_derived_block()57 gr_derived_block::gr_derived_block()
58 : gr::hier_block2("gr_derived_block",
59 gr::io_signature::make(1, 1, sizeof(int)), // Input signature
60 gr::io_signature::make(1, 1, sizeof(int))) // Output signature
61 {
62 gr::block_sptr copy(gr::blocks::copy::make(sizeof(int)));
63
64 connect(self(), 0, copy, 0);
65 connect(copy, 0, self(), 0);
66 }
67
~gr_derived_block()68 gr_derived_block::~gr_derived_block() {}
69
BOOST_AUTO_TEST_CASE(test_1)70 BOOST_AUTO_TEST_CASE(test_1)
71 {
72 gr::top_block_sptr tb(gr::make_top_block("test"));
73
74 gr::block_sptr src(gr::blocks::null_source::make(sizeof(int)));
75 gr::block_sptr head(gr::blocks::head::make(sizeof(int), 1000));
76 gr_derived_block_sptr blk(gr_make_derived_block());
77 gr::block_sptr dst(gr::blocks::null_sink::make(sizeof(int)));
78
79 tb->connect(src, 0, head, 0);
80 tb->connect(head, 0, blk, 0);
81 tb->connect(blk, 0, dst, 0);
82
83 tb->run();
84 }
85