summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyuho Jo <kyuho.jo@samsung.com>2015-04-06 16:56:09 +0900
committerKyuho Jo <kyuho.jo@samsung.com>2015-04-06 17:05:03 +0900
commit44e2f4831958f38840103e2c96868b108293c761 (patch)
tree465ddc70f16679eb581b2d89f9e0189604e76ee0
parent460c4b6f72d112add8a53b37d4111e3cae12dc74 (diff)
downloadnotification-44e2f4831958f38840103e2c96868b108293c761.tar.gz
notification-44e2f4831958f38840103e2c96868b108293c761.tar.bz2
notification-44e2f4831958f38840103e2c96868b108293c761.zip
Test application for notification API
Change-Id: I3995828c1d097be29549015c0c336e2e811d46ac Signed-off-by: Kyuho Jo <kyuho.jo@samsung.com>
-rwxr-xr-xCMakeLists.txt2
-rwxr-xr-xtest-app/CMakeLists.txt44
-rwxr-xr-xtest-app/main.c392
3 files changed, 438 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b406607..53ec145 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,6 +13,8 @@ SET(DBFILE ".notification.db")
SET(MAJOR_VER 0)
SET(VERSION ${MAJOR_VER}.1.0)
+ADD_SUBDIRECTORY(test-app)
+
SET(SRCS
./src/notification.c
./src/notification_noti.c
diff --git a/test-app/CMakeLists.txt b/test-app/CMakeLists.txt
new file mode 100755
index 0000000..6e53af2
--- /dev/null
+++ b/test-app/CMakeLists.txt
@@ -0,0 +1,44 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(notification C)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Debug")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+MESSAGE("")
+MESSAGE(">>> current directory: ${CMAKE_CURRENT_SOURCE_DIR}")
+MESSAGE(">>> Build type: ${CMAKE_BUILD_TYPE}")
+
+SET(VISIBILITY "-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VISIBILITY} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections")
+
+##########################################################
+# Define Test App
+##########################################################
+
+SET(TEST-APP-SRCS
+ ${CMAKE_SOURCE_DIR}/test-app/main.c
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/include
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(test_app_pkgs REQUIRED glib-2.0 gthread-2.0 vconf appsvc capi-appfw-application)
+
+FOREACH(flag ${test_app_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+ADD_EXECUTABLE(notification-test-app ${TEST-APP-SRCS})
+TARGET_LINK_LIBRARIES(notification-test-app ${test_app_pkgs_LDFLAGS} notification)
+
+# INSTALL(TARGETS notification-test-app DESTINATION bin)
+
diff --git a/test-app/main.c b/test-app/main.c
new file mode 100755
index 0000000..e132f2f
--- /dev/null
+++ b/test-app/main.c
@@ -0,0 +1,392 @@
+/*
+ * Test application for notification API
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Kyuho Jo <kyuho.jo@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+/* common header */
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+/* open header */
+#include <glib.h>
+
+/* notification header */
+#include <notification.h>
+#include <notification_status.h>
+
+/*-----------------------------------------------------------------------------------------*/
+/* types */
+typedef enum testapp_menu_type {
+ TESTAPP_MENU_TYPE_MAIN_MENU = 1,
+ TESTAPP_MENU_TYPE_BASIC_TEST_MENU = 2,
+} testapp_menu_type_e;
+
+/*-----------------------------------------------------------------------------------------*/
+/* function prototypes */
+static void testapp_system_signal_handler (int signal_number);
+void testapp_show_prompt (testapp_menu_type_e menu);
+
+/*-----------------------------------------------------------------------------------------*/
+/* implementation */
+void testapp_print (char *fmt, ...)
+{
+ va_list args = {0};
+ va_start(args, fmt);
+ vfprintf (stdout, fmt, args);
+ va_end (args);
+ fflush (stdout);
+}
+
+static gboolean testapp_initialize_testing ()
+{
+ struct timeval tv_1, tv_2;
+ int interval;
+
+ /* register signal handler */
+ if ( signal (SIGINT, testapp_system_signal_handler) == SIG_ERR ) {
+ testapp_print ("register signal handler fail\n");
+ return FALSE;
+ }
+
+ if ( signal (SIGQUIT, testapp_system_signal_handler) == SIG_ERR ) {
+ testapp_print ("register signal handler fail\n");
+ return FALSE;
+ }
+
+ if ( signal (SIGTSTP, testapp_system_signal_handler) == SIG_ERR ) {
+ testapp_print ("register signal handler fail\n");
+ return FALSE;
+ }
+
+ if ( signal (SIGTERM, testapp_system_signal_handler) == SIG_ERR ) {
+ testapp_print ("register signal handler fail\n");
+ return FALSE;
+ }
+
+
+ gettimeofday(&tv_1, NULL);
+
+ /* TODO : initializing notification */
+
+ gettimeofday(&tv_2, NULL);
+ interval = tv_2.tv_usec - tv_1.tv_usec;
+ testapp_print("\t Initializing Proceed time %d us\n",interval);
+
+
+ return TRUE;
+}
+
+static gboolean testapp_finalize_testing ()
+{
+ /* TODO : finalizing notification */
+
+ return TRUE;
+}
+
+static void testapp_system_signal_handler (int signal_number)
+{
+ testapp_print ("signal:%d\n", signal_number);
+ switch (signal_number) {
+ case SIGQUIT:
+ case SIGINT:
+ case SIGTSTP:
+ case SIGTERM:
+ testapp_finalize_testing();
+ break;
+
+ default:
+ testapp_print ("unhandled signal:%d\n", signal_number);
+ break;
+ }
+ exit(0);
+}
+
+
+
+
+void testapp_show_menu (testapp_menu_type_e menu)
+{
+ switch (menu) {
+ case TESTAPP_MENU_TYPE_MAIN_MENU:
+ testapp_print ("==========================================\n");
+ testapp_print (" Notification test application \n");
+ testapp_print ("==========================================\n");
+ testapp_print ("1. Basic Test\n");
+ testapp_print ("0. Exit \n");
+ testapp_print ("------------------------------------------\n");
+ break;
+ case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
+ testapp_print ("==========================================\n");
+ testapp_print (" Basic test menu \n");
+ testapp_print ("==========================================\n");
+ testapp_print (" 1. Post a simple notification\n");
+ testapp_print (" 2. Post simple notifications repeatedly\n");
+ testapp_print (" 3. Post a notification on indicator\n");
+ testapp_print (" 4. Post status status message\n");
+ testapp_print ("------------------------------------------\n");
+ break;
+ default:
+ break;
+ }
+}
+/* Common { ------------------------------------------------------------------*/
+
+static int testapp_add_a_notification()
+{
+ notification_h noti_handle = NULL;
+ int noti_err = NOTIFICATION_ERROR_NONE;
+
+ noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
+
+ if (noti_handle == NULL) {
+ testapp_print("notification_create failed");
+ goto FINISH_OFF;
+ }
+
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "3", "3", NOTIFICATION_VARIABLE_TYPE_NONE);
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_1, "I'm Info 1", "INFO_1", NOTIFICATION_VARIABLE_TYPE_NONE);
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, "I'm Info Sub 1", "INFO_SUB_1", NOTIFICATION_VARIABLE_TYPE_NONE);
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_2, "I'm Info 2", "INFO_2", NOTIFICATION_VARIABLE_TYPE_NONE);
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, "I'm Info Sub 2", "INFO_SUB_2", NOTIFICATION_VARIABLE_TYPE_NONE);
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_3, "I'm Info 3", "INFO_3", NOTIFICATION_VARIABLE_TYPE_NONE);
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_SUB_3, "I'm Info Sub 3", "INFO_SUB_3", NOTIFICATION_VARIABLE_TYPE_NONE);
+
+ noti_err = notification_post(noti_handle);
+
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ testapp_print("notification_post failed[%d]", noti_err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if (noti_handle)
+ notification_free(noti_handle);
+
+ return noti_err;
+}
+
+/* Common } ------------------------------------------------------------------*/
+
+/* Basic Test { --------------------------------------------------------------*/
+static int testapp_test_post_notification()
+{
+ int err = NOTIFICATION_ERROR_NONE;
+
+ if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
+ testapp_print("testapp_add_a_notification failed[%d]", err);
+ goto FINISH_OFF;
+ }
+
+
+FINISH_OFF:
+
+ return err;
+}
+
+static int testapp_test_post_notifications()
+{
+ int err = NOTIFICATION_ERROR_NONE;
+ int repeat_count = 0;
+ int i = 0;
+
+ testapp_print("Input count : ");
+
+ if (0 >= scanf("%d", &repeat_count))
+ testapp_print("Invalid input");
+
+ for (i = 0; i < repeat_count; i++) {
+ if ((err = testapp_add_a_notification()) != NOTIFICATION_ERROR_NONE) {
+ testapp_print("testapp_add_a_notification failed[%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+
+
+FINISH_OFF:
+ return err;
+}
+
+static int testapp_test_post_notification_on_indicator()
+{
+ notification_h noti_handle = NULL;
+ int noti_err = NOTIFICATION_ERROR_NONE;
+
+ noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
+
+ if (noti_handle == NULL) {
+ testapp_print("notification_create failed");
+ goto FINISH_OFF;
+ }
+
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "TITLE", NOTIFICATION_VARIABLE_TYPE_NONE);
+ noti_err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, "I'm Content", "CONTENT", NOTIFICATION_VARIABLE_TYPE_NONE);
+
+ noti_err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_INDICATOR);
+
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ testapp_print("notification_set_display_applist failed[%d]", noti_err);
+ goto FINISH_OFF;
+ }
+
+ noti_err = notification_post(noti_handle);
+
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ testapp_print("notification_post failed[%d]", noti_err);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+ if (noti_handle)
+ notification_free(noti_handle);
+
+ return noti_err;
+}
+
+static int testapp_test_post_status_message()
+{
+ int noti_err = NOTIFICATION_ERROR_NONE;
+
+
+ noti_err = notification_status_message_post("This is only a test");
+
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ testapp_print("notification_status_message_post failed[%d]", noti_err);
+ }
+
+ return noti_err;
+}
+
+
+
+static gboolean testapp_interpret_command_basic_test (int selected_number)
+{
+ gboolean go_to_loop = TRUE;
+
+ switch (selected_number) {
+ case 1:
+ testapp_test_post_notification();
+ break;
+
+ case 2:
+ testapp_test_post_notifications();
+ break;
+
+ case 3:
+ testapp_test_post_notification_on_indicator();
+ break;
+
+ case 4:
+ testapp_test_post_status_message();
+ break;
+
+ case 0:
+ go_to_loop = FALSE;
+ break;
+
+ default:
+ break;
+ }
+
+ return go_to_loop;
+
+}
+
+void testapp_notification_main ()
+{
+ gboolean go_to_loop = TRUE;
+ int menu_number = 0;
+
+ while (go_to_loop) {
+ testapp_show_menu (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
+ testapp_show_prompt (TESTAPP_MENU_TYPE_BASIC_TEST_MENU);
+
+ if (0 >= scanf("%d", &menu_number))
+ testapp_print("Invalid input");
+
+ go_to_loop = testapp_interpret_command_basic_test(menu_number);
+ }
+}
+/* Basic Test } ---------------------------------------------------------------*/
+
+
+/* Main { ---------------------------------------------------------------------*/
+static gboolean testapp_interpret_command (int menu_number)
+{
+ gboolean go_to_loop = TRUE;
+
+ switch (menu_number) {
+ case 1:
+ testapp_notification_main();
+ break;
+
+ case 0:
+ go_to_loop = FALSE;
+ break;
+
+ default:
+ break;
+ }
+
+ return go_to_loop;
+}
+
+void testapp_show_prompt (testapp_menu_type_e menu)
+{
+ switch (menu) {
+ case TESTAPP_MENU_TYPE_MAIN_MENU:
+ testapp_print ("[MAIN]# ");
+ break;
+
+ case TESTAPP_MENU_TYPE_BASIC_TEST_MENU:
+ testapp_print ("[BASIC_TEST]# ");
+ break;
+ }
+}
+
+int main (int argc, char *argv[])
+{
+ gboolean go_to_loop = TRUE;
+ int menu_number = 0;
+
+ if ( testapp_initialize_testing() == FALSE ) {
+ testapp_print ("Initializing failed.\n");
+ exit(0);
+ }
+
+ while (go_to_loop) {
+ testapp_show_menu (TESTAPP_MENU_TYPE_MAIN_MENU);
+ testapp_show_prompt (TESTAPP_MENU_TYPE_MAIN_MENU);
+ if (0 >= scanf ("%d", &menu_number))
+ testapp_print("Invalid input");
+ go_to_loop = testapp_interpret_command (menu_number);
+ }
+
+ testapp_finalize_testing();
+
+ exit(0);
+}
+/* Main } ---------------------------------------------------------------------*/
+