1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
* This file is part of the libsigrokdecode project.
*
* Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
*
* 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 "../libsigrokdecode.h" /* First, to avoid compiler warning. */
#include <stdlib.h>
#include <check.h>
/*
* Check whether srd_decoder_load_all() works.
* If it returns != SRD_OK (or segfaults) this test will fail.
*/
START_TEST(test_load_all)
{
int ret;
srd_init(NULL);
ret = srd_decoder_load_all();
fail_unless(ret == SRD_OK, "srd_decoder_load_all() failed: %d.", ret);
srd_exit();
}
END_TEST
/*
* Check whether srd_decoder_load() works.
* If it returns != SRD_OK (or segfaults) this test will fail.
*/
START_TEST(test_load)
{
int ret;
srd_init(NULL);
ret = srd_decoder_load("uart");
fail_unless(ret == SRD_OK, "srd_decoder_load(uart) failed: %d.", ret);
ret = srd_decoder_load("spi");
fail_unless(ret == SRD_OK, "srd_decoder_load(spi) failed: %d.", ret);
ret = srd_decoder_load("usb_signalling");
fail_unless(ret == SRD_OK, "srd_decoder_load(usb_signalling) failed: %d.", ret);
srd_exit();
}
END_TEST
/*
* Check whether srd_decoder_load() fails for non-existing or bogus PDs.
* If it returns SRD_OK (or segfaults) this test will fail.
*/
START_TEST(test_load_bogus)
{
srd_init(NULL);
fail_unless(srd_decoder_load(NULL) != SRD_OK);
fail_unless(srd_decoder_load("") != SRD_OK);
fail_unless(srd_decoder_load(" ") != SRD_OK);
fail_unless(srd_decoder_load("nonexisting") != SRD_OK);
fail_unless(srd_decoder_load("UART") != SRD_OK);
fail_unless(srd_decoder_load("UaRt") != SRD_OK);
fail_unless(srd_decoder_load("u a r t") != SRD_OK);
fail_unless(srd_decoder_load("uart ") != SRD_OK);
fail_unless(srd_decoder_load(" uart") != SRD_OK);
fail_unless(srd_decoder_load(" uart ") != SRD_OK);
fail_unless(srd_decoder_load("uart spi") != SRD_OK);
srd_exit();
}
END_TEST
Suite *suite_decoder(void)
{
Suite *s;
TCase *tc;
s = suite_create("decoder");
tc = tcase_create("load");
tcase_add_test(tc, test_load_all);
tcase_add_test(tc, test_load);
tcase_add_test(tc, test_load_bogus);
suite_add_tcase(s, tc);
return s;
}
|