Browse Source

Image test refactoring

v1.x
Tj Holowaychuk 14 years ago
parent
commit
3a5c0d8ada
  1. 4
      src/Image.cc
  2. 10
      test/image.test.js

4
src/Image.cc

@ -197,6 +197,7 @@ Image::load() {
void
Image::loadSync() {
HandleScope scope;
TryCatch try_catch;
loadSurface();
if (try_catch.HasCaught()) {
@ -256,6 +257,7 @@ Image::error(TryCatch &try_catch) {
Handle<Value>
Image::loadSurface() {
HandleScope scope;
switch (extension(filename)) {
case Image::PNG: return loadPNG();
#ifdef HAVE_JPEG
@ -271,6 +273,7 @@ Image::loadSurface() {
Handle<Value>
Image::loadPNG() {
HandleScope scope;
_surface = cairo_image_surface_create_from_png(filename);
cairo_status_t status = cairo_surface_status(_surface);
if (status) {
@ -290,6 +293,7 @@ Image::loadPNG() {
Handle<Value>
Image::loadJPEG() {
HandleScope scope;
FILE *stream = fopen(filename, "r");
// Generalized errors

10
test/image.test.js

@ -37,6 +37,7 @@ module.exports = {
'test Image#onerror': function(assert, beforeExit){
var img = new Image
, error
, n = 0;
assert.strictEqual(false, img.complete);
@ -46,19 +47,20 @@ module.exports = {
img.onerror = function(err){
++n;
assert.strictEqual(false, img.complete);
assert.ok(err instanceof Error, 'did not invoke onerror() with error');
error = err;
};
try {
img.src = png + 's';
} catch (err) {
assert.fail('got error ' + err);
assert.fail('error did not invoke onerror(): ' + err);
}
assert.equal(img.src, png + 's');
beforeExit(function(){
assert.ok(error instanceof Error, 'did not invoke onerror() with error');
assert.strictEqual(false, img.complete);
assert.equal(1, n);
});
},

Loading…
Cancel
Save