From 3b5189075bbaca7775787ed6d365cbf38fdc5076 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 25 Jan 2012 03:16:08 +0000 Subject: [PATCH] Cleaning tests git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@143 64b25241-fba3-4117-9849-534c7e92360d --- src/algorithms/tracking/libs/cordic.cc | 39 +++++++- src/core/libs/string_converter.cc | 96 ++++++++++++------- src/core/libs/string_converter.h | 6 +- src/tests/arithmetic/cordic_test.cc | 44 +++++++-- .../control_message_factory_test.cc | 16 ++-- src/tests/flowgraph/pass_through_test.cc | 7 +- src/tests/gnss_block/gnss_sdr_valve_test.cc | 50 ---------- .../gnuradio_block/gnss_sdr_valve_test.cc | 12 +-- .../string_converter/string_converter_test.cc | 20 ++-- src/tests/test_main.cc | 4 +- 10 files changed, 170 insertions(+), 124 deletions(-) delete mode 100644 src/tests/gnss_block/gnss_sdr_valve_test.cc diff --git a/src/algorithms/tracking/libs/cordic.cc b/src/algorithms/tracking/libs/cordic.cc index 555cb1411..237c30012 100644 --- a/src/algorithms/tracking/libs/cordic.cc +++ b/src/algorithms/tracking/libs/cordic.cc @@ -1,3 +1,36 @@ +/*! + * \file cordic.cc + * \brief Implementation of the CORDIC (COordinate Rotation DIgital Computer) algorithm + * \author Carles Fernandez-Prades, 2012. cfernandez(at)cttc.es + * + * This is a modified implementation of the one found at + * http://www.dspguru.com/dsp/faqs/cordic + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR 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 of the License, or + * at your option) any later version. + * + * GNSS-SDR 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 GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + #include #include #include "cordic.h" @@ -13,9 +46,8 @@ Cordic::Cordic(int max_L) { double K, dummy; int L; - - //CORDIC_TABLE *mp_cordic_table = NULL; - mp_cordic_table = (CORDIC_TABLE *) calloc(max_L + 1, sizeof(CORDIC_TABLE)); + //mp_cordic_table = (CORDIC_TABLE *) calloc(max_L + 1, sizeof(CORDIC_TABLE)); + mp_cordic_table = (CORDIC_TABLE *) malloc((max_L + 1) * sizeof(CORDIC_TABLE)); if (!mp_cordic_table) { /* failed to calloc table */ @@ -43,7 +75,6 @@ Cordic::Cordic(int max_L) Cordic::~Cordic () { free(mp_cordic_table); - //mp_cordic_table = ((void *) 0); // nullptr m_max_L = INVALID_K; } diff --git a/src/core/libs/string_converter.cc b/src/core/libs/string_converter.cc index 5b90d71de..78aa5cc29 100644 --- a/src/core/libs/string_converter.cc +++ b/src/core/libs/string_converter.cc @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------- * - * Copyright (C) 2010-2011 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) * * GNSS-SDR is a software defined Global Navigation * Satellite Systems receiver @@ -34,92 +34,124 @@ #include #include -StringConverter::StringConverter() { -} +StringConverter::StringConverter() +{} -StringConverter::~StringConverter() { -} +StringConverter::~StringConverter() +{} -bool StringConverter::convert(std::string value, bool default_value) { - - if(value.compare("true") == 0) { +bool StringConverter::convert(std::string value, bool default_value) +{ + if(value.compare("true") == 0) + { return true; - } else if(value.compare("false") == 0) { + } + else if(value.compare("false") == 0) + { return false; - } else { + } + else + { return default_value; - } + } } -long StringConverter::convert(std::string value, long default_value) { - +long StringConverter::convert(std::string value, long default_value) +{ std::stringstream stream(value); long result; stream >> result; - if(stream.fail()) { + if(stream.fail()) + { return default_value; - } else { + } + else + { return result; - } + } } -int StringConverter::convert(std::string value, int default_value) { + +int StringConverter::convert(std::string value, int default_value) +{ std::stringstream stream(value); int result; stream >> result; - if(stream.fail()) { + if(stream.fail()) + { return default_value; - } else { + } + else + { return result; - } + } } -unsigned int StringConverter::convert(std::string value, unsigned int default_value) { + +unsigned int StringConverter::convert(std::string value, unsigned int default_value) +{ std::stringstream stream(value); unsigned int result; stream >> result; - if(stream.fail()) { + if(stream.fail()) + { return default_value; - } else { + } + else + { return result; - } + } } -float StringConverter::convert(std::string value, float default_value) { + + + +float StringConverter::convert(std::string value, float default_value) +{ std::stringstream stream(value); float result; stream >> result; - if(stream.fail()) { + if(stream.fail()) + { return default_value; - } else { + } + else + { return result; - } + } } -double StringConverter::convert(std::string value, double default_value) { + + + +double StringConverter::convert(std::string value, double default_value) +{ std::stringstream stream(value); double result; stream >> result; - if(stream.fail()) { + if(stream.fail()) + { return default_value; - } else { + } + else + { return result; - } + } } diff --git a/src/core/libs/string_converter.h b/src/core/libs/string_converter.h index 4fb336835..12a293c7e 100644 --- a/src/core/libs/string_converter.h +++ b/src/core/libs/string_converter.h @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------- * - * Copyright (C) 2010-2011 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) * * GNSS-SDR is a software defined Global Navigation * Satellite Systems receiver @@ -35,8 +35,8 @@ #include -class StringConverter { - +class StringConverter +{ public: StringConverter(); virtual ~StringConverter(); diff --git a/src/tests/arithmetic/cordic_test.cc b/src/tests/arithmetic/cordic_test.cc index 238094117..49e5291c9 100644 --- a/src/tests/arithmetic/cordic_test.cc +++ b/src/tests/arithmetic/cordic_test.cc @@ -1,17 +1,51 @@ +/*! + * \file cordic_test.cc + * \brief Test of the CORDIC (COordinate Rotation DIgital Computer) algorithm + * \author Carles Fernandez-Prades, 2012. cfernandez(at)cttc.es + * + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR 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 of the License, or + * at your option) any later version. + * + * GNSS-SDR 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 GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + #include #include #include #include "cordic.h" #include +#include +#include // for RAND_MAX TEST(Cordic_Test, StandardCIsFasterThanCordic) { - int largest_k = 0; + int largest_k = 10; Cordic* cordicPtr; cordicPtr = new Cordic(largest_k); - double phase = 0.1; + double phase = rand(); + phase = (phase/RAND_MAX) * 3.141592; double cos_phase1 = 0; double sin_phase1 = 0; double cos_phase2 = 0; @@ -42,10 +76,8 @@ TEST(Cordic_Test, StandardCIsFasterThanCordic) gettimeofday(&tv, NULL); long long int end2 = tv.tv_sec *1000000 + tv.tv_usec; - std::cout << "CORDIC sin =" << sin_phase2 << " computed in " << (end1-begin1) << " microseconds" << std::endl; - std::cout << "STD sin =" << sin(phase) << " computed in " << (end2-begin2) << " microseconds" << std::endl; + std::cout << "CORDIC sin =" << sin_phase1 << " computed " << niter << " times in " << (end1-begin1) << " microseconds" << std::endl; + std::cout << "STD sin =" << sin_phase2 << " computed " << niter << " times in " << (end2-begin2) << " microseconds" << std::endl; EXPECT_TRUE((end2-begin2) < (end1-begin1)); - - } diff --git a/src/tests/control_thread/control_message_factory_test.cc b/src/tests/control_thread/control_message_factory_test.cc index 65883d8b8..99105b561 100644 --- a/src/tests/control_thread/control_message_factory_test.cc +++ b/src/tests/control_thread/control_message_factory_test.cc @@ -45,8 +45,9 @@ TEST(Control_Message_Factory_Test, GetQueueMessage) gr_message_sptr queue_message = factory->GetQueueMessage(0, 0); ControlMessage *control_message = (ControlMessage*)queue_message->msg(); - EXPECT_EQ(0, control_message->who); - EXPECT_EQ(0, control_message->what); + unsigned int expected0 = 0; + EXPECT_EQ(expected0, control_message->who); + EXPECT_EQ(expected0, control_message->what); EXPECT_EQ(sizeof(ControlMessage), queue_message->length()); delete factory; @@ -67,9 +68,11 @@ TEST(Control_Message_Factory_Test, GetControlMessages) memcpy(queue_message->msg(), control_message, sizeof(ControlMessage)); std::vector *control_messages = factory->GetControlMessages(queue_message); - EXPECT_EQ(1, control_messages->size()); - EXPECT_EQ(1, control_messages->at(0)->who); - EXPECT_EQ(4, control_messages->at(0)->what); + unsigned int expected1 = 1; + unsigned int expected4 = 4; + EXPECT_EQ(expected1, control_messages->size()); + EXPECT_EQ(expected1, control_messages->at(0)->who); + EXPECT_EQ(expected4, control_messages->at(0)->what); delete control_message; delete control_messages; @@ -93,7 +96,8 @@ TEST(Control_Message_Factory_Test, GetControlMessagesWrongSize) memcpy(queue_message->msg() + sizeof(ControlMessage), &another_int, sizeof(int)); std::vector *control_messages = factory->GetControlMessages(queue_message); - EXPECT_EQ(0, control_messages->size()); + unsigned int expected0 = 0; + EXPECT_EQ(expected0, control_messages->size()); delete control_message; delete control_messages; diff --git a/src/tests/flowgraph/pass_through_test.cc b/src/tests/flowgraph/pass_through_test.cc index 2d66e2b73..130f72825 100644 --- a/src/tests/flowgraph/pass_through_test.cc +++ b/src/tests/flowgraph/pass_through_test.cc @@ -32,8 +32,6 @@ #include -#include -#include #include "pass_through.h" #include "in_memory_configuration.h" @@ -42,14 +40,13 @@ TEST(Pass_Through_Test, Instantiate) { InMemoryConfiguration* config = new InMemoryConfiguration(); - config->set_property("Test.item_type", "gr_complex"); config->set_property("Test.vector_size", "2"); - Pass_Through *signal_conditioner = new Pass_Through(config, "Test", 1, 1); EXPECT_STREQ("gr_complex", signal_conditioner->item_type().c_str()); - EXPECT_EQ(2, signal_conditioner->vector_size()); + unsigned int expected2 = 2; + EXPECT_EQ(expected2, signal_conditioner->vector_size()); delete signal_conditioner; } diff --git a/src/tests/gnss_block/gnss_sdr_valve_test.cc b/src/tests/gnss_block/gnss_sdr_valve_test.cc deleted file mode 100644 index 1c63f7eed..000000000 --- a/src/tests/gnss_block/gnss_sdr_valve_test.cc +++ /dev/null @@ -1,50 +0,0 @@ - -/** - * Copyright notice - */ - -/** - * Author: Carlos Avilés, 2010. carlos.avilesr(at)googlemail.com - */ - -/** - * This class implements unit tests for a the valve custom block. - * - */ - -#include -#include -#include -#include - -#include - -#include "gnss_sdr_valve.h" - -#include -#include - -using google::LogMessage; - -TEST(GNSS_SDR_VALVE, CheckEventSentAfter100Samples) { - - gr_msg_queue_sptr queue = gr_make_msg_queue(0); - - gr_top_block_sptr top_block = gr_make_top_block("gnss_sdr_valve_test"); - gr_block_sptr valve = gnss_sdr_make_valve(sizeof(float), 100, queue); - gr_sig_source_f_sptr source = gr_make_sig_source_f(100, GR_CONST_WAVE, 100, 1, 0); - gr_block_sptr sink = gr_make_null_sink(sizeof(float)); - - LOG_AT_LEVEL(INFO) << "Queue count is " << queue->count(); - EXPECT_EQ(0, queue->count()); - - top_block->connect(source, 0, valve, 0); - top_block->connect(valve, 0, sink, 0); - - top_block->run(); - top_block->stop(); - - LOG_AT_LEVEL(INFO) << "Queue count is " << queue->count(); - EXPECT_EQ(1, queue->count()); - -} diff --git a/src/tests/gnuradio_block/gnss_sdr_valve_test.cc b/src/tests/gnuradio_block/gnss_sdr_valve_test.cc index 02da52d50..37f9208e0 100644 --- a/src/tests/gnuradio_block/gnss_sdr_valve_test.cc +++ b/src/tests/gnuradio_block/gnss_sdr_valve_test.cc @@ -37,10 +37,6 @@ #include #include #include "gnss_sdr_valve.h" -//#include -//#include - -//using google::LogMessage; TEST(Valve_Test, CheckEventSentAfter100Samples) { @@ -51,8 +47,8 @@ TEST(Valve_Test, CheckEventSentAfter100Samples) gr_sig_source_f_sptr source = gr_make_sig_source_f(100, GR_CONST_WAVE, 100, 1, 0); gr_block_sptr sink = gr_make_null_sink(sizeof(float)); - //LOG_AT_LEVEL(INFO) << "Queue count is " << queue->count(); - EXPECT_EQ(0, queue->count()); + unsigned int expected0 = 0; + EXPECT_EQ(expected0, queue->count()); top_block->connect(source, 0, valve, 0); top_block->connect(valve, 0, sink, 0); @@ -60,6 +56,6 @@ TEST(Valve_Test, CheckEventSentAfter100Samples) top_block->run(); top_block->stop(); - //LOG_AT_LEVEL(INFO) << "Queue count is " << queue->count(); - EXPECT_EQ(1, queue->count()); + unsigned int expected1 = 1; + EXPECT_EQ(expected1, queue->count()); } diff --git a/src/tests/string_converter/string_converter_test.cc b/src/tests/string_converter/string_converter_test.cc index 969793195..77d5c62b2 100644 --- a/src/tests/string_converter/string_converter_test.cc +++ b/src/tests/string_converter/string_converter_test.cc @@ -37,20 +37,21 @@ TEST(String_Converter_Test, StringToBool) { - StringConverter *converter = new StringConverter(); + StringConverter* converter; + converter = new StringConverter(); bool conversion_result = converter->convert("false", true); EXPECT_EQ(false, conversion_result); delete converter; } - - TEST(String_Converter_Test, StringToSizeT) { - StringConverter *converter = new StringConverter(); + StringConverter* converter; + converter = new StringConverter(); size_t conversion_result = converter->convert("8", 1); - EXPECT_EQ(8, conversion_result); + unsigned int expected = 8; + EXPECT_EQ(expected, conversion_result); delete converter; } @@ -59,7 +60,8 @@ TEST(String_Converter_Test, StringToSizeT) TEST(String_Converter_Test, StringToBoolFail) { - StringConverter *converter = new StringConverter(); + StringConverter* converter; + converter = new StringConverter(); bool conversion_result = converter->convert("lse", true); EXPECT_EQ(true, conversion_result); delete converter; @@ -70,8 +72,10 @@ TEST(String_Converter_Test, StringToBoolFail) TEST(String_Converter_Test, StringToSizeTFail) { - StringConverter *converter = new StringConverter(); + StringConverter* converter; + converter = new StringConverter(); size_t conversion_result = converter->convert("false", 1); - EXPECT_EQ(1, conversion_result); + unsigned int expected1 = 1; + EXPECT_EQ(expected1, conversion_result); delete converter; } diff --git a/src/tests/test_main.cc b/src/tests/test_main.cc index f09d17c91..87cfb3c5f 100644 --- a/src/tests/test_main.cc +++ b/src/tests/test_main.cc @@ -46,12 +46,12 @@ #include "control_thread.h" -//#include "control_thread/control_message_factory_test.cc" +#include "control_thread/control_message_factory_test.cc" //#include "control_thread/control_thread_test.cc" #include "configuration/file_configuration_test.cc" //#include "flowgraph/file_output_filter_test.cc" //#include "flowgraph/file_signal_source_test.cc" -//#include "flowgraph/pass_through_test.cc" +#include "flowgraph/pass_through_test.cc" //#include "flowgraph/gnss_flowgraph_test.cc" //#include "gnss_block/file_output_filter_test.cc" //#include "gnss_block/gnss_block_factory_test.cc"