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