From 340924fcd3bcf1f0d0ca1e8fd32bfe75b02ab59b Mon Sep 17 00:00:00 2001 From: Rusty Lynch Date: Tue, 10 Sep 2013 11:49:40 -0700 Subject: [PATCH] Add unit test for sending and recieving notifications Change-Id: Id3c6aa1868a9267d3ffea18a5fcb863bec1f3cf0 --- Makefile.am | 10 ++- packaging/notification-service.spec | 11 +++ sample_display_client.c | 64 +++++++++++++++ send_notification.c | 157 ++++++++++++++++++++++++++++++++++++ 4 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 sample_display_client.c create mode 100644 send_notification.c diff --git a/Makefile.am b/Makefile.am index c0b4bbc..5b7257b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -bin_PROGRAMS = notification-service +bin_PROGRAMS = notification-service sample-display-client send-notification AM_CFLAGS = $(GCC_CFLAGS) AM_CPPFLAGS = $(GCC_CFLAGS) @@ -10,6 +10,14 @@ notification_service_SOURCES = \ notification_service_CFLAGS = -I. $(TIZEN_CFLAGS) notification_service_LDADD = $(TIZEN_LIBS) +send_notification_SOURCES = send_notification.c +send_notification_CFLAGS = -I. $(TIZEN_CFLAGS) +send_notification_LDADD = $(TIZEN_LIBS) + +sample_display_client_SOURCES = sample_display_client.c +sample_display_client_CFLAGS = -I. $(TIZEN_CFLAGS) +sample_display_client_LDADD = $(TIZEN_LIBS) + SCRIPT_IN_FILES = \ notifications.service.in \ notifications.socket.in diff --git a/packaging/notification-service.spec b/packaging/notification-service.spec index 4028a2c..d2e8b4d 100644 --- a/packaging/notification-service.spec +++ b/packaging/notification-service.spec @@ -15,6 +15,12 @@ Headless notification service that collects incoming notifications from the the platform, maintains a database of active notifications, and broadcast updates to all listeners. +%package test +Summary: Test clients for %{name} +Group: Application Framework/Notifications +%description test +This package provides unit test used in the development of the notification service. + %prep %setup -q -n %{name}-%{version} @@ -34,3 +40,8 @@ rm -rf %{buildroot} %{_libdir}/systemd/system/notifications.service %{_libdir}/systemd/system/notifications.socket %{_libdir}/systemd/system/sockets.target.wants/notifications.socket + +%files test +%defattr(-,root,root,-) +%{_bindir}/sample-display-client +%{_bindir}/send-notification diff --git a/sample_display_client.c b/sample_display_client.c new file mode 100644 index 0000000..1f449f0 --- /dev/null +++ b/sample_display_client.c @@ -0,0 +1,64 @@ +#include +#include +#include + +static void __noti_changed_cb(void *data, notification_type_e type) +{ + notification_h noti = NULL; + notification_list_h notification_list = NULL; + notification_list_h get_list = NULL; + int count = 0, group_id = 0, priv_id = 0, show_noti = 0, num = 1; + char *pkgname = NULL; + char *title = NULL; + char *str_count = NULL; + int i = 1; + char buf[512] = {0}; + + notification_get_list(NOTIFICATION_TYPE_NOTI, -1, ¬ification_list); + if (notification_list) { + get_list = notification_list_get_head(notification_list); + noti = notification_list_get_data(get_list); + while(get_list != NULL) { + notification_get_id(noti, &group_id, &priv_id); + notification_get_pkgname(noti, &pkgname); + if(pkgname == NULL){ + notification_get_application(noti, &pkgname); + } + + notification_get_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &str_count); + if (!str_count) { + count = 0; + } else { + count = atoi(str_count); + } + notification_get_title(noti, &title, NULL); + + fprintf(stdout, "NOTIFICATION: %s - %s - %i - %i\n", pkgname, title, count, num); + + get_list = notification_list_get_next(get_list); + noti = notification_list_get_data(get_list); + num++; + } + } + if (notification_list != NULL) { + notification_free_list(notification_list); + notification_list = NULL; + } +} + +int +main(int argc, char **argv) +{ + if (!ecore_init()) { + fprintf(stderr, "ERROR: Cannot init Ecore!\n"); + return -1; + } + + notification_resister_changed_cb(__noti_changed_cb, NULL); + ecore_main_loop_begin(); + + shutdown: + ecore_shutdown(); + return 0; +} + diff --git a/send_notification.c b/send_notification.c new file mode 100644 index 0000000..52e5686 --- /dev/null +++ b/send_notification.c @@ -0,0 +1,157 @@ +#include +#include +#include +#include + +const char *error_to_string(notification_error_e error) +{ + if (error == NOTIFICATION_ERROR_INVALID_DATA) + return "NOTIFICATION_ERROR_INVALID_DATA"; + if (error == NOTIFICATION_ERROR_NO_MEMORY) + return "NOTIFICATION_ERROR_NO_MEMORY"; + if (error == NOTIFICATION_ERROR_FROM_DB) + return "NOTIFICATION_ERROR_FROM_DB"; + if (error == NOTIFICATION_ERROR_ALREADY_EXIST_ID) + return "NOTIFICATION_ERROR_ALREADY_EXIST_ID"; + if (error == NOTIFICATION_ERROR_FROM_DBUS) + return "NOTIFICATION_ERROR_FROM_DBUS"; + if (error == NOTIFICATION_ERROR_NOT_EXIST_ID) + return "NOTIFICATION_ERROR_NOT_EXIST_ID"; + if (error == NOTIFICATION_ERROR_IO) + return "NOTIFICATION_ERROR_IO"; + if (error == NOTIFICATION_ERROR_SERVICE_NOT_READY) + return "NOTIFICATION_ERROR_SERVICE_NOT_READY"; + if (error == NOTIFICATION_ERROR_NONE) + return "NOTIFICATION_ERROR_NONE"; + + return "UNHANDLED ERROR"; +} + +static Eina_Bool remove_all(const Ecore_Getopt *parser, + const Ecore_Getopt_Desc *desc, + const char *str, + void *data, + Ecore_Getopt_Value *storage) +{ + notification_error_e err = NOTIFICATION_ERROR_NONE; + + err = notification_delete_all_by_type("SEND_TEST_PKG", NOTIFICATION_TYPE_NOTI); + if (err != NOTIFICATION_ERROR_NONE) { + fprintf(stderr, "Unable to remove notifications: %s\n", error_to_string(err)); + exit(-1); + } + + exit(0); + + // will never reach here + return 0; +} + +static const Ecore_Getopt optdesc = { + "send notification test utility", + NULL, + "0.0", + "(C) 2013 Intel Corp", + "Flora", + "Test utility for sending notifications", + 0, + { + ECORE_GETOPT_STORE_STR('t', "title", "Title"), + ECORE_GETOPT_STORE_STR('c', "content", "Content"), + ECORE_GETOPT_STORE_STR('i', "icon", "Path to icon"), + ECORE_GETOPT_STORE_STR('m', "image", "Path to image"), + ECORE_GETOPT_STORE_INT('y', "imagetype", "Image type enum value"), + ECORE_GETOPT_CALLBACK_NOARGS('r', "removeall", "Remove all notifications", remove_all, NULL), + ECORE_GETOPT_HELP('h', "help"), + ECORE_GETOPT_SENTINEL + } +}; + +int +main(int argc, char **argv) +{ + char *title = NULL; + char *content = NULL; + char *icon = NULL; + char *image = NULL; + int imageType = 0; + Eina_Bool remove = EINA_FALSE; + notification_h noti = NULL; + notification_error_e err = NOTIFICATION_ERROR_NONE; + + Ecore_Getopt_Value values[] = { + ECORE_GETOPT_VALUE_STR(title), + ECORE_GETOPT_VALUE_STR(content), + ECORE_GETOPT_VALUE_STR(icon), + ECORE_GETOPT_VALUE_STR(image), + ECORE_GETOPT_VALUE_INT(imageType), + ECORE_GETOPT_VALUE_NONE + }; + + if (!ecore_init()) { + fprintf(stderr, "ERROR: Cannot init Ecore!\n"); + return -1; + } + + if (ecore_getopt_parse(&optdesc, values, argc, argv) < 0) { + fprintf(stderr, "Parsing arguments failed!\n"); + return -1; + } + + noti = notification_new(NOTIFICATION_TYPE_NOTI, + NOTIFICATION_GROUP_ID_NONE, + NOTIFICATION_PRIV_ID_NONE); + if (noti == NULL) { + fprintf(stderr, "Failed to create notification: %s\n", error_to_string(err)); + return -1; + } + + err = notification_set_pkgname(noti, "SEND_TEST_PKG"); + if (err != NOTIFICATION_ERROR_NONE) { + fprintf(stderr, "Unable to set pkgname: %s\n", error_to_string(err)); + return -1; + } + + err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, + title ? title : "Default Title", + NULL, NOTIFICATION_VARIABLE_TYPE_NONE); + if (err != NOTIFICATION_ERROR_NONE) { + fprintf(stderr, "Unable to set notification title: %s\n", error_to_string(err)); + return -1; + } + + err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, + title ? title : "Default Content", + NULL, NOTIFICATION_VARIABLE_TYPE_NONE); + if (err != NOTIFICATION_ERROR_NONE) { + fprintf(stderr, "Unable to set notification content: %s\n", error_to_string(err)); + return -1; + } + + if (icon) { + err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon); + if (err != NOTIFICATION_ERROR_NONE) { + fprintf(stderr, "Unable to set notification icon path: %s\n", error_to_string(err)); + return -1; + } + } + + if (image) { + err = notification_set_image(noti, imageType, image); + if (err != NOTIFICATION_ERROR_NONE) { + fprintf(stderr, "Unable to set notification image path: %s\n", error_to_string(err)); + return -1; + } + } + + err = notification_insert(noti, NULL); + if (err != NOTIFICATION_ERROR_NONE) { + fprintf(stderr, "Unable to insert notification: %s\n", error_to_string(err)); + return -1; + } + + fprintf(stdout, "Sent Notification > %s : %s : %s : %s : %i\n", + title, content, icon, image, imageType); + return 0; +} + -- 2.7.4