2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
22 #include <boost/test/unit_test.hpp>
24 #include <libsigrok/libsigrok.h>
26 #include "../../pv/data/decoder.h"
27 #include "../../pv/devicemanager.h"
28 #include "../../pv/sigsession.h"
29 #include "../../pv/view/decodesignal.h"
31 using namespace boost;
34 BOOST_AUTO_TEST_SUITE(DecoderTest)
36 BOOST_AUTO_TEST_CASE(TwoDecoder)
40 sr_context *ctx = NULL;
42 BOOST_REQUIRE(sr_init(&ctx) == SR_OK);
45 BOOST_REQUIRE(srd_init(NULL) == SRD_OK);
47 srd_decoder_load_all();
50 pv::DeviceManager dm(ctx);
51 pv::SigSession ss(dm);
53 const GSList *l = srd_decoder_list();
55 srd_decoder *const dec = (struct srd_decoder*)l->data;
58 map<const srd_probe*, shared_ptr<view::LogicSignal> > probes;
59 ss.add_decoder(dec, probes,
60 g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
61 (GDestroyNotify)g_variant_unref));
63 ss.add_decoder(dec, probes,
64 g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
65 (GDestroyNotify)g_variant_unref));
67 // Check the signals were created
68 const vector< shared_ptr<view::DecodeSignal> > sigs =
69 ss.get_decode_signals();
71 shared_ptr<data::Decoder> dec0 = sigs[0]->decoder();
74 shared_ptr<data::Decoder> dec1 = sigs[0]->decoder();
77 // Wait for the decode threads to complete
78 dec0->_decode_thread.join();
79 dec1->_decode_thread.join();
81 // Check there were no errors
82 BOOST_CHECK_EQUAL(dec0->error_message().isEmpty(), true);
83 BOOST_CHECK_EQUAL(dec1->error_message().isEmpty(), true);
91 BOOST_AUTO_TEST_SUITE_END()