Skip to content

Commit

Permalink
Merge branch 'master' into merge-stat
Browse files Browse the repository at this point in the history
  • Loading branch information
mykmelez committed Dec 2, 2014
2 parents c47b39c + d5076a7 commit 7df9226
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 10 deletions.
34 changes: 34 additions & 0 deletions libs/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ var fs = (function() {
window.setZeroTimeout(function() { cb(value) });
} else {
var transaction = this.db.transaction(Store.DBSTORENAME, "readonly");
if (DEBUG_FS) { console.log("get " + key + " initiated"); }
var objectStore = transaction.objectStore(Store.DBSTORENAME);
var req = objectStore.get(key);
req.onerror = function() {
console.error("Error getting " + key + ": " + req.error.name);
};
transaction.oncomplete = (function() {
if (DEBUG_FS) { console.log("get " + key + " completed"); }
var value = req.result;
if (value === undefined) {
value = null;
Expand All @@ -101,33 +103,60 @@ var fs = (function() {
this.map.set(key, value);

var transaction = this.db.transaction(Store.DBSTORENAME, "readwrite");
if (DEBUG_FS) { console.log("put " + key + " initiated"); }
var objectStore = transaction.objectStore(Store.DBSTORENAME);
var req = objectStore.put(value, key);
req.onerror = function() {
console.error("Error putting " + key + ": " + req.error.name);
};
transaction.oncomplete = function() {
if (DEBUG_FS) { console.log("put " + key + " completed"); }
};
};

Store.prototype.removeItem = function(key) {
this.map.delete(key);

var transaction = this.db.transaction(Store.DBSTORENAME, "readwrite");
if (DEBUG_FS) { console.log("delete " + key + " initiated"); }
var objectStore = transaction.objectStore(Store.DBSTORENAME);
var req = objectStore.delete(key);
req.onerror = function() {
console.error("Error deleting " + key + ": " + req.error.name);
};
transaction.oncomplete = function() {
if (DEBUG_FS) { console.log("delete " + key + " completed"); }
};
};

Store.prototype.clear = function() {
this.map.clear();

var transaction = this.db.transaction(Store.DBSTORENAME, "readwrite");
if (DEBUG_FS) { console.log("clear initiated"); }
var objectStore = transaction.objectStore(Store.DBSTORENAME);
var req = objectStore.clear();
req.onerror = function() {
console.error("Error clearing store: " + req.error.name);
};
transaction.oncomplete = function() {
if (DEBUG_FS) { console.log("clear completed"); }
};
}

Store.prototype.sync = function(cb) {
// Process a readwrite transaction to ensure previous writes have completed,
// so we leave the datastore in a consistent state. This is a bit hacky;
// we should instead monitor ongoing transactions and call our callback
// once they've all completed.
var transaction = this.db.transaction(Store.DBSTORENAME, "readwrite");
if (DEBUG_FS) { console.log("get \"\" initiated"); }
var objectStore = transaction.objectStore(Store.DBSTORENAME);
objectStore.get("");
transaction.oncomplete = function() {
if (DEBUG_FS) { console.log("get \"\" completed"); }
cb();
};
}

var store = new Store();
Expand Down Expand Up @@ -632,6 +661,10 @@ var fs = (function() {
initRootDir(cb || function() {});
}

function storeSync(cb) {
store.sync(cb);
}

return {
dirname: dirname,
init: init,
Expand All @@ -655,5 +688,6 @@ var fs = (function() {
rename: rename,
stat: stat,
clear: clear,
storeSync: storeSync,
};
})();
16 changes: 7 additions & 9 deletions midp/gfx.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,9 @@
texture = texture.canvas; // Render the canvas, not the context.
}

var w = sw, h = sh;
var g = this;
withGraphics(g, function(c) {
withAnchor(g, c, anchor, x, y, w, h, function(x, y) {
withAnchor(g, c, anchor, x, y, sw, sh, function(x, y) {
c.translate(x, y);
if (transform === TRANS_MIRROR || transform === TRANS_MIRROR_ROT180)
c.scale(-1, 1);
Expand All @@ -831,7 +830,7 @@
c.rotate(Math.PI);
if (transform === TRANS_ROT270 || transform === TRANS_MIRROR_ROT270)
c.rotate(1.5 * Math.PI);
c.drawImage(texture, sx, sy, w, h, 0, 0, sw, sh);
c.drawImage(texture, sx, sy, sw, sh, 0, 0, sw, sh);
});
});
});
Expand All @@ -843,12 +842,11 @@
withClip(g, c, x1, y1, function(x, y) {
withSize(dx, dy, function(dx, dy) {
withPixel(g, c, function() {
var ctx = MIDP.Context2D;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + dx, y + dy);
ctx.stroke();
ctx.closePath();
c.beginPath();
c.moveTo(x, y);
c.lineTo(x + dx, y + dy);
c.stroke();
c.closePath();
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion tests/automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var gfxTests = [
{ name: "gfx/ImageProcessingTest", maxDifferent: 6184 },
{ name: "gfx/CreateImageWithRegionTest", maxDifferent: 0 },
{ name: "gfx/DrawSubstringTest", maxDifferent: 332 },
{ name: "gfx/DrawLineOffscreenCanvasTest", maxDifferent: 0 },
];

var expectedUnitTestResults = [
Expand Down Expand Up @@ -101,7 +102,7 @@ casper.test.begin("unit tests", 7 + gfxTests.length, function(test) {
casper
.thenOpen("http://localhost:8000/tests/fstests.html")
.waitForText("DONE", function() {
test.assertTextExists("DONE: 126 PASS, 0 FAIL", "run fs.js unit tests");
test.assertTextExists("DONE: 127 PASS, 0 FAIL", "run fs.js unit tests");
});

casper
Expand Down
10 changes: 10 additions & 0 deletions tests/fstests.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,16 @@ tests.push(function() {
});
});

tests.push(function() {
fs.storeSync(function() {
// There's nothing we can check, since the sync status of the store
// is private to the fs module, but we have at least confirmed that the call
// resulted in the callback being called.
ok(true, "storeSync callback called");
next();
});
});

fs.init(function() {
fs.clear(function() {
next();
Expand Down
42 changes: 42 additions & 0 deletions tests/gfx/DrawLineOffscreenCanvasTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package gfx;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class DrawLineOffscreenCanvasTest extends MIDlet {
private Display display;

class TestCanvas extends Canvas {
protected void paint(Graphics screenG) {
Image image = Image.createImage(getWidth(), getHeight());
Graphics g = image.getGraphics();

g.setColor(255, 0, 0);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0, 0, 255);
g.drawLine(20, 80, 20, getHeight() - 80);
g.drawLine(10, 10, getWidth() - 10, getHeight() - 10);
g.drawLine(200, 80, 200, getHeight() - 80);

screenG.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);

System.out.println("PAINTED");
}
}

public DrawLineOffscreenCanvasTest() {
display = Display.getDisplay(this);
}

public void startApp() {
TestCanvas test = new TestCanvas();
display.setCurrent(test);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}
}

Binary file added tests/gfx/DrawLineOffscreenCanvasTest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7df9226

Please sign in to comment.