blob: bf0a43f9e7f4c73ffd8d25e48f53ae7c4c1f4320 [file] [log] [blame]
Ryan Dahl55048cd2011-03-10 08:54:521// Copyright Joyent, Inc. and other Node contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to permit
8// persons to whom the Software is furnished to do so, subject to the
9// following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
Oleg Efimov0ce9cba2010-12-04 22:45:5222var path = require('path');
Oleg Efimov093dfaf2010-12-05 22:33:5223var assert = require('assert');
Ryan Dahl7a2e7842009-10-31 18:02:3024
25exports.testDir = path.dirname(__filename);
Oleg Efimov0ce9cba2010-12-04 22:45:5226exports.fixturesDir = path.join(exports.testDir, 'fixtures');
27exports.libDir = path.join(exports.testDir, '../lib');
28exports.tmpDir = path.join(exports.testDir, 'tmp');
arlolra724ccf12010-02-26 20:06:3229exports.PORT = 12346;
Ryan Dahl4b8f5032009-09-20 16:19:3330
Oleg Efimov0ce9cba2010-12-04 22:45:5231var util = require('util');
Micheil Smithe38eb0c2010-10-11 21:04:0932for (var i in util) exports[i] = util[i];
Herbert Vojčíkcf2b2062010-08-17 15:21:4333//for (var i in exports) global[i] = exports[i];
34
Oleg Efimov0665f022010-12-05 19:15:3035function protoCtrChain(o) {
Herbert Vojčíkcf2b2062010-08-17 15:21:4336 var result = [];
37 for (; o; o = o.__proto__) { result.push(o.constructor); }
38 return result.join();
39}
40
Oleg Efimov0ce9cba2010-12-04 22:45:5241exports.indirectInstanceOf = function(obj, cls) {
Herbert Vojčíkcf2b2062010-08-17 15:21:4342 if (obj instanceof cls) { return true; }
43 var clsChain = protoCtrChain(cls.prototype);
44 var objChain = protoCtrChain(obj);
45 return objChain.slice(-clsChain.length) === clsChain;
46};
Ryan Dahl02cc39f2010-12-04 21:40:3947
48
49// Turn this off if the test should not check for global leaks.
50exports.globalCheck = true;
51
Oleg Efimov0665f022010-12-05 19:15:3052process.on('exit', function() {
Ryan Dahl02cc39f2010-12-04 21:40:3953 if (!exports.globalCheck) return;
Oleg Efimov0665f022010-12-05 19:15:3054 var knownGlobals = [setTimeout,
55 setInterval,
56 clearTimeout,
57 clearInterval,
58 console,
59 Buffer,
60 process,
61 global];
Ryan Dahl02cc39f2010-12-04 21:40:3962
Ryan Dahle9257b82011-02-10 02:50:2663 if (global.DTRACE_HTTP_SERVER_RESPONSE) {
Ryan Dahl068b7332011-01-25 01:50:1064 knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE);
65 knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST);
Ryan Dahle9257b82011-02-10 02:50:2666 knownGlobals.push(DTRACE_HTTP_CLIENT_RESPONSE);
67 knownGlobals.push(DTRACE_HTTP_CLIENT_REQUEST);
Ryan Dahl068b7332011-01-25 01:50:1068 knownGlobals.push(DTRACE_NET_STREAM_END);
69 knownGlobals.push(DTRACE_NET_SERVER_CONNECTION);
Ryan Dahle9257b82011-02-10 02:50:2670 knownGlobals.push(DTRACE_NET_SOCKET_READ);
71 knownGlobals.push(DTRACE_NET_SOCKET_WRITE);
Ryan Dahl068b7332011-01-25 01:50:1072 }
73
Ryan Dahl02cc39f2010-12-04 21:40:3974 for (var x in global) {
75 var found = false;
76
77 for (var y in knownGlobals) {
78 if (global[x] === knownGlobals[y]) {
79 found = true;
80 break;
81 }
82 }
83
84 if (!found) {
Oleg Efimov0665f022010-12-05 19:15:3085 console.error('Unknown global: %s', x);
Oleg Efimov093dfaf2010-12-05 22:33:5286 assert.ok(false, 'Unknown global founded');
Ryan Dahl02cc39f2010-12-04 21:40:3987 }
88 }
89});
Ryan Dahlaac5cbe2011-02-18 18:05:3190
91
92// This function allows one two run an HTTP test agaist both HTTPS and
93// normal HTTP modules. This ensures they fit the same API.
94exports.httpTest = function httpTest(cb) {
95};
96