Commit 426a2de1 by Konstantin Käfer

update test to work with current version

parent e81c2c95
var sqlite = require('sqlite3_bindings'),
var sqlite = require('sqlite3'),
Step = require('step'),
fs = require('fs'),
assert = require('assert');
var db = new sqlite.Database();
assert = require('assert')
Buffer = require('buffer').Buffer;
// lots of elmo
var elmo = fs.readFile(__dirname + '/elmo.png', 'binary');
var elmo = fs.readFileSync(__dirname + '/support/elmo.png', 'binary');
var elmo_str = elmo.toString('binary');
exports['Blob overflow test'] = function(beforeExit) {
var db = new sqlite.Database();
var total = 100;
var inserted = 0;
var retrieved = 0;
exports['Blob overflow test'] = function() {
Step(
function() {
db.open(__dirname + '/blobtest.sqlite', this);
db.open('', this);
},
function() {
db.prepare(
'CREATE TABLE IF NOT EXISTS elmos ('
+ 'image BLOB);',
function(err, statement) {
var next = this;
db.prepare('CREATE TABLE elmos (image BLOB);', function(err, statement) {
assert.isUndefined(err);
statement.step(this);
}.bind(this));
statement.step(next);
});
},
function(err) {
db.prepare(
'INSERT INTO elmos (image) '
+ 'VALUES (?)',
function(err, statement) {
function() {
var group = this.group();
for (var i = 0; i < total; i++) {
var next = group();
db.prepare('INSERT INTO elmos (image) VALUES (?)', function(err, statement) {
assert.isUndefined(err);
statement.bind(1, elmo, function() {
statement.step(function(err) {
assert.isUndefined(err);
inserted++;
next();
});
});
});
}
},
function() {
var next = this;
db.execute('SELECT COUNT(*) as amount FROM elmos', function(err, rows) {
assert.isUndefined(err);
statement.bind(0, elmo);
statement.step(this);
}.bind(this));
assert.eql(rows[0].amount, total);
next();
});
},
function() {
var group = this.group();
for (var i = 0; i < 1000000; i++) {
console.log('ELMO');
db.prepare(
'INSERT INTO elmos (image) '
+ 'VALUES (?)',
function(err, statement) {
Step(
function() {
statement.bind(0, elmo, this);
},
function() {
// DO IT
statement.step(group());
var next = this;
db.prepare('SELECT image FROM elmos;', function(err, statement) {
assert.isUndefined(err);
fetch();
function fetch() {
statement.step(function(err, row) {
assert.isUndefined(err);
if (row) {
// Not using assert.equal here because it's image data
// and we don't want that in the command line.
assert.ok(elmo_str === row.image);
retrieved++;
fetch();
}
);
}.bind(this));
}
else {
next();
}
});
}
});
}
);
beforeExit(function() {
assert.eql(inserted, total);
assert.eql(retrieved, total);
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment