Ryan Dahl | 55048cd | 2011-03-10 08:54:52 | [diff] [blame^] | 1 | // 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 Efimov | 0ce9cba | 2010-12-04 22:45:52 | [diff] [blame] | 22 | var path = require('path'); |
Oleg Efimov | 093dfaf | 2010-12-05 22:33:52 | [diff] [blame] | 23 | var assert = require('assert'); |
Ryan Dahl | 7a2e784 | 2009-10-31 18:02:30 | [diff] [blame] | 24 | |
| 25 | exports.testDir = path.dirname(__filename); |
Oleg Efimov | 0ce9cba | 2010-12-04 22:45:52 | [diff] [blame] | 26 | exports.fixturesDir = path.join(exports.testDir, 'fixtures'); |
| 27 | exports.libDir = path.join(exports.testDir, '../lib'); |
| 28 | exports.tmpDir = path.join(exports.testDir, 'tmp'); |
arlolra | 724ccf1 | 2010-02-26 20:06:32 | [diff] [blame] | 29 | exports.PORT = 12346; |
Ryan Dahl | 4b8f503 | 2009-09-20 16:19:33 | [diff] [blame] | 30 | |
Oleg Efimov | 0ce9cba | 2010-12-04 22:45:52 | [diff] [blame] | 31 | var util = require('util'); |
Micheil Smith | e38eb0c | 2010-10-11 21:04:09 | [diff] [blame] | 32 | for (var i in util) exports[i] = util[i]; |
Herbert Vojčík | cf2b206 | 2010-08-17 15:21:43 | [diff] [blame] | 33 | //for (var i in exports) global[i] = exports[i]; |
| 34 | |
Oleg Efimov | 0665f02 | 2010-12-05 19:15:30 | [diff] [blame] | 35 | function protoCtrChain(o) { |
Herbert Vojčík | cf2b206 | 2010-08-17 15:21:43 | [diff] [blame] | 36 | var result = []; |
| 37 | for (; o; o = o.__proto__) { result.push(o.constructor); } |
| 38 | return result.join(); |
| 39 | } |
| 40 | |
Oleg Efimov | 0ce9cba | 2010-12-04 22:45:52 | [diff] [blame] | 41 | exports.indirectInstanceOf = function(obj, cls) { |
Herbert Vojčík | cf2b206 | 2010-08-17 15:21:43 | [diff] [blame] | 42 | 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 Dahl | 02cc39f | 2010-12-04 21:40:39 | [diff] [blame] | 47 | |
| 48 | |
| 49 | // Turn this off if the test should not check for global leaks. |
| 50 | exports.globalCheck = true; |
| 51 | |
Oleg Efimov | 0665f02 | 2010-12-05 19:15:30 | [diff] [blame] | 52 | process.on('exit', function() { |
Ryan Dahl | 02cc39f | 2010-12-04 21:40:39 | [diff] [blame] | 53 | if (!exports.globalCheck) return; |
Oleg Efimov | 0665f02 | 2010-12-05 19:15:30 | [diff] [blame] | 54 | var knownGlobals = [setTimeout, |
| 55 | setInterval, |
| 56 | clearTimeout, |
| 57 | clearInterval, |
| 58 | console, |
| 59 | Buffer, |
| 60 | process, |
| 61 | global]; |
Ryan Dahl | 02cc39f | 2010-12-04 21:40:39 | [diff] [blame] | 62 | |
Ryan Dahl | e9257b8 | 2011-02-10 02:50:26 | [diff] [blame] | 63 | if (global.DTRACE_HTTP_SERVER_RESPONSE) { |
Ryan Dahl | 068b733 | 2011-01-25 01:50:10 | [diff] [blame] | 64 | knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE); |
| 65 | knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST); |
Ryan Dahl | e9257b8 | 2011-02-10 02:50:26 | [diff] [blame] | 66 | knownGlobals.push(DTRACE_HTTP_CLIENT_RESPONSE); |
| 67 | knownGlobals.push(DTRACE_HTTP_CLIENT_REQUEST); |
Ryan Dahl | 068b733 | 2011-01-25 01:50:10 | [diff] [blame] | 68 | knownGlobals.push(DTRACE_NET_STREAM_END); |
| 69 | knownGlobals.push(DTRACE_NET_SERVER_CONNECTION); |
Ryan Dahl | e9257b8 | 2011-02-10 02:50:26 | [diff] [blame] | 70 | knownGlobals.push(DTRACE_NET_SOCKET_READ); |
| 71 | knownGlobals.push(DTRACE_NET_SOCKET_WRITE); |
Ryan Dahl | 068b733 | 2011-01-25 01:50:10 | [diff] [blame] | 72 | } |
| 73 | |
Ryan Dahl | 02cc39f | 2010-12-04 21:40:39 | [diff] [blame] | 74 | 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 Efimov | 0665f02 | 2010-12-05 19:15:30 | [diff] [blame] | 85 | console.error('Unknown global: %s', x); |
Oleg Efimov | 093dfaf | 2010-12-05 22:33:52 | [diff] [blame] | 86 | assert.ok(false, 'Unknown global founded'); |
Ryan Dahl | 02cc39f | 2010-12-04 21:40:39 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | }); |
Ryan Dahl | aac5cbe | 2011-02-18 18:05:31 | [diff] [blame] | 90 | |
| 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. |
| 94 | exports.httpTest = function httpTest(cb) { |
| 95 | }; |
| 96 | |