Skip to content

Commit 2514db2

Browse files
committed
Merge pull request #23 from neo4j/1.0-tck
1.0 tck
2 parents 2c435d6 + 3077faf commit 2514db2

File tree

12 files changed

+567
-105
lines changed

12 files changed

+567
-105
lines changed

gulpfile.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
19+
2020
var browserify = require('browserify');
2121
var source = require('vinyl-source-stream');
2222
var buffer = require('vinyl-buffer');
@@ -42,6 +42,7 @@ var runSequence = require('run-sequence');
4242
var path = require('path');
4343
var childProcess = require("child_process");
4444
var minimist = require('minimist');
45+
var cucumber = require('gulp-cucumber');
4546

4647
gulp.task('default', ["test"]);
4748

@@ -89,10 +90,10 @@ gulp.task('build-browser-test', function(){
8990
cb();
9091
}))
9192
.pipe( through.obj( function( testFiles, enc, cb) {
92-
browserify({
93+
browserify({
9394
entries: testFiles,
9495
cache: {},
95-
debug: true
96+
debug: true
9697
}).transform(babelify.configure({
9798
ignore: /external/
9899
}))
@@ -131,7 +132,7 @@ gulp.task('all', function(cb){
131132
});
132133

133134
gulp.task('test', function(cb){
134-
runSequence('test-nodejs', 'test-browser', cb);
135+
runSequence('test-nodejs', 'test-browser', 'run-tck', cb);
135136
});
136137

137138
gulp.task('test-nodejs', ['nodejs'], function () {
@@ -186,6 +187,23 @@ gulp.task('download-neo4j', function() {
186187
}
187188
});
188189

190+
var featureFiles = 'https://s3-eu-west-1.amazonaws.com/remoting.neotechnology.com/driver-compliance/tck.tar.gz';
191+
var featureHome = './build/tck';
192+
193+
gulp.task('download-tck', function() {
194+
return download(featureFiles)
195+
.pipe(decompress({strip: 1}))
196+
.pipe(gulp.dest(featureHome));
197+
});
198+
199+
gulp.task('run-tck', ['download-tck', 'nodejs'], function() {
200+
return gulp.src(featureHome + "/*").pipe(cucumber({
201+
'steps': 'test/v1/tck/steps/*.js',
202+
'format': 'pretty',
203+
'tags' : "~@in_dev"
204+
}));
205+
});
206+
189207
var runPowershell = function( cmd ) {
190208
var spawn = childProcess.spawn, child;
191209
child = spawn("powershell.exe",[

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"gulp-babel": "^5.2.1",
2727
"gulp-batch": "^1.0.5",
2828
"gulp-concat": "^2.6.0",
29-
"gulp-cucumber": "^0.0.12",
29+
"gulp-cucumber": "0.0.14",
3030
"gulp-decompress": "^1.2.0",
3131
"gulp-download": "^0.0.1",
3232
"gulp-if": "^1.2.5",

src/v1/integer.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
19+
2020
// 64-bit Integer library, originally from Long.js by dcodeIO
2121
// https://github.com/dcodeIO/Long.js
2222
// License Apache 2
@@ -94,7 +94,7 @@ class Integer {
9494
if (this.isZero())
9595
return '0';
9696
var rem;
97-
if (this.isNegative()) {
97+
if (this.isNegative()) {
9898
if (this.equals(Integer.MIN_VALUE)) {
9999
// We need to change the Integer value before it can be negated, so we remove
100100
// the bottom-most digit in this base and then recurse to do the rest.
@@ -162,7 +162,7 @@ class Integer {
162162
*/
163163
isZero() {
164164
return this.high === 0 && this.low === 0;
165-
}
165+
}
166166

167167
/**
168168
* Tests if this Integer's value is negative.
@@ -205,8 +205,6 @@ class Integer {
205205
equals(other) {
206206
if (!Integer.isInteger(other))
207207
other = Integer.fromValue(other);
208-
if ((this.high >>> 31) === 1 && (other.high >>> 31) === 1)
209-
return false;
210208
return this.high === other.high && this.low === other.low;
211209
}
212210

@@ -821,4 +819,4 @@ export default {
821819
Integer,
822820
int,
823821
isInt
824-
}
822+
}

src/v1/internal/buf.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -57,50 +57,50 @@ class BaseBuffer
5757
* @param p
5858
*/
5959
getInt16 (p) {
60-
return this.getInt8(p) << 8
61-
| this.getUInt8(p + 1) & 0xFF;
60+
return this.getInt8(p) << 8
61+
| this.getUInt8(p + 1);
6262
}
6363

6464
/**
6565
* @param p
6666
*/
6767
getUInt16 (p) {
68-
return this.getUInt8(p) << 8
69-
| this.getUInt8(p + 1) & 0xFF;
68+
return this.getUInt8(p) << 8
69+
| this.getUInt8(p + 1);
7070
}
7171

7272
/**
7373
* @param p
7474
*/
7575
getInt32 (p) {
76-
return this.getInt8(p) << 24
77-
| this.getUInt8(p + 1) << 16 & 0xFF
78-
| this.getUInt8(p + 2) << 8 & 0xFF
79-
| this.getUInt8(p + 3) & 0xFF;
76+
return this.getInt8(p) << 24
77+
| this.getUInt8(p + 1) << 16
78+
| this.getUInt8(p + 2) << 8
79+
| this.getUInt8(p + 3);
8080
}
8181

8282
/**
8383
* @param p
8484
*/
8585
getUInt32 (p) {
8686
return this.getUInt8(p) << 24
87-
| this.getUInt8(p + 1) << 16 & 0xFF
88-
| this.getUInt8(p + 2) << 8 & 0xFF
89-
| this.getUInt8(p + 3) & 0xFF;
87+
| this.getUInt8(p + 1) << 16
88+
| this.getUInt8(p + 2) << 8
89+
| this.getUInt8(p + 3);
9090
}
9191

9292
/**
9393
* @param p
9494
*/
9595
getInt64 (p) {
9696
return this.getInt8(p) << 56
97-
| this.getUInt8(p + 1) << 48 & 0xFF
98-
| this.getUInt8(p + 2) << 40 & 0xFF
99-
| this.getUInt8(p + 3) << 32 & 0xFF
100-
| this.getUInt8(p + 4) << 24 & 0xFF
101-
| this.getUInt8(p + 5) << 16 & 0xFF
102-
| this.getUInt8(p + 6) << 8 & 0xFF
103-
| this.getUInt8(p + 7) & 0xFF;
97+
| this.getUInt8(p + 1) << 48
98+
| this.getUInt8(p + 2) << 40
99+
| this.getUInt8(p + 3) << 32
100+
| this.getUInt8(p + 4) << 24
101+
| this.getUInt8(p + 5) << 16
102+
| this.getUInt8(p + 6) << 8
103+
| this.getUInt8(p + 7);
104104
}
105105

106106
/**
@@ -119,7 +119,7 @@ class BaseBuffer
119119
*/
120120
putInt16 ( p, val ) {
121121
this.putInt8( p, val >> 8 );
122-
this.putUInt8( p + 1, val & 0xFF );
122+
this.putUInt8( p + 1, val & 0xFF );
123123
}
124124

125125
/**

src/v1/internal/ch-dummy.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import {CombinedBuffer} from './buf';
21+
const observer = {
22+
instance: null,
23+
updateInstance: (instance) => {
24+
observer.instance = instance
25+
}
26+
}
27+
28+
class DummyChannel {
29+
constructor(opts) {
30+
this.written = [];
31+
}
32+
write( buf ) {
33+
this.written.push(buf);
34+
observer.updateInstance(this);
35+
}
36+
toHex() {
37+
var out = "";
38+
for( var i=0; i<this.written.length; i++ ) {
39+
out += this.written[i].toHex();
40+
}
41+
return out;
42+
}
43+
toBuffer () {
44+
return new CombinedBuffer( this.written );
45+
}
46+
}
47+
48+
export default {
49+
channel: DummyChannel,
50+
observer: observer
51+
}

src/v1/internal/connector.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,12 @@ class Connection {
337337
* Crete new connection to the provided url.
338338
* @access private
339339
* @param {string} url - 'neo4j'-prefixed URL to Neo4j Bolt endpoint
340+
* @param {Channel} channel - Optionally inject Channel to be used.
340341
* @return {Connection} - New connection
341342
*/
342-
function connect( url ) {
343-
return new Connection( new Channel({
343+
function connect( url, channel = null) {
344+
channel = channel || Channel;
345+
return new Connection( new channel({
344346
host: host(url),
345347
port: port(url)
346348
}));

src/v1/internal/packstream.js

+28-28
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ class Structure {
6565
for (var i = 0; i < this.fields.length; i++) {
6666
if(i > 0) { fieldStr+=", " }
6767
fieldStr += this.fields[i];
68-
};
69-
70-
var util = require('util')
71-
console.log(util.inspect(this));
72-
68+
}
7369
return "Structure(" + this.signature + ", [" + this.fields + "])"
7470
}
7571
}
@@ -128,25 +124,26 @@ class Packer {
128124
var high = x.high,
129125
low = x.low;
130126

131-
this._ch.writeUInt8(INT_64);
132-
this._ch.writeUInt32( high );
133-
this._ch.writeUInt32( low );
134-
// TODO Use the branches below to sort out most efficient packed format
135-
// if (-0x10 <= x && x < 0x80) {
136-
// this._ch.writeUInt8(x);
137-
// } else if (-0x80 <= x && x < -0x10) {
138-
// this._ch.writeUInt8(INT_8);
139-
// this._ch.writeUInt8(x);
140-
// } else if (-0x8000 <= x && x < 0x8000) {
141-
// this._ch.writeUInt8(INT_16);
142-
// this._ch.writeInt16(x);
143-
// } else if (-0x80000000 <= x && x < 0x80000000) {
144-
// this._ch.writeUInt8(INT_32);
145-
// this._ch.writeInt32(x);
146-
// } else {
147-
//
148-
// }
149-
127+
if (x.greaterThanOrEqual(-0x10) && x.lessThan(0x80)) {
128+
this._ch.writeInt8(low);
129+
}
130+
else if (x.greaterThanOrEqual(-0x80) && x.lessThan(-0x10)) {
131+
this._ch.writeUInt8(INT_8);
132+
this._ch.writeInt8(low);
133+
}
134+
else if (x.greaterThanOrEqual(-0x8000) && x.lessThan(0x8000)) {
135+
this._ch.writeUInt8(INT_16);
136+
this._ch.writeInt16(low);
137+
}
138+
else if (x.greaterThanOrEqual(-0x80000000) && x.lessThan(0x80000000)) {
139+
this._ch.writeUInt8(INT_32);
140+
this._ch.writeInt32(low);
141+
}
142+
else {
143+
this._ch.writeUInt8(INT_64);
144+
this._ch.writeInt32(high);
145+
this._ch.writeInt32(low);
146+
}
150147
}
151148

152149
packFloat(x) {
@@ -171,7 +168,7 @@ class Packer {
171168
this._ch.writeBytes(bytes);
172169
} else if (size < 0x100000000) {
173170
this._ch.writeUInt8(STRING_32);
174-
this._ch.writeUInt8((size/16777216>>0)%256); // TODO: Why is it shifting by 0 here?
171+
this._ch.writeUInt8((size/16777216>>0)%256);
175172
this._ch.writeUInt8((size/65536>>0)%256);
176173
this._ch.writeUInt8((size/256>>0)%256);
177174
this._ch.writeUInt8(size%256);
@@ -188,7 +185,9 @@ class Packer {
188185
this._ch.writeUInt8(LIST_8)
189186
this._ch.writeUInt8(size);
190187
} else if (size < 0x10000) {
191-
this._ch.writeUInt8(LIST_16, size/256>>0, size%256);
188+
this._ch.writeUInt8(LIST_16);
189+
this._ch.writeUInt8((size/256>>0)%256);
190+
this._ch.writeUInt8(size%256);
192191
} else if (size < 0x100000000) {
193192
this._ch.writeUInt8(LIST_32);
194193
this._ch.writeUInt8((size/16777216>>0)%256);
@@ -301,10 +300,11 @@ class Unpacker {
301300
} else if (marker == INT_16) {
302301
return int(buffer.readInt16());
303302
} else if (marker == INT_32) {
304-
return int(buffer.readInt32());
303+
let b = buffer.readInt32();
304+
return int(b);
305305
} else if (marker == INT_64) {
306306
let high = buffer.readInt32();
307-
let low = buffer.readUInt32();
307+
let low = buffer.readInt32();
308308
return new Integer( low, high );
309309
} else if (marker == STRING_8) {
310310
return utf8.decode( buffer, buffer.readUInt8());

0 commit comments

Comments
 (0)