diff options
author | Maximilian Stiefel <stiefel.maximilian@online.de> | 2018-03-17 13:46:07 +0100 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-03-22 23:35:40 +0100 |
commit | f5d9d86bae8ed97a43a4501236daa4a34d54dcc0 (patch) | |
tree | f169e31221c33720de00ee580caa55fa01c0d0e0 | |
parent | 38b6d3216652fcf329babfe81bdd5bfde1c4afef (diff) |
Solved the issue without C++11 and introduced the proposed improvements. Fixes #1648
-rw-r--r-- | gr-digital/lib/ofdm_carrier_allocator_cvc_impl.cc | 9 | ||||
-rw-r--r-- | gr-digital/lib/ofdm_carrier_allocator_cvc_impl.h | 12 | ||||
-rwxr-xr-x | gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py | 58 |
3 files changed, 45 insertions, 34 deletions
diff --git a/gr-digital/lib/ofdm_carrier_allocator_cvc_impl.cc b/gr-digital/lib/ofdm_carrier_allocator_cvc_impl.cc index 7635efeea5..7df2caeb3b 100644 --- a/gr-digital/lib/ofdm_carrier_allocator_cvc_impl.cc +++ b/gr-digital/lib/ofdm_carrier_allocator_cvc_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2013-2018 Free Software Foundation, Inc. + * Copyright 2013, 2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -74,9 +74,8 @@ namespace gr { d_output_is_shifted(output_is_shifted) { // Sanity checks - // Since C++11: Get pointer to underlying array // If that is is null, the input is wrong -> force user to use ((),) in python - if (d_occupied_carriers.data() == nullptr) { + if (d_occupied_carriers.empty()) { throw std::invalid_argument("Occupied carriers must be of type vector of vector i.e. ((),)."); } for (unsigned i = 0; i < d_occupied_carriers.size(); i++) { @@ -92,7 +91,7 @@ namespace gr { } } } - if (d_pilot_carriers.data() == nullptr) { + if (d_pilot_carriers.empty()) { throw std::invalid_argument("Pilot carriers must be of type vector of vector i.e. ((),)."); } for (unsigned i = 0; i < d_pilot_carriers.size(); i++) { @@ -108,7 +107,7 @@ namespace gr { } } } - if (d_pilot_symbols.data() == nullptr) { + if (d_pilot_symbols.empty()) { throw std::invalid_argument("Pilot symbols must be of type vector of vector i.e. ((),)."); } for (unsigned i = 0; i < std::max(d_pilot_carriers.size(), d_pilot_symbols.size()); i++) { diff --git a/gr-digital/lib/ofdm_carrier_allocator_cvc_impl.h b/gr-digital/lib/ofdm_carrier_allocator_cvc_impl.h index 8f6da1267d..8599355ebb 100644 --- a/gr-digital/lib/ofdm_carrier_allocator_cvc_impl.h +++ b/gr-digital/lib/ofdm_carrier_allocator_cvc_impl.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ -/* - * Copyright 2013-2018 Free Software Foundation, Inc. - * +/* + * Copyright 2013 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, diff --git a/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py b/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py index bd1dfb0915..bbf58c473f 100755 --- a/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py +++ b/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright 2012-2018 Free Software Foundation, Inc. +# Copyright 2012, 2018 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -208,32 +208,44 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): self.assertEqual(correct_offsets[key], tag.offset) self.assertTrue(all(tags_found.values())) - @gr_unittest.unittest.skip("Skipping test with wrong input (caused SIGFPE earlier, now throws a simple std::invalid_argument with useful message)") def test_004_t (self): """ - Provoking exception (earlier SIGFPE). + Provoking RuntimeError exceptions providing wrong user input (earlier invisible SIGFPE). """ fft_len = 6 - tx_symbols = (1, 2, 3) - pilot_symbols = () - occupied_carriers = ((-1, 1, 2),) - pilot_carriers = () - expected_result = (0, 0, 1, 0, 2, 3) - src = blocks.vector_source_c(tx_symbols, False, 1) - alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, (), - self.tsb_key) - sink = blocks.tsb_vector_sink_c(fft_len) - self.tb.connect( - src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), - alloc, - sink - ) - self.tb.run () - self.assertEqual(sink.data()[0], expected_result) + + # Occupied carriers + with self.assertRaises(RuntimeError) as oc: + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + (), + ((),), + ((),), + (), + self.tsb_key) + + # Pilot carriers + with self.assertRaises(RuntimeError) as pc: + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + ((),), + (), + ((),), + (), + self.tsb_key) + + # Pilot carrier symbols + with self.assertRaises(RuntimeError) as ps: + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + ((),), + ((),), + (), + (), + self.tsb_key) + + + self.assertEqual(str(oc.exception), "Occupied carriers must be of type vector of vector i.e. ((),).") + self.assertEqual(str(pc.exception), "Pilot carriers must be of type vector of vector i.e. ((),).") + self.assertEqual(str(ps.exception), "Pilot symbols must be of type vector of vector i.e. ((),).") + if __name__ == '__main__': gr_unittest.run(qa_digital_carrier_allocator_cvc, "qa_digital_carrier_allocator_cvc.xml") |