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'), Step = require('step'),
fs = require('fs'), fs = require('fs'),
assert = require('assert'); assert = require('assert')
Buffer = require('buffer').Buffer;
var db = new sqlite.Database();
// lots of elmo // 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( Step(
function() { function() {
db.open(__dirname + '/blobtest.sqlite', this); db.open('', this);
}, },
function() { function() {
db.prepare( var next = this;
'CREATE TABLE IF NOT EXISTS elmos (' db.prepare('CREATE TABLE elmos (image BLOB);', function(err, statement) {
+ 'image BLOB);',
function(err, statement) {
assert.isUndefined(err);
statement.step(this);
}.bind(this));
},
function(err) {
db.prepare(
'INSERT INTO elmos (image) '
+ 'VALUES (?)',
function(err, statement) {
assert.isUndefined(err); assert.isUndefined(err);
statement.bind(0, elmo); statement.step(next);
statement.step(this); });
}.bind(this));
}, },
function() { function() {
var group = this.group(); var group = this.group();
for (var i = 0; i < 1000000; i++) { for (var i = 0; i < total; i++) {
console.log('ELMO'); var next = group();
db.prepare( db.prepare('INSERT INTO elmos (image) VALUES (?)', function(err, statement) {
'INSERT INTO elmos (image) ' assert.isUndefined(err);
+ 'VALUES (?)', statement.bind(1, elmo, function() {
function(err, statement) { statement.step(function(err) {
Step( assert.isUndefined(err);
inserted++;
next();
});
});
});
}
},
function() { function() {
statement.bind(0, elmo, this); var next = this;
db.execute('SELECT COUNT(*) as amount FROM elmos', function(err, rows) {
assert.isUndefined(err);
assert.eql(rows[0].amount, total);
next();
});
}, },
function() { function() {
// DO IT var next = this;
statement.step(group()); 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();
} }
); else {
}.bind(this)); 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