speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/1] add set notification all test


From: Andrei Kholodnyi
Subject: [PATCH 1/1] add set notification all test
Date: Tue, 28 Sep 2010 21:54:59 +0200

From: Andrei Kholodnyi <address@hidden>
To: address@hidden

This test sets all notifications to "on" using SPD_ALL
then it sends two messages to receive all notifications
---
 src/tests/Makefile.am                 |    6 +-
 src/tests/spd_set_notifications_all.c |  187 +++++++++++++++++++++++++++++++++
 2 files changed, 192 insertions(+), 1 deletions(-)
 create mode 100644 src/tests/spd_set_notifications_all.c

diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index a4d25a6..98a7ef6 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -4,7 +4,8 @@ c_api = $(top_builddir)/src/api/c
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/api/c
 
-bin_PROGRAMS = long_message clibrary clibrary2 run_test connection_recovery
+bin_PROGRAMS = long_message clibrary clibrary2 run_test connection_recovery \
+               spd_set_notifications_all
 
 long_message_SOURCES = long_message.c
 long_message_LDADD = $(c_api)/libspeechd.la -lpthread $(EXTRA_SOCKET_LIBS)
@@ -19,6 +20,9 @@ connection_recovery_SOURCES = connection-recovery.c
 connection_recovery_LDADD = $(c_api)/libspeechd.la \
        -lpthread $(EXTRA_SOCKET_LIBS)
 
+spd_set_notifications_all_SOURCES = spd_set_notifications_all.c
+spd_set_notifications_all_LDADD = $(c_api)/libspeechd.la -lpthread 
$(EXTRA_SOCKET_LIBS)
+
 run_test_SOURCES = run_test.c
 run_test_LDADD = $(c_api)/libspeechd.la -lpthread $(EXTRA_SOCKET_LIBS)
 
diff --git a/src/tests/spd_set_notifications_all.c 
b/src/tests/spd_set_notifications_all.c
new file mode 100644
index 0000000..a523ddb
--- /dev/null
+++ b/src/tests/spd_set_notifications_all.c
@@ -0,0 +1,187 @@
+/*
+* spd_set_notifications_all.c - test SPD_ALL behaviour
+*
+* Copyright (c) 2010 Andrei Kholodnyi <Andrei.Kholodnyi at gmail.com>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* This program 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 General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "libspeechd.h"
+
+#define TEST_NAME __FILE__
+#define TEST_WAIT_COUNT (100)
+static int notification_mask;
+static SPDConnection *spd;
+
+static const char * events[] ={
+    "SPD_EVENT_BEGIN",
+    "SPD_EVENT_END",
+    "SPD_EVENT_INDEX_MARK",
+    "SPD_EVENT_CANCEL",
+    "SPD_EVENT_PAUSE",
+    "SPD_EVENT_RESUME"
+};
+
+/* Callback for Speech Dispatcher notifications */
+void notification_cb(size_t msg_id, size_t client_id, SPDNotificationType type)
+{
+    notification_mask |= (1 << type);
+    printf("notification %s received for msg_id %d\n", events[type], msg_id);
+}
+
+void index_mark_cb(size_t msg_id, size_t client_id, SPDNotificationType type, 
char *index_mark)
+{
+    notification_mask |= (1 << type);
+    printf("notification %s received for msg_id %d\n", events[type], msg_id);
+}
+
+int main(int argc, char *argv[])
+{
+    int result, count;
+
+    /* Open Speech Dispatcher connection in THREADED mode. */
+    spd = spd_open(TEST_NAME, __FUNCTION__, NULL, SPD_MODE_THREADED);
+    if (!spd) {
+        printf("Speech-dispatcher: Failed to open connection. \n");
+        exit (1);
+    }
+
+    printf("Speech-dispatcher: connection opened. \n");
+
+    spd->callback_begin = notification_cb;
+    spd->callback_end = notification_cb;
+    spd->callback_cancel = notification_cb;
+    spd->callback_pause = notification_cb;
+    spd->callback_resume = notification_cb;
+    spd->callback_im = index_mark_cb;
+
+    /* Ask Speech Dispatcher to notify us about these events. */
+    result = spd_set_notification_on(spd, SPD_ALL);
+    if (result == -1) {
+        printf("Notification SPD_ALL not set correctly \n");
+        exit(1);
+    }
+    printf("Notification SPD_ALL registered \n");
+
+    /* The message is spoken as SSML */
+    result = spd_set_data_mode(spd, SPD_DATA_SSML);
+    if (result == -1) {
+        printf("Could not set spd_set_data_mode() to SPD_DATA_SSML \n");
+        exit(1);
+    }
+
+    result = spd_say(spd, SPD_MESSAGE, "<speak> \
+                                        S S M L or Speech <mark 
name=\"mark1\"/> Synthesis Markup Language is an XML \
+                                        language. \
+                                        </speak>");
+    if (result == -1) {
+        printf("spd_say() failed. \n");
+        exit(1);
+    }
+    printf("msg_id %d sent to test SPD_BEGIN, SPD_PAUSE, "
+           "SPD_RESUME, SPD_INDEX_MARKS and SPD_END notifications\n", result);
+
+    count = 0;
+    while (~notification_mask & SPD_BEGIN) {
+       sleep(1);
+        if (count++ == TEST_WAIT_COUNT) {
+            printf("SPD_BEGIN wait count exceeded \n");
+            exit(1);
+       }
+    }
+
+    result = spd_pause(spd);
+    if (result == -1) {
+        printf("spd_pause() failed. \n");
+        exit(1);
+    }
+
+    count = 0;
+    while (~notification_mask & SPD_PAUSE) {
+       sleep(1);
+        if (count++ == TEST_WAIT_COUNT) {
+            printf("SPD_PAUSE wait count exceeded \n");
+            exit(1);
+       }
+    }
+
+    result = spd_resume(spd);
+    if (result == -1) {
+        printf("spd_resume() failed. \n");
+        exit(1);
+    }
+
+    count = 0;
+    while (~notification_mask & SPD_RESUME) {
+       sleep(1);
+        if (count++ == TEST_WAIT_COUNT) {
+            printf("SPD_PAUSE wait count exceeded \n");
+            exit(1);
+       }
+    }
+
+    count = 0;
+    while (~notification_mask & SPD_INDEX_MARKS) {
+       sleep(1);
+        if (count++ == TEST_WAIT_COUNT) {
+            printf("SPD_INDEX_MARKS wait count exceeded \n");
+            exit(1);
+       }
+    }
+
+    count = 0;
+    while (~notification_mask & SPD_END) {
+       sleep(1);
+        if (count++ == TEST_WAIT_COUNT) {
+            printf("SPD_END wait count exceeded \n");
+            exit(1);
+       }
+    }
+
+    result = spd_say(spd, SPD_MESSAGE, "<speak> \
+                                        S S M L or Speech <mark 
name=\"mark1\"/> Synthesis Markup Language is an XML \
+                                        language. \
+                                        </speak>");
+    if (result == -1) {
+        printf("spd_say() failed. \n");
+        exit(1);
+    }
+    printf("msg_id %d sent to test SPD_CANCEL notification\n", result);
+
+    result = spd_cancel(spd);
+    if (result == -1) {
+        printf("spd_cancel() failed. \n");
+        exit(1);
+    }
+
+    count = 0;
+    while (~notification_mask & SPD_CANCEL) {
+       sleep(1);
+        if (count++ == TEST_WAIT_COUNT) {
+            printf("SPD_CANCEL wait count exceeded \n");
+            exit(1);
+       }
+    }
+
+    printf("All notifications received. \n");
+
+    spd_close(spd);
+    printf("Speech-dispatcher: connection closed. \n");
+
+    exit(0);
+}
-- 
1.6.0.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]