From: Joel Holdsworth Date: Tue, 15 Oct 2013 11:35:00 +0000 (+0100) Subject: Added initial decoder unit test X-Git-Tag: pulseview-0.2.0~243 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3b3a445c072df27ae4e1831f6078467d84baa425;p=pulseview.git Added initial decoder unit test --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e383d713..a8f152c1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,34 +18,101 @@ ## along with this program. If not, see . ## +list(APPEND PKGDEPS + libsigrok>=0.2.0 + libsigrokdecode>=0.2.0 +) + +find_package(PkgConfig) +pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS}) + # Find the platform's thread library (needed for boost-thread). # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value. find_package(Threads) find_package(Boost 1.46 COMPONENTS system unit_test_framework REQUIRED) +#FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 qmake-mac) +find_package(Qt4 REQUIRED) + set(pulseview_TEST_SOURCES + ${PROJECT_SOURCE_DIR}/pv/devicemanager.cpp + ${PROJECT_SOURCE_DIR}/pv/sigsession.cpp + ${PROJECT_SOURCE_DIR}/pv/view/cursorpair.cpp + ${PROJECT_SOURCE_DIR}/pv/data/analog.cpp ${PROJECT_SOURCE_DIR}/pv/data/analogsnapshot.cpp - ${PROJECT_SOURCE_DIR}/pv/data/snapshot.cpp + ${PROJECT_SOURCE_DIR}/pv/data/decoder.cpp + ${PROJECT_SOURCE_DIR}/pv/data/logic.cpp ${PROJECT_SOURCE_DIR}/pv/data/logicsnapshot.cpp + ${PROJECT_SOURCE_DIR}/pv/data/snapshot.cpp + ${PROJECT_SOURCE_DIR}/pv/data/signaldata.cpp + ${PROJECT_SOURCE_DIR}/pv/view/analogsignal.cpp + ${PROJECT_SOURCE_DIR}/pv/view/cursor.cpp + ${PROJECT_SOURCE_DIR}/pv/view/cursorpair.cpp + ${PROJECT_SOURCE_DIR}/pv/view/decodesignal.cpp + ${PROJECT_SOURCE_DIR}/pv/view/header.cpp + ${PROJECT_SOURCE_DIR}/pv/view/logicsignal.cpp + ${PROJECT_SOURCE_DIR}/pv/view/marginwidget.cpp + ${PROJECT_SOURCE_DIR}/pv/view/ruler.cpp + ${PROJECT_SOURCE_DIR}/pv/view/selectableitem.cpp + ${PROJECT_SOURCE_DIR}/pv/view/signal.cpp + ${PROJECT_SOURCE_DIR}/pv/view/timemarker.cpp + ${PROJECT_SOURCE_DIR}/pv/view/trace.cpp + ${PROJECT_SOURCE_DIR}/pv/view/tracepalette.cpp + ${PROJECT_SOURCE_DIR}/pv/view/view.cpp + ${PROJECT_SOURCE_DIR}/pv/view/viewport.cpp + ${PROJECT_SOURCE_DIR}/pv/view/decode/annotation.cpp + ${PROJECT_SOURCE_DIR}/pv/widgets/colourbutton.cpp + ${PROJECT_SOURCE_DIR}/pv/widgets/colourpopup.cpp + ${PROJECT_SOURCE_DIR}/pv/widgets/popup.cpp + ${PROJECT_SOURCE_DIR}/pv/widgets/wellarray.cpp data/analogsnapshot.cpp + data/decoder.cpp data/logicsnapshot.cpp test.cpp ) +# This list includes only QObject derrived class headers +set(pulseview_TEST_HEADERS + ${PROJECT_SOURCE_DIR}/pv/sigsession.h + ${PROJECT_SOURCE_DIR}/pv/data/decoder.h + ${PROJECT_SOURCE_DIR}/pv/view/cursor.h + ${PROJECT_SOURCE_DIR}/pv/view/decodesignal.h + ${PROJECT_SOURCE_DIR}/pv/view/header.h + ${PROJECT_SOURCE_DIR}/pv/view/logicsignal.h + ${PROJECT_SOURCE_DIR}/pv/view/marginwidget.h + ${PROJECT_SOURCE_DIR}/pv/view/ruler.h + ${PROJECT_SOURCE_DIR}/pv/view/selectableitem.h + ${PROJECT_SOURCE_DIR}/pv/view/signal.h + ${PROJECT_SOURCE_DIR}/pv/view/timemarker.h + ${PROJECT_SOURCE_DIR}/pv/view/trace.h + ${PROJECT_SOURCE_DIR}/pv/view/view.h + ${PROJECT_SOURCE_DIR}/pv/view/viewport.h + ${PROJECT_SOURCE_DIR}/pv/widgets/colourbutton.h + ${PROJECT_SOURCE_DIR}/pv/widgets/colourpopup.h + ${PROJECT_SOURCE_DIR}/pv/widgets/wellarray.h +) + +qt4_wrap_cpp(pulseview_TEST_HEADERS_MOC ${pulseview_TEST_HEADERS}) + add_definitions(-DBOOST_TEST_DYN_LINK) +add_definitions(${QT_DEFINITIONS}) include_directories( ${Boost_INCLUDE_DIRS} + ${PKGDEPS_INCLUDE_DIRS} ) set(PULSEVIEW_LINK_LIBS ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + ${PKGDEPS_LIBRARIES} + ${QT_LIBRARIES} ) add_executable(pulseview-test ${pulseview_TEST_SOURCES} + ${pulseview_TEST_HEADERS_MOC} ) target_link_libraries(pulseview-test ${PULSEVIEW_LINK_LIBS}) diff --git a/test/data/decoder.cpp b/test/data/decoder.cpp new file mode 100644 index 00000000..8ea5d181 --- /dev/null +++ b/test/data/decoder.cpp @@ -0,0 +1,71 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include /* First, so we avoid a _POSIX_C_SOURCE warning. */ + +#include + +#include "../../pv/devicemanager.h" +#include "../../pv/sigsession.h" +#include "../../pv/view/signal.h" + +using namespace boost; +using namespace std; + +BOOST_AUTO_TEST_SUITE(DecoderTest) + +BOOST_AUTO_TEST_CASE(TwoDecoder) +{ + sr_context *ctx = NULL; + + BOOST_REQUIRE(sr_init(&ctx) == SR_OK); + BOOST_REQUIRE(ctx); + + BOOST_REQUIRE(srd_init(NULL) == SRD_OK); + + srd_decoder_load_all(); + + { + pv::DeviceManager dm(ctx); + pv::SigSession ss(dm); + + const GSList *l = srd_decoder_list(); + BOOST_REQUIRE(l); + srd_decoder *const dec = (struct srd_decoder*)l->data; + BOOST_REQUIRE(dec); + + map > probes; + BOOST_CHECK (ss.add_decoder(dec, probes, + g_hash_table_new_full(g_str_hash, g_str_equal, g_free, + (GDestroyNotify)g_variant_unref))); + + BOOST_CHECK (ss.add_decoder(dec, probes, + g_hash_table_new_full(g_str_hash, g_str_equal, g_free, + (GDestroyNotify)g_variant_unref))); + } + + + srd_exit(); + sr_exit(ctx); +} + +BOOST_AUTO_TEST_SUITE_END()