summaryrefslogtreecommitdiff
path: root/gr-howto-write-a-block/lib
diff options
context:
space:
mode:
Diffstat (limited to 'gr-howto-write-a-block/lib')
-rw-r--r--gr-howto-write-a-block/lib/CMakeLists.txt33
-rw-r--r--gr-howto-write-a-block/lib/qa_howto.cc41
-rw-r--r--gr-howto-write-a-block/lib/qa_howto.h38
-rw-r--r--gr-howto-write-a-block/lib/qa_square2_ff.cc49
-rw-r--r--gr-howto-write-a-block/lib/qa_square2_ff.h46
-rw-r--r--gr-howto-write-a-block/lib/qa_square_ff.cc49
-rw-r--r--gr-howto-write-a-block/lib/qa_square_ff.h46
-rw-r--r--gr-howto-write-a-block/lib/test_howto.cc43
8 files changed, 316 insertions, 29 deletions
diff --git a/gr-howto-write-a-block/lib/CMakeLists.txt b/gr-howto-write-a-block/lib/CMakeLists.txt
index 83b510e3f9..1d00f0ccc9 100644
--- a/gr-howto-write-a-block/lib/CMakeLists.txt
+++ b/gr-howto-write-a-block/lib/CMakeLists.txt
@@ -22,6 +22,9 @@
########################################################################
include(GrPlatform) #define LIB_SUFFIX
+include_directories(${Boost_INCLUDE_DIR})
+link_directories(${Boost_LIBRARY_DIRS})
+
add_library(gnuradio-howto SHARED square_ff_impl.cc square2_ff_impl.cc)
target_link_libraries(gnuradio-howto ${Boost_LIBRARIES} ${GRUEL_LIBRARIES} ${GNURADIO_CORE_LIBRARIES})
set_target_properties(gnuradio-howto PROPERTIES DEFINE_SYMBOL "gnuradio_howto_EXPORTS")
@@ -38,17 +41,25 @@ install(TARGETS gnuradio-howto
########################################################################
# Build and register unit test
########################################################################
-find_package(Boost COMPONENTS unit_test_framework)
-
include(GrTest)
-set(GR_TEST_TARGET_DEPS gnuradio-howto)
-#turn each test cpp file into an executable with an int main() function
-add_definitions(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN)
-add_executable(qa_square_ff qa_square_ff.cc)
-target_link_libraries(qa_square_ff gnuradio-howto ${Boost_LIBRARIES})
-GR_ADD_TEST(qa_square_ff qa_square_ff)
+include_directories(${CPPUNIT_INCLUDE_DIRS})
+
+list(APPEND test_howto_sources
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_howto.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/qa_howto.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/qa_square_ff.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/qa_square2_ff.cc
+)
+
+add_executable(test-howto ${test_howto_sources})
+
+target_link_libraries(
+ test-howto
+ ${GNURADIO_CORE_LIBRARIES}
+ ${Boost_LIBRARIES}
+ ${CPPUNIT_LIBRARIES}
+ gnuradio-howto
+)
-add_executable(qa_square2_ff qa_square2_ff.cc)
-target_link_libraries(qa_square2_ff gnuradio-howto ${Boost_LIBRARIES})
-GR_ADD_TEST(qa_square2_ff qa_square2_ff)
+GR_ADD_TEST(test_howto test-howto)
diff --git a/gr-howto-write-a-block/lib/qa_howto.cc b/gr-howto-write-a-block/lib/qa_howto.cc
new file mode 100644
index 0000000000..6200da9b48
--- /dev/null
+++ b/gr-howto-write-a-block/lib/qa_howto.cc
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2012 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.
+ */
+
+/*
+ * This class gathers together all the test cases for the gr-filter
+ * directory into a single test suite. As you create new test cases,
+ * add them here.
+ */
+
+#include "qa_howto.h"
+#include "qa_square_ff.h"
+#include "qa_square2_ff.h"
+
+CppUnit::TestSuite *
+qa_howto::suite()
+{
+ CppUnit::TestSuite *s = new CppUnit::TestSuite("howto");
+
+ s->addTest(gr::howto::qa_square_ff::suite());
+ s->addTest(gr::howto::qa_square2_ff::suite());
+
+ return s;
+}
diff --git a/gr-howto-write-a-block/lib/qa_howto.h b/gr-howto-write-a-block/lib/qa_howto.h
new file mode 100644
index 0000000000..8eff956b61
--- /dev/null
+++ b/gr-howto-write-a-block/lib/qa_howto.h
@@ -0,0 +1,38 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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.
+ */
+
+#ifndef _QA_HOWTO_H_
+#define _QA_HOWTO_H_
+
+#include <gruel/attributes.h>
+#include <cppunit/TestSuite.h>
+
+//! collect all the tests for the gr-filter directory
+
+class __GR_ATTR_EXPORT qa_howto
+{
+ public:
+ //! return suite of tests for all of gr-filter directory
+ static CppUnit::TestSuite *suite();
+};
+
+#endif /* _QA_HOWTO_H_ */
diff --git a/gr-howto-write-a-block/lib/qa_square2_ff.cc b/gr-howto-write-a-block/lib/qa_square2_ff.cc
index fac704a6d5..672e75691b 100644
--- a/gr-howto-write-a-block/lib/qa_square2_ff.cc
+++ b/gr-howto-write-a-block/lib/qa_square2_ff.cc
@@ -19,14 +19,45 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <boost/test/unit_test.hpp>
+#include "qa_square2_ff.h"
+#include <cppunit/TestAssert.h>
-BOOST_AUTO_TEST_CASE(qa_square2_ff_t1){
- BOOST_CHECK_EQUAL(2 + 2, 4);
- // TODO BOOST_* test macros here
-}
+#include <vector>
+#include <gr_top_block.h>
+#include <gr_vector_source_f.h>
+#include <gr_vector_sink_f.h>
+#include <howto/square2_ff.h>
-BOOST_AUTO_TEST_CASE(qa_square2_ff_t2){
- BOOST_CHECK_EQUAL(2 + 2, 4);
- // TODO BOOST_* test macros here
-}
+namespace gr {
+ namespace howto {
+
+ void
+ qa_square2_ff::t1()
+ {
+ std::vector<float> data(5,0);
+ std::vector<float> result(5,0);
+ std::vector<float> output(5,0);
+ for(size_t i = 0; i < data.size(); i++) {
+ data[i] = i;
+ result[i] = i*i;
+ }
+
+ gr_top_block_sptr tb = gr_make_top_block("dial_tone");
+ gr_vector_source_f_sptr src = gr_make_vector_source_f(data);
+ gr_vector_sink_f_sptr snk = gr_make_vector_sink_f();
+
+ square2_ff::sptr op = square2_ff::make();
+
+ tb->connect(src, 0, op, 0);
+ tb->connect(op, 0, snk, 0);
+ tb->run();
+
+ output = snk->data();
+
+ for(size_t i = 0; i < data.size(); i++) {
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(output[i], result[i], 0.0001);
+ }
+ }
+
+ } /* namespace howto */
+} /* namespace gr */
diff --git a/gr-howto-write-a-block/lib/qa_square2_ff.h b/gr-howto-write-a-block/lib/qa_square2_ff.h
new file mode 100644
index 0000000000..5260cabda9
--- /dev/null
+++ b/gr-howto-write-a-block/lib/qa_square2_ff.h
@@ -0,0 +1,46 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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.
+ */
+
+#ifndef _QA_SQUARE2_FF_H_
+#define _QA_SQUARE2_FF_H_
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
+
+namespace gr {
+ namespace howto {
+
+ class qa_square2_ff : public CppUnit::TestCase
+ {
+ public:
+ CPPUNIT_TEST_SUITE(qa_square2_ff);
+ CPPUNIT_TEST(t1);
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+ void t1();
+ };
+
+ } /* namespace howto */
+} /* namespace gr */
+
+#endif /* _QA_SQUARE2_FF_H_ */
diff --git a/gr-howto-write-a-block/lib/qa_square_ff.cc b/gr-howto-write-a-block/lib/qa_square_ff.cc
index bf474e7155..dedd934e16 100644
--- a/gr-howto-write-a-block/lib/qa_square_ff.cc
+++ b/gr-howto-write-a-block/lib/qa_square_ff.cc
@@ -19,14 +19,45 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <boost/test/unit_test.hpp>
+#include "qa_square_ff.h"
+#include <cppunit/TestAssert.h>
-BOOST_AUTO_TEST_CASE(qa_square_ff_t1){
- BOOST_CHECK_EQUAL(2 + 2, 4);
- // TODO BOOST_* test macros here
-}
+#include <vector>
+#include <gr_top_block.h>
+#include <gr_vector_source_f.h>
+#include <gr_vector_sink_f.h>
+#include <howto/square_ff.h>
-BOOST_AUTO_TEST_CASE(qa_square_ff_t2){
- BOOST_CHECK_EQUAL(2 + 2, 4);
- // TODO BOOST_* test macros here
-}
+namespace gr {
+ namespace howto {
+
+ void
+ qa_square_ff::t1()
+ {
+ std::vector<float> data(5,0);
+ std::vector<float> result(5,0);
+ std::vector<float> output(5,0);
+ for(size_t i = 0; i < data.size(); i++) {
+ data[i] = i;
+ result[i] = i*i;
+ }
+
+ gr_top_block_sptr tb = gr_make_top_block("dial_tone");
+ gr_vector_source_f_sptr src = gr_make_vector_source_f(data);
+ gr_vector_sink_f_sptr snk = gr_make_vector_sink_f();
+
+ square_ff::sptr op = square_ff::make();
+
+ tb->connect(src, 0, op, 0);
+ tb->connect(op, 0, snk, 0);
+ tb->run();
+
+ output = snk->data();
+
+ for(size_t i = 0; i < data.size(); i++) {
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(output[i], result[i], 0.0001);
+ }
+ }
+
+ } /* namespace howto */
+} /* namespace gr */
diff --git a/gr-howto-write-a-block/lib/qa_square_ff.h b/gr-howto-write-a-block/lib/qa_square_ff.h
new file mode 100644
index 0000000000..eed699b0be
--- /dev/null
+++ b/gr-howto-write-a-block/lib/qa_square_ff.h
@@ -0,0 +1,46 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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.
+ */
+
+#ifndef _QA_SQUARE_FF_H_
+#define _QA_SQUARE_FF_H_
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
+
+namespace gr {
+ namespace howto {
+
+ class qa_square_ff : public CppUnit::TestCase
+ {
+ public:
+ CPPUNIT_TEST_SUITE(qa_square_ff);
+ CPPUNIT_TEST(t1);
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+ void t1();
+ };
+
+ } /* namespace howto */
+} /* namespace gr */
+
+#endif /* _QA_SQUARE_FF_H_ */
diff --git a/gr-howto-write-a-block/lib/test_howto.cc b/gr-howto-write-a-block/lib/test_howto.cc
new file mode 100644
index 0000000000..bf344265d7
--- /dev/null
+++ b/gr-howto-write-a-block/lib/test_howto.cc
@@ -0,0 +1,43 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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.
+ */
+
+#include <cppunit/TextTestRunner.h>
+#include <cppunit/XmlOutputter.h>
+
+#include <gr_unittests.h>
+#include "qa_howto.h"
+#include <iostream>
+
+int
+main (int argc, char **argv)
+{
+ CppUnit::TextTestRunner runner;
+ std::ofstream xmlfile(get_unittest_path("howto.xml").c_str());
+ CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile);
+
+ runner.addTest(qa_howto::suite());
+ runner.setOutputter(xmlout);
+
+ bool was_successful = runner.run("", false);
+
+ return was_successful ? 0 : 1;
+}