2 * This file is part of the libsigrokdecode project.
4 * Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
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, see <http://www.gnu.org/licenses/>.
21 #include <libsigrokdecode.h> /* First, to avoid compiler warning. */
27 * Check whether srd_inst_new() works.
28 * If it returns NULL (or segfaults) this test will fail.
30 START_TEST(test_inst_new
)
32 struct srd_session
*sess
;
33 struct srd_decoder_inst
*inst
;
35 srd_init(DECODERS_TESTDIR
);
36 srd_decoder_load("uart");
37 srd_session_new(&sess
);
38 inst
= srd_inst_new(sess
, "uart", NULL
);
39 fail_unless(inst
!= NULL
, "srd_inst_new() failed.");
45 * Check whether multiple srd_inst_new() calls work.
46 * If any of them returns NULL (or segfaults) this test will fail.
48 START_TEST(test_inst_new_multiple
)
50 struct srd_session
*sess
;
51 struct srd_decoder_inst
*inst1
, *inst2
, *inst3
;
53 inst1
= inst2
= inst3
= NULL
;
55 srd_init(DECODERS_TESTDIR
);
56 srd_decoder_load_all();
57 srd_session_new(&sess
);
59 /* Multiple srd_inst_new() calls must work. */
60 inst1
= srd_inst_new(sess
, "uart", NULL
);
61 fail_unless(inst1
!= NULL
, "srd_inst_new() 1 failed.");
62 inst2
= srd_inst_new(sess
, "spi", NULL
);
63 fail_unless(inst2
!= NULL
, "srd_inst_new() 2 failed.");
64 inst3
= srd_inst_new(sess
, "can", NULL
);
65 fail_unless(inst3
!= NULL
, "srd_inst_new() 3 failed.");
67 /* The returned instance pointers must not be the same. */
68 fail_unless(inst1
!= inst2
);
69 fail_unless(inst1
!= inst3
);
70 fail_unless(inst2
!= inst3
);
72 /* Each instance must have another py_inst than any of the others. */
73 fail_unless(inst1
->py_inst
!= inst2
->py_inst
);
74 fail_unless(inst1
->py_inst
!= inst3
->py_inst
);
75 fail_unless(inst2
->py_inst
!= inst3
->py_inst
);
82 * Check whether srd_inst_option_set() works for an empty options hash.
83 * If it returns != SRD_OK (or segfaults) this test will fail.
85 START_TEST(test_inst_option_set_empty
)
88 struct srd_session
*sess
;
89 struct srd_decoder_inst
*inst
;
92 srd_init(DECODERS_TESTDIR
);
93 srd_decoder_load_all();
94 srd_session_new(&sess
);
95 inst
= srd_inst_new(sess
, "uart", NULL
);
96 options
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
,
97 (GDestroyNotify
)g_variant_unref
);
98 ret
= srd_inst_option_set(inst
, options
);
99 fail_unless(ret
== SRD_OK
, "srd_inst_option_set() with empty options "
100 "hash failed: %d.", ret
);
106 * Check whether srd_inst_option_set() works for bogus options.
107 * If it returns != SRD_OK (or segfaults) this test will fail.
109 START_TEST(test_inst_option_set_bogus
)
112 struct srd_session
*sess
;
113 struct srd_decoder_inst
*inst
;
116 srd_init(DECODERS_TESTDIR
);
117 srd_decoder_load_all();
118 srd_session_new(&sess
);
119 inst
= srd_inst_new(sess
, "uart", NULL
);
121 options
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
,
122 (GDestroyNotify
)g_variant_unref
);
125 ret
= srd_inst_option_set(NULL
, options
);
126 fail_unless(ret
!= SRD_OK
, "srd_inst_option_set() with NULL "
127 "instance failed: %d.", ret
);
129 /* NULL 'options' GHashTable. */
130 ret
= srd_inst_option_set(inst
, NULL
);
131 fail_unless(ret
!= SRD_OK
, "srd_inst_option_set() with NULL "
132 "options hash failed: %d.", ret
);
134 /* NULL instance and NULL 'options' GHashTable. */
135 ret
= srd_inst_option_set(NULL
, NULL
);
136 fail_unless(ret
!= SRD_OK
, "srd_inst_option_set() with NULL "
137 "instance and NULL options hash failed: %d.", ret
);
143 Suite
*suite_inst(void)
148 s
= suite_create("inst");
150 tc
= tcase_create("new");
151 tcase_add_checked_fixture(tc
, srdtest_setup
, srdtest_teardown
);
152 tcase_add_test(tc
, test_inst_new
);
153 tcase_add_test(tc
, test_inst_new_multiple
);
154 suite_add_tcase(s
, tc
);
156 tc
= tcase_create("option");
157 tcase_add_checked_fixture(tc
, srdtest_setup
, srdtest_teardown
);
158 tcase_add_test(tc
, test_inst_option_set_empty
);
159 tcase_add_test(tc
, test_inst_option_set_bogus
);
160 suite_add_tcase(s
, tc
);