--- /dev/null
+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"};
+ });
+
+ 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));
+ });
+ });
+
+ 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);
+ });
+
+ 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 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));
+ });
+ });
+
+ 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()
+ .on('pass', function(test) {
+ console.log(test.title + " OK");
+ })
+ .on('fail', function(test, err) {
+ console.error(test.title + " FAILED");
+ console.error(err);
+ })
+ .on('end', function() {
+ console.log('All done');
+ });
+