Commit 97980036 by Orlando Vazquez

Use async-testing for the place holder tests

parent d71ef30a
......@@ -119,6 +119,23 @@ interface however lacks the necessary notification mechanism to alert the
caller when the SQLite call has completed. In other words, to be able to
support callbacks, we use the synchronous driver within a seperate thread.
BUILDING
--------
To build the bindings:
git clone http://github.com/orlandov/node-sqlite.git
cd node-sqlite
node-waf configure build
TESTS
-----
Running the unit tests could not be easier. Simply:
git submodule update --init
./run-tests
SEE ALSO
--------
......
NODE_PATH=. async-testing/node-async-test tests
require.paths.push(__dirname + '/..');
sys = require('sys');
fs = require('fs');
path = require('path');
......@@ -10,12 +8,8 @@ sqlite = require('sqlite3_bindings');
puts = sys.puts;
inspect = sys.inspect;
// createa table
// prepare a statement (with options) that inserts
// do a step
// check that the result has a lastInsertedId property
var suite = exports.suite = new TestSuite("node-sqlite last inserted id test");
var name = "Caching of affectedRows";
var suite = exports[name] = new TestSuite(name);
function createTestTable(db, callback) {
db.prepare('CREATE TABLE table1 (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)',
......
var sqlite = require('../sqlite3_bindings');
var sys = require('sys');
assert = require('assert');
require.paths.push(__dirname + '/..');
var puts = sys.puts;
var inspect = sys.inspect;
sys = require('sys');
fs = require('fs');
path = require('path');
function test_by_index(callback) {
db = new sqlite.Database();
db.open(":memory:", function () {
puts("Opened ok");
db.prepare("SELECT ? AS foo, ? AS bar, ? AS baz"
, function (error, statement) {
if (error) throw error;
puts("Prepared ok");
statement.bind(1, "hi", function (error) {
if (error) throw error;
puts("bound ok");
statement.bind(2, "there", function (error) {
TestSuite = require('async-testing/async_testing').TestSuite;
sqlite = require('sqlite3_bindings');
puts = sys.puts;
inspect = sys.inspect;
var name = "Binding statement place holders";
var suite = exports[name] = new TestSuite("Binding statement place holders");
var tests = [
{ "Bind placeholders by index":
function (assert, finished) {
var self = this;
self.db.open(":memory:", function () {
self.db.prepare("SELECT ? AS foo, ? AS bar, ? AS baz"
, function (error, statement) {
if (error) throw error;
puts("bound ok");
statement.bind(3, "world", function (error) {
statement.bind(1, "hi", function (error) {
if (error) throw error;
puts("bound ok");
statement.step(function (error, row) {
statement.bind(2, "there", function (error) {
if (error) throw error;
assert.deepEqual(row, { foo: 'hi', bar: 'there', baz: 'world' });
puts("Test ok");
statement.bind(3, "world", function (error) {
if (error) throw error;
statement.step(function (error, row) {
if (error) throw error;
assert.deepEqual(row
, { foo: 'hi'
, bar: 'there'
, baz: 'world'
});
finished();
});
});
});
});
});
});
});
});
}
function test_num_array(callback) {
db = new sqlite.Database();
db.open(":memory:", function () {
puts("Opened ok");
db.prepare("SELECT CAST(? AS INTEGER) AS foo, CAST(? AS INTEGER) AS bar, CAST(? AS INTEGER) AS baz"
, function (error, statement) {
if (error) throw error;
puts("Prepared ok");
statement.bindArray([1, 2, 3], function (error) {
statement.step(function (error, row) {
}
}
, { "Bind placeholders using an array":
function (assert, finished) {
var self = this;
self.db.open(":memory:", function () {
self.db.prepare("SELECT ? AS foo, ? AS bar, ? AS baz"
, function (error, statement) {
if (error) throw error;
assert.deepEqual(row, { foo: 1, bar: 2, baz: 3 });
puts("Test ok");
});
});
});
});
}
function test_by_array(callback) {
db = new sqlite.Database();
db.open(":memory:", function () {
puts("Opened ok");
db.prepare("SELECT ? AS foo, ? AS bar, ? AS baz"
, function (error, statement) {
if (error) throw error;
puts("Prepared ok");
statement.bindArray(['hi', 'there', 'world'], function (error) {
if (error) throw error;
puts("bound ok");
statement.step(function (error, row) {
if (error) throw error;
assert.deepEqual(row, { foo: 'hi', bar: 'there', baz: 'world' });
statement.reset();
statement.bindArray([1, 2, null], function (error) {
statement.bindArray(['hi', 'there', 'world'], function (error) {
if (error) throw error;
statement.step(function (error, row) {
if (error) throw error;
assert.deepEqual(row, { foo: 1, bar: 2, baz: null });
puts("Test ok");
assert.deepEqual(row
, { foo: 'hi'
, bar: 'there'
, baz: 'world'
});
statement.reset();
statement.bindArray([1, 2, null], function (error) {
statement.step(function (error, row) {
if (error) throw error;
assert.deepEqual(row, { foo: 1, bar: 2, baz: null });
finished();
});
});
});
});
});
});
});
});
}
function test_by_object(callback) {
db = new sqlite.Database();
db.open(":memory:", function () {
puts("Opened ok");
db.prepare("SELECT $x AS foo, $y AS bar, $z AS baz"
, function (error, statement) {
if (error) throw error;
puts("Prepared ok");
statement.bindObject({ $x: 'hi', $y: null, $z: 'world' }, function (error) {
if (error) throw error;
puts("bound ok");
statement.step(function (error, row) {
}
}
, { "Bind placeholders using an object":
function (assert, finished) {
var self = this;
self.db.open(":memory:", function () {
self.db.prepare("SELECT $x AS foo, $y AS bar, $z AS baz"
, function (error, statement) {
if (error) throw error;
assert.deepEqual(row, { foo: 'hi', bar: null, baz: 'world' });
statement.reset();
statement.bindArray([1, 2, null], function (error) {
statement.bindObject({ $x: 'hi', $y: null, $z: 'world' }, function (error) {
if (error) throw error;
statement.step(function (error, row) {
if (error) throw error;
assert.deepEqual(row, { foo: 1, bar: 2, baz: null });
puts("Test ok");
assert.deepEqual(row, { foo: 'hi', bar: null, baz: 'world' });
statement.reset();
statement.bindArray([1, 2, null], function (error) {
statement.step(function (error, row) {
if (error) throw error;
assert.deepEqual(row, { foo: 1, bar: 2, baz: null });
finished();
});
});
});
});
});
});
});
});
}
}
];
for (var i=0,il=tests.length; i < il; i++) {
suite.addTests(tests[i]);
}
test_num_array();
test_by_index();
test_by_array();
test_by_object();
var currentTest = 0;
var testCount = tests.length;
suite.setup(function(finished, test) {
this.db = new sqlite.Database();
finished();
});
suite.teardown(function(finished) {
if (this.db) this.db.close(function (error) {
finished();
});
++currentTest == testCount;
});
if (module == require.main) {
suite.runTests();
}
require.paths.push(__dirname + '/..');
sys = require('sys');
fs = require('fs');
path = require('path');
......@@ -10,12 +8,8 @@ sqlite = require('sqlite3_bindings');
puts = sys.puts;
inspect = sys.inspect;
// createa table
// prepare a statement (with options) that inserts
// do a step
// check that the result has a lastInsertedId property
var suite = exports.suite = new TestSuite("node-sqlite last inserted id test");
var name = "Caching of lastInsertedRowID";
var suite = exports[name] = new TestSuite(name);
function createTestTable(db, callback) {
db.prepare('CREATE TABLE table1 (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)',
......
require.paths.push(__dirname + '/..');
sys = require('sys');
fs = require('fs');
path = require('path');
......@@ -10,7 +8,8 @@ sqlite = require('sqlite3_bindings');
puts = sys.puts;
inspect = sys.inspect;
var suite = exports.suite = new TestSuite("node-sqlite low level tests");
var name = "SQLite bindings";
var suite = exports[name] = new TestSuite(name);
function createTestTable(db, callback) {
db.prepare('CREATE TABLE test1 (column1 TEXT)',
......
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