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