]> sigrok.org Git - pulseview.git/commitdiff
Added initial decoder unit test
authorJoel Holdsworth <redacted>
Tue, 15 Oct 2013 11:35:00 +0000 (12:35 +0100)
committerJoel Holdsworth <redacted>
Tue, 15 Oct 2013 22:10:48 +0000 (23:10 +0100)
test/CMakeLists.txt
test/data/decoder.cpp [new file with mode: 0644]

index e383d7138c2fb3ef5852fc19f5713978d886a484..a8f152c165cf710bf64825bb4bed87f1793f75b6 100644 (file)
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ##
 
+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 (file)
index 0000000..8ea5d18
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 <boost/test/unit_test.hpp>
+
+#include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
+
+#include <libsigrok/libsigrok.h>
+
+#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<const srd_probe*, shared_ptr<pv::view::Signal> > 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()