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