From f34aee7e4c87c6215f568fdbe32a74dad0529daa Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 20 Jun 2013 11:38:49 +0200 Subject: [PATCH] Add unit test for presence information. --- tester/liblinphone_tester.h | 1 + tester/presence_tester.c | 81 ++++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 391769030..5d9b5b49c 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -151,6 +151,7 @@ typedef struct _stats { int number_of_LinphonePresenceActivityVacation; int number_of_LinphonePresenceActivityWorking; int number_of_LinphonePresenceActivityWorship; + LinphonePresenceModel *last_received_presence; int number_of_inforeceived; int number_of_inforeceived_with_body; diff --git a/tester/presence_tester.c b/tester/presence_tester.c index bcef76879..e7122659f 100644 --- a/tester/presence_tester.c +++ b/tester/presence_tester.c @@ -43,7 +43,6 @@ void new_subscribtion_request(LinphoneCore *lc, LinphoneFriend *lf, const char * void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) { stats* counters; - LinphonePresenceModel* presence; LinphonePresenceActivity activity = LinphonePresenceActivityOffline; char* from=linphone_address_as_string(linphone_friend_get_address(lf)); ms_message("New Notify request from [%s] ",from); @@ -51,8 +50,8 @@ void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) { counters = get_stats(lc); counters->number_of_NotifyReceived++; - presence = linphone_friend_get_presence_model(lf); - linphone_presence_model_get_activity(presence, &activity, NULL); + counters->last_received_presence = linphone_friend_get_presence_model(lf); + linphone_presence_model_get_activity(counters->last_received_presence, &activity, NULL); switch(activity) { case LinphonePresenceActivityOffline: counters->number_of_LinphonePresenceActivityOffline++; break; @@ -115,26 +114,28 @@ void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) { } } +static void wait_core(LinphoneCore *core) { + int i; + + for (i = 0; i < 10; i++) { + linphone_core_iterate(core); + ms_usleep(100000); + } +} + static void simple_publish(void) { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneProxyConfig* proxy; LinphonePresenceModel* presence; - int i=0; + linphone_core_get_default_proxy(marie->lc,&proxy); linphone_proxy_config_edit(proxy); linphone_proxy_config_enable_publish(proxy,TRUE); linphone_proxy_config_done(proxy); - for (i=0;i<10;i++) { - linphone_core_iterate(marie->lc); - ms_usleep(100000); - } - presence = linphone_core_get_presence_model(marie->lc); - linphone_presence_model_set_activity(presence,LinphonePresenceActivityOffline,NULL); + wait_core(marie->lc); + presence =linphone_presence_model_new_with_activity(LinphonePresenceActivityOffline,NULL); linphone_core_set_presence_model(marie->lc,0,NULL,presence); - for (i=0;i<10;i++) { - linphone_core_iterate(marie->lc); - ms_usleep(100000); - } + wait_core(marie->lc); linphone_core_manager_destroy(marie); } @@ -205,11 +206,63 @@ static void call_with_presence(void) { linphone_core_manager_destroy(pauline); } +static void presence_information(void) { + const char *bike_description = "Riding my bike"; + const char *vacation_note = "I'm on vacation until July 4th"; + const char *vacation_lang = "en"; + LinphoneCoreManager *marie = presence_linphone_core_manager_new("marie"); + LinphoneCoreManager *pauline = presence_linphone_core_manager_new("pauline"); + LinphonePresenceModel *presence; + LinphonePresenceActivity activity = LinphonePresenceActivityOffline; + char *description = NULL; + char *note = NULL; + + CU_ASSERT_TRUE(subscribe_to_callee_presence(marie, pauline)); + + /* Presence activity without description. */ + presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityDinner, NULL); + linphone_core_set_presence_model(pauline->lc, 0, NULL, presence); + wait_core(marie->lc); + CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityDinner, 1); + linphone_presence_model_get_activity(marie->stat.last_received_presence, &activity, &description); + CU_ASSERT_EQUAL(activity, LinphonePresenceActivityDinner); + CU_ASSERT_PTR_NULL(description); + + /* Presence activity with description. */ + presence = linphone_presence_model_new_with_activity(LinphonePresenceActivitySteering, bike_description); + linphone_core_set_presence_model(pauline->lc, 0, NULL, presence); + wait_core(marie->lc); + CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivitySteering, 1); + linphone_presence_model_get_activity(marie->stat.last_received_presence, &activity, &description); + CU_ASSERT_EQUAL(activity, LinphonePresenceActivitySteering); + CU_ASSERT_PTR_NOT_NULL(description); + if (description != NULL) CU_ASSERT_EQUAL(strcmp(description, bike_description), 0); + + /* Presence activity with description and note. */ + presence = linphone_presence_model_new_with_activity_and_note(LinphonePresenceActivityVacation, NULL, vacation_note, vacation_lang); + linphone_core_set_presence_model(pauline->lc, 0, NULL, presence); + wait_core(marie->lc); + CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityVacation, 1); + linphone_presence_model_get_activity(marie->stat.last_received_presence, &activity, &description); + CU_ASSERT_EQUAL(activity, LinphonePresenceActivityVacation); + CU_ASSERT_PTR_NULL(description); + note = linphone_presence_model_get_note(marie->stat.last_received_presence, NULL); + CU_ASSERT_PTR_NOT_NULL(note); + if (note != NULL) { + CU_ASSERT_EQUAL(strcmp(note, vacation_note), 0); + ms_free(note); + } + + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); +} + test_t presence_tests[] = { { "Simple Subscribe", simple_subscribe }, { "Simple Publish", simple_publish }, { "Call with Presence", call_with_presence }, { "Unsubscribe while subscribing", unsubscribe_while_subscribing }, + { "Presence information", presence_information }, }; test_suite_t presence_test_suite = {