Skip to content

Commit

Permalink
a few test tweaks for corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Nov 1, 2014
1 parent 3e91865 commit 8c14fdd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/browser/tests-browserified.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ suite('Explicit Error States', function() {
'GLU_TESS_MISSING_BEGIN_POLYGON',
'did not throw GLU_TESS_MISSING_BEGIN_POLYGON');
});
test('should recover if error caught', function() {
var tess = createTessellator(libtess);

// overwrite error handler
var errorValue = -1;
var errorHandler = function missingBeginPolygonHandler(errorNumber) {
errorValue = errorNumber;
};
tess.gluTessCallback(libtess.gluEnum.GLU_TESS_ERROR, errorHandler);

tess.gluTessBeginContour();

// test that error was correctly generated
assert.strictEqual(errorValue,
libtess.errorType.GLU_TESS_MISSING_BEGIN_POLYGON,
'did not throw GLU_TESS_MISSING_BEGIN_POLYGON');

// test that tess has recovered and data entry can proceed
assert.doesNotThrow(tess.gluTessEndContour.bind(tess));
});
});

// from the original README:
Expand Down Expand Up @@ -305,6 +325,13 @@ suite('Explicit Error States', function() {
}
tess.gluTessEndContour();

// the mesh isn't created until the cache is emptied, so add a dummy contour
// to force it to empty (see internal comment in gluTessBeginContour) to
// fully cover libtess.GluTesselator.makeDormant_
tess.gluTessBeginContour();
tess.gluTessVertex([0, 0, 0], [0, 0, 0]);
tess.gluTessEndContour();

test('should throw if next polygon begun without calling it', function() {
tess.gluTessBeginPolygon();
assert.strictEqual(errorValue,
Expand Down
27 changes: 27 additions & 0 deletions test/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ suite('Explicit Error States', function() {
'GLU_TESS_MISSING_BEGIN_POLYGON',
'did not throw GLU_TESS_MISSING_BEGIN_POLYGON');
});
test('should recover if error caught', function() {
var tess = createTessellator(libtess);

// overwrite error handler
var errorValue = -1;
var errorHandler = function missingBeginPolygonHandler(errorNumber) {
errorValue = errorNumber;
};
tess.gluTessCallback(libtess.gluEnum.GLU_TESS_ERROR, errorHandler);

tess.gluTessBeginContour();

// test that error was correctly generated
assert.strictEqual(errorValue,
libtess.errorType.GLU_TESS_MISSING_BEGIN_POLYGON,
'did not throw GLU_TESS_MISSING_BEGIN_POLYGON');

// test that tess has recovered and data entry can proceed
assert.doesNotThrow(tess.gluTessEndContour.bind(tess));
});
});

// from the original README:
Expand Down Expand Up @@ -139,6 +159,13 @@ suite('Explicit Error States', function() {
}
tess.gluTessEndContour();

// the mesh isn't created until the cache is emptied, so add a dummy contour
// to force it to empty (see internal comment in gluTessBeginContour) to
// fully cover libtess.GluTesselator.makeDormant_
tess.gluTessBeginContour();
tess.gluTessVertex([0, 0, 0], [0, 0, 0]);
tess.gluTessEndContour();

test('should throw if next polygon begun without calling it', function() {
tess.gluTessBeginPolygon();
assert.strictEqual(errorValue,
Expand Down

0 comments on commit 8c14fdd

Please sign in to comment.