From 2f38bbf1894103d2a36fb907e58cd5a563186f89 Mon Sep 17 00:00:00 2001 From: Wojciech Kosowicz Date: Mon, 23 Mar 2015 16:03:12 +0100 Subject: [PATCH] [Content] TCT tests fixes Fixed throwing errors in playlist methods. Added releaseDate for video elements [Verification] All tests passed 230/230 Change-Id: I62007eb557294e775a9283e90f1454a6ebeb6824 Signed-off-by: Wojciech Kosowicz --- src/content/content_manager.cc | 51 +++++++++++++++------------------- src/content/js/datatypes.js | 2 +- src/content/js/manager.js | 8 ++++++ src/content/js/playlist.js | 14 ++++++++++ 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/content/content_manager.cc b/src/content/content_manager.cc index c6cd6e88..c19183fd 100755 --- a/src/content/content_manager.cc +++ b/src/content/content_manager.cc @@ -52,6 +52,23 @@ static int get_utc_offset() { return gmtime_hours; } +std::string get_date(char* tmpStr) { + if (tmpStr) { + struct tm* result = (struct tm*) calloc(1, sizeof(struct tm)); + if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", result) == NULL) { + return std::string(); + } else { + time_t t = mktime(result);// + get_utc_offset() * 3600; + std::stringstream str_date; + str_date << t; + free(tmpStr); + free(result); + tmpStr = NULL; + return str_date.str(); + } + } + return std::string(); +} void ContentToJson(media_info_h info, picojson::object& o) { int ret; @@ -75,21 +92,7 @@ void ContentToJson(media_info_h info, picojson::object& o) { image_meta_h img; if (MEDIA_CONTENT_ERROR_NONE == media_info_get_image(info, &img)) { if (MEDIA_CONTENT_ERROR_NONE == image_meta_get_date_taken(img, &tmpStr)) { - if (tmpStr) { - struct tm* result = (struct tm*) calloc(1, sizeof(struct tm)); - if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", result) == NULL) { - LoggerE("Couldn't convert supplied date."); - } - else { - time_t t = mktime(result);// + get_utc_offset() * 3600; - std::stringstream str_date; - str_date << t; - o["releaseDate"] = picojson::value(str_date.str()); - free(tmpStr); - free(result); - tmpStr = NULL; - } - } + o["releaseDate"] = picojson::value(get_date(tmpStr)); } if (MEDIA_CONTENT_ERROR_NONE == image_meta_get_width(img, &tmpInt)) { o["width"] = picojson::value(static_cast(tmpInt)); @@ -167,6 +170,9 @@ void ContentToJson(media_info_h info, picojson::object& o) { if (MEDIA_CONTENT_ERROR_NONE == video_meta_get_duration(video, &tmpInt)) { o["duration"] = picojson::value(static_cast(tmpInt)); } + if (MEDIA_CONTENT_ERROR_NONE == video_meta_get_recorded_date(video, &tmpStr)) { + o["releaseDate"] = picojson::value(get_date(tmpStr)); + } } picojson::object geo; if (MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble)) { @@ -182,20 +188,7 @@ void ContentToJson(media_info_h info, picojson::object& o) { audio_meta_h audio; if (MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(info, &audio)) { if (MEDIA_CONTENT_ERROR_NONE == audio_meta_get_recorded_date(audio, &tmpStr)) { - if (tmpStr) { - struct tm* result = (struct tm*) calloc(1, sizeof(struct tm)); - - if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", result) == NULL) { - LoggerD("Couldn't convert supplied date."); - } - time_t t = mktime(result) + get_utc_offset() * 3600; - std::stringstream str_date; - str_date << t; - o["releaseDate"] = picojson::value(str_date.str()); - free(tmpStr); - free(result); - tmpStr = NULL; - } + o["releaseDate"] = picojson::value(get_date(tmpStr)); } if (MEDIA_CONTENT_ERROR_NONE == audio_meta_get_album(audio, &tmpStr)) { if (tmpStr) { diff --git a/src/content/js/datatypes.js b/src/content/js/datatypes.js index 3dc178bd..3078ad7f 100644 --- a/src/content/js/datatypes.js +++ b/src/content/js/datatypes.js @@ -685,7 +685,7 @@ function PlaylistItem(data) { return content; }, set: function(v) { - if (edit_.isAllowed && v instanceof Content ) { + if (edit_.isAllowed && v instanceof Content) { content = v; } }, diff --git a/src/content/js/manager.js b/src/content/js/manager.js index d623a630..18f9871f 100644 --- a/src/content/js/manager.js +++ b/src/content/js/manager.js @@ -223,6 +223,14 @@ ContentManager.prototype.createPlaylist = function(name, successCallback, errorC {name: 'sourcePlaylist', type: types_.PLATFORM_OBJECT, values: Playlist, optional: true, nullable: true} ]); + if (!arguments.length || !type_.isString(arguments[0]) || + (type_.isString(arguments[0]) && !arguments[0].length)) { + setTimeout(function() { + args.errorCallback(new WebAPIException(WebAPIException.INVALID_VALUES_ERR)); + }, 0); + return; + } + var data = { name: args.name, sourcePlaylist: args.sourcePlaylist diff --git a/src/content/js/playlist.js b/src/content/js/playlist.js index 6e5aeeb7..e75cbf27 100644 --- a/src/content/js/playlist.js +++ b/src/content/js/playlist.js @@ -162,6 +162,13 @@ Playlist.prototype.get = function (successCallback, errorCallback, count, offset {name: 'offset', type: types_.LONG, optional: true} ]); + if (args.offset < 0 || args.count < 0) { + setTimeout(function() { + args.errorCallback(new WebAPIException(WebAPIException.INVALID_VALUES_ERR)); + }, 0); + return; + } + var data = { playlistId: this.id, count: type_.isNullOrUndefined(args.count) ? -1 : args.count, @@ -193,6 +200,13 @@ Playlist.prototype.setOrder = function (items, successCallback, errorCallback) { {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); + if (!args.items.length) { + setTimeout(function() { + args.errorCallback(new WebAPIException(WebAPIException.INVALID_VALUES_ERR)); + }, 0); + return; + } + var members = []; for (var i = 0; i < args.items.length; i++) { members.push(args.items[i].content.memberId); -- 2.34.1