From 0fcb6fe1dd3f73bfb0828b15ba86889e265ed9d9 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 1 Feb 2018 16:07:48 +0100 Subject: [PATCH] Fixed CPIM tests --- src/chat/chat-room/abstract-chat-room.h | 2 ++ src/chat/chat-room/basic-chat-room.h | 4 +-- src/chat/chat-room/client-group-chat-room.cpp | 8 +++++ src/chat/chat-room/client-group-chat-room.h | 4 ++- src/chat/chat-room/proxy-chat-room.cpp | 8 +++++ src/chat/chat-room/proxy-chat-room.h | 2 ++ .../chat-room/server-group-chat-room-stub.cpp | 8 +++++ src/chat/chat-room/server-group-chat-room.h | 2 ++ tester/cpim-tester.cpp | 30 +++++++++++++++++-- 9 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/chat/chat-room/abstract-chat-room.h b/src/chat/chat-room/abstract-chat-room.h index 06064e177..46f5aec29 100644 --- a/src/chat/chat-room/abstract-chat-room.h +++ b/src/chat/chat-room/abstract-chat-room.h @@ -51,6 +51,8 @@ public: typedef EnumMask CapabilitiesMask; + virtual void allowCpim (bool value) = 0; + virtual void allowMultipart (bool value) = 0; virtual bool canHandleCpim () const = 0; virtual bool canHandleMultipart () const = 0; diff --git a/src/chat/chat-room/basic-chat-room.h b/src/chat/chat-room/basic-chat-room.h index 86b7e76d3..e66aceba0 100644 --- a/src/chat/chat-room/basic-chat-room.h +++ b/src/chat/chat-room/basic-chat-room.h @@ -33,8 +33,8 @@ class LINPHONE_PUBLIC BasicChatRoom : public ChatRoom { friend class CorePrivate; public: - void allowCpim (bool value); - void allowMultipart (bool value); + void allowCpim (bool value) override; + void allowMultipart (bool value) override; bool canHandleCpim () const override; bool canHandleMultipart () const override; diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index b47d33188..b21c5920b 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -205,6 +205,14 @@ shared_ptr ClientGroupChatRoom::getCore () const { return ChatRoom::getCore(); } +void ClientGroupChatRoom::allowCpim (bool value) { + +} + +void ClientGroupChatRoom::allowMultipart (bool value) { + +} + bool ClientGroupChatRoom::canHandleCpim () const { return true; } diff --git a/src/chat/chat-room/client-group-chat-room.h b/src/chat/chat-room/client-group-chat-room.h index cc547cd39..dc518e6e3 100644 --- a/src/chat/chat-room/client-group-chat-room.h +++ b/src/chat/chat-room/client-group-chat-room.h @@ -56,7 +56,9 @@ public: ); std::shared_ptr getCore () const; - + + void allowCpim (bool value) override; + void allowMultipart (bool value) override; bool canHandleCpim () const override; bool canHandleMultipart () const override; diff --git a/src/chat/chat-room/proxy-chat-room.cpp b/src/chat/chat-room/proxy-chat-room.cpp index 3ad94ae82..bf984d2a1 100644 --- a/src/chat/chat-room/proxy-chat-room.cpp +++ b/src/chat/chat-room/proxy-chat-room.cpp @@ -298,6 +298,14 @@ const IdentityAddress &ProxyChatRoom::getConferenceAddress () const { // ----------------------------------------------------------------------------- +void ProxyChatRoom::allowCpim (bool value) { + +} + +void ProxyChatRoom::allowMultipart (bool value) { + +} + bool ProxyChatRoom::canHandleCpim () const { L_D(); return d->chatRoom->canHandleCpim(); diff --git a/src/chat/chat-room/proxy-chat-room.h b/src/chat/chat-room/proxy-chat-room.h index 1f2a3ce4b..16a5c49aa 100644 --- a/src/chat/chat-room/proxy-chat-room.h +++ b/src/chat/chat-room/proxy-chat-room.h @@ -75,6 +75,8 @@ public: const IdentityAddress &getConferenceAddress () const override; + void allowCpim (bool value) override; + void allowMultipart (bool value) override; bool canHandleCpim () const override; bool canHandleMultipart () const override; diff --git a/src/chat/chat-room/server-group-chat-room-stub.cpp b/src/chat/chat-room/server-group-chat-room-stub.cpp index 13e54827d..6375740f7 100644 --- a/src/chat/chat-room/server-group-chat-room-stub.cpp +++ b/src/chat/chat-room/server-group-chat-room-stub.cpp @@ -125,6 +125,14 @@ ServerGroupChatRoom::CapabilitiesMask ServerGroupChatRoom::getCapabilities () co return 0; } +void ServerGroupChatRoom::allowCpim (bool value) { + +} + +void ServerGroupChatRoom::allowMultipart (bool value) { + +} + bool ServerGroupChatRoom::canHandleCpim () const { return true; } diff --git a/src/chat/chat-room/server-group-chat-room.h b/src/chat/chat-room/server-group-chat-room.h index c63604dd0..bd480533c 100644 --- a/src/chat/chat-room/server-group-chat-room.h +++ b/src/chat/chat-room/server-group-chat-room.h @@ -47,6 +47,8 @@ public: std::shared_ptr getCore () const; + void allowCpim (bool value) override; + void allowMultipart (bool value) override; bool canHandleCpim () const override; bool canHandleMultipart () const override; diff --git a/tester/cpim-tester.cpp b/tester/cpim-tester.cpp index ce36ef05a..a98ca133d 100644 --- a/tester/cpim-tester.cpp +++ b/tester/cpim-tester.cpp @@ -389,17 +389,40 @@ static void build_message () { BC_ASSERT_STRING_EQUAL(strMessage.c_str(), expectedMessage.c_str()); } +static int fake_im_encryption_engine_process_incoming_message_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room, LinphoneChatMessage *msg) { + BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_content_type(msg), ContentType::Cpim.asString().c_str()); // Encryption is the first receiving step, so this message should be CPIM + return -1; +} + +static int fake_im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room, LinphoneChatMessage *msg) { + BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_content_type(msg), ContentType::Cpim.asString().c_str()); // Encryption is the last sending step, so this message should be CPIM + return -1; +} + static void cpim_chat_message_modifier_base(bool_t use_multipart) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); LpConfig *config = linphone_core_get_config(marie->lc); + + // We use a fake encryption engine just to check the internal content type during the sending/receiving process + LinphoneImEncryptionEngine *marie_imee = linphone_im_encryption_engine_new(); + LinphoneImEncryptionEngineCbs *marie_cbs = linphone_im_encryption_engine_get_callbacks(marie_imee); + LinphoneImEncryptionEngine *pauline_imee = linphone_im_encryption_engine_new(); + LinphoneImEncryptionEngineCbs *pauline_cbs = linphone_im_encryption_engine_get_callbacks(pauline_imee); + linphone_im_encryption_engine_cbs_set_process_outgoing_message(marie_cbs, fake_im_encryption_engine_process_outgoing_message_cb); + linphone_im_encryption_engine_cbs_set_process_incoming_message(pauline_cbs, fake_im_encryption_engine_process_incoming_message_cb); + linphone_core_set_im_encryption_engine(marie->lc, marie_imee); + linphone_core_set_im_encryption_engine(pauline->lc, pauline_imee); + lp_config_set_int(config, "sip", "use_cpim", 1); IdentityAddress paulineAddress(linphone_address_as_string_uri_only(pauline->identity)); shared_ptr marieRoom = marie->lc->cppPtr->getOrCreateBasicChatRoom(paulineAddress); + marieRoom->allowCpim(true); shared_ptr marieMessage = marieRoom->createChatMessage("Hello CPIM"); if (use_multipart) { + marieRoom->allowMultipart(true); Content *content = new Content(); content->setContentType(ContentType::PlainText); content->setBody("Hello Part 2"); @@ -408,14 +431,17 @@ static void cpim_chat_message_modifier_base(bool_t use_multipart) { marieMessage->send(); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageReceived,1)); - BC_ASSERT_TRUE(marieMessage->getInternalContent().getContentType() == ContentType::Cpim); + BC_ASSERT_STRING_EQUAL(marieMessage->getInternalContent().getContentType().asString().c_str(), ""); // Internal content is cleaned after message is sent or received BC_ASSERT_PTR_NOT_NULL(pauline->stat.last_received_chat_message); if (pauline->stat.last_received_chat_message != NULL) { BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_text(pauline->stat.last_received_chat_message), "Hello CPIM"); - BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_content_type(pauline->stat.last_received_chat_message), "text/plain"); + BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_content_type(pauline->stat.last_received_chat_message), ContentType::PlainText.asString().c_str()); } + linphone_im_encryption_engine_unref(marie_imee); + linphone_im_encryption_engine_unref(pauline_imee); + linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }