2011-03-10 09:54:52 +01:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2010-12-04 23:45:52 +01:00
|
|
|
var path = require('path');
|
2010-12-05 23:33:52 +01:00
|
|
|
var assert = require('assert');
|
2009-10-31 19:02:30 +01:00
|
|
|
|
|
|
|
exports.testDir = path.dirname(__filename);
|
2010-12-04 23:45:52 +01:00
|
|
|
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
|
|
|
|
exports.libDir = path.join(exports.testDir, '../lib');
|
|
|
|
exports.tmpDir = path.join(exports.testDir, 'tmp');
|
2010-02-26 21:06:32 +01:00
|
|
|
exports.PORT = 12346;
|
2009-09-20 18:19:33 +02:00
|
|
|
|
2010-12-04 23:45:52 +01:00
|
|
|
var util = require('util');
|
2010-10-11 23:04:09 +02:00
|
|
|
for (var i in util) exports[i] = util[i];
|
2010-08-17 17:21:43 +02:00
|
|
|
//for (var i in exports) global[i] = exports[i];
|
|
|
|
|
2010-12-05 20:15:30 +01:00
|
|
|
function protoCtrChain(o) {
|
2010-08-17 17:21:43 +02:00
|
|
|
var result = [];
|
|
|
|
for (; o; o = o.__proto__) { result.push(o.constructor); }
|
|
|
|
return result.join();
|
|
|
|
}
|
|
|
|
|
2010-12-04 23:45:52 +01:00
|
|
|
exports.indirectInstanceOf = function(obj, cls) {
|
2010-08-17 17:21:43 +02:00
|
|
|
if (obj instanceof cls) { return true; }
|
|
|
|
var clsChain = protoCtrChain(cls.prototype);
|
|
|
|
var objChain = protoCtrChain(obj);
|
|
|
|
return objChain.slice(-clsChain.length) === clsChain;
|
|
|
|
};
|
2010-12-04 22:40:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Turn this off if the test should not check for global leaks.
|
|
|
|
exports.globalCheck = true;
|
|
|
|
|
2010-12-05 20:15:30 +01:00
|
|
|
process.on('exit', function() {
|
2010-12-04 22:40:39 +01:00
|
|
|
if (!exports.globalCheck) return;
|
2010-12-05 20:15:30 +01:00
|
|
|
var knownGlobals = [setTimeout,
|
|
|
|
setInterval,
|
|
|
|
clearTimeout,
|
|
|
|
clearInterval,
|
|
|
|
console,
|
|
|
|
Buffer,
|
|
|
|
process,
|
|
|
|
global];
|
2010-12-04 22:40:39 +01:00
|
|
|
|
2011-02-10 03:50:26 +01:00
|
|
|
if (global.DTRACE_HTTP_SERVER_RESPONSE) {
|
2011-01-25 02:50:10 +01:00
|
|
|
knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE);
|
|
|
|
knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST);
|
2011-02-10 03:50:26 +01:00
|
|
|
knownGlobals.push(DTRACE_HTTP_CLIENT_RESPONSE);
|
|
|
|
knownGlobals.push(DTRACE_HTTP_CLIENT_REQUEST);
|
2011-01-25 02:50:10 +01:00
|
|
|
knownGlobals.push(DTRACE_NET_STREAM_END);
|
|
|
|
knownGlobals.push(DTRACE_NET_SERVER_CONNECTION);
|
2011-02-10 03:50:26 +01:00
|
|
|
knownGlobals.push(DTRACE_NET_SOCKET_READ);
|
|
|
|
knownGlobals.push(DTRACE_NET_SOCKET_WRITE);
|
2011-01-25 02:50:10 +01:00
|
|
|
}
|
|
|
|
|
2010-12-04 22:40:39 +01:00
|
|
|
for (var x in global) {
|
|
|
|
var found = false;
|
|
|
|
|
|
|
|
for (var y in knownGlobals) {
|
|
|
|
if (global[x] === knownGlobals[y]) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2010-12-05 20:15:30 +01:00
|
|
|
console.error('Unknown global: %s', x);
|
2010-12-05 23:33:52 +01:00
|
|
|
assert.ok(false, 'Unknown global founded');
|
2010-12-04 22:40:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-02-18 19:05:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
// This function allows one two run an HTTP test agaist both HTTPS and
|
|
|
|
// normal HTTP modules. This ensures they fit the same API.
|
|
|
|
exports.httpTest = function httpTest(cb) {
|
|
|
|
};
|
|
|
|
|