From 5e06398490f80ab0fbb2d7ea495ee566cd2b2acf Mon Sep 17 00:00:00 2001 From: Rafal Galka Date: Mon, 29 Dec 2014 15:59:54 +0100 Subject: [PATCH] [Contact] TCT fixes [Verification] Following TCT should pass: - ContactManager_get_personId_invalid - ContactManager_getAddressBook_addressBookId_invalid - ContactManager_remove_personId_invalid - AddressBook_get_id_invalid - AddressBook_getGroup_groupId_invalid - AddressBook_remove_id_invalid - AddressBook_removeGroup_groupId_invalid - AddressBook_removeGroup_invalid_argument - AddressBook_updateGroup_invalid_argument - Person_link_personId_invalid - Person_unlink_contactId_invalid Change-Id: If93d0c5abfe188409d31735a38146247ca7f0ca6 --- src/contact/addressbook.cc | 56 +++++-------- src/contact/contact_manager.cc | 18 ++-- src/contact/js/tizen.contact.AddressBook.js | 82 +++++++++++-------- .../js/tizen.contact.ContactManager.js | 62 ++++++++------ src/contact/js/tizen.contact.Person.js | 38 +++++---- 5 files changed, 132 insertions(+), 124 deletions(-) diff --git a/src/contact/addressbook.cc b/src/contact/addressbook.cc index 4bbb950e..96d6590c 100644 --- a/src/contact/addressbook.cc +++ b/src/contact/addressbook.cc @@ -281,8 +281,7 @@ void AddressBook_find(const JsonObject& args, JsonArray& array) { // TODO implement contact filter and sorting. const JsonObject& address_book = FromJson(args, "addressBook"); long addressbook_id = common::stol(FromJson(address_book, "id")); - // Read calendar by ID - int error_code = 0; + int error_code; contacts_query_h query = nullptr; contacts_filter_h filter = nullptr; @@ -305,6 +304,7 @@ void AddressBook_find(const JsonObject& args, JsonArray& array) { int record_count = 0; error_code = contacts_list_get_count(list, &record_count); + ContactUtil::ErrorChecker(error_code, "Failed contacts_list_get_count"); contacts_list_first(list); for (unsigned int i = 0; i < record_count; i++) { @@ -332,17 +332,13 @@ void AddressBook_addGroup(const JsonObject& args, JsonObject& out) { int err = CONTACTS_ERROR_NONE; contacts_record_h contacts_record = nullptr; err = contacts_record_create(_contacts_group._uri, &contacts_record); - ContactUtil::ErrorChecker(err, - "Error during executing contacts_record_create()"); + ContactUtil::ErrorChecker(err, "Error during executing contacts_record_create()"); - ContactUtil::ContactsRecordHPtr record(&contacts_record, - ContactUtil::ContactsDeleter); + ContactUtil::ContactsRecordHPtr record(&contacts_record, ContactUtil::ContactsDeleter); - long addressbook_id = - common::stol(FromJson(args, "addressBookId")); + long addressbook_id = common::stol(FromJson(args, "addressBookId")); addressbook_id = (IsUnified(addressbook_id)) ? 0 : addressbook_id; - ContactUtil::SetIntInRecord(contacts_record, _contacts_group.address_book_id, - addressbook_id); + ContactUtil::SetIntInRecord(contacts_record, _contacts_group.address_book_id, addressbook_id); ContactUtil::ExportContactGroupToContactsRecord(contacts_record, group); int groupId = 0; @@ -350,8 +346,7 @@ void AddressBook_addGroup(const JsonObject& args, JsonObject& out) { ContactUtil::ErrorChecker(err, "Error during insert group record"); out.insert(std::make_pair("id", std::to_string(groupId))); - out.insert( - std::make_pair("addressBookId", std::to_string(addressbook_id))); + out.insert(std::make_pair("addressBookId", std::to_string(addressbook_id))); } void AddressBook_getGroup(const JsonObject& args, JsonObject& out) { @@ -367,14 +362,13 @@ void AddressBook_getGroup(const JsonObject& args, JsonObject& out) { contacts_record_h contacts_record = nullptr; err = contacts_db_get_record(_contacts_group._uri, id, &contacts_record); if (CONTACTS_ERROR_NONE != err || nullptr == contacts_record) { - throw common::NotFoundException("Don't find group with this id"); + LoggerE("Group not exist"); + throw common::NotFoundException("Group not exist"); } - ContactUtil::ContactsRecordHPtr record(&contacts_record, - ContactUtil::ContactsDeleter); + ContactUtil::ContactsRecordHPtr record(&contacts_record, ContactUtil::ContactsDeleter); - long addressbook_id = - common::stol(FromJson(args, "addressBook", "id")); + long addressbook_id = common::stol(FromJson(args, "addressBook", "id")); if (IsUnified(addressbook_id)) { int address_book_id = 0; ContactUtil::GetIntFromRecord( @@ -397,10 +391,8 @@ void AddressBook_updateGroup(const JsonObject& args, JsonObject&) { throw common::InvalidValuesException("Group object is not added"); } - long addressbook_id = - common::stol(FromJson(args, "addressBookId")); - long group_addressbook_id = - common::stol(FromJson(group, "addressBookId")); + long addressbook_id = common::stol(FromJson(args, "addressBookId")); + long group_addressbook_id = common::stol(FromJson(group, "addressBookId")); if (IsUnified(addressbook_id) && (addressbook_id != group_addressbook_id)) { LoggerE("Wrong address book"); throw common::InvalidValuesException("Wrong address book"); @@ -416,14 +408,11 @@ void AddressBook_updateGroup(const JsonObject& args, JsonObject&) { throw common::InvalidValuesException("Incorrect group id"); } - int err = CONTACTS_ERROR_NONE; contacts_record_h contacts_record = nullptr; - err = - contacts_db_get_record(_contacts_group._uri, group_id, &contacts_record); - if (CONTACTS_ERROR_INVALID_PARAMETER == err) { - LoggerE("Error during executing contacts_db_get_record()"); - throw common::NotFoundException( - "Error during executing contacts_db_get_record()"); + int err = contacts_db_get_record(_contacts_group._uri, group_id, &contacts_record); + if (CONTACTS_ERROR_NONE != err || nullptr == contacts_record) { + LoggerE("Group not exist"); + throw common::NotFoundException("Group not exist"); } ContactUtil::ErrorChecker(err, @@ -449,14 +438,13 @@ void AddressBook_removeGroup(const JsonObject& args, JsonObject&) { throw common::InvalidValuesException("Incorrect group id"); } - int err = CONTACTS_ERROR_NONE; + int err; long addressbook_id = AddressBookId(args); if (!IsUnified(addressbook_id)) { contacts_record_h contacts_record = nullptr; err = contacts_db_get_record(_contacts_group._uri, id, &contacts_record); if (CONTACTS_ERROR_NONE != err || contacts_record == nullptr) { - LoggerE("No group"); - throw common::UnknownException("No group"); + throw common::NotFoundException("Group not exist"); } int group_addressbook_id = 0; @@ -465,15 +453,13 @@ void AddressBook_removeGroup(const JsonObject& args, JsonObject&) { &group_addressbook_id); if (group_addressbook_id != addressbook_id) { - throw common::UnknownException( - "Contact is not a member of this address book"); + throw common::UnknownException("Contact is not a member of this address book"); } } err = contacts_db_delete_record(_contacts_group._uri, id); if (CONTACTS_ERROR_INVALID_PARAMETER == err) { - LoggerE("Problem during db_update_record"); - throw common::NotFoundException("Problem during db_delete_record"); + throw common::UnknownException("Problem during db_delete_record"); } ContactUtil::ErrorChecker(err, "Problem during db_delete_record"); } diff --git a/src/contact/contact_manager.cc b/src/contact/contact_manager.cc index 30dec6e1..b1e794ee 100644 --- a/src/contact/contact_manager.cc +++ b/src/contact/contact_manager.cc @@ -137,18 +137,16 @@ void ContactManager_getAddressBook(const JsonObject& args, JsonObject& out) { namespace { void ContactManager_get_internal(int person_id, JsonObject* out) { - int error_code = 0; contacts_record_h contacts_record = nullptr; - error_code = contacts_db_get_record(_contacts_person._uri, person_id, - &contacts_record); + int error_code = contacts_db_get_record(_contacts_person._uri, person_id, &contacts_record); if (CONTACTS_ERROR_NONE != error_code) { LoggerE("Person with id: %d, not found, error: %d", person_id, error_code); throw NotFoundException("Person not found"); } - ContactUtil::ContactsRecordHPtr contacts_record_ptr( - &contacts_record, ContactUtil::ContactsDeleter); + ContactUtil::ContactsRecordHPtr contacts_record_ptr(&contacts_record, + ContactUtil::ContactsDeleter); ContactUtil::ImportPersonFromContactsRecord(contacts_record, out); } @@ -156,9 +154,8 @@ void ContactManager_get_internal(int person_id, JsonObject* out) { void ContactManager_get(const JsonObject& args, JsonObject& out) { ContactUtil::CheckDBConnection(); - long person_id = common::stol(FromJson(args, "personID")); + long person_id = common::stol(FromJson(args, "personId")); - JsonValue val{JsonObject{}}; ContactManager_get_internal(person_id, &out); } @@ -166,16 +163,13 @@ void ContactManager_update(const JsonObject& args, JsonObject&) { ContactUtil::CheckDBConnection(); const JsonObject& person = FromJson(args, "person"); long person_id = common::stol(FromJson(person, "id")); - int error_code = 0; contacts_record_h contacts_record = nullptr; - error_code = contacts_db_get_record(_contacts_person._uri, person_id, - &contacts_record); + int error_code = contacts_db_get_record(_contacts_person._uri, person_id, &contacts_record); if (CONTACTS_ERROR_NONE != error_code) { - LoggerE("Error during updating person, error code: %d", error_code); - throw UnknownException("Error during updating person"); + throw NotFoundException("Person not found"); } ContactUtil::ExportPersonToContactsRecord(contacts_record, person); diff --git a/src/contact/js/tizen.contact.AddressBook.js b/src/contact/js/tizen.contact.AddressBook.js index ad898e6a..3ea51985 100644 --- a/src/contact/js/tizen.contact.AddressBook.js +++ b/src/contact/js/tizen.contact.AddressBook.js @@ -138,14 +138,17 @@ var AddressBook = function(id, name, readOnly) { }; AddressBook.prototype.get = function() { - var args = AV.validateArgs(arguments, [ - { - name: 'id', - type: AV.Types.STRING, - optional: false, - nullable: false - } - ]); + var args = AV.validateArgs(arguments, [{ + name: 'id', + type: AV.Types.STRING, + optional: false, + nullable: false + }]); + + if (String(Converter.toLong(args.id)) !== args.id) { + // TCT: AddressBook_get_id_invalid + throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR); + } var result = native_.callSync('AddressBook_get', { // TODO move to only sending the address book id (in all functions) @@ -357,14 +360,17 @@ AddressBook.prototype.updateBatch = function() { }; AddressBook.prototype.remove = function() { - var args = AV.validateArgs(arguments, [ - { - name: 'id', - type: AV.Types.STRING, - optional: false, - nullable: false - } - ]); + var args = AV.validateArgs(arguments, [{ + name: 'id', + type: AV.Types.STRING, + optional: false, + nullable: false + }]); + + if (String(Converter.toLong(args.id)) !== args.id) { + // TCT: AddressBook_remove_id_invalid + throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR); + } var result = native_.callSync('AddressBook_remove', { addressBook: this, @@ -572,17 +578,22 @@ AddressBook.prototype.removeChangeListener = function(watchId) { }; AddressBook.prototype.getGroup = function() { - var args = AV.validateArgs(arguments, [ - { - name: 'groupId', - type: AV.Types.STRING, - optional: false, - nullable: false - } - ]); + var args = AV.validateArgs(arguments, [{ + name: 'groupId', + type: AV.Types.STRING, + optional: false, + nullable: false + }]); + + if (String(Converter.toLong(args.groupId)) !== args.groupId) { + // TCT: AddressBook_getGroup_groupId_invalid + throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR); + } - var result = native_.callSync('AddressBook_getGroup', - {addressBook: this, id: args.groupId}); + var result = native_.callSync('AddressBook_getGroup', { + addressBook: this, + id: args.groupId + }); if (native_.isFailure(result)) { throw native_.getErrorObject(result); } @@ -635,14 +646,17 @@ AddressBook.prototype.updateGroup = function() { }; AddressBook.prototype.removeGroup = function() { - var args = AV.validateArgs(arguments, [ - { - name: 'groupId', - type: AV.Types.STRING, - optional: false, - nullable: false - } - ]); + var args = AV.validateArgs(arguments, [{ + name: 'groupId', + type: AV.Types.STRING, + optional: false, + nullable: false + }]); + + if (String(Converter.toLong(args.groupId)) !== args.groupId) { + // TCT: AddressBook_removeGroup_groupId_invalid + throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR); + } var result = native_.callSync('AddressBook_removeGroup', {addressBook: this, id: args.groupId}); diff --git a/src/contact/js/tizen.contact.ContactManager.js b/src/contact/js/tizen.contact.ContactManager.js index 57b5df2a..9d1914c7 100644 --- a/src/contact/js/tizen.contact.ContactManager.js +++ b/src/contact/js/tizen.contact.ContactManager.js @@ -82,15 +82,17 @@ ContactManager.prototype.getDefaultAddressBook = function() { // Gets the address book with the specified identifier. ContactManager.prototype.getAddressBook = function() { - // validation - var args = AV.validateArgs(arguments, [ - { - name: 'addressBookId', - type: AV.Types.STRING, - optional: false, - nullable: false - } - ]); + var args = AV.validateArgs(arguments, [{ + name: 'addressBookId', + type: AV.Types.STRING, + optional: false, + nullable: false + }]); + + if (String(Converter.toLong(args.addressBookId)) !== args.addressBookId) { + // TCT: ContactManager_getAddressBook_addressBookId_invalid + throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR); + } var result = native_.callSync('ContactManager_getAddressBook', { addressBookID: args.addressBookId @@ -117,8 +119,13 @@ ContactManager.prototype.get = function() { } ]); + if (String(Converter.toLong(args.personId)) !== args.personId) { + // TCT: ContactManager_get_personId_invalid + throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR); + } + var result = native_.callSync('ContactManager_get', { - personID: args.personId + personId: args.personId }); _checkError(result); @@ -130,15 +137,13 @@ ContactManager.prototype.get = function() { // Updates a person in the address book synchronously. ContactManager.prototype.update = function() { // validation - var args = AV.validateArgs(arguments, [ - { - name: 'person', - type: AV.Types.PLATFORM_OBJECT, - values: Person, - optional: false, - nullable: false - } - ]); + var args = AV.validateArgs(arguments, [{ + name: 'person', + type: AV.Types.PLATFORM_OBJECT, + values: Person, + optional: false, + nullable: false + }]); var result = native_.callSync('ContactManager_update', { person: args.person }); _checkError(result); @@ -192,14 +197,17 @@ ContactManager.prototype.updateBatch = function() { // Removes a person from the contact DB synchronously. ContactManager.prototype.remove = function() { // validation - var args = AV.validateArgs(arguments, [ - { - name: 'personId', - type: AV.Types.STRING, - optional: false, - nullable: false - } - ]); + var args = AV.validateArgs(arguments, [{ + name: 'personId', + type: AV.Types.STRING, + optional: false, + nullable: false + }]); + + if (String(Converter.toLong(args.personId)) !== args.personId) { + // TCT: ContactManager_remove_personId_invalid + throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR); + } var result = native_.callSync('ContactManager_remove', {personId: args.personId}); _checkError(result); diff --git a/src/contact/js/tizen.contact.Person.js b/src/contact/js/tizen.contact.Person.js index 1cd3c3e0..d6c1ef5a 100644 --- a/src/contact/js/tizen.contact.Person.js +++ b/src/contact/js/tizen.contact.Person.js @@ -126,14 +126,17 @@ var Person = function(data) { // Aggregates another person to this person. Person.prototype.link = function() { - var args = AV.validateArgs(arguments, [ - { - name: 'personId', - type: AV.Types.STRING, - optional: false, - nullable: false - } - ]); + var args = AV.validateArgs(arguments, [{ + name: 'personId', + type: AV.Types.STRING, + optional: false, + nullable: false + }]); + + if (String(Converter.toLong(args.personId)) !== args.personId) { + // TCT: Person_link_personId_invalid + throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR); + } var result = native_.callSync('Person_link', { // TODO move to only sending the person id (in all functions) @@ -151,14 +154,17 @@ Person.prototype.link = function() { // Separates a contact from this person. Person.prototype.unlink = function(contactId) { - var args = AV.validateArgs(arguments, [ - { - name: 'contactId', - type: AV.Types.STRING, - optional: false, - nullable: false - } - ]); + var args = AV.validateArgs(arguments, [{ + name: 'contactId', + type: AV.Types.STRING, + optional: false, + nullable: false + }]); + + if (String(Converter.toLong(args.contactId)) !== args.contactId) { + // TCT: Person_unlink_contactId_invalid + throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR); + } var result = native_.callSync('Person_unlink', { // TODO move to only sending the person id (in all functions) -- 2.34.1