From fa25d15ed1a7b85869229055ef32166ef1d8bef2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 19 Aug 2012 14:27:11 -0700 Subject: runtime: work on unit tests --- include/gnuradio/block.hpp | 12 ----------- include/gnuradio/element.hpp | 15 ++++++++++++++ include/gnuradio/gr_block.h | 11 ++-------- include/gnuradio/gr_hier_block2.h | 8 ++++++++ include/gnuradio/gr_top_block.h | 17 +++++++++++++++- include/gnuradio/gr_unittests.h | 43 +++++++++++++++++++++++++++++++++++++++ include/gnuradio/hier_block.hpp | 1 - include/gnuradio/top_block.hpp | 16 ++++++++++++++- 8 files changed, 99 insertions(+), 24 deletions(-) create mode 100644 include/gnuradio/gr_unittests.h (limited to 'include') diff --git a/include/gnuradio/block.hpp b/include/gnuradio/block.hpp index 418657f..42f5f8d 100644 --- a/include/gnuradio/block.hpp +++ b/include/gnuradio/block.hpp @@ -75,18 +75,6 @@ struct GR_RUNTIME_API Block : Element * Basic routines from basic block ******************************************************************/ - long unique_id(void) const; - - std::string name(void) const; - - size_t input_size(const size_t which_input) const; - - size_t output_size(const size_t which_output) const; - - void set_input_size(const size_t size, const size_t which_input); - - void set_output_size(const size_t size, const size_t which_output); - size_t history(const size_t which_input = 0) const; void set_history(const size_t history, const size_t which_input = 0); diff --git a/include/gnuradio/element.hpp b/include/gnuradio/element.hpp index dc153fe..849323a 100644 --- a/include/gnuradio/element.hpp +++ b/include/gnuradio/element.hpp @@ -19,6 +19,7 @@ #include #include +#include namespace gnuradio { @@ -29,6 +30,8 @@ struct GR_RUNTIME_API Element : boost::shared_ptr //! Create an empty element Element(void); + Element(const std::string &name); + /*! * Create an element from a shared pointer to an element. * Good for that factory function/shared ptr paradigm. @@ -38,6 +41,18 @@ struct GR_RUNTIME_API Element : boost::shared_ptr boost::shared_ptr(*reinterpret_cast(elem.get())) { } + long unique_id(void) const; + + std::string name(void) const; + + void set_output_signature(gr_io_signature_sptr); + + void set_input_signature(gr_io_signature_sptr); + + gr_io_signature_sptr input_signature(void) const; + + gr_io_signature_sptr output_signature(void) const; + }; } //namespace gnuradio diff --git a/include/gnuradio/gr_block.h b/include/gnuradio/gr_block.h index 7418e3d..92f613a 100644 --- a/include/gnuradio/gr_block.h +++ b/include/gnuradio/gr_block.h @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -38,14 +37,6 @@ struct GR_RUNTIME_API gr_block : gnuradio::Block template void set_msg_handler(T msg_handler){/*LOL*/} - void set_output_signature(gr_io_signature_sptr); - - void set_input_signature(gr_io_signature_sptr); - - gr_io_signature_sptr input_signature(void) const; - - gr_io_signature_sptr output_signature(void) const; - //! implements work -> calls general work int work( const InputItems &input_items, @@ -74,4 +65,6 @@ struct GR_RUNTIME_API gr_block : gnuradio::Block ) = 0; }; +typedef boost::shared_ptr gr_block_sptr; + #endif /*INCLUDED_GNURADIO_GR_BLOCK_H*/ diff --git a/include/gnuradio/gr_hier_block2.h b/include/gnuradio/gr_hier_block2.h index dd8fdae..7bf1ae9 100644 --- a/include/gnuradio/gr_hier_block2.h +++ b/include/gnuradio/gr_hier_block2.h @@ -39,4 +39,12 @@ struct GR_RUNTIME_API gr_hier_block2 : gnuradio::HierBlock }; +typedef boost::shared_ptr gr_hier_block2_sptr; + +GR_RUNTIME_API gr_hier_block2_sptr gr_make_hier_block2( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature +); + #endif /*INCLUDED_GNURADIO_GR_HIER_BLOCK2_H*/ diff --git a/include/gnuradio/gr_top_block.h b/include/gnuradio/gr_top_block.h index 199d7b5..8630606 100644 --- a/include/gnuradio/gr_top_block.h +++ b/include/gnuradio/gr_top_block.h @@ -18,15 +18,30 @@ #define INCLUDED_GNURADIO_GR_TOP_BLOCK_H #include +#include #include -struct GR_RUNTIME_API gr_top_block : gr_hier_block2 +struct GR_RUNTIME_API gr_top_block : gnuradio::TopBlock { gr_top_block(void); gr_top_block(const std::string &name); + void lock(void) + { + //NOP + } + + void unlock(void) + { + this->update(); + } + }; +typedef boost::shared_ptr gr_top_block_sptr; + +GR_RUNTIME_API gr_top_block_sptr gr_make_top_block(const std::string &name); + #endif /*INCLUDED_GNURADIO_GR_TOP_BLOCK_H*/ diff --git a/include/gnuradio/gr_unittests.h b/include/gnuradio/gr_unittests.h new file mode 100644 index 0000000..9fbf228 --- /dev/null +++ b/include/gnuradio/gr_unittests.h @@ -0,0 +1,43 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010,2011 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 3, 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static std::string get_unittest_path(const std::string &filename){ + boost::filesystem::path path = boost::filesystem::current_path() / ".unittests"; + if (!boost::filesystem::is_directory(path)) boost::filesystem::create_directory(path); + return (path / filename).string(); +} diff --git a/include/gnuradio/hier_block.hpp b/include/gnuradio/hier_block.hpp index 1518af5..55f996e 100644 --- a/include/gnuradio/hier_block.hpp +++ b/include/gnuradio/hier_block.hpp @@ -19,7 +19,6 @@ #include #include -#include namespace gnuradio { diff --git a/include/gnuradio/top_block.hpp b/include/gnuradio/top_block.hpp index c131c7d..eb5f6b5 100644 --- a/include/gnuradio/top_block.hpp +++ b/include/gnuradio/top_block.hpp @@ -19,7 +19,6 @@ #include #include -#include namespace gnuradio { @@ -27,6 +26,21 @@ namespace gnuradio struct GR_RUNTIME_API TopBlock : HierBlock { TopBlock(void); + + TopBlock(const std::string &name); + + void update(void); + + void run(void) + { + this->start(); + this->stop(); + this->wait(); + } + + void start(void); + void stop(void); + void wait(void); }; } //namespace gnuradio -- cgit