--- /dev/null
+#include <stdio.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <glib-unix.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <account.h>
+#include <account-types.h>
+#include <account-error.h>
+#include <time.h>
+#include <sys/time.h>
+#include "util.h"
+
+#define check_fail(exp) \
+ if (!(exp)) { \
+ return true; \
+ }
+
+
+GMainLoop *global_loop = NULL;
+static account_h account = NULL;
+
+const char* user_name = "test_user_name";
+const char* package_name = "account-test";
+const char* display_name = "test_display_name";
+const char* icon_path = "test_icon_path";
+const char* domain_name = "test_domain_name";
+const char* email_address = "test_email_address";
+const char* source = "source";
+const char* key = "key";
+const char* value = "value";
+const char* user_text = "user_text";
+const char* access_token = "test_access_token";
+
+const char* contact_capability = ACCOUNT_SUPPORTS_CAPABILITY_CONTACT;
+
+const account_auth_type_e auth_type = ACCOUNT_AUTH_TYPE_OAUTH;
+const account_capability_state_e capability_state = ACCOUNT_CAPABILITY_ENABLED;
+const account_secrecy_state_e secrecy_state = ACCOUNT_SECRECY_VISIBLE;
+const account_sync_state_e sync_state = ACCOUNT_SYNC_STATUS_OFF;
+
+static void _account_free_text(char *text)
+{
+ if (text != NULL) {
+ free(text);
+ text = NULL;
+ }
+}
+
+
+static bool account_call_back(account_h account, void *user_data)
+{
+ const char* key = "key";
+ char* str = NULL;
+ int value = -1;
+ account_capability_state_e cap_value = 0;
+ account_auth_type_e auth_value = 0;
+ account_secrecy_state_e secret_value = 0;
+ account_sync_state_e sync_value = 0;
+ int ret = ACCOUNT_ERROR_NONE;
+ int i = -1;
+ check_fail(user_data!=NULL);
+ account_h _account = *((account_h*)user_data);
+
+ ret = account_get_package_name(_account, &str);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Package Name : %s\n"_RESET, str);
+ _account_free_text(str);
+
+ ret = account_get_user_name(_account, &str);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] User Name : %s\n"_RESET, str);
+ _account_free_text(str);
+
+ ret = account_get_display_name(_account, &str);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Display Name : %s\n"_RESET, str);
+ _account_free_text(str);
+
+ ret = account_get_icon_path(_account, &str);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Icon Path : %s\n"_RESET, str);
+ _account_free_text(str);
+
+ ret = account_get_domain_name(_account, &str);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Domain Name : %s\n"_RESET, str);
+ _account_free_text(str);
+
+ ret = account_get_email_address(_account, &str);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Email Address : %s\n"_RESET, str);
+ _account_free_text(str);
+
+ ret = account_get_source(_account, &str);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Get Source : %s\n"_RESET, str);
+ _account_free_text(str);
+
+ ret = account_get_custom(_account, key, &str);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Get Custom : %s\n"_RESET, str);
+ _account_free_text(str);
+
+ ret = account_get_capability(_account, contact_capability, &cap_value);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Get Capability : %d\n"_RESET, cap_value);
+
+ ret = account_get_access_token(_account, &str);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Get Access Token : %s\n"_RESET, str);
+ _account_free_text(str);
+
+ for (i = 0; i < 5; i++){
+ ret = account_get_user_text(_account, i, &str);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] User Text : %s\n"_RESET, str);
+ _account_free_text(str);
+ }
+
+ for (i = 0; i < 5; i++){
+ ret = account_get_user_int(_account, i, &value);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] User Int : %d\n"_RESET, value);
+ }
+
+ ret = account_get_auth_type(_account, &auth_value);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Auth Type : %d\n"_RESET, auth_value);
+
+ ret = account_get_secret(_account, &secret_value);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Secret Value : %d\n"_RESET, secret_value);
+
+ ret = account_get_sync_support(_account, &sync_value);
+ check_fail(ret == ACCOUNT_ERROR_NONE);
+ printf(_BOLDCYAN"[Account Callback] Sync Value : %d\n"_RESET, sync_value);
+
+ return true;
+}
+
+
+int account_update_to_db_by_id_test(void)
+{
+ int account_id = -1;
+ int ret = ACCOUNT_ERROR_NONE;
+ char* update_user_name = "update_user_name";
+
+ ret = account_set_user_name(account, user_name);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account User Name\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_package_name(account, package_name);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account User Name\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_insert_to_db(account, &account_id);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account User Name\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_user_name(account, update_user_name);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account User Name\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_update_to_db_by_id(account, account_id);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account User Name\n"_RESET);
+ goto RETURN;
+ }
+
+RETURN:
+
+ if(ACCOUNT_ERROR_NONE != ret) {
+ account_destroy(account);
+ printf(_BOLDCYAN"Fail to account_update_to_db_by_id_test\n"_RESET);
+ }
+
+ return ret;
+}
+
+
+
+
+int account_insert_to_db_test(void)
+{
+ int account_id = -1;
+ int ret = ACCOUNT_ERROR_NONE;
+
+ int i = -1;
+
+ ret = account_set_user_name(account, user_name);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account User Name\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_package_name(account, package_name);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Package Name\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_display_name(account, display_name);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Display Name\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_icon_path(account, icon_path);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Icon Path\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_domain_name(account, domain_name);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Domain Name\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_email_address(account, email_address);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Email Address\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_source(account, source);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Source\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_custom(account, key, value);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Custom\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_capability(account, contact_capability, capability_state);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Capability\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_access_token(account, access_token);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Access Token\n"_RESET);
+ goto RETURN;
+ }
+
+ for (i = 0; i < 5; i++){
+ ret = account_set_user_text(account, i, user_text);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account User Text\n"_RESET);
+ goto RETURN;
+ }
+ }
+
+ for (i = 0; i < 5; i++){
+ ret = account_set_user_int(account, i, i*10);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account User Int\n"_RESET);
+ goto RETURN;
+ }
+ }
+
+ ret = account_set_auth_type(account, auth_type);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Auth Type\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_secret(account, secrecy_state);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Secret\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_set_sync_support(account, sync_state);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to set Account Sync Support\n"_RESET);
+ goto RETURN;
+ }
+
+ ret = account_insert_to_db(account, &account_id);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to Insert to DB\n"_RESET);
+ }
+
+RETURN:
+ if(ACCOUNT_ERROR_NONE != ret) {
+ account_destroy(account);
+ printf(_BOLDCYAN"Fail to account_insert_to_db_test\n"_RESET);
+ }
+
+ return ret;
+}
+
+void print_menu(void)
+{
+ sleep(1);
+ printf(_BOLDRED"\nAccount Test Menu\n"_RESET
+ _GREEN"1.Account Create\n"_RESET
+ _GREEN"2.Insert To DB\n"_RESET
+ _GREEN"3.Update To DB by ID\n"_RESET
+ _GREEN"4.Account Query by User Name\n"_RESET
+ _BOLDGREEN"d.Delete DB by User Name\n"_RESET
+ "q.Exit with Account Destroy:\n");
+}
+
+/* messaging_api_receive_test */
+int account_api_test(void)
+{
+ int ret = ACCOUNT_ERROR_NONE;
+ char a[10];
+
+ while (1) {
+ print_menu();
+ ret = read(0, a, 10);
+
+ switch (a[0]) {
+ case '1':
+ ret = account_create(&account);
+ if(ACCOUNT_ERROR_NONE != ret) {
+ printf(_BOLDCYAN"Fail to create account handle\n"_RESET);
+ }
+ break;
+
+ case '2':
+ if (account != NULL) {
+ ret = account_insert_to_db_test();
+ if(ACCOUNT_ERROR_NONE == ret)
+ printf(_BOLDCYAN"Succeed to Insert to DB Test\n"_RESET);
+ else
+ printf(_BOLDCYAN"Fail to Insert to DB Test\n"_RESET);
+ } else {
+ printf(_BOLDCYAN"Need to Create Account\n"_RESET);
+ }
+ break;
+
+ case '3':
+ if (account != NULL) {
+ ret = account_update_to_db_by_id_test();
+ if(ACCOUNT_ERROR_NONE == ret)
+ printf(_BOLDCYAN"Succeed to Update to DB Test\n"_RESET);
+ else
+ printf(_BOLDCYAN"Fail to Update to DB Test\n"_RESET);
+ } else {
+ printf(_BOLDCYAN"Need to Create Account\n"_RESET);
+ }
+ break;
+
+ case '4':
+ if (account != NULL) {
+ ret = account_query_account_by_user_name(account_call_back, user_name, &account);
+ if(ACCOUNT_ERROR_NONE == ret)
+ printf(_BOLDCYAN"Succeed to Query Account by User Name Test\n"_RESET);
+ else
+ printf(_BOLDCYAN"Fail to Query Account by User Name Test\n"_RESET);
+ } else {
+ printf(_BOLDCYAN"Need to Create Account\n"_RESET);
+ }
+ break;
+
+ case 'd':
+ /* disconnect from push service*/
+ if (account != NULL) {
+ char* user_name_delete = "test_user_name";
+ char* package_name_delete = "account-test";
+ ret = account_delete_from_db_by_user_name(user_name_delete, package_name_delete);
+ if(ACCOUNT_ERROR_NONE == ret)
+ printf(_BOLDCYAN"Succeed to Delete DB by User Name Test\n"_RESET);
+ else
+ printf(_BOLDCYAN"Succeed to Delete DB by User Name Test\n"_RESET);
+ } else {
+ printf(_BOLDCYAN"Need to Create Account\n"_RESET);
+ }
+ break;
+
+ case 'q':
+ account_destroy(account);
+ return 0;
+
+ default:
+ break;
+ }
+
+ }
+}
+
+static gint sigterm_callback(void *data)
+{
+ account_destroy(account);
+
+ printf(_BOLDCYAN"SigTerm\n"_RESET);
+
+ g_main_loop_quit((GMainLoop*)data);
+
+ return FALSE;
+}
+
+void* StartApiTest()
+{
+ int ret = 0;
+
+ ret = account_api_test();
+
+ if (ret)
+ printf(_BOLDCYAN"Test Finished\n"_RESET);
+
+ printf(_BOLDCYAN"Bye\n"_RESET);
+
+ g_main_loop_quit(global_loop);
+ return NULL;
+}
+
+int main(int argc, char **argv)
+{
+ GMainLoop *loop;
+
+ pthread_t thd;
+
+ printf("\n");
+ printf(_YELLOW"############################\n");
+ printf(_YELLOW"######## Account Test ########\n");
+ printf(_YELLOW"############################\n"_RESET);
+
+ /* start transaction manager */
+ if (pthread_create(&thd, NULL, StartApiTest, NULL) != 0)
+ return -1;
+
+ /* mainloop of main thread */
+ global_loop = loop = g_main_loop_new(NULL, FALSE);
+
+ /* installing signal handlers */
+ g_unix_signal_add_full(G_PRIORITY_HIGH, SIGINT, sigterm_callback, loop, NULL);
+ g_unix_signal_add_full(G_PRIORITY_HIGH, SIGTERM, sigterm_callback, loop, NULL);
+
+ /* start application's main loop */
+ g_main_loop_run(loop);
+
+ /* cleanup after mainloop */
+ g_main_loop_unref(loop);
+
+ return 0;
+}
--- /dev/null
+/*
+* Account Test Client
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Contact : Sunghyuk Lee <sunghyuk.lee@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.
+*/
+
+#ifndef __TIZEN_ACCOUNT_TEST_UTIL_H__
+#define __TIZEN_ACCOUNT_TEST_UTIL_H__
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "PUSHTEST"
+
+#define _RESET "\033[0m"
+#define _BLACK "\033[30m" /* Black */
+#define _RED "\033[31m" /* Red */
+#define _GREEN "\033[32m" /* Green */
+#define _YELLOW "\033[33m" /* Yellow */
+#define _BLUE "\033[34m" /* Blue */
+#define _PURPLE "\033[35m" /* Purple */
+#define _CYAN "\033[36m" /* Cyan */
+#define _WHITE "\033[37m" /* White */
+#define _BOLDBLACK "\033[1m\033[30m" /* Bold Black */
+#define _BOLDRED "\033[1m\033[31m" /* Bold Red */
+#define _BOLDGREEN "\033[1m\033[32m" /* Bold Green */
+#define _BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
+#define _BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
+#define _BOLDPURPLE "\033[1m\033[35m" /* Bold Purple */
+#define _BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
+#define _BOLDWHITE "\033[1m\033[37m" /* Bold White */
+
+#define _I(fmt, arg...) do { LOGI(fmt, ##arg); } while (0)
+#define _W(fmt, arg...) do { LOGW(fmt, ##arg); } while (0)
+#define _E(fmt, arg...) do { LOGE(fmt, ##arg); } while (0)
+#define _D(fmt, arg...) do { LOGD(fmt, ##arg); } while (0)
+#define _SE(fmt, arg...) do { LOGE(fmt, ##arg); } while (0)
+#define _SD(fmt, arg...) do { LOGD(fmt, ##arg); } while (0)
+#define _SW(fmt, arg...) do { LOGW(fmt, ##arg); } while (0)
+
+#define _free(p) do { if (p) { free(p); p = NULL; } } while (0)
+#define _FUNC_ENTER do { LOGD("start"); } while (0)
+#define _FUNC_LEAVE do { LOGD("end"); } while (0)
+
+#endif /* __TIZEN_ACCOUNT_TEST_UTIL_H__ */