From 8c14fddeb7a5bc0935784a4b8711c0d6d847158b Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Sun, 2 Nov 2014 07:35:13 +1100 Subject: [PATCH] a few test tweaks for corner cases --- test/browser/tests-browserified.js | 27 +++++++++++++++++++++++++++ test/errors.test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/test/browser/tests-browserified.js b/test/browser/tests-browserified.js index 6a934b4..860cc38 100755 --- a/test/browser/tests-browserified.js +++ b/test/browser/tests-browserified.js @@ -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: @@ -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, diff --git a/test/errors.test.js b/test/errors.test.js index c9d25b9..0203883 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -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: @@ -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,