Skip to content

Commit

Permalink
add unit test for PR #92
Browse files Browse the repository at this point in the history
  • Loading branch information
yathit committed Dec 25, 2015
1 parent 6d631b7 commit 2ac3631
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 31 deletions.
59 changes: 56 additions & 3 deletions src/ydn/db/conn/schema_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ var schema, debug_console;
var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall();




function setUp() {
// ydn.debug.log('ydn.db.con', 'finest');
// ydn.db.con.IndexedDb.DEBUG = true;
Expand Down Expand Up @@ -430,7 +428,6 @@ function test_blob_column() {

function test_data_index_add() {
if (options.mechanisms[0] != 'indexeddb') {
reachedFinalContinuation = true;
return;
}
// only work in IndexedDB
Expand Down Expand Up @@ -547,5 +544,61 @@ function test_multi_connection() {



function test_multiple_multi_entry_index() {

var db_name = 'test_' + Math.random();
var schema = {
stores: [{
name: 'ms1',
keyPath: 'a',
indexes: [{
name: 'ab',
keyPath: ['a', 'b']
}, {
name: 'de',
keyPath: ['d', 'e']
}]
}]
};

var db = new ydn.db.crud.Storage(db_name, schema, options);

var value = 'a' + Math.random();
asyncTestCase.waitForAsync('put');
var data = [{
a: 1,
b: 2,
d: 4,
e: 5
}, {
a: 11,
b: 12,
d: 14,
e: 15
}];
db.onReady(function(e) {
if (e) {
console.error(e);
fail(String(e));
}
db.put('ms1', data).addBoth(function(y) {
// console.log('put key ' + y);
db.valuesByIndex('ms1', 'ab', ydn.db.KeyRange.only([1, 2])).addBoth(function(x) {
// console.log(data[0], x[0]);
assertObjectEquals('get by ab index', data[0], x[0]);
asyncTestCase.continueTesting();
asyncTestCase.waitForAsync('de');
db.valuesByIndex('ms1', 'de', ydn.db.KeyRange.only([14, 15])).addBoth(function(x) {
assertObjectEquals('get by de index', data[1], x[0]);
asyncTestCase.continueTesting();
ydn.db.deleteDatabase(db.getName(), db.getType());
db.close();
});
});

});
});

}


15 changes: 8 additions & 7 deletions src/ydn/db/crud/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ ydn.db.crud.Storage.prototype.keys = function(store_name, arg2, arg3, arg4,
*
* @inheritDoc
*/
ydn.db.crud.Storage.prototype.keysByIndex = function(store_name, arg2, arg3, arg4,
arg5, arg6, arg7) {
return this.getCoreOperator().keysByIndex(store_name, arg2, arg3, arg4, arg5, arg6,
arg7);
ydn.db.crud.Storage.prototype.keysByIndex = function(store_name, index_name,
opt_kr, opt_limit, opt_offset, opt_reverse, opt_unique) {
return this.getCoreOperator().keysByIndex(store_name, index_name,
opt_kr, opt_limit, opt_offset, opt_reverse, opt_unique);
};


Expand All @@ -199,9 +199,10 @@ ydn.db.crud.Storage.prototype.values = function(arg1, arg2, arg3, arg4, arg5,
/**
* @inheritDoc
*/
ydn.db.crud.Storage.prototype.valuesByIndex = function(arg1, arg2, arg3, arg4, arg5,
arg6) {
return this.getCoreOperator().valuesByIndex(arg1, arg2, arg3, arg4, arg5, arg6);
ydn.db.crud.Storage.prototype.valuesByIndex = function(store_name, index_name,
opt_kr, opt_limit, opt_offset, opt_reverse, opt_unique) {
return this.getCoreOperator().valuesByIndex(store_name, index_name, opt_kr,
opt_limit, opt_offset, opt_reverse, opt_unique);
};


Expand Down
20 changes: 8 additions & 12 deletions test/storage/schema_idb_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@

<script src="../../../closure-library/closure/goog/base.js"></script>
<script src="../../../closure-library/closure/goog/deps.js"></script>
<script type="text/javascript" src="../../../ydn-base/src/deps.js"></script>
<script type="text/javascript" src="../../src/deps.js"></script>
<script src="../../../ydn-base/src/deps.js"></script>
<script src="../../src/deps.js"></script>

<script>
goog.require('goog.testing.ContinuationTestCase');
goog.require('goog.testing.jsunit');
options = {mechanisms: ['indexeddb']};
goog.require('ydn.db.crud.Storage');
goog.require('goog.events.EventTarget');
window.options = {mechanisms: ['indexeddb']};
goog.require('ydn.db.con.SchemaTest');
</script>
<script type="text/javascript" src="../../src/ydn/db/tr/inject.js"></script>
<script type="text/javascript" src="../../src/ydn/db/tr/event_installer.js"></script>
<script type="text/javascript" src="../../src/ydn/db/crud/inject.js"></script>
<script type="text/javascript" src="schema_test.js"></script>

<script src="../../src/ydn/db/tr/inject.js"></script>
<script src="../../src/ydn/db/tr/event_installer.js"></script>
<script src="../../src/ydn/db/crud/inject.js"></script>
</body>
</html>
14 changes: 5 additions & 9 deletions test/storage/schema_ls_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@
<script type="text/javascript" src="../../../ydn-base/src/deps.js"></script>
<script type="text/javascript" src="../../src/deps.js"></script>
<script>
goog.require('goog.testing.ContinuationTestCase');
goog.require('goog.testing.jsunit');
options = {mechanisms: ['localstorage']};
goog.require('ydn.db.crud.Storage');
goog.require('goog.events.EventTarget');
window.options = {mechanisms: ['indexeddb']};
goog.require('ydn.db.con.SchemaTest');
</script>
<script type="text/javascript" src="../../src/ydn/db/tr/inject.js"></script>
<script type="text/javascript" src="../../src/ydn/db/tr/event_installer.js"></script>
<script type="text/javascript" src="../../src/ydn/db/crud/inject.js"></script>
<script type="text/javascript" src="schema_test.js"></script>
<script src="../../src/ydn/db/tr/inject.js"></script>
<script src="../../src/ydn/db/tr/event_installer.js"></script>
<script src="../../src/ydn/db/crud/inject.js"></script>

</body>
</html>

0 comments on commit 2ac3631

Please sign in to comment.