1 /* -*- c++ -*- */
2 /*
3 * Copyright 2004.2013 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/block.h>
28 #include <gnuradio/blocks/null_sink.h>
29 #include <gnuradio/blocks/null_source.h>
30 #include <boost/test/unit_test.hpp>
31
BOOST_AUTO_TEST_CASE(t0)32 BOOST_AUTO_TEST_CASE(t0)
33 {
34 // test creation of sources
35 gr::block_sptr src1(gr::blocks::null_source::make(sizeof(int)));
36 BOOST_REQUIRE_EQUAL(std::string("null_source"), src1->name());
37 BOOST_REQUIRE_EQUAL(0, src1->input_signature()->max_streams());
38 BOOST_REQUIRE_EQUAL(1, src1->output_signature()->min_streams());
39 BOOST_REQUIRE_EQUAL(-1, src1->output_signature()->max_streams());
40 BOOST_REQUIRE_EQUAL((int)sizeof(int),
41 src1->output_signature()->sizeof_stream_item(0));
42
43 gr::block_sptr src2(gr::blocks::null_source::make(sizeof(short)));
44 BOOST_REQUIRE_EQUAL(std::string("null_source"), src2->name());
45 BOOST_REQUIRE_EQUAL(0, src2->input_signature()->max_streams());
46 BOOST_REQUIRE_EQUAL(1, src2->output_signature()->min_streams());
47 BOOST_REQUIRE_EQUAL(-1, src2->output_signature()->max_streams());
48 BOOST_REQUIRE_EQUAL((int)sizeof(short),
49 src2->output_signature()->sizeof_stream_item(0));
50 }
51
52
BOOST_AUTO_TEST_CASE(t1)53 BOOST_AUTO_TEST_CASE(t1)
54 {
55 // test creation of sinks
56 gr::block_sptr dst1(gr::blocks::null_sink::make(sizeof(int)));
57 BOOST_REQUIRE_EQUAL(std::string("null_sink"), dst1->name());
58 BOOST_REQUIRE_EQUAL(1, dst1->input_signature()->min_streams());
59 BOOST_REQUIRE_EQUAL(-1, dst1->input_signature()->max_streams());
60 BOOST_REQUIRE_EQUAL((int)sizeof(int), dst1->input_signature()->sizeof_stream_item(0));
61
62 BOOST_REQUIRE_EQUAL(0, dst1->output_signature()->max_streams());
63
64 gr::block_sptr dst2(gr::blocks::null_sink::make(sizeof(short)));
65 BOOST_REQUIRE_EQUAL(std::string("null_sink"), dst2->name());
66 BOOST_REQUIRE_EQUAL(1, dst2->input_signature()->min_streams());
67 BOOST_REQUIRE_EQUAL(-1, dst2->input_signature()->max_streams());
68 BOOST_REQUIRE_EQUAL((int)sizeof(short),
69 dst2->input_signature()->sizeof_stream_item(0));
70 BOOST_REQUIRE_EQUAL(0, dst2->output_signature()->max_streams());
71 }
72
73 #include <gnuradio/block_detail.h>
74 #include <gnuradio/blocks/nop.h>
75 #include <gnuradio/buffer.h>
76 #include <gnuradio/top_block.h>
77
BOOST_AUTO_TEST_CASE(t2)78 BOOST_AUTO_TEST_CASE(t2)
79 {
80 gr::block_sptr src1(gr::blocks::null_source::make(sizeof(int)));
81 gr::block_sptr nop(gr::blocks::nop::make(sizeof(int)));
82 gr::block_sptr dst1(gr::blocks::null_sink::make(sizeof(int)));
83
84 gr::top_block_sptr tb(gr::make_top_block("t2"));
85 tb->connect(src1, 0, nop, 0);
86 tb->connect(nop, 0, dst1, 0);
87 tb->start();
88
89 const char* obuf = nop->detail()->output(0)->base();
90 int obsize = nop->detail()->output(0)->bufsize();
91 const char* ibuf = nop->detail()->input(0)->buffer()->base();
92 int ibsize = nop->detail()->input(0)->buffer()->bufsize();
93
94 BOOST_REQUIRE(obuf != NULL);
95 BOOST_REQUIRE(ibuf != NULL);
96 BOOST_REQUIRE(obsize > 0);
97 BOOST_REQUIRE(ibsize > 0);
98
99 tb->stop();
100 tb->wait();
101 }
102