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, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <libsigrokdecode.h> /* First, to avoid compiler warning. */
28 * Check various basic init related things.
30 * - Check whether an srd_init() call with path == NULL works.
31 * If it returns != SRD_OK (or segfaults) this test will fail.
33 * - Check whether a subsequent srd_exit() works.
34 * If it returns != SRD_OK (or segfaults) this test will fail.
36 START_TEST(test_init_exit)
41 fail_unless(ret == SRD_OK, "srd_init() failed: %d.", ret);
43 fail_unless(ret == SRD_OK, "srd_exit() failed: %d.", ret);
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.
53 START_TEST(test_init_exit_2)
58 fail_unless(ret == SRD_OK, "srd_init() 1 failed: %d.", ret);
60 fail_unless(ret != SRD_OK, "srd_init() 2 didn't fail: %d.", ret);
62 fail_unless(ret == SRD_OK, "srd_exit() 2 failed: %d.", ret);
64 fail_unless(ret == SRD_OK, "srd_exit() 1 failed: %d.", ret);
69 * Check whether three nested srd_init()/srd_exit() calls work/fail correctly.
71 START_TEST(test_init_exit_3)
76 fail_unless(ret == SRD_OK, "srd_init() 1 failed: %d.", ret);
78 fail_unless(ret != SRD_OK, "srd_init() 2 didn't fail: %d.", ret);
80 fail_unless(ret != SRD_OK, "srd_init() 3 didn't fail: %d.", ret);
82 fail_unless(ret == SRD_OK, "srd_exit() 3 failed: %d.", ret);
84 fail_unless(ret == SRD_OK, "srd_exit() 2 failed: %d.", ret);
86 fail_unless(ret == SRD_OK, "srd_exit() 1 failed: %d.", ret);
90 Suite *suite_core(void)
95 s = suite_create("core");
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);