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