diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-02-12 10:21:01 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-02-12 10:21:01 +0100 |
commit | a84687a3e0776f47deec0ddb7b8f2a47eb0ea877 (patch) | |
tree | a84b5657ab8a0334de6366b50cf96bc857f2e20c /doc/zmq-ctrl/cpp/test | |
parent | 1f7576701b54bf83d600780483017457841e830b (diff) | |
parent | 277d29a529c37a8fe59883291e43db8ff8831b22 (diff) | |
download | dabmod-a84687a3e0776f47deec0ddb7b8f2a47eb0ea877.tar.gz dabmod-a84687a3e0776f47deec0ddb7b8f2a47eb0ea877.tar.bz2 dabmod-a84687a3e0776f47deec0ddb7b8f2a47eb0ea877.zip |
Merge raspine/master, with ZMQ Remote-Control code
This adds zmq rc fixes and an example tool to interface to it
Diffstat (limited to 'doc/zmq-ctrl/cpp/test')
-rwxr-xr-x | doc/zmq-ctrl/cpp/test/CMakeLists.txt | 31 | ||||
-rw-r--r-- | doc/zmq-ctrl/cpp/test/README | 14 | ||||
-rw-r--r-- | doc/zmq-ctrl/cpp/test/ctrl_test.cpp | 94 |
3 files changed, 139 insertions, 0 deletions
diff --git a/doc/zmq-ctrl/cpp/test/CMakeLists.txt b/doc/zmq-ctrl/cpp/test/CMakeLists.txt new file mode 100755 index 0000000..4b877d0 --- /dev/null +++ b/doc/zmq-ctrl/cpp/test/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 2.6) +project (ctrl_test) + +ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -D_SCL_SECURE_NO_WARNINGS) + +set(BOOST_LIBRARYDIR) +set(BOOST_INCLUDEDIR) +set(BOOST_USE_MULTITHREADED ON) +set(BOOST_USE_STATIC_LIBS ON) +set(BOOST_MIN_VERSION 1.55) + +find_package( Boost ${BOOST_MIN_VERSION} REQUIRED + unit_test_framework + system + ) + +set(PROJECT_TEST_SRCS +${CMAKE_CURRENT_SOURCE_DIR}/ctrl_test.cpp +${CMAKE_CURRENT_SOURCE_DIR}/../OdrModCtrl.cpp +) + +include_directories( ${PROJECT_SOURCE_DIR}/../ ) +link_directories (/usr/local/lib) +add_executable(${PROJECT_NAME} ${PROJECT_TEST_SRCS}) + +target_link_libraries(${PROJECT_NAME} + zmq + ${Boost_LIBRARIES} + ) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") diff --git a/doc/zmq-ctrl/cpp/test/README b/doc/zmq-ctrl/cpp/test/README new file mode 100644 index 0000000..76a1188 --- /dev/null +++ b/doc/zmq-ctrl/cpp/test/README @@ -0,0 +1,14 @@ +Instructions for zmq ctrl api test program + +Dependencies boost, zmq (and cpp binding through zmq.hpp) + +Build instruction (make sure your in the directory of this file) +* mkdir build +* cd build +* cmake ../ +* make + +Run +* make sure the ODR-DABMOD is started and that zmq ctrl api is enabled +* make sure the zmq endpoint matches (see ctrl_test.cpp) +* run the ctrl_test diff --git a/doc/zmq-ctrl/cpp/test/ctrl_test.cpp b/doc/zmq-ctrl/cpp/test/ctrl_test.cpp new file mode 100644 index 0000000..fdfd35a --- /dev/null +++ b/doc/zmq-ctrl/cpp/test/ctrl_test.cpp @@ -0,0 +1,94 @@ +/** + * This is a test program for the zmq ctrl API of the odr-dabmod. + * + * Copyright (c) 2015 by Jörgen Scott (jorgen.scott@paneda.se) + + * This file is part of CtrlTest. + * + * ODR-DabMod 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. + * + * ODR-DabMod 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 ODR-DabMod. If not, see <http://www.gnu.org/licenses/>. + **/ +#define BOOST_TEST_MODULE "C++ unit tests for odr-mod zmq ctrl" +#include <boost/test/unit_test.hpp> +#include "OdrModCtrl.hpp" + + +// Variables used in the test suite +struct TemplateVars +{ + std::string error; + zmq::context_t context; + COdrModCtrl modCtrl; + + // NOTE: Make sure the odr-dabmod is started before running the test and + // that the zmq endpoint matches. + TemplateVars() : context(1), modCtrl(&context, "tcp://127.0.0.1:9400", 1000) {} + ~TemplateVars() {} +}; + +// Note. The odr-mod do not validate parameters therefore there are no tests +// made for setting invalid parameters. +BOOST_FIXTURE_TEST_SUITE(test_template1, TemplateVars) + +BOOST_AUTO_TEST_CASE (Ping) +{ + BOOST_CHECK(modCtrl.Ping() == true); +} + +BOOST_AUTO_TEST_CASE (DigitalGain) +{ + BOOST_CHECK(modCtrl.SetDigitalGain(0.5, error) == true); + double value; + BOOST_CHECK(modCtrl.GetDigitalGain(value, error) == true); + BOOST_CHECK(value == 0.5); +} + +BOOST_AUTO_TEST_CASE (TxGain) +{ + BOOST_CHECK(modCtrl.SetTxGain(50, error) == true); + double value; + BOOST_CHECK(modCtrl.GetTxGain(value, error) == true); + BOOST_CHECK(value == 50); +} + +BOOST_AUTO_TEST_CASE (TxFrequency) +{ + BOOST_CHECK(modCtrl.SetTxFrequency(234208000, error) == true); + double value; + BOOST_CHECK(modCtrl.GetTxFrequency(value, error) == true); + BOOST_CHECK(value == 234208000); +} + +BOOST_AUTO_TEST_CASE (Muting) +{ + BOOST_CHECK(modCtrl.SetMuting(true, error) == true); + bool value; + BOOST_CHECK(modCtrl.GetMuting(value, error) == true); + BOOST_CHECK(value == true); + BOOST_CHECK(modCtrl.SetMuting(false, error) == true); +} + +BOOST_AUTO_TEST_CASE (StaticDelay) +{ + // reset first (by setting out of range value) or else test + // will fail on successive runs + BOOST_CHECK(modCtrl.SetStaticDelay(100000, error) == true); + BOOST_CHECK(modCtrl.SetStaticDelay(45000, error) == true); + uint32_t value; + BOOST_CHECK(modCtrl.GetStaticDelay(value, error) == true); + BOOST_CHECK(value == 45000); +} + + +BOOST_AUTO_TEST_SUITE_END() + |