From c75db3ed35e589991a95ced14025416d5c5677de Mon Sep 17 00:00:00 2001 From: Sakari Poussa Date: Thu, 18 Dec 2014 10:14:26 +0200 Subject: [PATCH] [Content] TCT fixes Improve Tizen Compliancy Test (TCT) suite pass rates: - Implement missing updateBatch method - Check for null and range assignments for js objects BUG=XWALK-2801 BUG=XWALK-2802 BUG=XWALK-2808 BUG=XWALK-2811 --- src/content/content_api.js | 32 +++++++++++++++++++++++++++++--- src/content/content_instance.cc | 40 ++++++++++++++++++++++++++++------------ src/content/content_instance.h | 1 + 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/content/content_api.js b/src/content/content_api.js index 1a2330a..7e8a422 100644 --- a/src/content/content_api.js +++ b/src/content/content_api.js @@ -60,10 +60,15 @@ function Folder(uri, id, type, title) { function Content(editableAttributes, id, name, type, mimeType, title, contentURI, thumnailURIs, releaseDate, modifiedDate, size, description, rating) { + var rating_ = rating, name_ = name; Object.defineProperties(this, { 'editableAttributes': { writable: false, value: editableAttributes, enumerable: true }, 'id': { writable: false, value: id, enumerable: true }, - 'name': { writable: true, value: name, enumerable: true }, + 'name': { + enumerable: true, + set: function(v) { if (v != null) name_ = v}, + get: function() { return name_; } + }, 'type': { writable: false, value: type, enumerable: true }, 'mimeType': { writable: false, value: mimeType, enumerable: true }, 'title': { writable: false, value: title, enumerable: true }, @@ -73,7 +78,11 @@ function Content(editableAttributes, id, name, type, mimeType, title, contentURI 'modifiedDate': { writable: false, value: parseDate(modifiedDate), enumerable: true }, 'size': { writable: false, value: size, enumerable: true }, 'description': { writable: true, value: description, enumerable: true }, - 'rating': { writable: true, value: rating, enumerable: true } + 'rating': { + enumerable: true, + set: function(v) { if (v != null && v >= 0 && v <= 10) rating_ = v; }, + get: function() { return rating_; } + } }); } @@ -92,11 +101,16 @@ function AudioContent(obj, album, genres, artists, composer, copyright, } function ImageContent(obj, geolocation, width, height, orientation) { + var orientation_ = orientation; Object.defineProperties(obj, { 'geolocation': { writable: true, value: geolocation, enumerable: true }, 'width': { writable: false, value: width, enumerable: true }, 'height': { writable: false, value: height, enumerable: true }, - 'orientation': { writable: true, value: orientation, enumerable: true } + 'orientation': { + enumerable: true, + set: function(v) { if (v != null) orientation_ = v; }, + get: function() { return orientation_; } + } }); } @@ -129,6 +143,18 @@ ContentManager.prototype.updateBatch = function(content, onsuccess, onerror) { if (!xwalk.utils.validateArguments('o?ff', arguments)) { throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR); } + + postMessage({ + cmd: 'ContentManager.updateBatch', + content: content + }, function(result) { + if (result.isError) { + if (onerror) + onerror(new tizen.WebAPIError(result.errorCode)); + } else if (onsuccess) { + onsuccess(); + } + }); }; ContentManager.prototype.getDirectories = function(onsuccess, onerror) { diff --git a/src/content/content_instance.cc b/src/content/content_instance.cc index b048281..78d02e0 100644 --- a/src/content/content_instance.cc +++ b/src/content/content_instance.cc @@ -100,6 +100,8 @@ void ContentInstance::HandleMessage(const char* message) { HandleFindRequest(v); } else if (cmd == "ContentManager.scanFile") { HandleScanFileRequest(v); + } else if (cmd == "ContentManager.updateBatch") { + HandleUpdateBatchRequest(v); } else { std::cerr << "Message " + cmd + " is not supported.\n"; } @@ -206,12 +208,14 @@ bool ContentInstance::HandleUpdateRequest(const picojson::value& msg) { no_error = false; } - if (msg.contains(STR_RATING) && - media_info_set_rating(handle, - std::stoi(msg.get(STR_RATING).to_str())) - != MEDIA_CONTENT_ERROR_NONE) { - std::cerr << "media_info_set_rating: error" << std::endl; - no_error = false; + if (msg.contains(STR_RATING)) { + int i = std::stoi(msg.get(STR_RATING).to_str()); + if (i >= 0 && i <= 10) { + if (media_info_set_rating(handle, i) != MEDIA_CONTENT_ERROR_NONE) { + std::cerr << "media_info_set_rating: error" << std::endl; + no_error = false; + } + } } // Commit the changes to DB @@ -223,6 +227,18 @@ bool ContentInstance::HandleUpdateRequest(const picojson::value& msg) { return no_error; } +void ContentInstance::HandleUpdateBatchRequest(const picojson::value& msg) { + picojson::array list = msg.get("content").get(); + + for (picojson::array::const_iterator i = list.begin(); i != list.end(); ++i) { + if (!HandleUpdateRequest((*i))) { + PostAsyncErrorReply(msg, WebApiAPIErrors::INVALID_MODIFICATION_ERR); + return; + } + } + PostAsyncSuccessReply(msg); +} + void ContentInstance::HandleGetDirectoriesRequest(const picojson::value& msg) { ContentFolderList folderList; if (media_folder_foreach_folder_from_db(NULL, @@ -707,23 +723,23 @@ void ContentItem::print(void) { std::cout << "ID: " << id() << std::endl; std::cout << "Name: " << name() << std::endl; std::cout << "Type: " << type() << std::endl; - std::cout << "MIME: " << mimeType() << std::endl; + std::cout << "MIME: " << mime_type() << std::endl; std::cout << "Title: " << title() << std::endl; - std::cout << "URI: " << contentURI() << std::endl; - std::cout << "ThumbnailURIs: " << thumbnailURIs() << std::endl; - std::cout << "Modified: " << modifiedDate(); + std::cout << "URI: " << content_uri() << std::endl; + std::cout << "ThumbnailURIs: " << thumbnail_uris() << std::endl; + std::cout << "Modified: " << modified_date(); std::cout << "Size: " << size() << std::endl; std::cout << "Description: " << description() << std::endl; std::cout << "Rating: " << rating() << std::endl; if (type() == "AUDIO") { - std::cout << "Release Date: " << releaseDate() << std::endl; + std::cout << "Release Date: " << release_date() << std::endl; std::cout << "Album: " << album() << std::endl; std::cout << "Genres: " << genres() << std::endl; std::cout << "Artists: " << artists() << std::endl; std::cout << "Composer: " << composer() << std::endl; std::cout << "Copyright: " << copyright() << std::endl; std::cout << "Bitrate: " << bitrate() << std::endl; - std::cout << "Track num: " << trackNumber() << std::endl; + std::cout << "Track num: " << track_number() << std::endl; std::cout << "Duration: " << duration() << std::endl; } else if (type() == "IMAGE") { std::cout << "Width/Height: " << width() << "/" << height() << std::endl; diff --git a/src/content/content_instance.h b/src/content/content_instance.h index 6b35d06..9bb6134 100644 --- a/src/content/content_instance.h +++ b/src/content/content_instance.h @@ -33,6 +33,7 @@ class ContentInstance : public common::Instance { virtual void HandleSyncMessage(const char* msg); bool HandleUpdateRequest(const picojson::value& json); + void HandleUpdateBatchRequest(const picojson::value& json); void HandleGetDirectoriesRequest(const picojson::value& json); void HandleGetDirectoriesReply(const picojson::value& json, ContentFolderList *); -- 2.7.4