2 * This file is part of the libsigrok project.
4 * Copyright (C) 2014 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
23 #include "../include/libsigrok/libsigrok.h"
26 static struct sr_context *sr_ctx;
28 static void setup(void)
32 ret = sr_init(&sr_ctx);
33 fail_unless(ret == SR_OK, "sr_init() failed: %d.", ret);
36 static void teardown(void)
40 ret = sr_exit(sr_ctx);
41 fail_unless(ret == SR_OK, "sr_exit() failed: %d.", ret);
45 * Check whether sr_session_new() works.
46 * If it returns != SR_OK (or segfaults) this test will fail.
48 START_TEST(test_session_new)
51 struct sr_session *sess;
53 ret = sr_session_new(&sess);
54 fail_unless(ret == SR_OK, "sr_session_new() failed: %d.", ret);
55 sr_session_destroy(sess);
60 * Check whether sr_session_new() fails for bogus parameters.
61 * If it returns SR_OK (or segfaults) this test will fail.
63 START_TEST(test_session_new_bogus)
67 ret = sr_session_new(NULL);
68 fail_unless(ret != SR_OK, "sr_session_new(NULL) worked.");
73 * Check whether multiple sr_session_new() calls work.
74 * If any call returns != SR_OK (or segfaults) this test will fail.
76 START_TEST(test_session_new_multiple)
79 struct sr_session *sess1, *sess2, *sess3;
81 sess1 = sess2 = sess3 = NULL;
83 /* Multiple sr_session_new() calls must work. */
84 ret = sr_session_new(&sess1);
85 fail_unless(ret == SR_OK, "sr_session_new() 1 failed: %d.", ret);
86 ret = sr_session_new(&sess2);
87 fail_unless(ret == SR_OK, "sr_session_new() 2 failed: %d.", ret);
88 ret = sr_session_new(&sess3);
89 fail_unless(ret == SR_OK, "sr_session_new() 3 failed: %d.", ret);
91 /* The returned session pointers must all be non-NULL. */
92 fail_unless(sess1 != NULL);
93 fail_unless(sess2 != NULL);
94 fail_unless(sess3 != NULL);
96 /* The returned session pointers must not be the same. */
97 fail_unless(sess1 != sess2);
98 fail_unless(sess1 != sess3);
99 fail_unless(sess2 != sess3);
101 /* Destroying any of the sessions must work. */
102 ret = sr_session_destroy(sess1);
103 fail_unless(ret == SR_OK, "sr_session_destroy() 1 failed: %d.", ret);
104 ret = sr_session_destroy(sess2);
105 fail_unless(ret == SR_OK, "sr_session_destroy() 2 failed: %d.", ret);
106 ret = sr_session_destroy(sess3);
107 fail_unless(ret == SR_OK, "sr_session_destroy() 3 failed: %d.", ret);
112 * Check whether sr_session_destroy() works.
113 * If it returns != SR_OK (or segfaults) this test will fail.
115 START_TEST(test_session_destroy)
118 struct sr_session *sess;
120 sr_session_new(&sess);
121 ret = sr_session_destroy(sess);
122 fail_unless(ret == SR_OK, "sr_session_destroy() failed: %d.", ret);
127 * Check whether sr_session_destroy() fails for bogus sessions.
128 * If it returns SR_OK (or segfaults) this test will fail.
130 START_TEST(test_session_destroy_bogus)
134 ret = sr_session_destroy(NULL);
135 fail_unless(ret != SR_OK, "sr_session_destroy() worked.");
139 Suite *suite_session(void)
144 s = suite_create("session");
146 tc = tcase_create("new_destroy");
147 tcase_add_checked_fixture(tc, setup, teardown);
148 tcase_add_test(tc, test_session_new);
149 tcase_add_test(tc, test_session_new_bogus);
150 tcase_add_test(tc, test_session_new_multiple);
151 tcase_add_test(tc, test_session_destroy);
152 tcase_add_test(tc, test_session_destroy_bogus);
153 suite_add_tcase(s, tc);