]> sigrok.org Git - pulseview.git/blob - test/data/decoder.cpp
8ea5d181b73eb4f3d97ff3eab5f10500136db68e
[pulseview.git] / test / data / decoder.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <boost/test/unit_test.hpp>
22
23 #include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
24
25 #include <libsigrok/libsigrok.h>
26
27 #include "../../pv/devicemanager.h"
28 #include "../../pv/sigsession.h"
29 #include "../../pv/view/signal.h"
30
31 using namespace boost;
32 using namespace std;
33
34 BOOST_AUTO_TEST_SUITE(DecoderTest)
35
36 BOOST_AUTO_TEST_CASE(TwoDecoder)
37 {
38         sr_context *ctx = NULL;
39
40         BOOST_REQUIRE(sr_init(&ctx) == SR_OK);
41         BOOST_REQUIRE(ctx);
42
43         BOOST_REQUIRE(srd_init(NULL) == SRD_OK);
44
45         srd_decoder_load_all();
46
47         {
48                 pv::DeviceManager dm(ctx);
49                 pv::SigSession ss(dm);
50
51                 const GSList *l = srd_decoder_list();
52                 BOOST_REQUIRE(l);
53                 srd_decoder *const dec = (struct srd_decoder*)l->data;
54                 BOOST_REQUIRE(dec);
55
56                 map<const srd_probe*, shared_ptr<pv::view::Signal> > probes;
57                 BOOST_CHECK (ss.add_decoder(dec, probes,
58                         g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
59                                 (GDestroyNotify)g_variant_unref)));
60
61                 BOOST_CHECK (ss.add_decoder(dec, probes,
62                         g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
63                                 (GDestroyNotify)g_variant_unref)));
64         }
65
66
67         srd_exit();
68         sr_exit(ctx);
69 }
70
71 BOOST_AUTO_TEST_SUITE_END()