Skip to content
Browse files

move to mocha for tests and update them

  • Loading branch information...
1 parent 81ca3b5 commit 66487d44f5853e5782954ff586ed2860420ff1ed @springmeyer springmeyer committed Apr 12, 2012
View
8 Makefile
@@ -30,15 +30,15 @@ uninstall:
@node-waf uninstall
test-tmp:
- @rm -rf tests/tmp
- @mkdir -p tests/tmp
+ @rm -rf test/tmp
+ @mkdir -p test/tmp
ifndef only
test: test-tmp
- @PATH=./node_modules/expresso/bin:${PATH} && NODE_PATH=./lib:$NODE_PATH expresso
+ @PATH=./node_modules/mocha/bin:${PATH} && NODE_PATH=./lib:$NODE_PATH mocha -R spec
else
test: test-tmp
- @PATH=./node_modules/expresso/bin:${PATH} && NODE_PATH=./lib:$NODE_PATH expresso test/${only}.test.js
+ @PATH=./node_modules/mocha/bin:${PATH} && NODE_PATH=./lib:$NODE_PATH mocha -R spec test/${only}.test.js
endif
fix:
View
76 test/color.test.js
@@ -1,36 +1,54 @@
var mapnik = require('mapnik');
+var assert = require('assert');
-exports['test color creation'] = function(beforeExit, assert) {
- // no 'new' keyword
- assert.throws(function() { mapnik.Color(); });
+describe('mapnik.Color', function() {
+ it('should throw with invalid usage', function() {
+ // no 'new' keyword
+ assert.throws(function() { mapnik.Color(); });
+ // invalid args
+ assert.throws(function() { new mapnik.Color(); });
+ assert.throws(function() { new mapnik.Color(1); });
+ assert.throws(function() { new mapnik.Color('foo'); });
+ });
- // invalid args
- assert.throws(function() { new mapnik.Color(); });
- assert.throws(function() { new mapnik.Color(1); });
- assert.throws(function() { new mapnik.Color('foo'); });
+ it('should be green via keyword', function() {
+ var c = new mapnik.Color('green');
+ assert.equal(c.r, 0);
+ assert.equal(c.g, 128);
+ assert.equal(c.b, 0);
+ assert.equal(c.a, 255);
+ assert.equal(c.hex(), '#008000');
+ assert.equal(c.toString(), 'rgb(0,128,0)');
+ });
- var c = new mapnik.Color('green');
- assert.equal(c.r, 0);
- assert.equal(c.g, 128);
- assert.equal(c.b, 0);
- assert.equal(c.a, 255);
- assert.equal(c.hex(), '#008000');
- assert.equal(c.toString(), 'rgb(0,128,0)');
- c = new mapnik.Color(0, 128, 0);
- assert.equal(c.r, 0);
- assert.equal(c.g, 128);
- assert.equal(c.b, 0);
- assert.equal(c.a, 255);
- assert.equal(c.hex(), '#008000');
- assert.equal(c.toString(), 'rgb(0,128,0)');
+ it('should be gray via rgb', function() {
+ var c = new mapnik.Color(0, 128, 0);
+ assert.equal(c.r, 0);
+ assert.equal(c.g, 128);
+ assert.equal(c.b, 0);
+ assert.equal(c.a, 255);
+ assert.equal(c.hex(), '#008000');
+ assert.equal(c.toString(), 'rgb(0,128,0)');
+ });
- c = new mapnik.Color(0, 128, 0, 255);
- assert.equal(c.r, 0);
- assert.equal(c.g, 128);
- assert.equal(c.b, 0);
- assert.equal(c.a, 255);
- assert.equal(c.hex(), '#008000');
- assert.equal(c.toString(), 'rgb(0,128,0)');
+ it('should be gray via rgba', function() {
+ var c = new mapnik.Color(0, 128, 0, 255);
+ assert.equal(c.r, 0);
+ assert.equal(c.g, 128);
+ assert.equal(c.b, 0);
+ assert.equal(c.a, 255);
+ assert.equal(c.hex(), '#008000');
+ assert.equal(c.toString(), 'rgb(0,128,0)');
+ });
-};
+ it('should be gray via rgba %', function() {
+ var c = new mapnik.Color('rgba(0%,50%,0%,1)');
+ assert.equal(c.r, 0);
+ assert.equal(c.g, 128);
+ assert.equal(c.b, 0);
+ assert.equal(c.a, 255);
+ assert.equal(c.hex(), '#008000');
+ assert.equal(c.toString(), 'rgb(0,128,0)');
+ });
+});
View
81 test/constants.test.js
@@ -1,30 +1,57 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var fs = require('fs');
-exports['test constants'] = function(beforeExit, assert) {
- assert.ok(mapnik.settings);
- assert.ok(mapnik.settings.paths);
- assert.ok(mapnik.settings.paths.fonts.length);
- assert.ok(fs.statSync(mapnik.settings.paths.fonts));
- assert.ok(mapnik.settings.paths.input_plugins.length);
- assert.ok(fs.statSync(mapnik.settings.paths.input_plugins));
-
- // reloading the default plugins path should return false as no more plugins are registered
- assert.ok(!mapnik.register_datasources(mapnik.settings.paths.input_plugins));
-
- /* has version info */
- assert.ok(mapnik.versions);
- assert.ok(mapnik.versions.node);
- assert.ok(mapnik.versions.v8);
- assert.ok(mapnik.versions.mapnik);
- assert.ok(mapnik.versions.mapnik_number);
- assert.ok(mapnik.versions.boost);
- assert.ok(mapnik.versions.boost_number);
-
- assert.ok(mapnik.Geometry.Point,1);
- assert.ok(mapnik.Geometry.LineString,2);
- assert.ok(mapnik.Geometry.Polygon,3);
-
- // make sure we have some
- assert.ok(mapnik.datasources().length > 0);
-};
+describe('mapnik constants', function() {
+ it('should have valid settings', function() {
+ assert.ok(mapnik.settings);
+ assert.ok(mapnik.settings.paths);
+ assert.ok(mapnik.settings.paths.fonts.length);
+ assert.ok(fs.statSync(mapnik.settings.paths.fonts));
+ assert.ok(mapnik.settings.paths.input_plugins.length);
+ assert.ok(fs.statSync(mapnik.settings.paths.input_plugins));
+
+ // reloading the default plugins path should return false as no more plugins are registered
+ assert.ok(!mapnik.register_datasources(mapnik.settings.paths.input_plugins));
+
+ /* has version info */
+ assert.ok(mapnik.versions);
+ assert.ok(mapnik.versions.node);
+ assert.ok(mapnik.versions.v8);
+ assert.ok(mapnik.versions.mapnik);
+ assert.ok(mapnik.versions.mapnik_number);
+ assert.ok(mapnik.versions.boost);
+ assert.ok(mapnik.versions.boost_number);
+
+ assert.ok(mapnik.Geometry.Point, 1);
+ assert.ok(mapnik.Geometry.LineString, 2);
+ assert.ok(mapnik.Geometry.Polygon, 3);
+
+ // make sure we have some
+ assert.ok(mapnik.datasources().length > 0);
+ });
+
+ it('should have valid version info', function() {
+ /* has version info */
+ assert.ok(mapnik.versions);
+ assert.ok(mapnik.versions.node);
+ assert.ok(mapnik.versions.v8);
+ assert.ok(mapnik.versions.mapnik);
+ assert.ok(mapnik.versions.mapnik_number);
+ assert.ok(mapnik.versions.boost);
+ assert.ok(mapnik.versions.boost_number);
+
+ assert.ok(mapnik.Geometry.Point, 1);
+ assert.ok(mapnik.Geometry.LineString, 2);
+ assert.ok(mapnik.Geometry.Polygon, 3);
+
+ // make sure we have some
+ assert.ok(mapnik.datasources().length > 0);
+ });
+
+ it('should expose Geometry enums', function() {
+ assert.ok(mapnik.Geometry.Point, 1);
+ assert.ok(mapnik.Geometry.LineString, 2);
+ assert.ok(mapnik.Geometry.Polygon, 3);
+ });
+});
View
232 test/datasource.test.js
@@ -1,133 +1,135 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var fs = require('fs');
var path = require('path');
-exports['test datasource creation'] = function(beforeExit, assert) {
- assert.throws(function() { mapnik.Datasource('foo'); });
- assert.throws(function() { mapnik.Datasource({ 'foo': 1 }); });
- assert.throws(function() { mapnik.Datasource({ 'type': 'foo' }); });
- assert.throws(function() { mapnik.Datasource({ 'type': 'shape' }); });
+describe('mapnik.Datasource', function() {
+ it('should throw with invalid usage', function() {
+ assert.throws(function() { mapnik.Datasource('foo'); });
+ assert.throws(function() { mapnik.Datasource({ 'foo': 1 }); });
+ assert.throws(function() { mapnik.Datasource({ 'type': 'foo' }); });
+ assert.throws(function() { mapnik.Datasource({ 'type': 'shape' }); });
- assert.throws(function() { new mapnik.Datasource('foo'); },
- /Must provide an object, eg \{type: 'shape', file : 'world.shp'\}/);
+ assert.throws(function() { new mapnik.Datasource('foo'); },
+ /Must provide an object, eg \{type: 'shape', file : 'world.shp'\}/);
- assert.throws(function() { new mapnik.Datasource({ 'foo': 1 }); },
- /Could not create datasource. Required parameter 'type' is missing/);
+ assert.throws(function() { new mapnik.Datasource({ 'foo': 1 }); },
+ /Could not create datasource. Required parameter 'type' is missing/);
- assert.throws(function() { new mapnik.Datasource({ 'type': 'foo' }); },
- /Could not create datasource. No plugin found for type 'foo'/);
+ assert.throws(function() { new mapnik.Datasource({ 'type': 'foo' }); },
+ /Could not create datasource. No plugin found for type 'foo'/);
- assert.throws(function() { new mapnik.Datasource({ 'type': 'shape' }); },
- /Shape Plugin: missing <file> parameter/);
-};
+ assert.throws(function() { new mapnik.Datasource({ 'type': 'shape' }); },
+ /Shape Plugin: missing <file> parameter/);
+ });
-exports['test datasource'] = function(beforeExit, assert) {
- var options = {
- type: 'shape',
- file: './examples/data/world_merc.shp'
- };
+ it('should validate with known shapefile', function() {
+ var options = {
+ type: 'shape',
+ file: './examples/data/world_merc.shp'
+ };
- var ds = new mapnik.Datasource(options);
- assert.ok(ds);
- assert.deepEqual(ds.parameters(), options);
+ var ds = new mapnik.Datasource(options);
+ assert.ok(ds);
+ assert.deepEqual(ds.parameters(), options);
- var features = ds.features();
- assert.equal(features.length, 245);
- assert.deepEqual(features[244], {
- AREA: 1638094,
- FIPS: 'RS',
- ISO2: 'RU',
- ISO3: 'RUS',
- LAT: 61.988,
- LON: 96.689,
- NAME: 'Russia',
- POP2005: 143953092,
- REGION: 150,
- SUBREGION: 151,
- UN: 643,
- __id__: 245
- });
+ var features = ds.features();
+ assert.equal(features.length, 245);
+ assert.deepEqual(features[244], {
+ AREA: 1638094,
+ FIPS: 'RS',
+ ISO2: 'RU',
+ ISO3: 'RUS',
+ LAT: 61.988,
+ LON: 96.689,
+ NAME: 'Russia',
+ POP2005: 143953092,
+ REGION: 150,
+ SUBREGION: 151,
+ UN: 643,
+ __id__: 245
+ });
- assert.deepEqual(ds.describe(), {
- type: 'vector',
- extent: [
- -20037508.342789248,
- -8283343.693882697,
- 20037508.342789244,
- 18365151.363070473
- ],
- encoding: 'utf-8',
- fields: {
- FIPS: 'String',
- ISO2: 'String',
- ISO3: 'String',
- UN: 'Number',
- NAME: 'String',
- AREA: 'Number',
- POP2005: 'Number',
- REGION: 'Number',
- SUBREGION: 'Number',
- LON: 'Number',
- LAT: 'Number'
- },
- geometry_type: 'multipolygon',
- has_features: true
+ assert.deepEqual(ds.describe(), {
+ type: 'vector',
+ extent: [
+ -20037508.342789248,
+ -8283343.693882697,
+ 20037508.342789244,
+ 18365151.363070473
+ ],
+ encoding: 'utf-8',
+ fields: {
+ FIPS: 'String',
+ ISO2: 'String',
+ ISO3: 'String',
+ UN: 'Number',
+ NAME: 'String',
+ AREA: 'Number',
+ POP2005: 'Number',
+ REGION: 'Number',
+ SUBREGION: 'Number',
+ LON: 'Number',
+ LAT: 'Number'
+ },
+ geometry_type: 'multipolygon',
+ has_features: true
+ });
});
-};
+ it('should validate with known geojson', function() {
+ // same datasource but from json file (originally converted with ogr2ogr)
+ var options = {
+ type: 'ogr',
+ file: './examples/data/world_merc.json',
+ layer_by_index: 0
+ };
-exports['test JSON datasource'] = function(beforeExit, assert) {
- // same datasource but from json file (originally converted with ogr2ogr)
- var options = {
- type: 'ogr',
- file: './examples/data/world_merc.json',
- layer_by_index: 0
- };
+ var ds = new mapnik.Datasource(options);
+ assert.ok(ds);
+ assert.deepEqual(ds.parameters(), options);
- var ds = new mapnik.Datasource(options);
- assert.ok(ds);
- assert.deepEqual(ds.parameters(), options);
-
- var features = ds.features();
- assert.equal(features.length, 245);
- assert.deepEqual(features[244], {
- AREA: 1638094,
- FIPS: 'RS',
- ISO2: 'RU',
- ISO3: 'RUS',
- LAT: 61.988,
- LON: 96.689,
- NAME: 'Russia',
- POP2005: 143953092,
- REGION: 150,
- SUBREGION: 151,
- UN: 643,
- __id__: 245
- });
+ var features = ds.features();
+ assert.equal(features.length, 245);
+ assert.deepEqual(features[244], {
+ AREA: 1638094,
+ FIPS: 'RS',
+ ISO2: 'RU',
+ ISO3: 'RUS',
+ LAT: 61.988,
+ LON: 96.689,
+ NAME: 'Russia',
+ POP2005: 143953092,
+ REGION: 150,
+ SUBREGION: 151,
+ UN: 643,
+ __id__: 245
+ });
- assert.deepEqual(ds.describe(), {
- type: 'vector',
- extent: [
- -20037508.342789,
- -8283343.693883,
- 20037508.342789,
- 18365151.36307
- ],
- encoding: 'utf-8',
- fields: {
- FIPS: 'String',
- ISO2: 'String',
- ISO3: 'String',
- UN: 'Number',
- NAME: 'String',
- AREA: 'Number',
- POP2005: 'Number',
- REGION: 'Number',
- SUBREGION: 'Number',
- LON: 'Number',
- LAT: 'Number'
- },
- geometry_type: 'multipolygon',
- has_features: true
+ assert.deepEqual(ds.describe(), {
+ type: 'vector',
+ extent: [
+ -20037508.342789,
+ -8283343.693883,
+ 20037508.342789,
+ 18365151.36307
+ ],
+ encoding: 'utf-8',
+ fields: {
+ FIPS: 'String',
+ ISO2: 'String',
+ ISO3: 'String',
+ UN: 'Number',
+ NAME: 'String',
+ AREA: 'Number',
+ POP2005: 'Number',
+ REGION: 'Number',
+ SUBREGION: 'Number',
+ LON: 'Number',
+ LAT: 'Number'
+ },
+ geometry_type: 'multipolygon',
+ has_features: true
+ });
});
-};
+});
View
52 test/expression.test.js
@@ -1,33 +1,33 @@
var mapnik = require('mapnik');
var assert = require('assert');
-exports['test expression'] = function(beforeExit) {
- // no 'new' keyword
- assert.throws(function() { mapnik.Expression(); });
+describe('mapnik.Expression', function() {
+ it('should throw with invalid usage', function() {
+ // no 'new' keyword
+ assert.throws(function() { mapnik.Expression(); });
+ // invalid args
+ assert.throws(function() { new mapnik.Expression(); });
+ assert.throws(function() { new mapnik.Expression(1); });
+ });
- // invalid args
- assert.throws(function() { new mapnik.Expression(); });
- assert.throws(function() { new mapnik.Expression(1); });
+ it('should accept complex expressions', function() {
+ // valid expression strings
+ var expr = new mapnik.Expression('[ATTR]');
+ var expr = new mapnik.Expression('[ATTR]+2');
+ var expr = new mapnik.Expression('[ATTR]/2');
- // valid expression strings
- var expr = new mapnik.Expression('[ATTR]');
- var expr = new mapnik.Expression('[ATTR]+2');
- var expr = new mapnik.Expression('[ATTR]/2');
+ var expr = new mapnik.Expression('[ATTR1]/[ATTR2]');
+ assert.equal(expr.toString(), '[ATTR1]/[ATTR2]');
- var expr = new mapnik.Expression('[ATTR1]/[ATTR2]');
- assert.equal(expr.toString(),'[ATTR1]/[ATTR2]');
-
- var expr = new mapnik.Expression('\'literal\'');
- assert.equal(expr.toString(),"'literal'");
-};
+ var expr = new mapnik.Expression('\'literal\'');
+ assert.equal(expr.toString(), "'literal'");
+ });
-
-exports['test expression evaluation'] = function(beforeExit) {
-
- var expr = new mapnik.Expression("[attr]='value'");
- var feature = new mapnik.Feature(0);
- feature.addAttributes({'attr':'value'});
- assert.equal(expr.evaluate(feature),true);
- assert.equal(expr.evaluate(feature).toString(),'true');
-
-};
+ it('should support evaluation to js types', function() {
+ var expr = new mapnik.Expression("[attr]='value'");
+ var feature = new mapnik.Feature(0);
+ feature.addAttributes({'attr': 'value'});
+ assert.equal(expr.evaluate(feature), true);
+ assert.equal(expr.evaluate(feature).toString(), 'true');
+ });
+});
View
70 test/feature.test.js
@@ -1,35 +1,47 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var fs = require('fs');
var path = require('path');
-exports['test features'] = function(beforeExit, assert) {
- var options = {
- type: 'shape',
- file: './examples/data/world_merc.shp'
- };
-
- var ds = new mapnik.Datasource(options);
- // get one feature
- var featureset = ds.featureset();
- var feature = featureset.next();
- assert.deepEqual(feature.attributes(), {
- AREA: 44,
- FIPS: 'AC',
- ISO2: 'AG',
- ISO3: 'ATG',
- LAT: 17.078,
- LON: -61.783,
- NAME: 'Antigua and Barbuda',
- POP2005: 83039,
- REGION: 19,
- SUBREGION: 29,
- UN: 28
+describe('mapnik.Feature ', function() {
+ it('should throw with invalid usage', function() {
+ // no 'new' keyword
+ assert.throws(function() { mapnik.Feature(); });
+ // invalid args
+ assert.throws(function() { new mapnik.Feature(); });
+ assert.throws(function() { new mapnik.Feature(1, 4, 5); });
+ assert.throws(function() { new mapnik.Feature('foo'); });
});
- // loop over all of them to ensure the proper feature count
- var count = 1;
- while ((feature = featureset.next())) {
- count++;
- }
- assert.equal(count, 245);
-};
+ it('should match known features', function() {
+ var options = {
+ type: 'shape',
+ file: './examples/data/world_merc.shp'
+ };
+
+ var ds = new mapnik.Datasource(options);
+ // get one feature
+ var featureset = ds.featureset();
+ var feature = featureset.next();
+ assert.deepEqual(feature.attributes(), {
+ AREA: 44,
+ FIPS: 'AC',
+ ISO2: 'AG',
+ ISO3: 'ATG',
+ LAT: 17.078,
+ LON: -61.783,
+ NAME: 'Antigua and Barbuda',
+ POP2005: 83039,
+ REGION: 19,
+ SUBREGION: 29,
+ UN: 28
+ });
+
+ // loop over all of them to ensure the proper feature count
+ var count = 1;
+ while ((feature = featureset.next())) {
+ count++;
+ }
+ assert.equal(count, 245);
+ });
+});
View
32 test/fonts.test.js
@@ -1,4 +1,5 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var fs = require('fs');
function oc(a) {
@@ -9,18 +10,23 @@ function oc(a) {
return o;
}
-exports['test fonts'] = function(beforeExit, assert) {
- // make sure we have default fonts
- assert.ok('DejaVu Sans Bold' in oc(mapnik.fonts()));
+describe('mapnik fonts ', function() {
+ it('should auto-register DejaVu fonts', function() {
+ // make sure we have default fonts
+ assert.ok('DejaVu Sans Bold' in oc(mapnik.fonts()));
+ });
- // make sure system font was loaded
- if (process.platform == 'darwin') {
- assert.ok('Times Regular' in oc(mapnik.fonts()));
- // it should already be loaded so trying to register more should return false
- assert.ok(!mapnik.register_fonts('/System/Library/Fonts/', { recurse: true }));
- }
+ it('should auto-register a system font like Times Regular on OS X', function() {
+ if (process.platform == 'darwin') {
+ assert.ok('Times Regular' in oc(mapnik.fonts()));
+ // it should already be loaded so trying to register more should return false
+ assert.ok(!mapnik.register_fonts('/System/Library/Fonts/', { recurse: true }));
+ }
+ });
- // will return true if new fonts are found
- // but should return false as we now call at startup
- assert.ok(!mapnik.register_system_fonts());
-};
+ it('should find new fonts when registering all system fonts', function() {
+ // will return true if new fonts are found
+ // but should return false as we now call at startup
+ assert.ok(!mapnik.register_system_fonts());
+ });
+});
View
144 test/grid.test.js
@@ -3,85 +3,89 @@ var assert = require('assert');
var fs = require('fs');
var path = require('path');
-exports['test grids'] = function(beforeExit) {
- // no 'new' keyword
- assert.throws(function() { mapnik.Grid(1, 1); });
+describe('mapnik.Grid ', function() {
+ it('should throw with invalid usage', function() {
+ // no 'new' keyword
+ assert.throws(function() { mapnik.Grid(1, 1); });
- // invalid args
- assert.throws(function() { new mapnik.Grid(); });
- assert.throws(function() { new mapnik.Grid(1); });
- assert.throws(function() { new mapnik.Grid('foo'); });
- assert.throws(function() { new mapnik.Grid('a', 'b', 'c'); });
+ // invalid args
+ assert.throws(function() { new mapnik.Grid(); });
+ assert.throws(function() { new mapnik.Grid(1); });
+ assert.throws(function() { new mapnik.Grid('foo'); });
+ assert.throws(function() { new mapnik.Grid('a', 'b', 'c'); });
+ });
- var grid = new mapnik.Grid(256, 256);
- assert.ok(grid instanceof mapnik.Grid);
+ it('should be initialized properly', function() {
+ var grid = new mapnik.Grid(256, 256);
+ assert.ok(grid instanceof mapnik.Grid);
- assert.equal(grid.width(), 256);
- assert.equal(grid.height(), 256);
- var v = grid.view(0, 0, 256, 256);
- assert.ok(v instanceof mapnik.GridView);
- assert.equal(v.width(), 256);
- assert.equal(v.height(), 256);
- assert.equal(grid.encodeSync().length, v.encodeSync().length);
+ assert.equal(grid.width(), 256);
+ assert.equal(grid.height(), 256);
+ var v = grid.view(0, 0, 256, 256);
+ assert.ok(v instanceof mapnik.GridView);
+ assert.equal(v.width(), 256);
+ assert.equal(v.height(), 256);
+ assert.equal(grid.encodeSync().length, v.encodeSync().length);
+ });
-
- var grid_blank = new mapnik.Grid(4,4);
- assert.equal(grid_blank.painted(),false);
- assert.equal(grid_blank.background,undefined);
-
- var m = new mapnik.Map(4,4);
- var l = new mapnik.Layer('test');
- m.add_layer(l);
+ it('should be painted after rendering', function(done) {
+ var grid_blank = new mapnik.Grid(4, 4);
+ assert.equal(grid_blank.painted(), false);
+ assert.equal(grid_blank.background, undefined);
+ var m = new mapnik.Map(4, 4);
+ var l = new mapnik.Layer('test');
+ m.add_layer(l);
- m.render(grid_blank,{layer:0},function(err,grid_blank) {
- assert.equal(grid_blank.painted(),false);
- assert.equal(grid_blank.background,undefined);
- });
+ m.render(grid_blank, {layer: 0},function(err,grid_blank) {
+ assert.equal(grid_blank.painted(), false);
+ assert.equal(grid_blank.background, undefined);
+ });
- var grid_blank2 = new mapnik.Grid(4,4);
- assert.equal(grid_blank2.painted(),false);
- assert.equal(grid_blank2.background,undefined);
+ var grid_blank2 = new mapnik.Grid(4, 4);
+ assert.equal(grid_blank2.painted(), false);
+ assert.equal(grid_blank2.background, undefined);
- var m2 = new mapnik.Map(4,4);
- var l = new mapnik.Layer('test');
- m2.add_layer(l);
-
- m2.background = new mapnik.Color('green');
- m2.render(grid_blank2,{layer:0},function(err,grid_blank2) {
- assert.equal(grid_blank2.painted(),false);
- //assert.ok(grid_blank2.background);
- });
+ var m2 = new mapnik.Map(4, 4);
+ var l = new mapnik.Layer('test');
+ m2.add_layer(l);
+ m2.background = new mapnik.Color('green');
+ m2.render(grid_blank2, {layer: 0},function(err,grid_blank2) {
+ assert.equal(grid_blank2.painted(), false);
+ //assert.ok(grid_blank2.background);
+ });
- var grid_blank3 = new mapnik.Grid(4,4);
- assert.equal(grid_blank3.painted(),false);
- assert.equal(grid_blank3.background,undefined);
- var m3 = new mapnik.Map(4,4);
- var s = '<Map>';
- s += '<Style name="points">';
- s += ' <Rule>';
- s += ' <PointSymbolizer />';
- s += ' </Rule>';
- s += '</Style>';
- s += '</Map>';
- m3.fromStringSync(s);
+ var grid_blank3 = new mapnik.Grid(4, 4);
+ assert.equal(grid_blank3.painted(), false);
+ assert.equal(grid_blank3.background, undefined);
- var mem_datasource = new mapnik.MemoryDatasource({'extent':'-180,-90,180,90'});
- mem_datasource.add({ 'x':0, 'y':0 });
- mem_datasource.add({ 'x':1, 'y':1 });
- mem_datasource.add({ 'x':2, 'y':2 });
- mem_datasource.add({ 'x':3, 'y':3 });
- var l = new mapnik.Layer('test');
- l.srs = m3.srs;
- l.styles = ["points"];
- l.datasource = mem_datasource;
- m3.add_layer(l);
- m3.zoomAll();
- m3.render(grid_blank3,{layer:0},function(err,grid_blank3) {
- assert.equal(grid_blank3.painted(),true);
- // TODO - expose grid background
- //assert.equal(grid_blank3.background,undefined);
- });
+ var m3 = new mapnik.Map(4, 4);
+ var s = '<Map>';
+ s += '<Style name="points">';
+ s += ' <Rule>';
+ s += ' <PointSymbolizer />';
+ s += ' </Rule>';
+ s += '</Style>';
+ s += '</Map>';
+ m3.fromStringSync(s);
-};
+ var mem_datasource = new mapnik.MemoryDatasource({'extent': '-180,-90,180,90'});
+ mem_datasource.add({ 'x': 0, 'y': 0 });
+ mem_datasource.add({ 'x': 1, 'y': 1 });
+ mem_datasource.add({ 'x': 2, 'y': 2 });
+ mem_datasource.add({ 'x': 3, 'y': 3 });
+ var l = new mapnik.Layer('test');
+ l.srs = m3.srs;
+ l.styles = ['points'];
+ l.datasource = mem_datasource;
+ m3.add_layer(l);
+ m3.zoomAll();
+ m3.render(grid_blank3, {layer: 0},function(err,grid_blank3) {
+ assert.equal(grid_blank3.painted(), true);
+ // TODO - expose grid background
+ //assert.equal(grid_blank3.background,undefined);
+ done();
+ });
+ });
+});
View
56 test/grid_view.test.js
@@ -3,28 +3,40 @@ var assert = require('assert');
var fs = require('fs');
var path = require('path');
+var grid;
+var view;
-exports['test grid view getPixel'] = function(beforeExit) {
- var grid = new mapnik.Grid(256, 256);
- var view = grid.view(0,0,256,256);
- assert.equal(view.isSolid(),true);
-
- var pixel = view.getPixel(0,0);
- assert.equal(pixel,0);
+describe('mapnik.GridView ', function() {
+ before(function(done) {
+ grid = new mapnik.Grid(256, 256);
+ view = grid.view(0, 0, 256, 256);
+ done();
+ });
- var map = new mapnik.Map(256, 256);
- map.loadSync('./examples/stylesheet.xml');
- map.zoomAll();
- var options = {'layer': 0,
- 'fields': ['NAME']
- };
- var grid = new mapnik.Grid(map.width, map.height, {key: '__id__'});
- map.render(grid, options, function(err, grid) {
-
- var view = grid.view(0,0,256,256);
- assert.equal(view.isSolid(),false);
- // hit alaska (USA is id 207)
- assert.equal(view.getPixel(25,100),207);
- })
+ it('should be solid', function() {
+ assert.equal(view.isSolid(), true);
+ });
-};
+ it('should have zero value for pixel', function() {
+ var pixel = view.getPixel(0, 0);
+ assert.equal(pixel, 0);
+ });
+
+ it('should be painted after rendering', function(done) {
+ var map = new mapnik.Map(256, 256);
+ map.loadSync('./examples/stylesheet.xml');
+ map.zoomAll();
+ var options = {'layer': 0,
+ 'fields': ['NAME']
+ };
+ var grid = new mapnik.Grid(map.width, map.height, {key: '__id__'});
+ map.render(grid, options, function(err, grid) {
+
+ var view = grid.view(0, 0, 256, 256);
+ assert.equal(view.isSolid(), false);
+ // hit alaska (USA is id 207)
+ assert.equal(view.getPixel(25, 100), 207);
+ done();
+ });
+ });
+});
View
145 test/image.test.js
@@ -1,92 +1,97 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var fs = require('fs');
var path = require('path');
-var Image = mapnik.Image;
+describe('mapnik.Image ', function() {
+ it('should throw with invalid usage', function() {
+ // no 'new' keyword
+ assert.throws(function() { mapnik.Image(1, 1); });
-exports['test images'] = function(beforeExit, assert) {
- // no 'new' keyword
- assert.throws(function() { Image(1, 1); });
-
- // invalid args
- assert.throws(function() { new Image(); });
- assert.throws(function() { new Image(1); });
- assert.throws(function() { new Image('foo'); });
- assert.throws(function() { new Image('a', 'b', 'c'); });
-
- var im = new Image(256, 256);
- assert.ok(im instanceof Image);
-
- assert.equal(im.width(), 256);
- assert.equal(im.height(), 256);
- var v = im.view(0, 0, 256, 256);
- assert.ok(v instanceof mapnik.ImageView);
- assert.equal(v.width(), 256);
- assert.equal(v.height(), 256);
- assert.equal(im.encodeSync().length, v.encodeSync().length);
+ // invalid args
+ assert.throws(function() { new mapnik.Image(); });
+ assert.throws(function() { new mapnik.Image(1); });
+ assert.throws(function() { new mapnik.Image('foo'); });
+ assert.throws(function() { new mapnik.Image('a', 'b', 'c'); });
+ });
- im.save('test/tmp/image.png');
+ it('should be initialized properly', function() {
+ var im = new mapnik.Image(256, 256);
+ assert.ok(im instanceof mapnik.Image);
- var im2 = new Image.open('test/tmp/image.png');
- assert.ok(im2 instanceof Image);
+ assert.equal(im.width(), 256);
+ assert.equal(im.height(), 256);
+ var v = im.view(0, 0, 256, 256);
+ assert.ok(v instanceof mapnik.ImageView);
+ assert.equal(v.width(), 256);
+ assert.equal(v.height(), 256);
+ assert.equal(im.encodeSync().length, v.encodeSync().length);
- assert.equal(im2.width(), 256);
- assert.equal(im2.height(), 256);
+ im.save('test/tmp/image.png');
- assert.equal(im.encodeSync().length, im2.encodeSync().length);
+ var im2 = new mapnik.Image.open('test/tmp/image.png');
+ assert.ok(im2 instanceof mapnik.Image);
- var im_blank = new Image(4, 4);
- assert.equal(im_blank.painted(), false);
- assert.equal(im_blank.background, undefined);
+ assert.equal(im2.width(), 256);
+ assert.equal(im2.height(), 256);
- var m = new mapnik.Map(4, 4);
+ assert.equal(im.encodeSync().length, im2.encodeSync().length);
+ });
- m.render(im_blank, {},function(err,im_blank) {
+ it('should be painted after rendering', function(done) {
+ var im_blank = new mapnik.Image(4, 4);
assert.equal(im_blank.painted(), false);
assert.equal(im_blank.background, undefined);
- });
- var im_blank2 = new Image(4, 4);
- assert.equal(im_blank2.painted(), false);
- assert.equal(im_blank2.background, undefined);
+ var m = new mapnik.Map(4, 4);
- var m2 = new mapnik.Map(4, 4);
+ m.render(im_blank, {},function(err,im_blank) {
+ assert.equal(im_blank.painted(), false);
+ assert.equal(im_blank.background, undefined);
+ });
- m2.background = new mapnik.Color('green');
- m2.render(im_blank2, {},function(err,im_blank2) {
+ var im_blank2 = new mapnik.Image(4, 4);
assert.equal(im_blank2.painted(), false);
- assert.ok(im_blank2.background);
- });
+ assert.equal(im_blank2.background, undefined);
+
+ var m2 = new mapnik.Map(4, 4);
+
+ m2.background = new mapnik.Color('green');
+ m2.render(im_blank2, {},function(err,im_blank2) {
+ assert.equal(im_blank2.painted(), false);
+ assert.ok(im_blank2.background);
+ });
- var im_blank3 = new Image(4, 4);
- assert.equal(im_blank3.painted(), false);
- assert.equal(im_blank3.background, undefined);
-
- var m3 = new mapnik.Map(4, 4);
- var s = '<Map>';
- s += '<Style name="points">';
- s += ' <Rule>';
- s += ' <PointSymbolizer />';
- s += ' </Rule>';
- s += '</Style>';
- s += '</Map>';
- m3.fromStringSync(s);
-
- var mem_datasource = new mapnik.MemoryDatasource({'extent': '-180,-90,180,90'});
- mem_datasource.add({ 'x': 0, 'y': 0 });
- mem_datasource.add({ 'x': 1, 'y': 1 });
- mem_datasource.add({ 'x': 2, 'y': 2 });
- mem_datasource.add({ 'x': 3, 'y': 3 });
- var l = new mapnik.Layer('test');
- l.srs = m3.srs;
- l.styles = ['points'];
- l.datasource = mem_datasource;
- m3.add_layer(l);
- m3.zoomAll();
- m3.render(im_blank3, {},function(err,im_blank3) {
- assert.equal(im_blank3.painted(), true);
+ var im_blank3 = new mapnik.Image(4, 4);
+ assert.equal(im_blank3.painted(), false);
assert.equal(im_blank3.background, undefined);
- });
-};
+ var m3 = new mapnik.Map(4, 4);
+ var s = '<Map>';
+ s += '<Style name="points">';
+ s += ' <Rule>';
+ s += ' <PointSymbolizer />';
+ s += ' </Rule>';
+ s += '</Style>';
+ s += '</Map>';
+ m3.fromStringSync(s);
+
+ var mem_datasource = new mapnik.MemoryDatasource({'extent': '-180,-90,180,90'});
+ mem_datasource.add({ 'x': 0, 'y': 0 });
+ mem_datasource.add({ 'x': 1, 'y': 1 });
+ mem_datasource.add({ 'x': 2, 'y': 2 });
+ mem_datasource.add({ 'x': 3, 'y': 3 });
+ var l = new mapnik.Layer('test');
+ l.srs = m3.srs;
+ l.styles = ['points'];
+ l.datasource = mem_datasource;
+ m3.add_layer(l);
+ m3.zoomAll();
+ m3.render(im_blank3, {},function(err,im_blank3) {
+ assert.equal(im_blank3.painted(), true);
+ assert.equal(im_blank3.background, undefined);
+ done();
+ });
+ });
+});
View
51 test/image_view.test.js
@@ -3,26 +3,37 @@ var assert = require('assert');
var fs = require('fs');
var path = require('path');
+describe('mapnik.ImageView ', function() {
+ it('should throw with invalid usage', function() {
+ // no 'new' keyword
+ assert.throws(function() { mapnik.Image(1, 1); });
-exports['test images view getPixel'] = function(beforeExit) {
- var im = new mapnik.Image(256, 256);
- var view = im.view(0,0,256,256);
- assert.equal(view.isSolid(),true);
- var pixel = view.getPixel(0,0);
- assert.equal(pixel.r,0);
- assert.equal(pixel.g,0);
- assert.equal(pixel.b,0);
- assert.equal(pixel.a,0);
+ // invalid args
+ assert.throws(function() { new mapnik.Image(); });
+ assert.throws(function() { new mapnik.Image(1); });
+ assert.throws(function() { new mapnik.Image('foo'); });
+ assert.throws(function() { new mapnik.Image('a', 'b', 'c'); });
+ });
- var im = new mapnik.Image(256, 256);
- im.background = new mapnik.Color(2,2,2,2);
- var view = im.view(0,0,256,256);
- assert.equal(view.isSolid(),true);
- var pixel = view.getPixel(0,0);
- assert.equal(pixel.r,2);
- assert.equal(pixel.g,2);
- assert.equal(pixel.b,2);
- assert.equal(pixel.a,2);
- assert.equal(view.getPixel(99999999,9999999),undefined);
+ it('should be initialized properly', function() {
+ var im = new mapnik.Image(256, 256);
+ var view = im.view(0, 0, 256, 256);
+ assert.equal(view.isSolid(), true);
+ var pixel = view.getPixel(0, 0);
+ assert.equal(pixel.r, 0);
+ assert.equal(pixel.g, 0);
+ assert.equal(pixel.b, 0);
+ assert.equal(pixel.a, 0);
-};
+ var im = new mapnik.Image(256, 256);
+ im.background = new mapnik.Color(2, 2, 2, 2);
+ var view = im.view(0, 0, 256, 256);
+ assert.equal(view.isSolid(), true);
+ var pixel = view.getPixel(0, 0);
+ assert.equal(pixel.r, 2);
+ assert.equal(pixel.g, 2);
+ assert.equal(pixel.b, 2);
+ assert.equal(pixel.a, 2);
+ assert.equal(view.getPixel(99999999, 9999999), undefined);
+ });
+});
View
62 test/layers.test.js
@@ -1,36 +1,40 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var fs = require('fs');
var path = require('path');
-exports['test layers'] = function(beforeExit, assert) {
- // no 'new' keyword
- assert.throws(function() { mapnik.Layer('foo'); });
- // invalid args
- assert.throws(function() { new mapnik.Layer(); });
- assert.throws(function() { new mapnik.Layer(1); });
- assert.throws(function() { new mapnik.Layer('a', 'b', 'c'); });
- assert.throws(function() { new mapnik.Layer(new mapnik.Layer('foo')); });
+describe('mapnik.Layer ', function() {
+ it('should throw with invalid usage', function() {
+ // no 'new' keyword
+ assert.throws(function() { mapnik.Layer('foo'); });
+ // invalid args
+ assert.throws(function() { new mapnik.Layer(); });
+ assert.throws(function() { new mapnik.Layer(1); });
+ assert.throws(function() { new mapnik.Layer('a', 'b', 'c'); });
+ assert.throws(function() { new mapnik.Layer(new mapnik.Layer('foo')); });
+ });
- // new layer
- var layer = new mapnik.Layer('foo', '+init=epsg:4326');
- assert.equal(layer.name, 'foo');
- assert.equal(layer.srs, '+init=epsg:4326');
- assert.deepEqual(layer.styles, []);
- // will be empty/undefined
- assert.ok(!layer.datasource);
- var options = {
- type: 'shape',
- file: './examples/data/world_merc.shp'
- };
+ it('should initialize properly', function() {
+ var layer = new mapnik.Layer('foo', '+init=epsg:4326');
+ assert.equal(layer.name, 'foo');
+ assert.equal(layer.srs, '+init=epsg:4326');
+ assert.deepEqual(layer.styles, []);
+ // will be empty/undefined
+ assert.ok(!layer.datasource);
+ var options = {
+ type: 'shape',
+ file: './examples/data/world_merc.shp'
+ };
- var ds = new mapnik.Datasource(options);
- layer.datasource = ds;
- assert.ok(layer.datasource instanceof mapnik.Datasource);
+ var ds = new mapnik.Datasource(options);
+ layer.datasource = ds;
+ assert.ok(layer.datasource instanceof mapnik.Datasource);
- // json representation
- var meta = layer.describe();
- assert.equal(meta.name, 'foo');
- assert.equal(meta.srs, '+init=epsg:4326');
- assert.deepEqual(meta.styles, []);
- assert.deepEqual(meta.datasource, options);
-};
+ // json representation
+ var meta = layer.describe();
+ assert.equal(meta.name, 'foo');
+ assert.equal(meta.srs, '+init=epsg:4326');
+ assert.deepEqual(meta.styles, []);
+ assert.deepEqual(meta.datasource, options);
+ });
+});
View
120 test/map.test.js
@@ -0,0 +1,120 @@
+var mapnik = require('mapnik');
+var assert = require('assert');
+var path = require('path');
+
+describe('mapnik.Map', function() {
+ it('should throw with invalid usage', function() {
+ // no 'new' keyword
+ assert.throws(function() { Map('foo'); });
+
+ // invalid args
+ assert.throws(function() { new mapnik.Map(); });
+ assert.throws(function() { new mapnik.Map(1); });
+ assert.throws(function() { new mapnik.Map('foo'); });
+ assert.throws(function() { new mapnik.Map('a', 'b', 'c'); });
+ assert.throws(function() { new mapnik.Map(new mapnik.Map(1, 1)); });
+ });
+
+ it('should be initialized properly', function() {
+ // TODO - more tests
+ var map = new mapnik.Map(600, 400);
+ assert.ok(map instanceof mapnik.Map);
+ map.extent = map.extent;
+ });
+
+ it('should have settable properties', function() {
+ var map = new mapnik.Map(600, 400);
+
+ assert.equal(map.width, 600);
+ assert.equal(map.height, 400);
+ map.resize(256, 256);
+ assert.equal(map.width, 256);
+ assert.equal(map.height, 256);
+
+ map.width = 100;
+ map.height = 100;
+ assert.equal(map.width, 100);
+ assert.equal(map.height, 100);
+
+ // TODO - need to expose aspect_fix_mode
+ //assert.equal(map.maximumExtent,undefined)
+ //map.maximumExtent = map.extent;
+ //assert.equal(map.maximumExtent,map.extent)
+ });
+
+ it('should load a stylesheet', function() {
+ var map = new mapnik.Map(600, 400);
+
+ assert.equal(map.width, 600);
+ assert.equal(map.height, 400);
+ assert.equal(map.srs, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs');
+ assert.equal(map.bufferSize, 0);
+ assert.equal(map.maximumExtent, undefined);
+
+ // Test loading a sample world map
+ map.loadSync('./examples/stylesheet.xml');
+
+ var layers = map.layers();
+ assert.equal(layers.length, 1);
+ assert.equal(layers[0].name, 'world');
+ assert.equal(layers[0].srs, '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over');
+ assert.deepEqual(layers[0].styles, ['style']);
+ assert.equal(layers[0].datasource.type, 'vector');
+ assert.equal(layers[0].datasource.parameters()['type'], 'shape');
+ assert.equal(path.normalize(layers[0].datasource.parameters()['file']), path.normalize(path.join(process.cwd(), 'examples/data/world_merc.shp')));
+
+ // clear styles and layers from previous load to set up for another
+ // otherwise layers are duplicated
+ map.clear();
+ var layers2 = map.layers();
+ assert.equal(layers2.length, 0);
+ });
+
+ it('should allow access to layers', function() {
+ var map = new mapnik.Map(600, 400);
+ map.loadSync('./examples/stylesheet.xml');
+ var layers = map.layers();
+ assert.equal(layers.length, 1);
+ assert.equal(layers[0].name, 'world');
+ assert.equal(layers[0].srs, '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over');
+ assert.deepEqual(layers[0].styles, ['style']);
+ assert.equal(layers[0].datasource.type, 'vector');
+ assert.equal(layers[0].datasource.parameters()['type'], 'shape');
+ assert.equal(path.normalize(layers[0].datasource.parameters()['file']), path.normalize(path.join(process.cwd(), 'examples/data/world_merc.shp')));
+
+ var layer = map.get_layer(0);
+ assert.ok(layer.datasource);
+
+ // get layer by name
+ var layer_same = map.get_layer('world');
+ assert.ok(layer_same.datasource);
+
+ // compare
+ assert.deepEqual(layer.datasource.describe(), layer_same.datasource.describe());
+
+ var options = {
+ type: 'shape',
+ file: './examples/data/world_merc.shp'
+ };
+
+ // make a change to layer, ensure it sticks
+ layer.name = 'a';
+ layer.styles = ['a'];
+ layer.srs = '+init=epsg:4326';
+ layer.datasource = new mapnik.Datasource(options);
+
+ // check for change, after adding to map
+ // adding to map should release original layer
+ // as a copy is made when added (I think)
+ map.add_layer(layer);
+ var added = map.layers()[1];
+ // make sure the layer is an identical copy to what is on map
+ assert.equal(added.name, layer.name);
+ assert.equal(added.srs, layer.srs);
+ assert.deepEqual(added.styles, layer.styles);
+ assert.deepEqual(added.datasource.parameters(), options);
+ assert.deepEqual(added.datasource.parameters(), new mapnik.Datasource(options).parameters());
+
+ });
+
+});
View
340 test/map_generation.test.js
@@ -1,294 +1,90 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var fs = require('fs');
var path = require('path');
var helper = require('./support/helper');
-var Map = mapnik.Map;
-
-var base_url = './examples/'; // must end with trailing slash
-var style_string = fs.readFileSync(base_url + 'stylesheet.xml', 'utf8');
-var map = new Map(600, 400);
-map.fromStringSync(style_string, {strict: true, base: base_url});
-map.zoomAll();
-
-exports['map constructor errors'] = function(beforeExit, assert) {
-
- // no 'new' keyword
- assert.throws(function() { Map('foo'); });
-
- // invalid args
- assert.throws(function() { new Map(); });
- assert.throws(function() { new Map(1); });
- assert.throws(function() { new Map('foo'); });
- assert.throws(function() { new Map('a', 'b', 'c'); });
- assert.throws(function() { new Map(new Map(1, 1)); });
-
-};
-
-
-exports['test asynchronous map rendering'] = function(beforeExit, assert) {
- var completed = false;
- var map = new Map(600, 400);
- assert.ok(map instanceof Map);
- map.extent = map.extent;
- var im = new mapnik.Image(map.width, map.height);
- map.render(im, {scale: 1}, function(err, image) {
- assert.ok(image);
- assert.ok(!err);
- var buffer = im.encodeSync('png');
- //assert.equal(helper.md5(buffer), 'ef33223235b26c782736c88933b35331');
+describe('mapnik rendering ', function() {
+ it('should render async (blank)', function(done) {
+ var map = new mapnik.Map(600, 400);
+ assert.ok(map instanceof mapnik.Map);
+ map.extent = map.extent;
+ var im = new mapnik.Image(map.width, map.height);
+ map.render(im, {scale: 1}, function(err, image) {
+ assert.ok(image);
+ assert.ok(!err);
+ var buffer = im.encodeSync('png');
+ done();
+ //assert.equal(helper.md5(buffer), 'ef33223235b26c782736c88933b35331');
+ });
});
-};
-
-exports['test asynchronous map rendering to file with actual data'] = function(beforeExit, assert) {
- var filename = './test/tmp/renderFile2.png';
- var map = new Map(600, 400);
- map.loadSync('./examples/stylesheet.xml');
- map.zoomAll();
- map.renderFile(filename, function(error) {
- assert.ok(!error);
- assert.ok(path.existsSync(filename));
+ it('should render async (real data)', function(done) {
+ var filename = './test/tmp/renderFile2.png';
+ var map = new mapnik.Map(600, 400);
+ map.loadSync('./examples/stylesheet.xml');
+ map.zoomAll();
+ map.renderFile(filename, function(error) {
+ assert.ok(!error);
+ assert.ok(path.existsSync(filename));
+ done();
+ });
});
-};
+ it('should render async to file (png)', function(done) {
+ var filename = './test/tmp/renderFile2.png';
+ var map = new mapnik.Map(600, 400);
+ map.loadSync('./examples/stylesheet.xml');
+ map.zoomAll();
+ map.renderFile(filename, function(error) {
+ assert.ok(!error);
+ assert.ok(path.existsSync(filename));
+ done();
+ });
+ });
-if(mapnik.supports.cairo) {
- exports['test asynchronous map rendering to file with actual data and cairo'] = function(beforeExit, assert) {
+ it('should render async to file (cairo format)', function(done) {
+ if (mapnik.supports.cairo) {
+ var filename = './test/tmp/renderFile2.pdf';
+ var map = new mapnik.Map(600, 400);
+ map.loadSync('./examples/stylesheet.xml');
+ map.zoomAll();
+ map.renderFile(filename, { format: 'pdf' }, function(error) {
+ if (error) {
+ console.log(error);
+ }
+ assert.ok(!error);
+ assert.ok(path.existsSync(filename));
+ done();
+ });
+ } else { done() }
+ });
- var filename = './test/tmp/renderFile2.pdf';
- var map = new Map(600, 400);
+ it('should render async to file (guessing format)', function(done) {
+ var filename = './test/tmp/renderFile.jpg';
+ var map = new mapnik.Map(600, 400);
map.loadSync('./examples/stylesheet.xml');
map.zoomAll();
- map.renderFile(filename, { format: "pdf" }, function(error) {
+ map.renderFile(filename, function(error) {
if (error) {
console.log(error);
}
assert.ok(!error);
assert.ok(path.existsSync(filename));
+ done();
});
- };
-}
-
-exports['test asynchronous map rendering to file with actual data (guess file type) '] = function(beforeExit, assert) {
-
- var filename = './test/tmp/renderFile.jpg';
- var map = new Map(600, 400);
- map.loadSync('./examples/stylesheet.xml');
- map.zoomAll();
- map.renderFile(filename, function(error) {
- if (error) {
- console.log(error);
- }
- assert.ok(!error);
- assert.ok(path.existsSync(filename));
- });
-
-};
-
-
-exports['test asynchronous map rendering to file and wrong input'] = function(beforeExit, assert) {
-
- var filename = './test/tmp/renderFile2.pdf';
- var map = new Map(600, 400);
- map.loadSync('./examples/stylesheet.xml');
- map.zoomAll();
- try {
- map.renderFile({ format: "pdf" }, function(error) {
- });
- } catch (e) {
- assert.ok(e);
- }
-
- try {
- map.renderFile(filename,null, function(error) {
- });
- } catch (ex) {
- assert.ok(ex);
- }
-
-};
-
-exports['test loading a stylesheet'] = function(beforeExit, assert) {
- var map = new Map(600, 400);
-
- assert.equal(map.width, 600);
- assert.equal(map.height, 400);
- assert.equal(map.srs, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs');
- assert.equal(map.bufferSize, 0);
- assert.equal(map.maximumExtent, undefined);
-
- // Test loading a sample world map
- map.loadSync('./examples/stylesheet.xml');
-
- var layers = map.layers();
- assert.equal(layers.length, 1);
- assert.equal(layers[0].name, 'world');
- assert.equal(layers[0].srs, '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over');
- assert.deepEqual(layers[0].styles, ['style']);
- assert.equal(layers[0].datasource.type, 'shape');
- assert.equal(path.normalize(layers[0].datasource.file), path.normalize(path.join(process.cwd(), 'examples/data/world_merc.shp')));
-
- // clear styles and layers from previous load to set up for another
- // otherwise layers are duplicated
- map.clear();
- var layers2 = map.layers();
- assert.equal(layers2.length, 0);
-};
-
-exports['test rendering with actual data'] = function(beforeExit, assert) {
- var filename = helper.filename();
- map.renderFileSync(filename);
- assert.ok(path.existsSync(filename));
- //assert.equal(helper.md5File(filename), 'aaf71787e4d5dcbab3c964192038f465');
-};
-
-exports['test map extents'] = function(beforeExit, assert) {
- var expected = [-20037508.3428, -14996604.5082, 20037508.3428, 25078412.1774];
- assert.notStrictEqual(map.extent, expected);
-
- var expected_precise = [-20037508.342789248, -8317435.060598943, 20037508.342789244, 18399242.72978672];
- assert.deepEqual(map.extent, expected_precise);
-};
-
-exports['test setting map properties'] = function(beforeExit, assert) {
- var map = new Map(600, 400);
-
- assert.equal(map.width, 600);
- assert.equal(map.height, 400);
- map.resize(256, 256);
- assert.equal(map.width, 256);
- assert.equal(map.height, 256);
-
- map.width = 100;
- map.height = 100;
- assert.equal(map.width, 100);
- assert.equal(map.height, 100);
-
- // TODO - need to expose aspect_fix_mode
- //assert.equal(map.maximumExtent,undefined)
- //map.maximumExtent = map.extent;
- //assert.equal(map.maximumExtent,map.extent)
-
-};
-
-exports['test map layers'] = function(beforeExit, assert) {
- var layers = map.layers();
- assert.equal(layers.length, 1);
- assert.equal(layers[0].name, 'world');
- assert.equal(layers[0].srs, '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over');
- assert.deepEqual(layers[0].styles, ['style']);
- assert.equal(layers[0].datasource.type, 'shape');
- assert.equal(path.normalize(layers[0].datasource.file), path.normalize(path.join(process.cwd(), 'examples/data/world_merc.shp')));
-};
-
-exports['test map features'] = function(beforeExit, assert) {
- // features
- var features = map.features(0); // for first and only layer
- assert.equal(features.length, 245);
- assert.deepEqual(features[244], {
- AREA: 1638094,
- FIPS: 'RS',
- ISO2: 'RU',
- ISO3: 'RUS',
- LAT: 61.988,
- LON: 96.689,
- NAME: 'Russia',
- POP2005: 143953092,
- REGION: 150,
- SUBREGION: 151,
- UN: 643,
- __id__: 245
});
- // feature slicing, just what you want
- var three_features = map.features(0, 0, 2); // for first and only layer
- assert.deepEqual(three_features, [
- {
- AREA: 44,
- FIPS: 'AC',
- ISO2: 'AG',
- ISO3: 'ATG',
- LAT: 17.078,
- LON: -61.783,
- NAME: 'Antigua and Barbuda',
- POP2005: 83039,
- REGION: 19,
- SUBREGION: 29,
- UN: 28,
- __id__: 1
- },
- {
- AREA: 238174,
- FIPS: 'AG',
- ISO2: 'DZ',
- ISO3: 'DZA',
- LAT: 28.163,
- LON: 2.632,
- NAME: 'Algeria',
- POP2005: 32854159,
- REGION: 2,
- SUBREGION: 15,
- UN: 12,
- __id__: 2
- },
- {
- AREA: 8260,
- FIPS: 'AJ',
- ISO2: 'AZ',
- ISO3: 'AZE',
- LAT: 40.43,
- LON: 47.395,
- NAME: 'Azerbaijan',
- POP2005: 8352021,
- REGION: 142,
- SUBREGION: 145,
- UN: 31,
- __id__: 3
+ it('should render async and throw with invalid format', function(done) {
+ var filename = './test/tmp/renderFile2.pdf';
+ var map = new mapnik.Map(600, 400);
+ map.loadSync('./examples/stylesheet.xml');
+ map.zoomAll();
+ try {
+ map.renderFile(filename, null, function(error) { });
+ } catch (ex) {
+ assert.ok(ex);
+ done();
}
- ]);
-};
-
-exports['test map datasource'] = function(beforeExit, assert) {
- // datasource meta data
- var described = map.describe_data();
- assert.deepEqual(described.world.extent, [-20037508.342789248, -8283343.693882697, 20037508.342789244, 18365151.363070473]);
- assert.equal(described.world.type, 'vector');
- assert.equal(described.world.encoding, 'iso-8859-1');
- assert.equal(described.world.fields.FIPS, 'String');
-
- // get layer by index
- var layer = map.get_layer(0);
- assert.deepEqual(layer.datasource, {});
-
- // get layer by name
- var layer_same = map.get_layer('world');
- assert.deepEqual(layer_same.datasource, {});
-
- // but it does have functions
- assert.deepEqual(layer.datasource.describe(), map.describe_data().world);
- assert.deepEqual(layer.datasource.describe(), layer_same.datasource.describe());
-
- var options = {
- type: 'shape',
- file: './examples/data/world_merc.shp'
- };
-
- // make a change to layer, ensure it sticks
- layer.name = 'a';
- layer.styles = ['a'];
- layer.srs = '+init=epsg:4326';
- layer.datasource = new mapnik.Datasource(options);
-
- // check for change, after adding to map
- // adding to map should release original layer
- // as a copy is made when added (I think)
- map.add_layer(layer);
- var added = map.layers()[1];
- // make sure the layer is an identical copy to what is on map
- assert.equal(added.name, layer.name);
- assert.equal(added.srs, layer.srs);
- assert.deepEqual(added.styles, layer.styles);
- assert.deepEqual(added.datasource, options);
- assert.deepEqual(added.datasource, new mapnik.Datasource(options).parameters());
-};
+ });
+});
View
94 test/palette.test.js
@@ -1,47 +1,57 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var fs = require('fs');
var path = require('path');
var helper = require('./support/helper');
-exports['test palette creation'] = function(beforeExit, assert) {
- var pal = new mapnik.Palette('\x01\x02\x03\x04');
- assert.equal('[Palette 1 color #01020304]', pal.toString());
-
- assert.throws(function() {
- new mapnik.Palette('\x01\x02\x03');
- }, (/invalid palette length/));
-
- pal = new mapnik.Palette('\x01\x02\x03', 'rgb');
- assert.equal('[Palette 1 color #010203]', pal.toString());
-
- pal = new mapnik.Palette('\xff\x09\x93\xFF\x01\x02\x03\x04');
- assert.equal('[Palette 2 colors #01020304 #ff0993]', pal.toString());
- assert.equal('\x01\x02\x03\x04\xff\x09\x93\xFF', pal.toBuffer().toString('binary'));
-};
-
-exports['test 64 color ACT palettes'] = function(beforeExit, assert) {
- var pal = new mapnik.Palette(fs.readFileSync('./test/support/palettes/palette64.act'), 'act');
- assert.equal('[Palette 64 colors #494746 #c37631 #89827c #d1955c #7397b9 #fc9237 #a09f9c #fbc147 #9bb3ce #b7c9a1 #b5d29c #c4b9aa #cdc4a5 #d5c8a3 #c1d7aa #ccc4b6 #dbd19c #b2c4d5 #eae487 #c9c8c6 #e4db99 #c9dcb5 #dfd3ac #cbd2c2 #d6cdbc #dbd2b6 #c0ceda #ece597 #f7ef86 #d7d3c3 #dfcbc3 #d1d0cd #d1e2bf #d3dec1 #dbd3c4 #e6d8b6 #f4ef91 #d3d3cf #cad5de #ded7c9 #dfdbce #fcf993 #ffff8a #dbd9d7 #dbe7cd #d4dce2 #e4ded3 #ebe3c9 #e0e2e2 #f4edc3 #fdfcae #e9e5dc #f4edda #eeebe4 #fefdc5 #e7edf2 #edf4e5 #f2efe9 #f6ede7 #fefedd #f6f4f0 #f1f5f8 #fbfaf8 #ffffff]', pal.toString());
-};
-
-exports['test 256 color ACT palettes'] = function(beforeExit, assert) {
-
- var pal = new mapnik.Palette(fs.readFileSync('./test/support/palettes/palette256.act'), 'act');
- assert.equal('[Palette 256 colors #272727 #3c3c3c #484847 #564b41 #605243 #6a523e #555555 #785941 #5d5d5d #746856 #676767 #956740 #ba712e #787777 #cb752a #c27c3d #b68049 #dc8030 #df9e10 #878685 #e1a214 #928b82 #a88a70 #ea8834 #e7a81d #cb8d55 #909090 #94938c #e18f48 #f68d36 #6f94b7 #e1ab2e #8e959b #c79666 #999897 #ff9238 #ef9447 #a99a88 #f1b32c #919ca6 #a1a09f #f0b04b #8aa4bf #f8bc39 #b3ac8f #d1a67a #e3b857 #a8a8a7 #ffc345 #a2adb9 #afaeab #f9ab69 #afbba4 #c4c48a #b4b2af #dec177 #9ab2cf #a3bebb #d7b491 #b6cd9e #b5d29c #b9c8a2 #f1c969 #c5c79e #bbbab9 #cabdaa #a6bcd1 #cec4a7 #e7cc89 #dad98a #d5c9a3 #fabd8a #c1d7aa #cec5b4 #d1d1a5 #d9cf9f #c5c4c3 #d3c7b5 #ddd59d #b4c6d6 #d1cbb4 #d1c7ba #d7d1aa #e1c6ab #cbc7c2 #dbd0a9 #e8e58a #fee178 #d3cbba #dfd7a3 #d2cfb9 #c9ddb5 #d2cbbe #c3cbce #d7cbba #dcceb2 #dfd3aa #e5dd9a #dbd3b1 #ceccc6 #d7cbbe #d7cfba #dfc3be #dfd3ae #cbcbcb #cbd3c3 #d3cfc0 #e0d8aa #d7cfbe #dbd3b8 #ebe596 #dfd8b0 #c0ceda #f1ee89 #decfbc #d7cfc4 #d7d3c3 #d1d0cd #d2dfc0 #dbd3c3 #e7c7c3 #e7d7b3 #f2ed92 #d1e2bf #dad7c3 #fef383 #d3d3cf #dbd3c7 #e0d3c2 #dfd7c0 #ebe4a8 #dbd7c7 #dfd3c7 #f7f38f #c9d4de #dcdcc5 #dfd7c7 #e7d5c2 #d6d5d4 #faf78e #d7dfca #fbfb8a #fffb86 #dfd7cb #e5ddc0 #dad7d2 #ecd6c1 #cfd7de #e8d0cc #fbfb8e #fffb8a #eae3b8 #e3d7cd #dfdbce #fffb8e #ffff8a #f5efa6 #dae6cc #e3dbcf #edddc3 #dddbd6 #d5dbdf #ffff91 #e3dbd3 #fefc99 #e7dbd2 #eaddcd #e3dfd3 #ebd7d3 #dddddd #d4dee6 #e2dfd7 #fcdcc0 #e7dbd7 #e7dfd3 #ebe4cb #f4eeb8 #e3dfdb #e7dfd7 #ebded5 #e7e3d7 #fefea6 #e1ecd6 #ece5d3 #e7e3db #dee3e5 #ebe3db #efdfdb #efe3d8 #f4efc9 #e6ecdb #ebe3df #ebe7db #f0ecd3 #e5e6e5 #efe7da #ebe7df #efe3df #fefeb8 #dfe7ef #ebe7e3 #edebde #efe7e0 #e8efe0 #e7f3df #ebebe3 #e7ebe8 #f5edd9 #efebe3 #e3ebf1 #e9efe7 #ebebea #efebe7 #f0efe2 #ecf3e5 #fefdc9 #efefe7 #f3efe7 #f5f3e1 #f2efe9 #e9eef4 #ffeddf #efefef #f3efeb #f3f3eb #f0f7eb #fbf7e1 #fefed8 #f3f3ef #f7f3eb #eef3f7 #f7f7ea #f3f3f3 #f3f7ef #f7f3ef #f3f3f7 #f7f3f3 #f7f7ef #fffee3 #f3f7f7 #f7f7f3 #fcf7ee #f7f7f7 #f7fbf4 #f5f7fb #fbf7f6 #fffeef #f7fbfb #fbfbf7 #fbfbfb #fbfbff #fbfffb #fffbfb #fbffff #fffffb #ffffff]', pal.toString());
-};
-
-exports['test palette rendering'] = function(beforeExit, assert) {
- var map = new mapnik.Map(600, 400);
- map.fromStringSync(fs.readFileSync('./examples/stylesheet.xml', 'utf8'), { strict: true, base: './examples/' });
- map.zoomAll();
-
- pal = new mapnik.Palette('\xff\x00\xff\xff\xff\xff', 'rgb');
-
- // Test rendering a blank image
- var filename = helper.filename();
- var buffer = map.renderSync('png', {palette: pal});
- assert.ok(buffer.length < 7000);
- map.renderFileSync(filename, {palette: pal});
- var stat = fs.statSync(filename);
- assert.ok(stat.size < 7000);
-};
+describe('mapnik.Palette ', function() {
+ it('should throw with invalid usage', function() {
+ // no 'new' keyword
+ assert.throws(function() { mapnik.Palette(); });
+ // invalid args
+ assert.throws(function() { new mapnik.Palette(); });
+ assert.throws(function() { new mapnik.Palette(1); });
+ assert.throws(function() { new mapnik.Palette('foo'); });
+ assert.throws(function() {
+ new mapnik.Palette('\x01\x02\x03');
+ }, (/invalid palette length/));
+ });
+
+ it('should be initialized property', function() {
+ var pal = new mapnik.Palette('\x01\x02\x03\x04');
+ assert.equal('[Palette 1 color #01020304]', pal.toString());
+
+ pal = new mapnik.Palette('\x01\x02\x03', 'rgb');
+ assert.equal('[Palette 1 color #010203]', pal.toString());
+
+ pal = new mapnik.Palette('\xff\x09\x93\xFF\x01\x02\x03\x04');
+ assert.equal('[Palette 2 colors #01020304 #ff0993]', pal.toString());
+ assert.equal('\x01\x02\x03\x04\xff\x09\x93\xFF', pal.toBuffer().toString('binary'));
+ });
+
+ it('should support 64 color ACT palettes', function() {
+ var pal = new mapnik.Palette(fs.readFileSync('./test/support/palettes/palette64.act'), 'act');
+ assert.equal('[Palette 64 colors #494746 #c37631 #89827c #d1955c #7397b9 #fc9237 #a09f9c #fbc147 #9bb3ce #b7c9a1 #b5d29c #c4b9aa #cdc4a5 #d5c8a3 #c1d7aa #ccc4b6 #dbd19c #b2c4d5 #eae487 #c9c8c6 #e4db99 #c9dcb5 #dfd3ac #cbd2c2 #d6cdbc #dbd2b6 #c0ceda #ece597 #f7ef86 #d7d3c3 #dfcbc3 #d1d0cd #d1e2bf #d3dec1 #dbd3c4 #e6d8b6 #f4ef91 #d3d3cf #cad5de #ded7c9 #dfdbce #fcf993 #ffff8a #dbd9d7 #dbe7cd #d4dce2 #e4ded3 #ebe3c9 #e0e2e2 #f4edc3 #fdfcae #e9e5dc #f4edda #eeebe4 #fefdc5 #e7edf2 #edf4e5 #f2efe9 #f6ede7 #fefedd #f6f4f0 #f1f5f8 #fbfaf8 #ffffff]', pal.toString());
+ });
+
+ it('should support 256 color ACT palettes', function() {
+ var pal = new mapnik.Palette(fs.readFileSync('./test/support/palettes/palette256.act'), 'act');
+ assert.equal('[Palette 256 colors #272727 #3c3c3c #484847 #564b41 #605243 #6a523e #555555 #785941 #5d5d5d #746856 #676767 #956740 #ba712e #787777 #cb752a #c27c3d #b68049 #dc8030 #df9e10 #878685 #e1a214 #928b82 #a88a70 #ea8834 #e7a81d #cb8d55 #909090 #94938c #e18f48 #f68d36 #6f94b7 #e1ab2e #8e959b #c79666 #999897 #ff9238 #ef9447 #a99a88 #f1b32c #919ca6 #a1a09f #f0b04b #8aa4bf #f8bc39 #b3ac8f #d1a67a #e3b857 #a8a8a7 #ffc345 #a2adb9 #afaeab #f9ab69 #afbba4 #c4c48a #b4b2af #dec177 #9ab2cf #a3bebb #d7b491 #b6cd9e #b5d29c #b9c8a2 #f1c969 #c5c79e #bbbab9 #cabdaa #a6bcd1 #cec4a7 #e7cc89 #dad98a #d5c9a3 #fabd8a #c1d7aa #cec5b4 #d1d1a5 #d9cf9f #c5c4c3 #d3c7b5 #ddd59d #b4c6d6 #d1cbb4 #d1c7ba #d7d1aa #e1c6ab #cbc7c2 #dbd0a9 #e8e58a #fee178 #d3cbba #dfd7a3 #d2cfb9 #c9ddb5 #d2cbbe #c3cbce #d7cbba #dcceb2 #dfd3aa #e5dd9a #dbd3b1 #ceccc6 #d7cbbe #d7cfba #dfc3be #dfd3ae #cbcbcb #cbd3c3 #d3cfc0 #e0d8aa #d7cfbe #dbd3b8 #ebe596 #dfd8b0 #c0ceda #f1ee89 #decfbc #d7cfc4 #d7d3c3 #d1d0cd #d2dfc0 #dbd3c3 #e7c7c3 #e7d7b3 #f2ed92 #d1e2bf #dad7c3 #fef383 #d3d3cf #dbd3c7 #e0d3c2 #dfd7c0 #ebe4a8 #dbd7c7 #dfd3c7 #f7f38f #c9d4de #dcdcc5 #dfd7c7 #e7d5c2 #d6d5d4 #faf78e #d7dfca #fbfb8a #fffb86 #dfd7cb #e5ddc0 #dad7d2 #ecd6c1 #cfd7de #e8d0cc #fbfb8e #fffb8a #eae3b8 #e3d7cd #dfdbce #fffb8e #ffff8a #f5efa6 #dae6cc #e3dbcf #edddc3 #dddbd6 #d5dbdf #ffff91 #e3dbd3 #fefc99 #e7dbd2 #eaddcd #e3dfd3 #ebd7d3 #dddddd #d4dee6 #e2dfd7 #fcdcc0 #e7dbd7 #e7dfd3 #ebe4cb #f4eeb8 #e3dfdb #e7dfd7 #ebded5 #e7e3d7 #fefea6 #e1ecd6 #ece5d3 #e7e3db #dee3e5 #ebe3db #efdfdb #efe3d8 #f4efc9 #e6ecdb #ebe3df #ebe7db #f0ecd3 #e5e6e5 #efe7da #ebe7df #efe3df #fefeb8 #dfe7ef #ebe7e3 #edebde #efe7e0 #e8efe0 #e7f3df #ebebe3 #e7ebe8 #f5edd9 #efebe3 #e3ebf1 #e9efe7 #ebebea #efebe7 #f0efe2 #ecf3e5 #fefdc9 #efefe7 #f3efe7 #f5f3e1 #f2efe9 #e9eef4 #ffeddf #efefef #f3efeb #f3f3eb #f0f7eb #fbf7e1 #fefed8 #f3f3ef #f7f3eb #eef3f7 #f7f7ea #f3f3f3 #f3f7ef #f7f3ef #f3f3f7 #f7f3f3 #f7f7ef #fffee3 #f3f7f7 #f7f7f3 #fcf7ee #f7f7f7 #f7fbf4 #f5f7fb #fbf7f6 #fffeef #f7fbfb #fbfbf7 #fbfbfb #fbfbff #fbfffb #fffbfb #fbffff #fffffb #ffffff]', pal.toString());
+ });
+
+ it('should support rendering', function() {
+ var map = new mapnik.Map(600, 400);
+ map.fromStringSync(fs.readFileSync('./examples/stylesheet.xml', 'utf8'), { strict: true, base: './examples/' });
+ map.zoomAll();
+
+ var pal = new mapnik.Palette('\xff\x00\xff\xff\xff\xff', 'rgb');
+
+ // Test rendering a blank image
+ var filename = helper.filename();
+ var buffer = map.renderSync('png', {palette: pal});
+ assert.ok(buffer.length < 7000);
+ map.renderFileSync(filename, {palette: pal});
+ var stat = fs.statSync(filename);
+ assert.ok(stat.size < 7000);
+ });
+});
View
33 test/parameters.test.js
@@ -1,22 +1,23 @@
var mapnik = require('mapnik');
var assert = require('assert');
+var assert = require('assert');
var fs = require('fs');
var path = require('path');
+describe('mapnik.Parameters ', function() {
+ it('should be accessible from map', function() {
+ var map = new mapnik.Map(1, 1);
+ map.loadSync('./test/support/extra_arbitary_map_parameters.xml');
+ var params = map.parameters;
+ assert.equal(params.decimal, 0.999);
+ assert.equal(params.integer, 10);
+ assert.equal(params.key, 'value2');
+ });
-exports['test getting map parameters'] = function(beforeExit) {
- var map = new mapnik.Map(1,1);
- map.loadSync('./test/support/extra_arbitary_map_parameters.xml')
- var params = map.parameters;
- assert.equal(params.decimal,0.999);
- assert.equal(params.integer,10);
- assert.equal(params.key,'value2');
-};
-
-exports['test setting map parameters'] = function(beforeExit) {
- var map = new mapnik.Map(1,1);
- assert.equal(map.toXML(),'<?xml version="1.0" encoding="utf-8"?>\n<Map srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"/>\n');
- map.parameters = {'a':'b'};
- assert.equal(map.toXML(),'<?xml version="1.0" encoding="utf-8"?>\n<Map srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">\n <Parameters>\n <Parameter name="a" type="string">b</Parameter>\n </Parameters>\n</Map>\n'
-);
-};
+ it('should be settable on map', function() {
+ var map = new mapnik.Map(1, 1);
+ assert.equal(map.toXML(), '<?xml version="1.0" encoding="utf-8"?>\n<Map srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"/>\n');
+ map.parameters = {'a': 'b'};
+ assert.equal(map.toXML(), '<?xml version="1.0" encoding="utf-8"?>\n<Map srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">\n <Parameters>\n <Parameter name="a" type="string">b</Parameter>\n </Parameters>\n</Map>\n');
+ });
+});
View
87 test/projection.test.js
@@ -1,47 +1,50 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var fs = require('fs');
var path = require('path');
-exports['test projection creation'] = function(beforeExit, assert) {
- assert.throws(function() { new mapnik.Projection('+init=epsg:foo'); },
- /failed to initialize projection with: '\+init=epsg:foo'/);
- assert.throws(function() { new mapnik.Projection('+proj +foo'); },
- /failed to initialize projection with: '\+proj \+foo'/);
-
-
- var wgs84 = new mapnik.Projection('+init=epsg:4326');
- assert.ok(wgs84 instanceof mapnik.Projection);
-};
-
-exports['test projection'] = function(beforeExit, assert) {
- var merc;
- try {
- // perhaps we've got a savvy user?
- merc = new mapnik.Projection('+init=epsg:900913');
- }
- catch (err) {
- // newer versions of proj4 have this code which is == 900913
- merc = new mapnik.Projection('+init=epsg:3857');
- }
-
- assert.ok(merc instanceof mapnik.Projection,
- 'warning, could not create a spherical mercator projection ' +
- 'with either epsg:900913 or epsg:3857, so they must be missing ' +
- 'from your proj4 epsg table (/usr/local/share/proj/epsg)');
-
- long_lat_coords = [-122.33517, 47.63752];
- merc_coords = merc.forward(long_lat_coords);
-
- assert.equal(merc_coords.length, 2);
- assert.notStrictEqual(merc_coords, [-13618288.8305, 6046761.54747]);
- assert.notStrictEqual(long_lat_coords, merc.inverse(merc.forward(long_lat_coords)));
-
- long_lat_bounds = [-122.420654, 47.605006, -122.2435, 47.67764];
- merc_bounds = merc.forward(long_lat_bounds);
-
- assert.equal(merc_bounds.length, 4);
- var expected = [-13627804.8659, 6041391.68077, -13608084.1728, 6053392.19471];
- assert.notStrictEqual(merc_bounds, expected);
- assert.notStrictEqual(long_lat_bounds, merc.inverse(merc.forward(long_lat_bounds)));
-};
+describe('mapnik.Projection ', function() {
+ it('should throw with invalid usage', function() {
+ assert.throws(function() { new mapnik.Projection('+init=epsg:foo'); },
+ /failed to initialize projection with: '\+init=epsg:foo'/);
+ assert.throws(function() { new mapnik.Projection('+proj +foo'); },
+ /failed to initialize projection with: '\+proj \+foo'/);
+
+
+ var wgs84 = new mapnik.Projection('+init=epsg:4326');
+ assert.ok(wgs84 instanceof mapnik.Projection);
+ });
+
+ it('should initialize properly', function() {
+ var merc;
+ try {
+ // perhaps we've got a savvy user?
+ merc = new mapnik.Projection('+init=epsg:900913');
+ }
+ catch (err) {
+ // newer versions of proj4 have this code which is == 900913
+ merc = new mapnik.Projection('+init=epsg:3857');
+ }
+
+ assert.ok(merc instanceof mapnik.Projection,
+ 'warning, could not create a spherical mercator projection ' +
+ 'with either epsg:900913 or epsg:3857, so they must be missing ' +
+ 'from your proj4 epsg table (/usr/local/share/proj/epsg)');
+
+ var long_lat_coords = [-122.33517, 47.63752];
+ var merc_coords = merc.forward(long_lat_coords);
+
+ assert.equal(merc_coords.length, 2);
+ assert.notStrictEqual(merc_coords, [-13618288.8305, 6046761.54747]);
+ assert.notStrictEqual(long_lat_coords, merc.inverse(merc.forward(long_lat_coords)));
+
+ var long_lat_bounds = [-122.420654, 47.605006, -122.2435, 47.67764];
+ var merc_bounds = merc.forward(long_lat_bounds);
+
+ assert.equal(merc_bounds.length, 4);
+ var expected = [-13627804.8659, 6041391.68077, -13608084.1728, 6053392.19471];
+ assert.notStrictEqual(merc_bounds, expected);
+ assert.notStrictEqual(long_lat_bounds, merc.inverse(merc.forward(long_lat_bounds)));
+ });
+});
View
67 test/render-async.test.js
@@ -1,47 +1,19 @@
-var path = require('path');
var mapnik = require('mapnik');
+var assert = require('assert');
+var path = require('path');
-
-exports['test asynchronous map rendering to file'] = function(beforeExit, assert) {
- var map = new mapnik.Map(600, 400);
- var filename = './test/tmp/renderFile.png';
- map.renderFile(filename, function(error) {
- assert.ok(!error);
- assert.ok(path.existsSync(filename));
- });
-
-};
-
-exports['async render'] = function(beforeExit, assert) {
-
- var rendered = false;
- var map = new mapnik.Map(256, 256);
- map.load('./examples/stylesheet.xml', function(err,map) {
- map.zoomAll();
- var im = new mapnik.Image(map.width, map.height);
- map.render(im, function(err, im) {
- im.encode('png', function(err,buffer) {
- var string = im.toString();
- assert.ok(string);
- rendered = true;
- });
+describe('mapnik async rendering', function() {
+ it('should render to a file', function(done) {
+ var map = new mapnik.Map(600, 400);
+ var filename = './test/tmp/renderFile.png';
+ map.renderFile(filename, function(error) {
+ assert.ok(!error);
+ assert.ok(path.existsSync(filename));
+ done();
});
});
- beforeExit(function() {
- assert.equal(rendered, true);
- });
-};
-
-
-// TODO - pooled and cloned render
-
-exports['async render loop'] = function(beforeExit, assert) {
-
- var rendered = 0;
- var expected = 10;
-
- var render = function() {
+ it('should render to an image', function(done) {
var map = new mapnik.Map(256, 256);
map.load('./examples/stylesheet.xml', function(err,map) {
map.zoomAll();
@@ -50,22 +22,9 @@ exports['async render loop'] = function(beforeExit, assert) {
im.encode('png', function(err,buffer) {
var string = im.toString();
assert.ok(string);
- rendered++;
+ done();
});
});
});
- };
-
- var loop = function() {
- for (var i = 0; i < expected; ++i) {
- render();
- }
- }
- loop();
- loop();
- loop();
-
- beforeExit(function() {
- assert.equal(rendered, expected*3);
});
-};
+});
View
26 test/render-sync.test.js
@@ -1,20 +1,16 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var path = require('path');
var helper = require('./support/helper');
-exports['sync render to file'] = function(beforeExit, assert) {
-
- var rendered = false;
- var map = new mapnik.Map(256, 256);
- map.loadSync('./examples/stylesheet.xml');
- map.zoomAll();
- var im = new mapnik.Image(map.width, map.height);
- var filename = helper.filename();
- map.renderFileSync(filename);
- assert.ok(path.existsSync(filename));
- rendered = true;
-
- beforeExit(function() {
- assert.equal(rendered, true);
+describe('mapnik sync rendering ', function() {
+ it('should render to a file', function() {
+ var map = new mapnik.Map(256, 256);
+ map.loadSync('./examples/stylesheet.xml');
+ map.zoomAll();
+ var im = new mapnik.Image(map.width, map.height);
+ var filename = helper.filename();
+ map.renderFileSync(filename);
+ assert.ok(path.existsSync(filename));
});
-};
+});
View
75 test/render_grid.test.js
@@ -1,51 +1,42 @@
var mapnik = require('mapnik');
+var assert = require('assert');
var fs = require('fs');
var stylesheet = './examples/stylesheet.xml';
-exports['test simple_grid rendering'] = function(beforeExit, assert) {
- var rendered = false;
- var reference = fs.readFileSync('./test/support/grid2.json', 'utf8');
- var reference_view = fs.readFileSync('./test/support/grid_view.json', 'utf8');
+describe('mapnik grid rendering ', function() {
+ it('should match expected output', function() {
+ var reference = fs.readFileSync('./test/support/grid2.json', 'utf8');
+ var reference_view = fs.readFileSync('./test/support/grid_view.json', 'utf8');
- var map_grid = new mapnik.Map(256, 256);
- map_grid.load(stylesheet, {strict: true}, function(err,map) {
- if (err) throw err;
- map.zoomAll();
- var grid = new mapnik.Grid(map.width, map.height, {key: '__id__'});
-
- /*
- map.renderLayerSync(grid,0, {fields:['NAME']});
- // FIXME: segfault!
- grid_utf = grid.encodeSync('utf', {resolution: 4});
- rendered = true;
- // END TEMP
- */
- var options = {'layer': 0,
- 'fields': ['NAME']
- };
- map.render(grid, options, function(err, grid) {
- assert.ok(!err);
- grid_utf = grid.encodeSync('utf', {resolution: 4});
- //fs.writeFileSync('./ref.json',JSON.stringify(grid_utf))
- assert.equal(JSON.stringify(grid_utf), reference);
- // pull an identical view and compare it to original grid
- var gv = grid.view(0, 0, 256, 256);
- gv_utf = gv.encodeSync('utf', {resolution: 4});
- assert.equal(JSON.stringify(gv_utf), reference);
+ var map_grid = new mapnik.Map(256, 256);
+ map_grid.load(stylesheet, {strict: true}, function(err,map) {
+ if (err) throw err;
+ map.zoomAll();
+ var grid = new mapnik.Grid(map.width, map.height, {key: '__id__'});
- // pull a subsetted view (greenland basically)
- var gv2 = grid.view(64, 64, 64, 64);
- assert.equal(gv2.width(), 64);