Permalink
Browse files

Image test refactoring

  • Loading branch information...
1 parent bef75cc commit 3a5c0d8ada3b9d3da6f395fe9ec17489f13c9f88 @tj tj committed Mar 14, 2011
Showing with 10 additions and 4 deletions.
  1. +4 −0 src/Image.cc
  2. +6 −4 test/image.test.js
View
@@ -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
View
@@ -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);
});
},

0 comments on commit 3a5c0d8

Please sign in to comment.