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 ...@@ -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 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. 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 SEE ALSO
-------- --------
......
NODE_PATH=. async-testing/node-async-test tests
require.paths.push(__dirname + '/..');
sys = require('sys'); sys = require('sys');
fs = require('fs'); fs = require('fs');
path = require('path'); path = require('path');
...@@ -10,12 +8,8 @@ sqlite = require('sqlite3_bindings'); ...@@ -10,12 +8,8 @@ sqlite = require('sqlite3_bindings');
puts = sys.puts; puts = sys.puts;
inspect = sys.inspect; inspect = sys.inspect;
// createa table var name = "Caching of affectedRows";
// prepare a statement (with options) that inserts var suite = exports[name] = new TestSuite(name);
// do a step
// check that the result has a lastInsertedId property
var suite = exports.suite = new TestSuite("node-sqlite last inserted id test");
function createTestTable(db, callback) { function createTestTable(db, callback) {
db.prepare('CREATE TABLE table1 (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)', db.prepare('CREATE TABLE table1 (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)',
......
var sqlite = require('../sqlite3_bindings'); require.paths.push(__dirname + '/..');
var sys = require('sys');
assert = require('assert');
var puts = sys.puts; sys = require('sys');
var inspect = sys.inspect; fs = require('fs');
path = require('path');
function test_by_index(callback) { TestSuite = require('async-testing/async_testing').TestSuite;
db = new sqlite.Database(); sqlite = require('sqlite3_bindings');
db.open(":memory:", function () {
puts("Opened ok"); puts = sys.puts;
db.prepare("SELECT ? AS foo, ? AS bar, ? AS baz" inspect = sys.inspect;
, function (error, statement) {
if (error) throw error; var name = "Binding statement place holders";
puts("Prepared ok"); var suite = exports[name] = new TestSuite("Binding statement place holders");
statement.bind(1, "hi", function (error) {
if (error) throw error; var tests = [
puts("bound ok"); { "Bind placeholders by index":
statement.bind(2, "there", function (error) { 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; if (error) throw error;
puts("bound ok"); statement.bind(1, "hi", function (error) {
statement.bind(3, "world", function (error) {
if (error) throw error; if (error) throw error;
puts("bound ok"); statement.bind(2, "there", function (error) {
statement.step(function (error, row) {
if (error) throw error; if (error) throw error;
assert.deepEqual(row, { foo: 'hi', bar: 'there', baz: 'world' }); statement.bind(3, "world", function (error) {
puts("Test ok"); if (error) throw error;
statement.step(function (error, row) {
if (error) throw error;
assert.deepEqual(row
, { foo: 'hi'
, bar: 'there'
, baz: 'world'
});
finished();
});
});
}); });
}); });
}); });
}); });
}); }
}); }
} , { "Bind placeholders using an array":
function (assert, finished) {
function test_num_array(callback) { var self = this;
db = new sqlite.Database(); self.db.open(":memory:", function () {
db.open(":memory:", function () { self.db.prepare("SELECT ? AS foo, ? AS bar, ? AS baz"
puts("Opened ok"); , function (error, statement) {
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) {
if (error) throw error; if (error) throw error;
assert.deepEqual(row, { foo: 1, bar: 2, baz: 3 });
puts("Test ok");
});
});
});
});
}
function test_by_array(callback) { statement.bindArray(['hi', 'there', 'world'], function (error) {
db = new sqlite.Database(); if (error) throw error;
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.step(function (error, row) { statement.step(function (error, row) {
if (error) throw error; 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();
});
});
}); });
}); });
}); });
}); });
}); }
}); }
} , { "Bind placeholders using an object":
function (assert, finished) {
function test_by_object(callback) { var self = this;
db = new sqlite.Database(); self.db.open(":memory:", function () {
db.open(":memory:", function () { self.db.prepare("SELECT $x AS foo, $y AS bar, $z AS baz"
puts("Opened ok"); , function (error, statement) {
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) {
if (error) throw error; if (error) throw error;
assert.deepEqual(row, { foo: 'hi', bar: null, baz: 'world' }); statement.bindObject({ $x: 'hi', $y: null, $z: 'world' }, function (error) {
statement.reset(); if (error) throw error;
statement.bindArray([1, 2, null], function (error) {
statement.step(function (error, row) { statement.step(function (error, row) {
if (error) throw error; if (error) throw error;
assert.deepEqual(row, { foo: 1, bar: 2, baz: null }); assert.deepEqual(row, { foo: 'hi', bar: null, baz: 'world' });
puts("Test ok"); 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(); var currentTest = 0;
test_by_index(); var testCount = tests.length;
test_by_array();
test_by_object(); 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'); sys = require('sys');
fs = require('fs'); fs = require('fs');
path = require('path'); path = require('path');
...@@ -10,12 +8,8 @@ sqlite = require('sqlite3_bindings'); ...@@ -10,12 +8,8 @@ sqlite = require('sqlite3_bindings');
puts = sys.puts; puts = sys.puts;
inspect = sys.inspect; inspect = sys.inspect;
// createa table var name = "Caching of lastInsertedRowID";
// prepare a statement (with options) that inserts var suite = exports[name] = new TestSuite(name);
// do a step
// check that the result has a lastInsertedId property
var suite = exports.suite = new TestSuite("node-sqlite last inserted id test");
function createTestTable(db, callback) { function createTestTable(db, callback) {
db.prepare('CREATE TABLE table1 (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)', db.prepare('CREATE TABLE table1 (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)',
......
require.paths.push(__dirname + '/..');
sys = require('sys'); sys = require('sys');
fs = require('fs'); fs = require('fs');
path = require('path'); path = require('path');
...@@ -10,7 +8,8 @@ sqlite = require('sqlite3_bindings'); ...@@ -10,7 +8,8 @@ sqlite = require('sqlite3_bindings');
puts = sys.puts; puts = sys.puts;
inspect = sys.inspect; 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) { function createTestTable(db, callback) {
db.prepare('CREATE TABLE test1 (column1 TEXT)', 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