From 848b4f8e5a2178f96bfcc4b6d10803547bb170e4 Mon Sep 17 00:00:00 2001 From: Robert Karolak Date: Fri, 16 Jan 2015 08:58:02 +0100 Subject: [PATCH] [Messaging] Fixing tests in emails [Verification] More tests passes 253/309 Change-Id: I37fca437e316f3225095784d521bfbc09b4d32c8 Signed-off-by: Robert Karolak --- src/messaging/MsgCommon/Any.cpp | 7 +- src/messaging/message.cc | 13 +++ src/messaging/message_email.cc | 5 + src/messaging/message_service.cc | 2 +- src/messaging/messaging_api.js | 99 ++++++++++++++--- src/messaging/messaging_instance.cc | 158 ++++++++++++---------------- 6 files changed, 180 insertions(+), 104 deletions(-) diff --git a/src/messaging/MsgCommon/Any.cpp b/src/messaging/MsgCommon/Any.cpp index 4f5d450c..ffb45419 100644 --- a/src/messaging/MsgCommon/Any.cpp +++ b/src/messaging/MsgCommon/Any.cpp @@ -66,7 +66,12 @@ bool Any::toBool() const long Any::toLong() const { - return static_cast(m_value.get()); + if(m_value.is()){ + return static_cast(m_value.get()); + } else { + std::string str = m_value.get(); + return strtoul (str.c_str(), NULL, 0); + } } unsigned long Any::toULong() const diff --git a/src/messaging/message.cc b/src/messaging/message.cc index ac3bb480..a69f04d7 100644 --- a/src/messaging/message.cc +++ b/src/messaging/message.cc @@ -141,6 +141,7 @@ TelNetworkDefaultDataSubs_t Message::getSimIndex() const // *** attributes setters void Message::setId(int id) { + LoggerD("Entered"); m_id = id; m_id_set = true; m_body->setMessageId(m_id); @@ -148,12 +149,14 @@ void Message::setId(int id) void Message::setConversationId(int id) { + LoggerD("Entered"); m_conversation_id = id; m_conversation_id_set = true; } void Message::setFolderId(int id) { + LoggerD("Entered"); m_folder_id = id; m_folder_id_set = true; } @@ -162,18 +165,21 @@ void Message::setFolderId(int id) void Message::setTimeStamp(time_t timestamp) { + LoggerD("Entered"); m_timestamp = timestamp; m_timestamp_set = true; } void Message::setFrom(std::string from) { + LoggerD("Entered"); m_from = from; m_from_set = true; } void Message::setTO(std::vector &to) { + LoggerD("Entered"); // Recipient's format validation should be done by Core API service m_to = to; @@ -195,6 +201,7 @@ void Message::setBCC(std::vector &bcc) void Message::setBody(std::shared_ptr& body) { + LoggerD("Entered"); // while replacing message body old body should have some invalid id mark m_body->setMessageId(-1); @@ -206,6 +213,7 @@ void Message::setBody(std::shared_ptr& body) void Message::setIsRead(bool read) { + LoggerD("Entered"); m_is_read = read; } @@ -213,6 +221,7 @@ void Message::setIsRead(bool read) void Message::setIsHighPriority(bool highpriority) { + LoggerD("Entered"); // High priority field is used only in MessageEmail m_high_priority = highpriority; } @@ -224,12 +233,14 @@ void Message::setSubject(std::string subject) void Message::setInResponseTo(int inresp) { + LoggerD("Entered"); m_in_response = inresp; m_in_response_set = true; } void Message::setMessageStatus(MessageStatus status) { + LoggerD("Entered"); m_status = status; } @@ -240,12 +251,14 @@ void Message::setMessageAttachments(AttachmentPtrVector &attachments) void Message::setServiceId(int service_id) { + LoggerD("Entered"); m_service_id = service_id; m_service_id_set = true; } void Message::setSimIndex(TelNetworkDefaultDataSubs_t sim_index) { + LoggerD("Entered"); m_sim_index = sim_index; } diff --git a/src/messaging/message_email.cc b/src/messaging/message_email.cc index b95765bf..a2cf0f13 100644 --- a/src/messaging/message_email.cc +++ b/src/messaging/message_email.cc @@ -24,6 +24,7 @@ MessageEmail::~MessageEmail() // *** overrided methods void MessageEmail::setCC(std::vector &cc) { + LoggerD("Entered"); // CC recipient's format validation should be done by email service m_cc = cc; @@ -35,6 +36,7 @@ void MessageEmail::setCC(std::vector &cc) void MessageEmail::setBCC(std::vector &bcc) { + LoggerD("Entered"); // BCC recipient's format validation should be done by email service m_bcc = bcc; @@ -46,16 +48,19 @@ void MessageEmail::setBCC(std::vector &bcc) void MessageEmail::setSubject(std::string subject) { + LoggerD("Entered"); m_subject = subject; } void MessageEmail::setIsHighPriority(bool highpriority) { + LoggerD("Entered"); m_high_priority = highpriority; } void MessageEmail::setMessageAttachments(AttachmentPtrVector &attachments) { + LoggerD("Entered"); m_attachments = attachments; m_has_attachment = true; diff --git a/src/messaging/message_service.cc b/src/messaging/message_service.cc index 6b9b18e4..c79809d7 100644 --- a/src/messaging/message_service.cc +++ b/src/messaging/message_service.cc @@ -398,7 +398,7 @@ MessageService::~MessageService() picojson::object MessageService::toPicoJS() const { picojson::object picojs = picojson::object(); - picojs[JSON_SERVICE_ID] = picojson::value(static_cast(m_id)); + picojs[JSON_SERVICE_ID] = picojson::value(std::to_string(m_id)); picojs[JSON_SERVICE_TYPE] = picojson::value(MessagingUtil::messageTypeToString(m_msg_type)); picojs[JSON_SERVICE_NAME] = picojson::value(m_name); return picojs; diff --git a/src/messaging/messaging_api.js b/src/messaging/messaging_api.js index 3005e09d..07a0686d 100644 --- a/src/messaging/messaging_api.js +++ b/src/messaging/messaging_api.js @@ -363,7 +363,7 @@ function Message(type, data) { get: function () {return _internal.isHighPriority;}, set: function (value) { if (value instanceof InternalValues_) value = value.isHighPriority; - _internal.isHighPriority = value; + _internal.isHighPriority = !!value; }, enumerable: true } @@ -377,8 +377,7 @@ function Message(type, data) { get: function () {return _internal.subject;}, set: function (value) { if (value instanceof InternalValues_) value = value.subject; - if (typeof value !== 'string') return; - _internal.subject = value; + _internal.subject = String(value); }, enumerable: true } @@ -611,7 +610,7 @@ function MessageAttachment(filePath, mimeType) { if (!this.messageId) { propertyFactory_(this, 'messageId', null, Property.E); } - propertyFactory_(this, 'mimeType', mimeType || '', Property.E); + propertyFactory_(this, 'mimeType', mimeType || null, Property.E); propertyFactory_(this, 'filePath', filePath || '', Property.E); return this; @@ -1353,14 +1352,90 @@ function MessageConversation(data) { }; function MessageFolder(data) { - propertyFactory_(this, 'id' , data.id || null , Property.E ); - propertyFactory_(this, 'parentId' , data.parentId || null , Property.E ); - propertyFactory_(this, 'serviceId' , data.serviceId || '' , Property.E ); - propertyFactory_(this, 'contentType' , data.contentType || '' , Property.E ); - propertyFactory_(this, 'name' , data.name || '' , Property.E | Property.W); // TODO: setraises - propertyFactory_(this, 'path' , data.path || '' , Property.E ); - propertyFactory_(this, 'type' , data.type || '' , Property.E ); - propertyFactory_(this, 'synchronizable', data.synchronizable || false, Property.E | Property.W); // TODO: setraises + var _internal = { + id: data.id || null, + parentId: data.parentId || null, + serviceId: data.serviceId || '', + contentType: data.contentType || '', + name: data.name || '', + path: data.path || '', + type: data.type || '', + synchronizable: data.synchronizable || false + }; + + Object.defineProperty( + this, + 'id', + { + get: function () {return _internal.id;}, + enumerable: true + } + ); + + Object.defineProperty( + this, + 'parentId', + { + get: function () {return _internal.parentId;}, + enumerable: true + } + ); + + Object.defineProperty( + this, + 'serviceId', + { + get: function () {return _internal.serviceId;}, + enumerable: true + } + ); + + Object.defineProperty( + this, + 'contentType', + { + get: function () {return _internal.contentType;}, + enumerable: true + } + ); + + Object.defineProperty( + this, + 'name', + { + get: function () {return _internal.name;}, + set: function (value) { if (value) _internal.name = value;}, + enumerable: true + } + ); + + Object.defineProperty( + this, + 'path', + { + get: function () {return _internal.path;}, + enumerable: true + } + ); + + Object.defineProperty( + this, + 'type', + { + get: function () {return _internal.type;}, + enumerable: true + } + ); + + Object.defineProperty( + this, + 'synchronizable', + { + get: function () {return _internal.synchronizable;}, + set: function (value) { if (value) _internal.synchronizable = value;}, + enumerable: true + } + ); }; tizen.Message = Message; diff --git a/src/messaging/messaging_instance.cc b/src/messaging/messaging_instance.cc index 9c05c7c7..d1b930c6 100644 --- a/src/messaging/messaging_instance.cc +++ b/src/messaging/messaging_instance.cc @@ -6,6 +6,7 @@ #include "messaging_instance.h" #include +#include #include "common/logger.h" @@ -101,6 +102,19 @@ const char* FUN_MESSAGE_STORAGE_REMOVE_CHANGE_LISTENER = "MessageStorage_removeC const char* REMOVE_CHANGE_LISTENER_ARGS_WATCHID = "watchId"; const char* FUNCTIONS_HIDDEN_ARGS_SERVICE_ID = "serviceId"; + +auto getServiceIdFromJSON = [](picojson::object& data) -> int { + std::string serviceStrId; + try { + serviceStrId = + MessagingUtil::getValueFromJSONObject(data,FUNCTIONS_HIDDEN_ARGS_SERVICE_ID); + return std::stoi(serviceStrId); + } + catch(...) { + return -1; + } +}; + } MessagingInstance& MessagingInstance::getInstance() @@ -160,31 +174,6 @@ void MessagingInstance::GetMessageServices(const picojson::value& args, MessagingManager::getInstance().getMessageServices(serviceTag.to_str(), callbackId); } -/* Code used to testing in node.js console - // Define the success callback. - function serviceListCB(services) { - if (services.length > 0) { - var initDictionary = { - subject: "Testing subject", - to: ["r.klepaczko.testmail@gmail.com"], - cc: ["r.klepaczko.testmail@gmail.com"], - bcc: ["r.klepaczko.testmail@gmail.com"], - plainBody: "simple plain body", - htmlBody: "simle html body", - isHightPriority: false - } - msg = new tizen.Message("messaging.email", initDictionary); - msg.attachments = [new tizen.MessageAttachment("images/myimage.png", "image/png")]; - services[0].sendMessage(msg, function(data){ - console.log("Send email success"); - console.dir(data); - }, function(){ - console.log("Send email failed"); - }); - } - } - tizen.messaging.getMessageServices("messaging.email", serviceListCB); - */ void MessagingInstance::MessageServiceSendMessage(const picojson::value& args, picojson::object& out) { @@ -196,8 +185,7 @@ void MessagingInstance::MessageServiceSendMessage(const picojson::value& args, MessageRecipientsCallbackData* callback = new MessageRecipientsCallbackData(); callback->setMessage(MessagingUtil::jsonToMessage(v_message)); - auto serviceId = static_cast - (MessagingUtil::getValueFromJSONObject(data,FUNCTIONS_HIDDEN_ARGS_SERVICE_ID)); + int serviceId = getServiceIdFromJSON(data); callback->setAccountId(serviceId); auto json = std::shared_ptr(new picojson::value(picojson::object())); @@ -232,15 +220,12 @@ void MessagingInstance::MessageServiceLoadMessageBody(const picojson::value& arg MessageBodyCallbackData* callback = new MessageBodyCallbackData(); callback->setMessage(MessagingUtil::jsonToMessage(message)); - auto serviceId = static_cast( - MessagingUtil::getValueFromJSONObject(data, FUNCTIONS_HIDDEN_ARGS_SERVICE_ID)); - auto json = std::shared_ptr(new picojson::value(picojson::object())); picojson::object& obj = json->get(); obj[JSON_CALLBACK_ID] = picojson::value(callbackId); callback->setJson(json); - auto service = MessagingManager::getInstance().getMessageService(serviceId); + auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data)); service->loadMessageBody(callback); } @@ -255,14 +240,12 @@ void MessagingInstance::MessageServiceLoadMessageAttachment(const picojson::valu MessageAttachmentCallbackData* callback = new MessageAttachmentCallbackData(); callback->setMessageAttachment(MessagingUtil::jsonToMessageAttachment(attachment)); - int serviceId = static_cast( - MessagingUtil::getValueFromJSONObject(data, FUNCTIONS_HIDDEN_ARGS_SERVICE_ID)); auto json = std::shared_ptr(new picojson::value(picojson::object())); picojson::object& obj = json->get(); obj[JSON_CALLBACK_ID] = picojson::value(callbackId); callback->setJson(json); - auto service = MessagingManager::getInstance().getMessageService(serviceId); + auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data)); service->loadMessageAttachment(callback); } @@ -276,7 +259,13 @@ void MessagingInstance::MessageServiceSync(const picojson::value& args, picojson::value v_limit = data.at(SYNC_ARGS_LIMIT); const double callbackId = args.get(JSON_CALLBACK_ID).get(); - int id = static_cast(v_id.get()); + int id = -1; + try{ + id = std::stoi(v_id.get()); + } catch(...) { + LoggerE("Problem with MessageService"); + throw common::UnknownException("Problem with MessageService"); + } long limit = 0; if (v_limit.is()) { limit = static_cast(v_limit.get()); @@ -308,7 +297,14 @@ void MessagingInstance::MessageServiceSyncFolder(const picojson::value& args, picojson::value v_limit = data.at(SYNC_FOLDER_ARGS_LIMIT); const double callbackId = args.get(JSON_CALLBACK_ID).get(); - int id = static_cast(v_id.get()); + int id = -1; + try{ + id = std::stoi(v_id.get()); + } catch(...) { + LoggerE("Problem with MessageService"); + throw common::UnknownException("Problem with MessageService"); + } + long limit = 0; if (v_limit.is()) { limit = static_cast(v_limit.get()); @@ -336,44 +332,31 @@ void MessagingInstance::MessageServiceStopSync(const picojson::value& args, LoggerD("Entered"); picojson::object data = args.get(JSON_DATA).get(); - picojson::value v_id = data.at(STOP_SYNC_ARGS_ID); - picojson::value v_op_id = data.at(STOP_SYNC_ARGS_OPID); - - int id = static_cast(v_id.get()); - long op_id = 0; - if (v_op_id.is()) { - op_id = static_cast(v_op_id.get()); + if(data.find(STOP_SYNC_ARGS_ID) != data.end()){ + picojson::value v_id = data.at(STOP_SYNC_ARGS_ID); + picojson::value v_op_id = data.at(STOP_SYNC_ARGS_OPID); + + int id = -1; + try{ + id = std::stoi(v_id.get()); + } catch(...){ + LoggerD("Problem with MessageService"); + throw common::UnknownException("Problem with MessageService"); + } + + long op_id = 0; + if (v_op_id.is()) { + op_id = static_cast(v_op_id.get()); + } + MessagingManager::getInstance().getMessageService(id)->stopSync(op_id); + } else { + LoggerE("Unknown error"); + throw common::UnknownException("Unknown error"); } - MessagingManager::getInstance().getMessageService(id)->stopSync(op_id); - ReportSuccess(out); } -/* Code used to testing in node.js console - // Define the success callback. - function serviceListCB(services) { - if (services.length > 0) { - var initDictionary = { - subject: "Testing subject", - to: ["a.jacak.testmail@gmail.com", "r.klepaczko.testmail@gmail.com"], - cc: ["a.jacak.testmail@gmail.com", "r.klepaczko.testmail@gmail.com"], - bcc: ["a.jacak.testmail@gmail.com", "r.klepaczko.testmail@gmail.com"], - plainBody: "simple plain body", - htmlBody: "simle html body", - isHightPriority: false - } - msg = new tizen.Message("messaging.email", initDictionary); - msg.attachments = [new tizen.MessageAttachment("images/myimage.png", "image/png")]; - services[0].messageStorage.addDraftMessage(msg, function(){ - console.log("Add draft success"); - }, function(){ - console.log("Add draft failed"); - }); - } - } - tizen.messaging.getMessageServices("messaging.email", serviceListCB); - */ void MessagingInstance::MessageStorageAddDraft(const picojson::value& args, picojson::object& out) { @@ -386,7 +369,7 @@ void MessagingInstance::MessageStorageAddDraft(const picojson::value& args, MessageCallbackUserData* callback = new MessageCallbackUserData(); callback->setMessage(MessagingUtil::jsonToMessage(v_message)); - auto serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); + int serviceId = getServiceIdFromJSON(data); callback->setAccountId(serviceId); auto json = std::shared_ptr(new picojson::value(picojson::object())); @@ -416,7 +399,7 @@ void MessagingInstance::MessageStorageFindMessages(const picojson::value& args, long offset = static_cast (MessagingUtil::getValueFromJSONObject(data, FIND_FOLDERS_ARGS_OFFSET)); - int serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); + int serviceId = getServiceIdFromJSON(data); auto storage = MessagingManager::getInstance().getMessageService(serviceId)->getMsgStorage(); FindMsgCallbackUserData* callback = new FindMsgCallbackUserData(); @@ -455,8 +438,7 @@ void MessagingInstance::MessageStorageRemoveMessages(const picojson::value& args obj[JSON_CALLBACK_ID] = picojson::value(callbackId); callback->setJson(json); - int serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); - auto service = MessagingManager::getInstance().getMessageService(serviceId); + auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data)); service->getMsgStorage()->removeMessages(callback); } @@ -483,9 +465,7 @@ void MessagingInstance::MessageStorageUpdateMessages(const picojson::value& args obj[JSON_CALLBACK_ID] = picojson::value(callbackId); callback->setJson(json); - int serviceId = static_cast - (MessagingUtil::getValueFromJSONObject(data,FUNCTIONS_HIDDEN_ARGS_SERVICE_ID)); - auto service = MessagingManager::getInstance().getMessageService(serviceId); + auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data)); service->getMsgStorage()->updateMessages(callback); } @@ -505,7 +485,8 @@ void MessagingInstance::MessageStorageFindConversations(const picojson::value& a (MessagingUtil::getValueFromJSONObject(data, FIND_CONVERSATIONS_ARGS_LIMIT)); long offset = static_cast (MessagingUtil::getValueFromJSONObject(data, FIND_CONVERSATIONS_ARGS_OFFSET)); - int serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); + + int serviceId = getServiceIdFromJSON(data); ConversationCallbackData* callback = new ConversationCallbackData(); callback->setFilter(filter); @@ -543,8 +524,7 @@ void MessagingInstance::MessageStorageRemoveConversations(const picojson::value& obj[JSON_CALLBACK_ID] = picojson::value(callbackId); callback->setJson(json); - int serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); - auto service = MessagingManager::getInstance().getMessageService(serviceId); + auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data)); service->getMsgStorage()->removeConversations(callback); } @@ -556,21 +536,17 @@ void MessagingInstance::MessageStorageFindFolders(const picojson::value& args, picojson::object data = args.get(JSON_DATA).get(); const double callbackId = args.get(JSON_CALLBACK_ID).get(); - // TODO add support to CompositeFilter auto filter = MessagingUtil::jsonToAbstractFilter(data); - int serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); FoldersCallbackData* callback = new FoldersCallbackData(); callback->setFilter(filter); - auto json = std::shared_ptr(new picojson::value(picojson::object())); picojson::object& obj = json->get(); obj[JSON_CALLBACK_ID] = picojson::value(callbackId); callback->setJson(json); - - auto storage = MessagingManager::getInstance().getMessageService(serviceId)->getMsgStorage(); - storage->findFolders(callback); + auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data)); + service->getMsgStorage()->findFolders(callback); } void MessagingInstance::MessageStorageAddMessagesChangeListener(const picojson::value& args, @@ -580,7 +556,8 @@ void MessagingInstance::MessageStorageAddMessagesChangeListener(const picojson:: picojson::object data = args.get(JSON_DATA).get(); const long callbackId = static_cast(args.get(JSON_CALLBACK_ID).get()); - int serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); + int serviceId = getServiceIdFromJSON(data); + auto service = MessagingManager::getInstance().getMessageService(serviceId); std::shared_ptr callback(new MessagesChangeCallback( @@ -601,7 +578,8 @@ void MessagingInstance::MessageStorageAddConversationsChangeListener(const picoj picojson::object data = args.get(JSON_DATA).get(); const long callbackId = static_cast(args.get(JSON_CALLBACK_ID).get()); - int serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); + int serviceId = getServiceIdFromJSON(data); + auto service = MessagingManager::getInstance().getMessageService(serviceId); std::shared_ptr callback(new ConversationsChangeCallback( @@ -622,7 +600,8 @@ void MessagingInstance::MessageStorageAddFolderChangeListener(const picojson::va picojson::object data = args.get(JSON_DATA).get(); const long callbackId = static_cast(args.get(JSON_CALLBACK_ID).get()); - int serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); + int serviceId = getServiceIdFromJSON(data); + auto service = MessagingManager::getInstance().getMessageService(serviceId); std::shared_ptr callback(new FoldersChangeCallback( @@ -644,8 +623,7 @@ void MessagingInstance::MessageStorageRemoveChangeListener(const picojson::value const long watchId = static_cast( data.at(REMOVE_CHANGE_LISTENER_ARGS_WATCHID).get()); - int serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); - auto service = MessagingManager::getInstance().getMessageService(serviceId); + auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data)); service->getMsgStorage()->removeChangeListener(watchId); ReportSuccess(out); -- 2.34.1