]> sigrok.org Git - libsigrokdecode.git/blob - tests/check_core.c
Remove unreasonable test
[libsigrokdecode.git] / tests / check_core.c
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 static void setup(void)
26 {
27         /* Silence libsigrokdecode while the unit tests run. */
28         srd_log_loglevel_set(SRD_LOG_NONE);
29 }
30
31 static void teardown(void)
32 {
33 }
34
35 /*
36  * Check various basic init related things.
37  *
38  *  - Check whether an srd_init() call with path == NULL works.
39  *    If it returns != SRD_OK (or segfaults) this test will fail.
40  *
41  *  - Check whether a subsequent srd_exit() works.
42  *    If it returns != SRD_OK (or segfaults) this test will fail.
43  */
44 START_TEST(test_init_exit)
45 {
46         int ret;
47
48         ret = srd_init(NULL);
49         fail_unless(ret == SRD_OK, "srd_init() failed: %d.", ret);
50         ret = srd_exit();
51         fail_unless(ret == SRD_OK, "srd_exit() failed: %d.", ret);
52 }
53 END_TEST
54
55 /*
56  * Check whether nested srd_init()/srd_exit() calls work/fail correctly.
57  * Two consecutive srd_init() calls without any srd_exit() inbetween are
58  * not allowed and should fail. However, two consecutive srd_exit() calls
59  * are currently allowed, the second one will just be a NOP basically.
60  */
61 START_TEST(test_init_exit_2)
62 {
63         int ret;
64
65         ret = srd_init(NULL);
66         fail_unless(ret == SRD_OK, "srd_init() 1 failed: %d.", ret);
67         ret = srd_init(NULL);
68         fail_unless(ret != SRD_OK, "srd_init() 2 didn't fail: %d.", ret);
69         ret = srd_exit();
70         fail_unless(ret == SRD_OK, "srd_exit() 2 failed: %d.", ret);
71         ret = srd_exit();
72         fail_unless(ret == SRD_OK, "srd_exit() 1 failed: %d.", ret);
73 }
74 END_TEST
75
76 /*
77  * Check whether three nested srd_init()/srd_exit() calls work/fail correctly.
78  */
79 START_TEST(test_init_exit_3)
80 {
81         int ret;
82
83         ret = srd_init(NULL);
84         fail_unless(ret == SRD_OK, "srd_init() 1 failed: %d.", ret);
85         ret = srd_init(NULL);
86         fail_unless(ret != SRD_OK, "srd_init() 2 didn't fail: %d.", ret);
87         ret = srd_init(NULL);
88         fail_unless(ret != SRD_OK, "srd_init() 3 didn't fail: %d.", ret);
89         ret = srd_exit();
90         fail_unless(ret == SRD_OK, "srd_exit() 3 failed: %d.", ret);
91         ret = srd_exit();
92         fail_unless(ret == SRD_OK, "srd_exit() 2 failed: %d.", ret);
93         ret = srd_exit();
94         fail_unless(ret == SRD_OK, "srd_exit() 1 failed: %d.", ret);
95 }
96 END_TEST
97
98 Suite *suite_core(void)
99 {
100         Suite *s;
101         TCase *tc;
102
103         s = suite_create("core");
104
105         tc = tcase_create("init_exit");
106         tcase_add_checked_fixture(tc, setup, teardown);
107         tcase_add_test(tc, test_init_exit);
108         tcase_add_test(tc, test_init_exit_2);
109         tcase_add_test(tc, test_init_exit_3);
110         suite_add_tcase(s, tc);
111
112         return s;
113 }