WIP on TDR test stubs

This commit is contained in:
deadprogram 2014-02-18 07:18:25 -08:00
parent 02d0e138bb
commit 44eae49422
4 changed files with 140 additions and 7 deletions

22
dist/robot.js vendored
View File

@ -62,6 +62,7 @@
this.drivers = {}; this.drivers = {};
this.commands = []; this.commands = [];
this.registerAdaptor("./test/loopback", "loopback"); this.registerAdaptor("./test/loopback", "loopback");
this.registerAdaptor("./test/test-adaptor", "test");
this.registerDriver("./test/ping", "ping"); this.registerDriver("./test/ping", "ping");
this.testing = process.env['CYLON_TEST']; this.testing = process.env['CYLON_TEST'];
this.initConnections(opts.connection || opts.connections); this.initConnections(opts.connection || opts.connections);
@ -194,20 +195,29 @@
}; };
Robot.prototype.initAdaptor = function(adaptorName, connection, opts) { Robot.prototype.initAdaptor = function(adaptorName, connection, opts) {
var realAdaptor, testAdaptor;
if (opts == null) { if (opts == null) {
opts = {}; opts = {};
} }
return this.robot.requireAdaptor(adaptorName).adaptor({ realAdaptor = this.robot.requireAdaptor(adaptorName).adaptor({
name: adaptorName, name: adaptorName,
connection: connection, connection: connection,
extraParams: opts extraParams: opts
}); });
if (this.robot.testing != null) {
testAdaptor = this.robot.requireAdaptor('test').adaptor({
name: adaptorName,
connection: connection,
extraParams: opts
});
testAdaptor.proxyTestCommands(realAdaptor);
return testAdaptor;
} else {
return realAdaptor;
}
}; };
Robot.prototype.requireAdaptor = function(adaptorName) { Robot.prototype.requireAdaptor = function(adaptorName) {
if (this.robot.testing != null) {
return this.robot.adaptors['loopback'];
}
if (this.robot.adaptors[adaptorName] == null) { if (this.robot.adaptors[adaptorName] == null) {
this.robot.registerAdaptor("cylon-" + adaptorName, adaptorName); this.robot.registerAdaptor("cylon-" + adaptorName, adaptorName);
this.robot.adaptors[adaptorName].register(this); this.robot.adaptors[adaptorName].register(this);
@ -216,9 +226,11 @@
}; };
Robot.prototype.registerAdaptor = function(moduleName, adaptorName) { Robot.prototype.registerAdaptor = function(moduleName, adaptorName) {
console.log('here ' + moduleName);
if (this.adaptors[adaptorName] == null) { if (this.adaptors[adaptorName] == null) {
return this.adaptors[adaptorName] = require(moduleName); this.adaptors[adaptorName] = require(moduleName);
} }
return console.log('there');
}; };
Robot.prototype.initDriver = function(driverName, device, opts) { Robot.prototype.initDriver = function(driverName, device, opts) {

74
dist/test/test-adaptor.js vendored Normal file
View File

@ -0,0 +1,74 @@
/*
* Test adaptor
* cylonjs.com
*
* Copyright (c) 2013 The Hybrid Group
* Licensed under the Apache 2.0 license.
*/
(function() {
'use strict';
var namespace,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
namespace = require('node-namespace');
module.exports = {
adaptor: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(Cylon.Adaptors.TestAdaptor, args, function(){});
}
};
namespace('Cylon.Adaptors', function() {
return this.TestAdaptor = (function(_super) {
var method, _fn, _i, _len, _ref;
__extends(TestAdaptor, _super);
function TestAdaptor(opts) {
if (opts == null) {
opts = {};
}
TestAdaptor.__super__.constructor.apply(this, arguments);
this.commandList = [];
}
TestAdaptor.prototype.commands = function() {
return this.commandList;
};
TestAdaptor.prototype.proxyTestCommands = function(realAdaptor) {};
_ref = realAdaptor.commands();
_fn = function(method) {
this.self[method] = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return this.self.success();
};
return this.commandList.push(method);
};
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
method = _ref[_i];
_fn(method);
}
TestAdaptor.prototype.success = function() {
return true;
};
return TestAdaptor;
})(Cylon.Adaptor);
});
}).call(this);

View File

@ -60,6 +60,7 @@ namespace 'Cylon', ->
@commands = [] @commands = []
@registerAdaptor "./test/loopback", "loopback" @registerAdaptor "./test/loopback", "loopback"
@registerAdaptor "./test/test-adaptor", "test"
@registerDriver "./test/ping", "ping" @registerDriver "./test/ping", "ping"
@testing = process.env['CYLON_TEST'] @testing = process.env['CYLON_TEST']
@ -175,18 +176,29 @@ namespace 'Cylon', ->
# #
# Returns the adaptor # Returns the adaptor
initAdaptor: (adaptorName, connection, opts = {}) -> initAdaptor: (adaptorName, connection, opts = {}) ->
@robot.requireAdaptor(adaptorName).adaptor realAdaptor = @robot.requireAdaptor(adaptorName).adaptor
name: adaptorName, name: adaptorName,
connection: connection, connection: connection,
extraParams: opts extraParams: opts
if @robot.testing?
testAdaptor = @robot.requireAdaptor('test').adaptor
name: adaptorName,
connection: connection,
extraParams: opts
testAdaptor.proxyTestCommands(realAdaptor)
testAdaptor
else
realAdaptor
# Public: Requires a hardware adaptor and adds it to @robot.adaptors # Public: Requires a hardware adaptor and adds it to @robot.adaptors
# #
# adaptorName - module name of adaptor to require # adaptorName - module name of adaptor to require
# #
# Returns the module for the adaptor # Returns the module for the adaptor
requireAdaptor: (adaptorName) => requireAdaptor: (adaptorName) =>
return @robot.adaptors['loopback'] if @robot.testing? #return @robot.adaptors['test'] if @robot.testing?
unless @robot.adaptors[adaptorName]? unless @robot.adaptors[adaptorName]?
@robot.registerAdaptor "cylon-#{adaptorName}", adaptorName @robot.registerAdaptor "cylon-#{adaptorName}", adaptorName
@ -201,7 +213,9 @@ namespace 'Cylon', ->
# #
# Returns the registered module name # Returns the registered module name
registerAdaptor: (moduleName, adaptorName) => registerAdaptor: (moduleName, adaptorName) =>
console.log 'here ' + moduleName
@adaptors[adaptorName] = require(moduleName) unless @adaptors[adaptorName]? @adaptors[adaptorName] = require(moduleName) unless @adaptors[adaptorName]?
console.log 'there'
# Public: Init a hardware driver # Public: Init a hardware driver
# #

View File

@ -0,0 +1,33 @@
###
* Test adaptor
* cylonjs.com
*
* Copyright (c) 2013 The Hybrid Group
* Licensed under the Apache 2.0 license.
###
'use strict'
namespace = require 'node-namespace'
module.exports =
adaptor: (args...) ->
new Cylon.Adaptors.TestAdaptor(args...)
namespace 'Cylon.Adaptors', ->
class @TestAdaptor extends Cylon.Adaptor
constructor: (opts={}) ->
super
@commandList = []
commands: ->
@commandList
proxyTestCommands: (realAdaptor) ->
for method in realAdaptor.commands()
do (method) ->
@self[method] = (args...) -> @self.success()
@commandList.push method
success: ->
true