[Contact] TCT fixes
authorRafal Galka <r.galka@samsung.com>
Mon, 29 Dec 2014 14:59:54 +0000 (15:59 +0100)
committerRafal Galka <r.galka@samsung.com>
Wed, 31 Dec 2014 09:39:18 +0000 (18:39 +0900)
[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
src/contact/contact_manager.cc
src/contact/js/tizen.contact.AddressBook.js
src/contact/js/tizen.contact.ContactManager.js
src/contact/js/tizen.contact.Person.js

index 4bbb950e722f58b24a15e6da45efc719869afcc0..96d6590c09442e95b969c897c917c945318554fc 100644 (file)
@@ -281,8 +281,7 @@ void AddressBook_find(const JsonObject& args, JsonArray& array) {
   // TODO implement contact filter and sorting.
   const JsonObject& address_book = FromJson<JsonObject>(args, "addressBook");
   long addressbook_id = common::stol(FromJson<std::string>(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<JsonString>(args, "addressBookId"));
+  long addressbook_id = common::stol(FromJson<JsonString>(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<JsonString>(args, "addressBook", "id"));
+  long addressbook_id = common::stol(FromJson<JsonString>(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<JsonString>(args, "addressBookId"));
-  long group_addressbook_id =
-      common::stol(FromJson<JsonString>(group, "addressBookId"));
+  long addressbook_id = common::stol(FromJson<JsonString>(args, "addressBookId"));
+  long group_addressbook_id = common::stol(FromJson<JsonString>(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");
 }
index 30dec6e1dcc6543dd07a8fc3c0c65962574e8b4f..b1e794eeddcfa56a75659852568779ddfd117553 100644 (file)
@@ -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<JsonString>(args, "personID"));
+  long person_id = common::stol(FromJson<JsonString>(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<JsonObject>(args, "person");
   long person_id = common::stol(FromJson<JsonString>(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);
index ad898e6a8dd11adc37bef3795fd3f18b46d7aa85..3ea51985288024a7f20d687765514f6d8141971b 100644 (file)
@@ -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});
index 57b5df2a51c84fa220c3529bfda088d3c66de270..9d1914c7fea753b4424789056a3defdf4a1ddc4a 100644 (file)
@@ -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);
index 1cd3c3e0a95264e84f03d83f9622410b1c0c5cc2..d6c1ef5ad38f794e2659892a09341aa832e15abd 100644 (file)
@@ -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)