From: Michal Michalski Date: Tue, 13 Aug 2019 09:46:43 +0000 (+0200) Subject: [formatting] Code auto-formatting. X-Git-Tag: accepted/tizen/unified/20190814.065037~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F23%2F212023%2F1;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [formatting] Code auto-formatting. Executed ./code_format script on the repository to fix invalid formatting. Change-Id: Ieb8d825c4525dedc740319a3729ffd54280fef71 Signed-off-by: Michal Michalski --- diff --git a/src/bluetooth/bluetooth_gatt_service.cc b/src/bluetooth/bluetooth_gatt_service.cc index 270a772..d7c0222 100644 --- a/src/bluetooth/bluetooth_gatt_service.cc +++ b/src/bluetooth/bluetooth_gatt_service.cc @@ -515,18 +515,18 @@ void BluetoothGATTService::RemoveValueChangeListener(const picojson::value& args if (!IsStillConnected(address)) { LoggerW("Device with address %s is no longer connected", address.c_str()); } else { - bt_gatt_h handle = (bt_gatt_h) static_cast(args.get(kHandle).get()); + bt_gatt_h handle = (bt_gatt_h) static_cast(args.get(kHandle).get()); - int ret = bt_gatt_client_unset_characteristic_value_changed_cb(handle); + int ret = bt_gatt_client_unset_characteristic_value_changed_cb(handle); - if (BT_ERROR_NONE != ret) { - LoggerW("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d (%s)", ret, - get_error_message(ret)); - } else { - gatt_characteristic_.erase( - std::remove(gatt_characteristic_.begin(), gatt_characteristic_.end(), handle), - gatt_characteristic_.end()); - } + if (BT_ERROR_NONE != ret) { + LoggerW("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d (%s)", ret, + get_error_message(ret)); + } else { + gatt_characteristic_.erase( + std::remove(gatt_characteristic_.begin(), gatt_characteristic_.end(), handle), + gatt_characteristic_.end()); + } } ReportSuccess(out); } diff --git a/src/bluetooth/bluetooth_health_application.h b/src/bluetooth/bluetooth_health_application.h index 1305cff..36438bda 100644 --- a/src/bluetooth/bluetooth_health_application.h +++ b/src/bluetooth/bluetooth_health_application.h @@ -47,7 +47,8 @@ class BluetoothHealthApplication { void Unregister(const picojson::value& data, picojson::object& out); /** - * Signature: @code static void ToJson(short, const std::string&, const char*, picojson::object*); @endcode + * Signature: @code static void ToJson(short, const std::string&, const char*, picojson::object*); + * @endcode * Deprecated since tizen version 5.5 */ static void ToJson(short data_type, const std::string& name, const char* id, diff --git a/src/bluetooth/bluetooth_health_profile_handler.h b/src/bluetooth/bluetooth_health_profile_handler.h index e1a04f9..0fd81af 100644 --- a/src/bluetooth/bluetooth_health_profile_handler.h +++ b/src/bluetooth/bluetooth_health_profile_handler.h @@ -50,7 +50,8 @@ class BluetoothHealthProfileHandler { void RegisterSinkApp(const picojson::value& data, picojson::object& out); /** - * Signature: @code void connectToSource(peer, application, successCallback, errorCallback); @endcode + * Signature: @code void connectToSource(peer, application, successCallback, errorCallback); + * @endcode * Deprecated since tizen version 5.5 * JSON: @code data: {method: 'BluetoothHealthProfileHandler_connectToSource', * args: {peer: peer, application: application}} @endcode @@ -91,7 +92,8 @@ class BluetoothHealthProfileHandler { BluetoothHealthProfileHandler& operator=(const BluetoothHealthProfileHandler&) = delete; /** - * Signature: @code static void OnConnected(int, const char*, const char*, bt_hdp_channel_type_e, unsigned int, void*); @endcode + * Signature: @code static void OnConnected(int, const char*, const char*, bt_hdp_channel_type_e, + * unsigned int, void*); @endcode * Deprecated since tizen version 5.5 */ static void OnConnected(int result, const char* remote_address, const char* app_id, @@ -105,7 +107,8 @@ class BluetoothHealthProfileHandler { void* user_data); /** - * Signature: @code static void OnDataReceived(unsigned int, const char*, unsigned int, void*); @endcode + * Signature: @code static void OnDataReceived(unsigned int, const char*, unsigned int, void*); + * @endcode * Deprecated since tizen version 5.5 */ static void OnDataReceived(unsigned int channel, const char* data, unsigned int size, diff --git a/src/common/tools.cc b/src/common/tools.cc index cd4eeb4..d23347c 100644 --- a/src/common/tools.cc +++ b/src/common/tools.cc @@ -585,7 +585,8 @@ void PrintDeprecationWarningFor(const char* className, const char* replacement) } else { LoggerW( "DEPRECATION WARNING: %s is deprecated and using it is not recommended. Try using %s " - "instead", className, replacement); + "instead", + className, replacement); } } diff --git a/src/common/ut/json-utils.cc b/src/common/ut/json-utils.cc index 13cdcb0..044dd14 100644 --- a/src/common/ut/json-utils.cc +++ b/src/common/ut/json-utils.cc @@ -366,8 +366,7 @@ TEST_F(BundleToJsonTest, BytesArrayConversion) { string key = "key"; vector> value = {{0, 126, 255}, {1, 127, 254}}; - ASSERT_EQ(bundle_init_byte_array(bundleData, key.c_str(), value.size()), - BUNDLE_ERROR_NONE); + ASSERT_EQ(bundle_init_byte_array(bundleData, key.c_str(), value.size()), BUNDLE_ERROR_NONE); ASSERT_EQ( bundle_set_byte_array_element(bundleData, key.c_str(), 0, value[0].data(), value[0].size()), BUNDLE_ERROR_NONE); @@ -395,4 +394,3 @@ TEST_F(BundleToJsonTest, BytesArrayConversion) { EXPECT_EQ(bytes[1].get(), value[1][1]); EXPECT_EQ(bytes[2].get(), value[1][2]); } - diff --git a/src/common/ut/json-utils.h b/src/common/ut/json-utils.h index 653a821..cafc44c 100644 --- a/src/common/ut/json-utils.h +++ b/src/common/ut/json-utils.h @@ -19,4 +19,4 @@ class JsonToBundleTest; class BundleToJsonTest; -#endif // COMMON_UT_JSON_UTILS_H +#endif // COMMON_UT_JSON_UTILS_H diff --git a/src/common/ut/main.cc b/src/common/ut/main.cc index 044ac9f..f2a8898 100644 --- a/src/common/ut/main.cc +++ b/src/common/ut/main.cc @@ -24,4 +24,3 @@ int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } - diff --git a/src/filesystem/filesystem_manager.cc b/src/filesystem/filesystem_manager.cc index bb027b4..04315ad 100644 --- a/src/filesystem/filesystem_manager.cc +++ b/src/filesystem/filesystem_manager.cc @@ -109,8 +109,8 @@ FilesystemError copyDirectory(const std::string& originPath, const std::string& } if (nullptr == entry) { - LoggerD("No more entries in the directory"); - break; + LoggerD("No more entries in the directory"); + break; } if (std::strcmp(entry->d_name, ".") == 0 || std::strcmp(entry->d_name, "..") == 0) { diff --git a/src/filesystem/filesystem_utils.cc b/src/filesystem/filesystem_utils.cc index 9c84011..dccd81f 100644 --- a/src/filesystem/filesystem_utils.cc +++ b/src/filesystem/filesystem_utils.cc @@ -207,13 +207,12 @@ void ListDirectory(const std::string& path, std::functiond_name, ".") || 0 == std::strcmp(entry->d_name, "..")) { diff --git a/src/mediacontroller/js/ut/test_custom_command.js b/src/mediacontroller/js/ut/test_custom_command.js index 5ac7ba7..782552e 100644 --- a/src/mediacontroller/js/ut/test_custom_command.js +++ b/src/mediacontroller/js/ut/test_custom_command.js @@ -1,128 +1,161 @@ mocha.setup('bdd'); -describe('sendCommand', function () { - var client = null, server = null, sinfo = null, commandListenerId = null; - - before(function() { - server = tizen.mediacontroller.createServer(); - client = tizen.mediacontroller.getClient(); - server.updatePlaybackState('PLAY'); - sinfo = client.getLatestServerInfo(); - }); - - afterEach(function() { - server.removeCommandListener(commandListenerId); - }); - - it('should trigger command listener and success callback', function (done) { - commandListenerId = server.addCommandListener(function(client, command, data) { - chai.expect(command).to.equal("myCommand"); - chai.expect(Object.keys(data).length).to.equal(1); - chai.expect(data.key).to.equal("value"); - return {"key": "response data"}; +describe('sendCommand', function() { + var client = null, + server = null, + sinfo = null, + commandListenerId = null; + + before(function() { + server = tizen.mediacontroller.createServer(); + client = tizen.mediacontroller.getClient(); + server.updatePlaybackState('PLAY'); + sinfo = client.getLatestServerInfo(); }); - sinfo.sendCommand("myCommand", {key: "value"}, function(response) { - chai.expect(Object.keys(response).length).to.equal(1); - chai.expect(response.key).to.equal("response data"); - done(); - }, function(error) { - done(new Error(error)); + afterEach(function() { + server.removeCommandListener(commandListenerId); }); - }); - - it('should accept tizen.Bundle data argument', function (done) { - commandListenerId = server.addCommandListener(function(client, command, data) { - chai.expect(command).to.equal("myCommand"); - chai.expect(Object.keys(data).length).to.equal(1); - chai.expect(data.key).to.equal("value"); - return {"key": "response data"}; - }); - - sinfo.sendCommand("myCommand", new tizen.Bundle({key: "value"}), function(response) { - chai.expect(Object.keys(response).length).to.equal(1); - chai.expect(response.key).to.equal("response data"); - done(); - }, function(error) { - done(new Error(error)); - }); - }); - - it('should accept null data argument', function (done) { - commandListenerId = server.addCommandListener(function(client, command, data) { - chai.expect(command).to.equal("myCommand"); - chai.expect(data).to.equal(null); - return {"key": "response data"}; - }); - - sinfo.sendCommand("myCommand", null, function(response) { - chai.expect(Object.keys(response).length).to.equal(1); - chai.expect(response.key).to.equal("response data"); - done(); - }, function(error) { - done(new Error(error)); - }); - }); - it('should accept RequestReply as a response', function (done) { - commandListenerId = server.addCommandListener(function(client, command, data) { - chai.expect(command).to.equal("myCommand"); - chai.expect(data).to.equal(null); - return new tizen.mediacontroller.RequestReply({"key": "response data"}, 10); + it('should trigger command listener and success callback', function(done) { + commandListenerId = server.addCommandListener(function(client, command, data) { + chai.expect(command).to.equal('myCommand'); + chai.expect(Object.keys(data).length).to.equal(1); + chai.expect(data.key).to.equal('value'); + return { key: 'response data' }; + }); + + sinfo.sendCommand( + 'myCommand', + { key: 'value' }, + function(response) { + chai.expect(Object.keys(response).length).to.equal(1); + chai.expect(response.key).to.equal('response data'); + done(); + }, + function(error) { + done(new Error(error)); + } + ); }); - sinfo.sendCommand("myCommand", null, function(data, code) { - chai.expect(code).to.equal(10); - chai.expect(Object.keys(data).length).to.equal(1); - chai.expect(data.key).to.equal("response data"); - done(); - }, function(error) { - done(new Error(error)); + it('should accept tizen.Bundle data argument', function(done) { + commandListenerId = server.addCommandListener(function(client, command, data) { + chai.expect(command).to.equal('myCommand'); + chai.expect(Object.keys(data).length).to.equal(1); + chai.expect(data.key).to.equal('value'); + return { key: 'response data' }; + }); + + sinfo.sendCommand( + 'myCommand', + new tizen.Bundle({ key: 'value' }), + function(response) { + chai.expect(Object.keys(response).length).to.equal(1); + chai.expect(response.key).to.equal('response data'); + done(); + }, + function(error) { + done(new Error(error)); + } + ); }); - }); - it('should accept RequestReply with null data as a response', function (done) { - commandListenerId = server.addCommandListener(function(client, command, data) { - chai.expect(command).to.equal("myCommand"); - chai.expect(data).to.equal(null); - return new tizen.mediacontroller.RequestReply(null, 10); + it('should accept null data argument', function(done) { + commandListenerId = server.addCommandListener(function(client, command, data) { + chai.expect(command).to.equal('myCommand'); + chai.expect(data).to.equal(null); + return { key: 'response data' }; + }); + + sinfo.sendCommand( + 'myCommand', + null, + function(response) { + chai.expect(Object.keys(response).length).to.equal(1); + chai.expect(response.key).to.equal('response data'); + done(); + }, + function(error) { + done(new Error(error)); + } + ); }); - sinfo.sendCommand("myCommand", null, function(data, code) { - chai.expect(code).to.equal(10); - chai.expect(data).to.equal(null); - done(); - }, function(error) { - done(new Error(error)); + it('should accept RequestReply as a response', function(done) { + commandListenerId = server.addCommandListener(function(client, command, data) { + chai.expect(command).to.equal('myCommand'); + chai.expect(data).to.equal(null); + return new tizen.mediacontroller.RequestReply({ key: 'response data' }, 10); + }); + + sinfo.sendCommand( + 'myCommand', + null, + function(data, code) { + chai.expect(code).to.equal(10); + chai.expect(Object.keys(data).length).to.equal(1); + chai.expect(data.key).to.equal('response data'); + done(); + }, + function(error) { + done(new Error(error)); + } + ); }); - }); - it('should be okey to return nothing from command listener', function (done) { - commandListenerId = server.addCommandListener(function(client, command, data) { - chai.expect(command).to.equal("myCommand"); - chai.expect(data).to.equal(null); + it('should accept RequestReply with null data as a response', function(done) { + commandListenerId = server.addCommandListener(function(client, command, data) { + chai.expect(command).to.equal('myCommand'); + chai.expect(data).to.equal(null); + return new tizen.mediacontroller.RequestReply(null, 10); + }); + + sinfo.sendCommand( + 'myCommand', + null, + function(data, code) { + chai.expect(code).to.equal(10); + chai.expect(data).to.equal(null); + done(); + }, + function(error) { + done(new Error(error)); + } + ); }); - sinfo.sendCommand("myCommand", null, function(data, code) { - chai.expect(data).to.equal(null); - chai.expect(code).to.equal(0); - done(); - }, function(error) { - done(new Error(error)); + it('should be okey to return nothing from command listener', function(done) { + commandListenerId = server.addCommandListener(function(client, command, data) { + chai.expect(command).to.equal('myCommand'); + chai.expect(data).to.equal(null); + }); + + sinfo.sendCommand( + 'myCommand', + null, + function(data, code) { + chai.expect(data).to.equal(null); + chai.expect(code).to.equal(0); + done(); + }, + function(error) { + done(new Error(error)); + } + ); }); - }); }); mocha.checkLeaks(); -mocha.run() +mocha + .run() .on('pass', function(test) { - console.log(test.title + " OK"); + console.log(test.title + ' OK'); }) .on('fail', function(test, err) { - console.error(test.title + " FAILED"); + console.error(test.title + ' FAILED'); console.error(err); }) .on('end', function() { console.log('All done'); }); - diff --git a/src/mediacontroller/js/ut/test_search.js b/src/mediacontroller/js/ut/test_search.js index c6e7ab8..012a77d 100644 --- a/src/mediacontroller/js/ut/test_search.js +++ b/src/mediacontroller/js/ut/test_search.js @@ -1,227 +1,236 @@ mocha.setup('bdd'); describe('sendSearchRequest', function() { - var client = null, server = null, sinfo = null, listenerId = null; - - before(function() { - server = tizen.mediacontroller.createServer(); - client = tizen.mediacontroller.getClient(); - server.updatePlaybackState('PLAY'); - sinfo = client.getLatestServerInfo(); - }); - - afterEach(function() { - server.unsetSearchRequestListener(listenerId); - }); - - it('should trigger search request listener and reply callback', function (done) { - function requestCallback(client, request) { - chai.expect(request.length).to.equal(2); - var keywords = [request[0].keyword, request[1].keyword]; - chai.expect(keywords).to.have.members(['rock', 'pop']); - return new tizen.mediacontroller.RequestReply({key: ['tizen1', 'tizen2']}, 123); - } - server.setSearchRequestListener(requestCallback); - - var request = [ - new tizen.mediacontroller.SearchFilter('MUSIC', 'GENRE', 'rock', null), - new tizen.mediacontroller.SearchFilter('MUSIC', 'GENRE', 'pop', null) - ]; - - sinfo.sendSearchRequest(request, function(reply) { - chai.expect(reply.code).to.equal(123); - chai.expect(reply.data.get('key')).to.deep.equal(['tizen1', 'tizen2']); - done(); + var client = null, + server = null, + sinfo = null, + listenerId = null; + + before(function() { + server = tizen.mediacontroller.createServer(); + client = tizen.mediacontroller.getClient(); + server.updatePlaybackState('PLAY'); + sinfo = client.getLatestServerInfo(); + }); + + afterEach(function() { + server.unsetSearchRequestListener(listenerId); }); - }); - it('should raise InvalidValuesErr if too many filters in the request', function (done) { - var request = []; - for (var i = 0; i < 20 + 1; ++i) { - request.push( - new tizen.mediacontroller.SearchFilter('MUSIC', 'GENRE', 'genre' + i) - ); - } + it('should trigger search request listener and reply callback', function(done) { + function requestCallback(client, request) { + chai.expect(request.length).to.equal(2); + var keywords = [request[0].keyword, request[1].keyword]; + chai.expect(keywords).to.have.members(['rock', 'pop']); + return new tizen.mediacontroller.RequestReply( + { key: ['tizen1', 'tizen2'] }, + 123 + ); + } + server.setSearchRequestListener(requestCallback); + + var request = [ + new tizen.mediacontroller.SearchFilter('MUSIC', 'GENRE', 'rock', null), + new tizen.mediacontroller.SearchFilter('MUSIC', 'GENRE', 'pop', null) + ]; - try { sinfo.sendSearchRequest(request, function(reply) { - done(new Error("search request reply received unexpectedly")); + chai.expect(reply.code).to.equal(123); + chai.expect(reply.data.get('key')).to.deep.equal(['tizen1', 'tizen2']); + done(); }); - done(new Error("sendSearchRequest should fail but did not")); - } catch (error) { - chai.expect(error.name).to.equal('InvalidValuesError'); - done(); - } - }); + }); + + it('should raise InvalidValuesErr if too many filters in the request', function(done) { + var request = []; + for (var i = 0; i < 20 + 1; ++i) { + request.push( + new tizen.mediacontroller.SearchFilter('MUSIC', 'GENRE', 'genre' + i) + ); + } + + try { + sinfo.sendSearchRequest(request, function(reply) { + done(new Error('search request reply received unexpectedly')); + }); + done(new Error('sendSearchRequest should fail but did not')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + + it('should throw type mismatch error for invalid request type', function(done) { + try { + sinfo.sendSearchRequest('not-array', function(reply) { + done(new Error('search request reply received unexpectedly')); + }); + done(new Error('sendSearchRequest should fail but did not')); + } catch (error) { + chai.expect(error.name).to.equal('TypeMismatchError'); + done(); + } + }); + + it('set/unsetSearchRequestListener() methods should not throw an error', function(done) { + try { + server.unsetSearchRequestListener(); + server.setSearchRequestListener(function(client, request) {}); + server.unsetSearchRequestListener(); + server.setSearchRequestListener(function(client, request) {}); + server.unsetSearchRequestListener(); + done(); + } catch (error) { + done(new Error(error)); + } + }); - it('should throw type mismatch error for invalid request type', function (done) { - try { - sinfo.sendSearchRequest('not-array', function(reply) { - done(new Error("search request reply received unexpectedly")); + it('search filter objects should be properly constructed', function(done) { + var f1 = new tizen.mediacontroller.SearchFilter('MUSIC'); + chai.expect(f1.contentType).to.equal('MUSIC'); + chai.expect(f1.category).to.equal('NO_CATEGORY'); + chai.expect(f1.keyword).to.equal(null); + chai.expect(f1.extraData).to.equal(null); + + var f3 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen'); + chai.expect(f3.contentType).to.equal('MUSIC'); + chai.expect(f3.category).to.equal('TITLE'); + chai.expect(f3.keyword).to.equal('tizen'); + chai.expect(f3.extraData).to.equal(null); + + var f4 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen', {}); + chai.expect(f4.contentType).to.equal('MUSIC'); + chai.expect(f4.category).to.equal('TITLE'); + chai.expect(f4.keyword).to.equal('tizen'); + chai.expect(f4.extraData).to.satisfy(x => x instanceof tizen.Bundle); + + var f5 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen', { + key: 'value' }); - done(new Error("sendSearchRequest should fail but did not")); - } catch (error) { - chai.expect(error.name).to.equal('TypeMismatchError'); - done(); - } - }); - - it('set/unsetSearchRequestListener() methods should not throw an error', function (done) { - try { - server.unsetSearchRequestListener(); - server.setSearchRequestListener(function(client, request) {}); - server.unsetSearchRequestListener(); - server.setSearchRequestListener(function(client, request) {}); - server.unsetSearchRequestListener(); + chai.expect(f5.contentType).to.equal('MUSIC'); + chai.expect(f5.category).to.equal('TITLE'); + chai.expect(f5.keyword).to.equal('tizen'); + chai.expect(f5.extraData).to.satisfy(x => x instanceof tizen.Bundle); + chai.expect(f5.extraData.get('key')).to.equal('value'); + done(); - } catch (error) { - done(new Error(error)); - } - }); - - it('search filter objects should be properly constructed', function (done) { - var f1 = new tizen.mediacontroller.SearchFilter('MUSIC'); - chai.expect(f1.contentType).to.equal('MUSIC'); - chai.expect(f1.category).to.equal('NO_CATEGORY'); - chai.expect(f1.keyword).to.equal(null); - chai.expect(f1.extraData).to.equal(null); - - var f3 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen'); - chai.expect(f3.contentType).to.equal('MUSIC'); - chai.expect(f3.category).to.equal('TITLE'); - chai.expect(f3.keyword).to.equal('tizen'); - chai.expect(f3.extraData).to.equal(null); - - var f4 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen', {}); - chai.expect(f4.contentType).to.equal('MUSIC'); - chai.expect(f4.category).to.equal('TITLE'); - chai.expect(f4.keyword).to.equal('tizen'); - chai.expect(f4.extraData).to.satisfy((x) => x instanceof tizen.Bundle); - - var f5 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen', {"key": "value"}); - chai.expect(f5.contentType).to.equal('MUSIC'); - chai.expect(f5.category).to.equal('TITLE'); - chai.expect(f5.keyword).to.equal('tizen'); - chai.expect(f5.extraData).to.satisfy((x) => x instanceof tizen.Bundle); - chai.expect(f5.extraData.get("key")).to.equal('value'); - - done(); - }); - - it('search filter object setters should work properly', function (done) { - var f1 = new tizen.mediacontroller.SearchFilter('MUSIC'); - chai.expect(f1.contentType).to.equal('MUSIC'); - - f1.contentType = 'VIDEO'; - chai.expect(f1.contentType).to.equal('VIDEO'); - - try { - f1.contentType = 'INVALID VALUE'; - done(new Error("invalid content type value should cause error but did not")); - } - catch (error) { - chai.expect(error.name).to.equal("TypeMismatchError"); - } - - try { - f1.contentType = 10; - done(new Error("invalid content type value should cause error but did not")); - } - catch (error) { - chai.expect(error.name).to.equal('TypeMismatchError'); - } - - var f2 = new tizen.mediacontroller.SearchFilter('MUSIC'); - chai.expect(f2.category).to.equal('NO_CATEGORY'); - try { - f2.category = null; - done(new Error('search category is not nullable')); - } - catch (error) { - chai.expect(error.name).to.equal('TypeMismatchError'); - } - - try { - f2.category = 'INVALID VALUE'; - done(new Error('invalid category value should cause an error but did not')); - } - catch (error) { - chai.expect(error.name).to.equal('TypeMismatchError'); - } - - var f3 = new tizen.mediacontroller.SearchFilter('MUSIC'); - chai.expect(f3.keyword).to.be.null; - - f3.keyword = 'hello'; - chai.expect(f3.keyword).to.equal('hello'); - - f3.keyword = null; - chai.expect(f3.keyword).to.be.null; - - f3.keyword = ''; - chai.expect(f3.keyword).to.equal(''); - - var f4 = new tizen.mediacontroller.SearchFilter('MUSIC'); - chai.expect(f4.extraData).to.be.null; - - f4.extraData = new tizen.Bundle({key: "value"}); - chai.expect(f4.extraData.get('key')).to.equal('value'); - - f4.extraData = null; - chai.expect(f4.extraData).to.be.null; - - f4.extraData = {key: "value"}; - chai.expect(f4.extraData.get('key')).to.equal('value'); - - - f4.extraData = "invalid value"; - chai.expect(f4.extraData.data).to.be.empty; - - var f5 = new tizen.mediacontroller.SearchFilter('MUSIC', 'NO_CATEGORY', null); - chai.expect(f5.keyword).to.be.null; - - try { - f5.category = "TITLE"; - done(new Error("exception should be thrown if keyword == null and category != null")); - } - catch (error) { - chai.expect(error.name).to.equal("InvalidValuesError"); - } - - try { - var f6 = new tizen.mediacontroller.SearchFilter("MUSIC", "TITLE", null); - done(new Error("exception should be thrown if keyword == null and category != null")); - } - catch (error) { - chai.expect(error.name).to.equal("InvalidValuesError"); - } - - var f6 = new tizen.mediacontroller.SearchFilter("MUSIC", "TITLE", "tizen"); - try { - f6.keyword = null; - done(new Error("exception should be thrown if keyword == null and category != null")); - } - catch (error) { - chai.expect(error.name).to.equal("InvalidValuesError"); - } - - done(); - }); + }); + + it('search filter object setters should work properly', function(done) { + var f1 = new tizen.mediacontroller.SearchFilter('MUSIC'); + chai.expect(f1.contentType).to.equal('MUSIC'); + + f1.contentType = 'VIDEO'; + chai.expect(f1.contentType).to.equal('VIDEO'); + + try { + f1.contentType = 'INVALID VALUE'; + done(new Error('invalid content type value should cause error but did not')); + } catch (error) { + chai.expect(error.name).to.equal('TypeMismatchError'); + } + + try { + f1.contentType = 10; + done(new Error('invalid content type value should cause error but did not')); + } catch (error) { + chai.expect(error.name).to.equal('TypeMismatchError'); + } + + var f2 = new tizen.mediacontroller.SearchFilter('MUSIC'); + chai.expect(f2.category).to.equal('NO_CATEGORY'); + try { + f2.category = null; + done(new Error('search category is not nullable')); + } catch (error) { + chai.expect(error.name).to.equal('TypeMismatchError'); + } + + try { + f2.category = 'INVALID VALUE'; + done(new Error('invalid category value should cause an error but did not')); + } catch (error) { + chai.expect(error.name).to.equal('TypeMismatchError'); + } + + var f3 = new tizen.mediacontroller.SearchFilter('MUSIC'); + chai.expect(f3.keyword).to.be.null; + + f3.keyword = 'hello'; + chai.expect(f3.keyword).to.equal('hello'); + + f3.keyword = null; + chai.expect(f3.keyword).to.be.null; + + f3.keyword = ''; + chai.expect(f3.keyword).to.equal(''); + + var f4 = new tizen.mediacontroller.SearchFilter('MUSIC'); + chai.expect(f4.extraData).to.be.null; + + f4.extraData = new tizen.Bundle({ key: 'value' }); + chai.expect(f4.extraData.get('key')).to.equal('value'); + + f4.extraData = null; + chai.expect(f4.extraData).to.be.null; + + f4.extraData = { key: 'value' }; + chai.expect(f4.extraData.get('key')).to.equal('value'); + + f4.extraData = 'invalid value'; + chai.expect(f4.extraData.data).to.be.empty; + + var f5 = new tizen.mediacontroller.SearchFilter('MUSIC', 'NO_CATEGORY', null); + chai.expect(f5.keyword).to.be.null; + + try { + f5.category = 'TITLE'; + done( + new Error( + 'exception should be thrown if keyword == null and category != null' + ) + ); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + } + + try { + var f6 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', null); + done( + new Error( + 'exception should be thrown if keyword == null and category != null' + ) + ); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + } + + var f6 = new tizen.mediacontroller.SearchFilter('MUSIC', 'TITLE', 'tizen'); + try { + f6.keyword = null; + done( + new Error( + 'exception should be thrown if keyword == null and category != null' + ) + ); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + } + done(); + }); }); mocha.checkLeaks(); -mocha.run() +mocha + .run() .on('pass', function(test) { - console.log(test.title + " OK"); + console.log(test.title + ' OK'); }) .on('fail', function(test, err) { - console.error(test.title + " FAILED"); + console.error(test.title + ' FAILED'); console.error(err); }) .on('end', function() { console.log('All done'); }); - - - diff --git a/src/mediacontroller/mediacontroller_api.js b/src/mediacontroller/mediacontroller_api.js index 8dda839..0f3fe43 100755 --- a/src/mediacontroller/mediacontroller_api.js +++ b/src/mediacontroller/mediacontroller_api.js @@ -60,8 +60,6 @@ ListenerManager.prototype.addListener = function(callback) { return id; }; - - ListenerManager.prototype.addServerInfoListener = function(callback, name) { var id = this.nextId; if (!this.nativeSet) { @@ -114,40 +112,50 @@ ListenerManager.prototype.removeServerInfoListener = function(watchId) { } }; -var ServerCommandListener = new ListenerManager(native_, '_ServerCommandListener', function(msg, listener) { - // passing raw msg.data object instead of tizen.Bundle - // due to backward compatibility issue. - var reply = listener(msg.clientName, msg.command, msg.data); - - if (!(reply instanceof RequestReply)) { - reply = new RequestReply(xwalk.utils.type.isNullOrUndefined(reply) ? null : reply, 0); - } - - var nativeData = { - clientName: msg.clientName, - requestId: msg.requestId, - reply: reply - }; - - var result = native_.callSync('MediaControllerServer_replyCommand', nativeData); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } -}); +var ServerCommandListener = new ListenerManager( + native_, + '_ServerCommandListener', + function(msg, listener) { + // passing raw msg.data object instead of tizen.Bundle + // due to backward compatibility issue. + var reply = listener(msg.clientName, msg.command, msg.data); + + if (!(reply instanceof RequestReply)) { + reply = new RequestReply( + xwalk.utils.type.isNullOrUndefined(reply) ? null : reply, + 0 + ); + } -var ReplyCommandListener = new ListenerManager(native_, '_ReplyCommandListener', function(msg, listener, watchId) { - if (this.requestIdToListenerId[watchId] === msg.requestId) { + var nativeData = { + clientName: msg.clientName, + requestId: msg.requestId, + reply: reply + }; - // this listener is a wrapper around user callback which is neccessary - // due to difference between sendCommand() and new API methods. - listener(msg); + var result = native_.callSync('MediaControllerServer_replyCommand', nativeData); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + } +); - this.removeListener(watchId); - delete this.requestIdToListenerId[watchId]; +var ReplyCommandListener = new ListenerManager(native_, '_ReplyCommandListener', function( + msg, + listener, + watchId +) { + if (this.requestIdToListenerId[watchId] === msg.requestId) { + // this listener is a wrapper around user callback which is neccessary + // due to difference between sendCommand() and new API methods. + listener(msg); - return true; - } - return false; + this.removeListener(watchId); + delete this.requestIdToListenerId[watchId]; + + return true; + } + return false; }); var ServerPlaybackInfoListener = new ListenerManager( @@ -292,12 +300,12 @@ var MediaControllerContentAgeRating = { }; var MediaControllerSearchCategory = { - NO_CATEGORY: "NO_CATEGORY", - TITLE: "TITLE", - ARTIST: "ARTIST", - ALBUM: "ALBUM", - GENRE: "GENRE", - TPO: "TPO" + NO_CATEGORY: 'NO_CATEGORY', + TITLE: 'TITLE', + ARTIST: 'ARTIST', + ALBUM: 'ALBUM', + GENRE: 'GENRE', + TPO: 'TPO' }; var MediaControllerContentType = { @@ -1026,63 +1034,65 @@ MediaControllerServer.prototype.getAllPlaylists = function( }; function RequestReply(data, code) { - xwalk.utils.validator.isConstructorCall(this, RequestReply); - this.code = xwalk.utils.converter.toLong(code); - this.data = xwalk.utils.type.isNullOrUndefined(data) ? null : new tizen.Bundle(data); + xwalk.utils.validator.isConstructorCall(this, RequestReply); + this.code = xwalk.utils.converter.toLong(code); + this.data = xwalk.utils.type.isNullOrUndefined(data) ? null : new tizen.Bundle(data); } MediaControllerServer.prototype.setSearchRequestListener = function(listener) { - var args = validator_.validateArgs(arguments, [ - {name: 'listener', type: types_.FUNCTION} - ]); + var args = validator_.validateArgs(arguments, [ + { name: 'listener', type: types_.FUNCTION } + ]); - if (!native_.isListenerSet("SearchRequestListener")) { - var result = native_.callSync('MediaControllerServer_addSearchRequestListener', { - listenerId: "SearchRequestListener" - }); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); + if (!native_.isListenerSet('SearchRequestListener')) { + var result = native_.callSync('MediaControllerServer_addSearchRequestListener', { + listenerId: 'SearchRequestListener' + }); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } } - } - - var callback = function (msg) { - var request = []; - msg.request.forEach(function (filter) { - request.push(new SearchFilter( - filter.contentType, - filter.category, - filter.keyword, - filter.extraData - )); - }); - - var reply = args.listener(msg.clientName, request); - if (type_.isUndefined(reply)) { - reply = new RequestReply(null, 0); - } - - var nativeData = { - clientName: msg.clientName, - requestId: msg.requestId, - reply: reply - }; - - var result = native_.callSync('MediaControllerServer_replyCommand', nativeData); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - } - native_.addListener("SearchRequestListener", callback); -} + var callback = function(msg) { + var request = []; + msg.request.forEach(function(filter) { + request.push( + new SearchFilter( + filter.contentType, + filter.category, + filter.keyword, + filter.extraData + ) + ); + }); + + var reply = args.listener(msg.clientName, request); + if (type_.isUndefined(reply)) { + reply = new RequestReply(null, 0); + } + + var nativeData = { + clientName: msg.clientName, + requestId: msg.requestId, + reply: reply + }; + + var result = native_.callSync('MediaControllerServer_replyCommand', nativeData); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + }; + + native_.addListener('SearchRequestListener', callback); +}; MediaControllerServer.prototype.unsetSearchRequestListener = function() { - var result = native_.callSync('MediaControllerServer_removeSearchRequestListener'); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } - native_.removeListener("SearchRequestListener"); -} + var result = native_.callSync('MediaControllerServer_removeSearchRequestListener'); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + native_.removeListener('SearchRequestListener'); +}; function MediaControllerClient() {} @@ -1126,89 +1136,129 @@ MediaControllerClient.prototype.getLatestServerInfo = function() { }; function SearchFilter(contentType, category, keyword, extraData) { - validator_.isConstructorCall(this, SearchFilter); - var args = validator_.validateArgs(arguments, [ - {name: 'contentType', type: types_.ENUM, values: Object.values(MediaControllerContentType)}, - {name: 'category', type: types_.ENUM, values: Object.values(MediaControllerSearchCategory), optional: true}, - {name: 'keyword', type: types_.STRING, nullable: true, optional: true}, - ]); - - if (!args.hasOwnProperty("category")) {args.category = "NO_CATEGORY";} - if (!args.hasOwnProperty("keyword")) {args.keyword = null;} - - extraData = xwalk.utils.type.isUndefined(extraData) ? null : extraData; - args.extraData = xwalk.utils.type.isNull(extraData) ? null : new tizen.Bundle(extraData); - - var extraData_ = args.extraData; - var contentType_ = args.contentType; - var category_ = args.category; - var keyword_ = args.keyword; - - // keyword can be null only when category is NO_CATEGORY - if (xwalk.utils.type.isNull(keyword_) && category_ != MediaControllerSearchCategory.NO_CATEGORY) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); - } - - Object.defineProperties(this, { - contentType: { - enumerable: true, - get: function () { return contentType_; }, - set: function (newContentType) { - var args = validator_.validateArgs(arguments, [{ - name: 'newContentType', + validator_.isConstructorCall(this, SearchFilter); + var args = validator_.validateArgs(arguments, [ + { + name: 'contentType', type: types_.ENUM, values: Object.values(MediaControllerContentType) - }]); - contentType_ = args.newContentType; - } - }, - category: { - enumerable: true, - get: function () { return category_; }, - set: function (newCategory) { - var args = validator_.validateArgs(arguments, [{ - name: 'newCategory', - type: types_.ENUM, - values: Object.values(MediaControllerSearchCategory) - }]); - - // Keyword can be null only if category is NO_CATEGORY. - if (xwalk.utils.type.isNull(keyword_) && args.newCategory != MediaControllerSearchCategory.NO_CATEGORY) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); - } + }, + { + name: 'category', + type: types_.ENUM, + values: Object.values(MediaControllerSearchCategory), + optional: true + }, + { name: 'keyword', type: types_.STRING, nullable: true, optional: true } + ]); - category_ = args.newCategory; - } - }, - keyword: { - enumerable: true, - get: function () { return keyword_; }, - set: function (newKeyword) { - var args = validator_.validateArgs(arguments, [{ - name: 'newKeyword', - type: types_.STRING, - nullable: true - }]); - - // Keyword can only be null if category is NO_CATEGORY. - if (xwalk.utils.type.isNull(args.newKeyword) && this.category != MediaControllerSearchCategory.NO_CATEGORY) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); - } + if (!args.hasOwnProperty('category')) { + args.category = 'NO_CATEGORY'; + } + if (!args.hasOwnProperty('keyword')) { + args.keyword = null; + } - keyword_ = args.newKeyword; - } - }, - extraData: { - enumerable: true, - get: function () { return extraData_ }, - set: function (newData) { - if (xwalk.utils.type.isUndefined(newData)) { - newData = null; - } - extraData_ = xwalk.utils.type.isNull(newData) ? null : new tizen.Bundle(newData); - } + extraData = xwalk.utils.type.isUndefined(extraData) ? null : extraData; + args.extraData = xwalk.utils.type.isNull(extraData) + ? null + : new tizen.Bundle(extraData); + + var extraData_ = args.extraData; + var contentType_ = args.contentType; + var category_ = args.category; + var keyword_ = args.keyword; + + // keyword can be null only when category is NO_CATEGORY + if ( + xwalk.utils.type.isNull(keyword_) && + category_ != MediaControllerSearchCategory.NO_CATEGORY + ) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); } - }); + + Object.defineProperties(this, { + contentType: { + enumerable: true, + get: function() { + return contentType_; + }, + set: function(newContentType) { + var args = validator_.validateArgs(arguments, [ + { + name: 'newContentType', + type: types_.ENUM, + values: Object.values(MediaControllerContentType) + } + ]); + contentType_ = args.newContentType; + } + }, + category: { + enumerable: true, + get: function() { + return category_; + }, + set: function(newCategory) { + var args = validator_.validateArgs(arguments, [ + { + name: 'newCategory', + type: types_.ENUM, + values: Object.values(MediaControllerSearchCategory) + } + ]); + + // Keyword can be null only if category is NO_CATEGORY. + if ( + xwalk.utils.type.isNull(keyword_) && + args.newCategory != MediaControllerSearchCategory.NO_CATEGORY + ) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); + } + + category_ = args.newCategory; + } + }, + keyword: { + enumerable: true, + get: function() { + return keyword_; + }, + set: function(newKeyword) { + var args = validator_.validateArgs(arguments, [ + { + name: 'newKeyword', + type: types_.STRING, + nullable: true + } + ]); + + // Keyword can only be null if category is NO_CATEGORY. + if ( + xwalk.utils.type.isNull(args.newKeyword) && + this.category != MediaControllerSearchCategory.NO_CATEGORY + ) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); + } + + keyword_ = args.newKeyword; + } + }, + extraData: { + enumerable: true, + get: function() { + return extraData_; + }, + set: function(newData) { + if (xwalk.utils.type.isUndefined(newData)) { + newData = null; + } + extraData_ = xwalk.utils.type.isNull(newData) + ? null + : new tizen.Bundle(newData); + } + } + }); } function MediaControllerServerInfo(data) { @@ -1424,67 +1474,86 @@ MediaControllerServerInfo.prototype.sendRepeatState = function() { native_.call('MediaControllerServerInfo_sendRepeatState', data, callback); }; -MediaControllerServerInfo.prototype.sendCommand = function(command, data, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - {name: 'command', type: types_.STRING}, - {name: 'data', type: types_.DICTIONARY, nullable: true}, - {name: 'successCallback', type: types_.FUNCTION}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} - ]); +MediaControllerServerInfo.prototype.sendCommand = function( + command, + data, + successCallback, + errorCallback +) { + var args = validator_.validateArgs(arguments, [ + { name: 'command', type: types_.STRING }, + { name: 'data', type: types_.DICTIONARY, nullable: true }, + { name: 'successCallback', type: types_.FUNCTION }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - return; - } - native_.callIfPossible(args.successCallback, native_.getResultObject(result).data, - native_.getResultObject(result).code); - }; + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + return; + } + native_.callIfPossible( + args.successCallback, + native_.getResultObject(result).data, + native_.getResultObject(result).code + ); + }; - var nativeData = { - command: args.command, - data: args.data === null ? null : new tizen.Bundle(args.data), - name: this.name, - listenerId: ReplyCommandListener.listenerName - }; + var nativeData = { + command: args.command, + data: args.data === null ? null : new tizen.Bundle(args.data), + name: this.name, + listenerId: ReplyCommandListener.listenerName + }; - var replyListenerId = ReplyCommandListener.addListener(callback); - var result = native_.callSync('MediaControllerServerInfo_sendCommand', nativeData); + var replyListenerId = ReplyCommandListener.addListener(callback); + var result = native_.callSync('MediaControllerServerInfo_sendCommand', nativeData); - ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId; + ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId; }; -MediaControllerServerInfo.prototype.sendSearchRequest = function(request, successCallback, errorCallback) { - var args = validator_.validateArgs(arguments, [ - {name: 'request', type: types_.ARRAY, values: SearchFilter}, - {name: 'successCallback', type: types_.FUNCTION}, - {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} - ]); - - if (args.request.length < 1 || args.request.length > 20) { - throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); - } +MediaControllerServerInfo.prototype.sendSearchRequest = function( + request, + successCallback, + errorCallback +) { + var args = validator_.validateArgs(arguments, [ + { name: 'request', type: types_.ARRAY, values: SearchFilter }, + { name: 'successCallback', type: types_.FUNCTION }, + { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true } + ]); - var callback = function(result) { - if (native_.isFailure(result)) { - native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); - return; + if (args.request.length < 1 || args.request.length > 20) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR); } - var reply = native_.getResultObject(result); - native_.callIfPossible(args.successCallback, new RequestReply(reply.data, reply.code)); - }; - var nativeData = { - request: args.request, - name: this.name, - listenerId: ReplyCommandListener.listenerName - }; + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + return; + } + var reply = native_.getResultObject(result); + native_.callIfPossible( + args.successCallback, + new RequestReply(reply.data, reply.code) + ); + }; + + var nativeData = { + request: args.request, + name: this.name, + listenerId: ReplyCommandListener.listenerName + }; - var replyListenerId = ReplyCommandListener.addListener(callback); - var result = native_.callSync('MediaControllerServerInfo_sendSearchRequest', nativeData, callback); + var replyListenerId = ReplyCommandListener.addListener(callback); + var result = native_.callSync( + 'MediaControllerServerInfo_sendSearchRequest', + nativeData, + callback + ); - ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId; -} + ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId; +}; MediaControllerServerInfo.prototype.addServerStatusChangeListener = function(listener) { var args = validator_.validateArgs(arguments, [ @@ -1793,4 +1862,3 @@ MediaControllerPlaylist.prototype.getItems = function(successCallback, errorCall exports = new MediaControllerManager(); exports.SearchFilter = SearchFilter; exports.RequestReply = RequestReply; - diff --git a/src/mediacontroller/mediacontroller_client.cc b/src/mediacontroller/mediacontroller_client.cc index 71e29c5..2346c2a 100644 --- a/src/mediacontroller/mediacontroller_client.cc +++ b/src/mediacontroller/mediacontroller_client.cc @@ -544,8 +544,7 @@ void MediaControllerClient::OnMetadataUpdate(const char* server_name, mc_metadat PlatformResult MediaControllerClient::SendSearchRequest(const std::string& server_name, const picojson::value& request, const JsonCallback& callback, - char** request_id) -{ + char** request_id) { ScopeLogger(); mc_search_h search_request; SCOPE_EXIT { @@ -555,8 +554,8 @@ PlatformResult MediaControllerClient::SendSearchRequest(const std::string& serve int ret = mc_search_create(&search_request); if (MEDIA_CONTROLLER_ERROR_NONE != ret) { return LogAndCreateResult( - ErrorCode::UNKNOWN_ERR, "Unable to create search request.", - ("mc_search_create error: %d, message: %s", ret, get_error_message(ret))); + ErrorCode::UNKNOWN_ERR, "Unable to create search request.", + ("mc_search_create error: %d, message: %s", ret, get_error_message(ret))); } if (!request.is()) { @@ -565,56 +564,56 @@ PlatformResult MediaControllerClient::SendSearchRequest(const std::string& serve "MediaControllerClient::SendSearchRequest request param is not an array."); } - for (const auto& filter_obj: request.get()) { + for (const auto& filter_obj : request.get()) { const picojson::object& filter = filter_obj.get(); // contentType std::string content_type_str = filter.at("contentType").get(); mc_content_type_e content_type_e; - PlatformResult result = types::MediaControllerContentTypeEnum.getValue(content_type_str, &content_type_e); + PlatformResult result = + types::MediaControllerContentTypeEnum.getValue(content_type_str, &content_type_e); if (!result) { - LoggerE("MediaControllerContentTypeEnum.getValue(%s) failed.", content_type_str.c_str()); - return result; + LoggerE("MediaControllerContentTypeEnum.getValue(%s) failed.", content_type_str.c_str()); + return result; } // category std::string search_category_str = filter.at("category").get(); mc_search_category_e search_category_e; - result = types::MediaControllerSearchCategoryEnum.getValue(search_category_str, &search_category_e); + result = + types::MediaControllerSearchCategoryEnum.getValue(search_category_str, &search_category_e); if (!result) { - LoggerE("MediaControllerSearchCategoryEnum.getValue(%s) failed.", search_category_str.c_str()); - return result; + LoggerE("MediaControllerSearchCategoryEnum.getValue(%s) failed.", + search_category_str.c_str()); + return result; } // extra data bundle* bundle_data = nullptr; - SCOPE_EXIT { bundle_free(bundle_data); }; + SCOPE_EXIT { + bundle_free(bundle_data); + }; result = JsonToBundle(filter.at("extraData"), &bundle_data); if (!result) { - return LogAndCreateResult( - ErrorCode::INVALID_VALUES_ERR, "Unable to add data to bundle", - ("JsonToBundle() error message: %s", result.message().c_str())); + return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Unable to add data to bundle", + ("JsonToBundle() error message: %s", result.message().c_str())); } - ret = mc_search_set_condition( - search_request, - content_type_e, - search_category_e, - filter.at("keyword").get().c_str(), - bundle_data); + ret = mc_search_set_condition(search_request, content_type_e, search_category_e, + filter.at("keyword").get().c_str(), bundle_data); if (MEDIA_CONTROLLER_ERROR_NONE != ret) { return LogAndCreateResult( - ErrorCode::UNKNOWN_ERR, "Unable to set search condition.", - ("mc_search_set_condition error: %d, message: %s", ret, get_error_message(ret))); + ErrorCode::UNKNOWN_ERR, "Unable to set search condition.", + ("mc_search_set_condition error: %d, message: %s", ret, get_error_message(ret))); } } ret = mc_client_send_search_cmd(handle_, server_name.c_str(), search_request, request_id); if (MEDIA_CONTROLLER_ERROR_NONE != ret) { return LogAndCreateResult( - ErrorCode::UNKNOWN_ERR, "Unable to send search request.", - ("mc_client_send_search_cmd error: %d, message: %s", ret, get_error_message(ret))); + ErrorCode::UNKNOWN_ERR, "Unable to send search request.", + ("mc_client_send_search_cmd error: %d, message: %s", ret, get_error_message(ret))); } command_reply_callback_ = callback; @@ -641,8 +640,8 @@ PlatformResult MediaControllerClient::SendCommand(const std::string& server_name if (nullptr == bundle_data) { LoggerD("bundle is null"); } - int ret = mc_client_send_custom_cmd(handle_, server_name.c_str(), - command.c_str(), bundle_data, request_id); + int ret = mc_client_send_custom_cmd(handle_, server_name.c_str(), command.c_str(), bundle_data, + request_id); if (MEDIA_CONTROLLER_ERROR_NONE != ret) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Error sending custom command", diff --git a/src/mediacontroller/mediacontroller_client.h b/src/mediacontroller/mediacontroller_client.h index f41fa79..e073a77 100644 --- a/src/mediacontroller/mediacontroller_client.h +++ b/src/mediacontroller/mediacontroller_client.h @@ -49,8 +49,7 @@ class MediaControllerClient { common::PlatformResult SendSearchRequest(const std::string& server_name, const picojson::value& request, - const JsonCallback& callback, - char** request_id); + const JsonCallback& callback, char** request_id); common::PlatformResult SendCommand(const std::string& server_name, const std::string& command, const picojson::value& data, const JsonCallback& reply_cb, diff --git a/src/mediacontroller/mediacontroller_instance.cc b/src/mediacontroller/mediacontroller_instance.cc index fd9158b..41022de 100644 --- a/src/mediacontroller/mediacontroller_instance.cc +++ b/src/mediacontroller/mediacontroller_instance.cc @@ -419,8 +419,7 @@ void MediaControllerInstance::MediaControllerServerRemoveChangeRequestPlaybackIn } void MediaControllerInstance::MediaControllerServerAddSearchRequestListener( - const picojson::value& args, - picojson::object& out) { + const picojson::value& args, picojson::object& out) { ScopeLogger(); if (!server_) { @@ -445,13 +444,12 @@ void MediaControllerInstance::MediaControllerServerAddSearchRequestListener( } void MediaControllerInstance::MediaControllerServerRemoveSearchRequestListener( - const picojson::value& args, - picojson::object& out) { + const picojson::value& args, picojson::object& out) { ScopeLogger(); if (!server_) { - LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Server not initialized."), - &out, ("Failed: server_")); + LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Server not initialized."), &out, + ("Failed: server_")); return; } @@ -949,8 +947,7 @@ void MediaControllerInstance::MediaControllerServerInfoSendRepeatState(const pic } void MediaControllerInstance::MediaControllerServerInfoSendSearchRequest( - const picojson::value& args, - picojson::object& out) { + const picojson::value& args, picojson::object& out) { ScopeLogger(); if (!client_) { @@ -974,17 +971,13 @@ void MediaControllerInstance::MediaControllerServerInfoSendSearchRequest( free(request_id); }; - PlatformResult result = client_->SendSearchRequest( - args.get("name").get(), - args.get("request"), - reply_cb, - &request_id); + PlatformResult result = client_->SendSearchRequest(args.get("name").get(), + args.get("request"), reply_cb, &request_id); if (result) { ReportSuccess(out); out["requestId"] = picojson::value(std::string(request_id)); - } - else { + } else { LogAndReportError(result, &out, ("Failed to send command.")); } } @@ -1014,9 +1007,9 @@ void MediaControllerInstance::MediaControllerServerInfoSendCommand(const picojso free(request_id); }; - PlatformResult result = client_->SendCommand( - args.get("name").get(), args.get("command").get(), - args.get("data"), reply_cb, &request_id); + PlatformResult result = client_->SendCommand(args.get("name").get(), + args.get("command").get(), + args.get("data"), reply_cb, &request_id); if (result) { ReportSuccess(out); diff --git a/src/mediacontroller/mediacontroller_instance.h b/src/mediacontroller/mediacontroller_instance.h index 829a332..5757c94 100644 --- a/src/mediacontroller/mediacontroller_instance.h +++ b/src/mediacontroller/mediacontroller_instance.h @@ -50,8 +50,10 @@ class MediaControllerInstance : public common::ParsedInstance { void MediaControllerServerRemoveChangeRequestPlaybackInfoListener(const picojson::value& args, picojson::object& out); - void MediaControllerServerAddSearchRequestListener(const picojson::value& args, picojson::object& out); - void MediaControllerServerRemoveSearchRequestListener(const picojson::value& args, picojson::object& out); + void MediaControllerServerAddSearchRequestListener(const picojson::value& args, + picojson::object& out); + void MediaControllerServerRemoveSearchRequestListener(const picojson::value& args, + picojson::object& out); void MediaControllerServerReplyCommand(const picojson::value& args, picojson::object& out); void MediaControllerServerAddCommandListener(const picojson::value& args, picojson::object& out); @@ -76,7 +78,8 @@ class MediaControllerInstance : public common::ParsedInstance { void MediaControllerServerInfoSendRepeatMode(const picojson::value& args, picojson::object& out); void MediaControllerServerInfoSendRepeatState(const picojson::value& args, picojson::object& out); void MediaControllerServerInfoSendShuffleMode(const picojson::value& args, picojson::object& out); - void MediaControllerServerInfoSendSearchRequest(const picojson::value& args, picojson::object& out); + void MediaControllerServerInfoSendSearchRequest(const picojson::value& args, + picojson::object& out); void MediaControllerServerInfoSendCommand(const picojson::value& args, picojson::object& out); void MediaControllerServerInfoAddServerStatusChangeListener(const picojson::value& args, picojson::object& out); diff --git a/src/mediacontroller/mediacontroller_server.cc b/src/mediacontroller/mediacontroller_server.cc index acdbf19..ef3c0fd 100644 --- a/src/mediacontroller/mediacontroller_server.cc +++ b/src/mediacontroller/mediacontroller_server.cc @@ -328,15 +328,17 @@ void MediaControllerServer::OnSearchRequestReceived(const char* client_name, con std::string temp; PlatformResult result = types::MediaControllerContentTypeEnum.getName(content_type, &temp); if (!result) { - LoggerE("MediaControllerContentTypeEnum.getName() failed with error message: %s", result.message().c_str()); - return false; + LoggerE("MediaControllerContentTypeEnum.getName() failed with error message: %s", + result.message().c_str()); + return false; } object["contentType"] = picojson::value(temp); result = types::MediaControllerSearchCategoryEnum.getName(category, &temp); if (!result) { - LoggerE("MediaControllerSearchCategoryEnum.getName() failed with error message: %s", result.message().c_str()); - return false; + LoggerE("MediaControllerSearchCategoryEnum.getName() failed with error message: %s", + result.message().c_str()); + return false; } object["category"] = picojson::value(temp); @@ -345,8 +347,8 @@ void MediaControllerServer::OnSearchRequestReceived(const char* client_name, con picojson::value data_json; result = common::BundleToJson(data, &data_json); if (!result) { - LoggerE("BundleToJson failed with error message: %s", result.message().c_str()); - return false; + LoggerE("BundleToJson failed with error message: %s", result.message().c_str()); + return false; } object["extraData"] = data_json; @@ -390,8 +392,7 @@ void MediaControllerServer::OnCommandReceived(const char* client_name, const cha } PlatformResult MediaControllerServer::CommandReply(const std::string& client_name, - const std::string& request_id, - int code, + const std::string& request_id, int code, const picojson::value& data) { ScopeLogger(); bundle* bundle = nullptr; @@ -405,8 +406,8 @@ PlatformResult MediaControllerServer::CommandReply(const std::string& client_nam return result; } - int ret = mc_server_send_cmd_reply(handle_, client_name.c_str(), request_id.c_str(), - code, bundle); + int ret = + mc_server_send_cmd_reply(handle_, client_name.c_str(), request_id.c_str(), code, bundle); if (MEDIA_CONTROLLER_ERROR_NONE != ret) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Error sending command reply", @@ -422,8 +423,8 @@ PlatformResult MediaControllerServer::SetSearchRequestListener(const JsonCallbac int ret = mc_server_set_search_cmd_received_cb(handle_, OnSearchRequestReceived, this); if (MEDIA_CONTROLLER_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set search request callback.", - ("mc_server_set_search_cmd_received_cb() error: %d, message: %s", - ret, get_error_message(ret))); + ("mc_server_set_search_cmd_received_cb() error: %d, message: %s", ret, + get_error_message(ret))); } search_request_listener_ = callback; @@ -435,8 +436,8 @@ PlatformResult MediaControllerServer::UnsetSearchRequestListener() { int ret = mc_server_unset_search_cmd_received_cb(handle_); if (MEDIA_CONTROLLER_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to unset search request callback.", - ("mc_server_unset_search_cmd_received_cb() error: %d, message: %s", - ret, get_error_message(ret))); + ("mc_server_unset_search_cmd_received_cb() error: %d, message: %s", + ret, get_error_message(ret))); } search_request_listener_ = nullptr; return PlatformResult(ErrorCode::NO_ERROR); diff --git a/src/mediacontroller/mediacontroller_utils.cc b/src/mediacontroller/mediacontroller_utils.cc index ebe070c..2f3aaa5 100644 --- a/src/mediacontroller/mediacontroller_utils.cc +++ b/src/mediacontroller/mediacontroller_utils.cc @@ -85,18 +85,11 @@ const common::PlatformEnum MediaControllerContentTypeEnum{ {"MUSIC", MC_CONTENT_TYPE_MUSIC}, {"VIDEO", MC_CONTENT_TYPE_VIDEO}, {"OTHER", MC_CONTENT_TYPE_OTHER}, - {"UNDECIDED", MC_CONTENT_TYPE_UNDECIDED} -}; - -const common::PlatformEnum MediaControllerSearchCategoryEnum { - {"NONE", MC_SEARCH_NO_CATEGORY}, - {"TITLE", MC_SEARCH_TITLE}, - {"ARTIST", MC_SEARCH_ARTIST}, - {"ALBUM", MC_SEARCH_ALBUM}, - {"GENRE", MC_SEARCH_GENRE}, - {"TPO", MC_SEARCH_TPO} -}; + {"UNDECIDED", MC_CONTENT_TYPE_UNDECIDED}}; +const common::PlatformEnum MediaControllerSearchCategoryEnum{ + {"NONE", MC_SEARCH_NO_CATEGORY}, {"TITLE", MC_SEARCH_TITLE}, {"ARTIST", MC_SEARCH_ARTIST}, + {"ALBUM", MC_SEARCH_ALBUM}, {"GENRE", MC_SEARCH_GENRE}, {"TPO", MC_SEARCH_TPO}}; PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state) { ScopeLogger(); diff --git a/src/package/package_info_provider.cc b/src/package/package_info_provider.cc index 71c9550..40f1a6b 100644 --- a/src/package/package_info_provider.cc +++ b/src/package/package_info_provider.cc @@ -218,8 +218,8 @@ bool PackageInfoProvider::ConvertToPackageToObject(const pkgmgrinfo_pkginfo_h in }; picojson::array array_data; - ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_APP_COMPONENT_TYPE_ALL, PackageAppInfoCb, - &array_data); + ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_APP_COMPONENT_TYPE_ALL, + PackageAppInfoCb, &array_data); if (ret != PACKAGE_MANAGER_ERROR_NONE) { LoggerE("Failed to get app info: %d (%s)", ret, get_error_message(ret)); return false; diff --git a/src/tizen/js/ut/bundle_ut.js b/src/tizen/js/ut/bundle_ut.js index 4deb9c9..a0b2bce 100644 --- a/src/tizen/js/ut/bundle_ut.js +++ b/src/tizen/js/ut/bundle_ut.js @@ -1,200 +1,195 @@ mocha.setup('bdd'); -describe('default constructor', function () { - it('should initialize empty bundle object', function (done) { - var bundle = new tizen.Bundle(); - chai.expect(bundle.data).to.be.empty; - done(); - }); +describe('default constructor', function() { + it('should initialize empty bundle object', function(done) { + var bundle = new tizen.Bundle(); + chai.expect(bundle.data).to.be.empty; + done(); + }); }); -describe('json constructor', function () { - it('should properly initialize entries of all types', function (done) { - var json = { - key1: 'value', - key2: ['value1', 'value2'], - key3: new Uint8Array([1, 2, 3]), - key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])], - key5: [1, 2, 3], - key6: [[1, 2, 3], [4, 5, 6]], - key7: [], - key8: null, - key9: {}, - key10: [1,2,300] - }; - - var bundle = new tizen.Bundle(json); - chai.expect(bundle.data.key1).to.equal('value'); - chai.expect(bundle.data.key2).to.deep.equal(json.key2); - chai.expect(bundle.data.key3).to.deep.equal(json.key3); - chai.expect(bundle.data.key4).to.deep.equal(json.key4); - chai.expect(bundle.data.key5).to.deep.equal(json.key3); - chai.expect(bundle.data.key6).to.deep.equal(json.key4); - chai.expect(bundle.data.key7).to.be.empty; - chai.expect(bundle.data.key8).to.equal('null'); - chai.expect(bundle.data.key9).to.equal('[object Object]'); - chai.expect(bundle.data.key10).to.equal('1,2,300'); - done(); - }); +describe('json constructor', function() { + it('should properly initialize entries of all types', function(done) { + var json = { + key1: 'value', + key2: ['value1', 'value2'], + key3: new Uint8Array([1, 2, 3]), + key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])], + key5: [1, 2, 3], + key6: [[1, 2, 3], [4, 5, 6]], + key7: [], + key8: null, + key9: {}, + key10: [1, 2, 300] + }; + + var bundle = new tizen.Bundle(json); + chai.expect(bundle.data.key1).to.equal('value'); + chai.expect(bundle.data.key2).to.deep.equal(json.key2); + chai.expect(bundle.data.key3).to.deep.equal(json.key3); + chai.expect(bundle.data.key4).to.deep.equal(json.key4); + chai.expect(bundle.data.key5).to.deep.equal(json.key3); + chai.expect(bundle.data.key6).to.deep.equal(json.key4); + chai.expect(bundle.data.key7).to.be.empty; + chai.expect(bundle.data.key8).to.equal('null'); + chai.expect(bundle.data.key9).to.equal('[object Object]'); + chai.expect(bundle.data.key10).to.equal('1,2,300'); + done(); + }); }); -describe('copy constructor', function () { - it('should create deep copy of bundle data', function (done) { - var src = new tizen.Bundle({ - key1: 'value', - key2: ['value1', 'value2'], +describe('copy constructor', function() { + it('should create deep copy of bundle data', function(done) { + var src = new tizen.Bundle({ + key1: 'value', + key2: ['value1', 'value2'] + }); + var dest = new tizen.Bundle(src); + chai.expect(dest).to.deep.equal(src); + done(); }); - var dest = new tizen.Bundle(src); - chai.expect(dest).to.deep.equal(src); - done(); - }); }); -describe('setter and getter', function () { - it('should set string entry', function (done) { - var bundle = new tizen.Bundle(); - bundle.set('string', 'hello, world'); - chai.expect(bundle.get('string')).to.equal('hello, world'); - chai.expect(bundle.typeOf('string')).to.equal('STRING'); - done(); - }); - - it('should set string array entry', function (done) { - var bundle = new tizen.Bundle(); - bundle.set('stringArray', ['hello', 'world']); - chai.expect(bundle.get('stringArray')).to.deep.equal(['hello', 'world']); - chai.expect(bundle.typeOf('stringArray')).to.equal('STRING_ARRAY'); - done(); - }); - - it('should set byte stream entry', function (done) { - var bundle = new tizen.Bundle(); - bundle.set('bytes', new Uint8Array([1,2,3])); - chai.expect(bundle.get('bytes')).to.deep.equal(new Uint8Array([1,2,3])); - chai.expect(bundle.typeOf('bytes')).to.equal('BYTES'); - done(); - }); - - it('should set byte streams array entry', function (done) { - var bundle = new tizen.Bundle(); - bundle.set('bytesArray', [ - new Uint8Array([1,2,3]), - new Uint8Array([4,5,6]) - ]); - chai.expect(bundle.get('bytesArray')).to.deep.equal([ - new Uint8Array([1,2,3]), - new Uint8Array([4,5,6]) - ]); - chai.expect(bundle.typeOf('bytesArray')).to.equal('BYTES_ARRAY'); - done(); - }); - - it('should convert unsupported types to strings', function (done) { - var bundle = new tizen.Bundle(); - - bundle.set('other1', function () {}); - bundle.set('other2', undefined); - - chai.expect(bundle.typeOf('other1')).to.equal('STRING'); - chai.expect(bundle.get('other1')).to.equal('function () {}'); - - chai.expect(bundle.typeOf('other2')).to.equal('STRING'); - chai.expect(bundle.get('other2')).to.equal('undefined'); - - done(); - }); - - it('should throw NotFoundErr if key does not exist - get()', function (done) { - var bundle = new tizen.Bundle(); - try { - bundle.get("not-a-key"); - done(new Error("bundle.get() should fail but it did not")); - } - catch (error) { - chai.expect(error.code).to.equal(WebAPIException.NOT_FOUND_ERR); - done(); - } - }); - - it('should throw NotFoundErr if key does not exist - typeOf()', function (done) { - var bundle = new tizen.Bundle(); - try { - bundle.get("not-a-key"); - done(new Error("bundle.get() should fail but it did not")); - } - catch (error) { - chai.expect(error.code).to.equal(WebAPIException.NOT_FOUND_ERR); - done(); - } - }); +describe('setter and getter', function() { + it('should set string entry', function(done) { + var bundle = new tizen.Bundle(); + bundle.set('string', 'hello, world'); + chai.expect(bundle.get('string')).to.equal('hello, world'); + chai.expect(bundle.typeOf('string')).to.equal('STRING'); + done(); + }); + + it('should set string array entry', function(done) { + var bundle = new tizen.Bundle(); + bundle.set('stringArray', ['hello', 'world']); + chai.expect(bundle.get('stringArray')).to.deep.equal(['hello', 'world']); + chai.expect(bundle.typeOf('stringArray')).to.equal('STRING_ARRAY'); + done(); + }); + + it('should set byte stream entry', function(done) { + var bundle = new tizen.Bundle(); + bundle.set('bytes', new Uint8Array([1, 2, 3])); + chai.expect(bundle.get('bytes')).to.deep.equal(new Uint8Array([1, 2, 3])); + chai.expect(bundle.typeOf('bytes')).to.equal('BYTES'); + done(); + }); + + it('should set byte streams array entry', function(done) { + var bundle = new tizen.Bundle(); + bundle.set('bytesArray', [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]); + chai.expect(bundle.get('bytesArray')).to.deep.equal([ + new Uint8Array([1, 2, 3]), + new Uint8Array([4, 5, 6]) + ]); + chai.expect(bundle.typeOf('bytesArray')).to.equal('BYTES_ARRAY'); + done(); + }); + + it('should convert unsupported types to strings', function(done) { + var bundle = new tizen.Bundle(); + + bundle.set('other1', function() {}); + bundle.set('other2', undefined); + + chai.expect(bundle.typeOf('other1')).to.equal('STRING'); + chai.expect(bundle.get('other1')).to.equal('function () {}'); + + chai.expect(bundle.typeOf('other2')).to.equal('STRING'); + chai.expect(bundle.get('other2')).to.equal('undefined'); + + done(); + }); + + it('should throw NotFoundErr if key does not exist - get()', function(done) { + var bundle = new tizen.Bundle(); + try { + bundle.get('not-a-key'); + done(new Error('bundle.get() should fail but it did not')); + } catch (error) { + chai.expect(error.code).to.equal(WebAPIException.NOT_FOUND_ERR); + done(); + } + }); + + it('should throw NotFoundErr if key does not exist - typeOf()', function(done) { + var bundle = new tizen.Bundle(); + try { + bundle.get('not-a-key'); + done(new Error('bundle.get() should fail but it did not')); + } catch (error) { + chai.expect(error.code).to.equal(WebAPIException.NOT_FOUND_ERR); + done(); + } + }); }); -describe('forEach', function () { - it('should trigger callback for each entry', function (done) { - var json = { - key1: 'value', - key2: ['value1', 'value2'], - key3: new Uint8Array([1, 2, 3]), - key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])] - }; - var bundle = new tizen.Bundle(json); - var keys = Object.keys(json); - bundle.forEach(function (key, value, type) { - var index = keys.indexOf(key); - chai.expect(index).to.be.gte(0); - keys.splice(index, 1); +describe('forEach', function() { + it('should trigger callback for each entry', function(done) { + var json = { + key1: 'value', + key2: ['value1', 'value2'], + key3: new Uint8Array([1, 2, 3]), + key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])] + }; + var bundle = new tizen.Bundle(json); + var keys = Object.keys(json); + bundle.forEach(function(key, value, type) { + var index = keys.indexOf(key); + chai.expect(index).to.be.gte(0); + keys.splice(index, 1); + }); + chai.expect(keys).to.be.empty; + done(); }); - chai.expect(keys).to.be.empty; - done(); - }); }); -describe('toJSON', function () { - it('should properly convert bundle to json', function (done) { - var json = { - key1: 'value', - key2: ['value1', 'value2'], - key3: new Uint8Array([1, 2, 3]), - key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])] - }; - var result = new tizen.Bundle(json).toJSON(); - chai.expect(result.key1).to.equal(json.key1); - chai.expect(result.key2).to.deep.equal(json.key2); - chai.expect(result.key3).to.deep.equal([1,2,3]); - chai.expect(result.key4).to.deep.equal([[1,2,3], [4,5,6]]); - done(); - }); +describe('toJSON', function() { + it('should properly convert bundle to json', function(done) { + var json = { + key1: 'value', + key2: ['value1', 'value2'], + key3: new Uint8Array([1, 2, 3]), + key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])] + }; + var result = new tizen.Bundle(json).toJSON(); + chai.expect(result.key1).to.equal(json.key1); + chai.expect(result.key2).to.deep.equal(json.key2); + chai.expect(result.key3).to.deep.equal([1, 2, 3]); + chai.expect(result.key4).to.deep.equal([[1, 2, 3], [4, 5, 6]]); + done(); + }); }); -describe('toString', function () { - it('should properly convert bundle to string', function (done) { - var json = { - key1: 'value', - key2: ['value1', 'value2'], - key3: new Uint8Array([1, 2, 3]), - key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])], - key5: [1, 2, 3], - key6: [[1, 2, 3], [4, 5, 6]] - }; - var bundle = new tizen.Bundle(json); - var expected = - '{"key1":"value","key2":["value1","value2"],"key3":[1,2,3],' + - '"key4":[[1,2,3],[4,5,6]],"key5":[1,2,3],"key6":[[1,2,3],[4,5,6]]}'; - chai.expect(bundle.toString()).to.equal(expected); - done(); - }); +describe('toString', function() { + it('should properly convert bundle to string', function(done) { + var json = { + key1: 'value', + key2: ['value1', 'value2'], + key3: new Uint8Array([1, 2, 3]), + key4: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])], + key5: [1, 2, 3], + key6: [[1, 2, 3], [4, 5, 6]] + }; + var bundle = new tizen.Bundle(json); + var expected = + '{"key1":"value","key2":["value1","value2"],"key3":[1,2,3],' + + '"key4":[[1,2,3],[4,5,6]],"key5":[1,2,3],"key6":[[1,2,3],[4,5,6]]}'; + chai.expect(bundle.toString()).to.equal(expected); + done(); + }); }); mocha.checkLeaks(); -mocha.run() +mocha + .run() .on('pass', function(test) { - console.log(test.title + " OK"); + console.log(test.title + ' OK'); }) .on('fail', function(test, err) { - console.error(test.title + " FAILED"); + console.error(test.title + ' FAILED'); console.error(err); }) .on('end', function() { console.log('All done'); }); - diff --git a/src/tizen/tizen_api.js b/src/tizen/tizen_api.js index 7b96118..3cc39f8 100644 --- a/src/tizen/tizen_api.js +++ b/src/tizen/tizen_api.js @@ -514,11 +514,11 @@ function Bundle(arg) { // copy constructor if (arg instanceof tizen.Bundle) { - json = JSON.parse(arg.toString()); + json = JSON.parse(arg.toString()); } // json to bundle conversion else if (xwalk.utils.type.isObject(arg)) { - json = arg; + json = arg; } forEachOwnProperty( @@ -527,7 +527,7 @@ function Bundle(arg) { this.set(key, value); }.bind(this) ); -}; +} exports.Bundle = Bundle; exports.Bundle.prototype.constructor = exports.Bundle; diff --git a/src/widgetservice/widgetservice_instance.cc b/src/widgetservice/widgetservice_instance.cc index 1b36c66..c1a2bb5 100644 --- a/src/widgetservice/widgetservice_instance.cc +++ b/src/widgetservice/widgetservice_instance.cc @@ -476,7 +476,8 @@ void WidgetServiceInstance::CallWidgetLifecycleListener(const std::string& widge std::lock_guard lock(listener_mutex_); const auto it = listener_map_.find(widget_id); if (listener_map_.end() != it) { - Post(getWidgetStateChangeListenerToken("WidgetStateChangeCallback", widget_id), TizenSuccess{response}); + Post(getWidgetStateChangeListenerToken("WidgetStateChangeCallback", widget_id), + TizenSuccess{response}); return; }