diff options
Diffstat (limited to 'src/test-pull.c')
-rw-r--r-- | src/test-pull.c | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/src/test-pull.c b/src/test-pull.c index 993b7a3..281b8c4 100644 --- a/src/test-pull.c +++ b/src/test-pull.c @@ -1,3 +1,23 @@ +/*** + This file is part of libsydney. + + Copyright 2007-2008 Lennart Poettering + + libsydney is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 2.1 of the + License, or (at your option) any later version. + + libsydney is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with libsydney. If not, see + <http://www.gnu.org/licenses/>. +***/ + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -11,22 +31,11 @@ #include "sydney.h" #include "macro.h" -#define ASSERT_SUCCESS(x) do { \ - int _r; \ - if ((_r = x)) { \ - fprintf(stderr, "Operation <%s> failed: %s%s%s\n", \ - #x, \ - sa_strerror(_r), \ - _r == SA_ERROR_SYSTEM ? "; " : "", _r == SA_ERROR_SYSTEM ? strerror(errno) : ""); \ - } \ - assert(_r == SA_SUCCESS); \ -} while(0) - #define FREQ 440 static const float data[4] = { 0.0, 1.0, 0.0, -1.0 }; -static int callback(sa_stream_t *s, sa_event_t e) { +static int callback(sa_stream *s, sa_event_t e) { switch (e) { case SA_EVENT_INIT_THREAD: printf("Thread initialized.\n"); @@ -34,7 +43,7 @@ static int callback(sa_stream_t *s, sa_event_t e) { case SA_EVENT_ERROR: { int err; - ASSERT_SUCCESS(sa_stream_get_event_error(s, &err)); + sa_assert_se(sa_stream_get_event_error(s, &err) == 0); printf("Error: %s\n", sa_strerror(err)); return -1; } @@ -45,9 +54,10 @@ static int callback(sa_stream_t *s, sa_event_t e) { case SA_EVENT_REQUEST_IO: - ASSERT_SUCCESS(sa_stream_write(s, data, sizeof(data))); + sa_assert_se(sa_stream_write(s, data, sizeof(data)) == 0); return 0; + case SA_EVENT_XRUN: case _SA_EVENT_MAX: ; } @@ -57,21 +67,21 @@ static int callback(sa_stream_t *s, sa_event_t e) { int main(int argc, char *argv[]) { - sa_stream_t *s; + sa_stream *s; - ASSERT_SUCCESS(sa_stream_create_pcm(&s, "Sine Test (pull)", SA_MODE_WRONLY, SA_PCM_FORMAT_FLOAT32_NE, FREQ * 4, 1)); - ASSERT_SUCCESS(sa_stream_change_device(s, "/dev/dsp1")); - ASSERT_SUCCESS(sa_stream_open(s)); + sa_assert_se(sa_stream_create_pcm(&s, SA_MODE_WRONLY, SA_PCM_FORMAT_FLOAT32_NE, FREQ * 4, 1) == 0); + sa_assert_se(sa_stream_change_device(s, "/dev/dsp1") == 0); + sa_assert_se(sa_stream_open(s) == 0); - ASSERT_SUCCESS(sa_stream_start_thread(s, callback)); +/* sa_assert_se(sa_stream_start_thread(s, callback)); */ sleep(20); - ASSERT_SUCCESS(sa_stream_stop_thread(s)); +/* sa_assert_se(sa_stream_stop_thread(s)); */ - ASSERT_SUCCESS(sa_stream_drain(s)); + sa_assert_se(sa_stream_drain(s) == 0); - ASSERT_SUCCESS(sa_stream_destroy(s)); + sa_assert_se(sa_stream_destroy(s) == 0); return 0; } |