-
Notifications
You must be signed in to change notification settings - Fork 166
/
render-async.test.js
169 lines (157 loc) · 6.45 KB
/
render-async.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"use strict";
var test = require('tape');
var mapnik = require('../');
var exists = require('fs').existsSync || require('path').existsSync;
var path = require('path');
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'shape.input'));
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'gdal.input'));
test('should render to a file', (assert) => {
var map = new mapnik.Map(600, 400);
var filename = './test/tmp/renderFile.png';
map.renderFile(filename, {scale:1, scale_denominator:0, buffer_size:0, variables:{pizza:'pie'}}, function(error) {
assert.ok(!error);
assert.ok(exists(filename));
assert.end();
});
});
test('should fail to render two things at once', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var im = new mapnik.Image(map.width, map.height);
assert.throws(function() {
map.render(im, function(err, result) {});
map.render(im, function(err, result) {});
});
assert.end();
});
test('should fail to render two things at once with sync', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
var im = new mapnik.Image(map.width, map.height);
assert.throws(function() {
map.render(im, function(err, result) {});
map.renderSync(im);
});
assert.end();
});
test('should fail to renderFile two things at once', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
assert.throws(function() {
map.renderFile('./test/tmp/foo1.png', function(err, result) {});
map.renderFile('./test/tmp/foo2.png', function(err, result) {});
});
assert.end();
});
test('should fail to renderFile two things at once with Sync', (assert) => {
var map = new mapnik.Map(256, 256);
map.loadSync('./test/stylesheet.xml');
map.zoomAll();
assert.throws(function() {
map.renderFile('./test/tmp/foo1.png', function(err, result) {});
map.renderFileSync('./test/tmp/foo2.png');
});
assert.end();
});
test('should fail to render to an image gray8', (assert) => {
var map = new mapnik.Map(256, 256);
map.load('./test/stylesheet.xml', function(err,map) {
if (err) throw err;
map.zoomAll();
var im = new mapnik.Image(map.width, map.height, {type:mapnik.imageType.gray8});
assert.throws(function() { map.render(); } );
assert.throws(function() { map.render(im, null); } );
assert.throws(function() { map.render(null, function(err, im) {}); } );
assert.throws(function() { map.render({}, function(err, im) {}); } );
assert.throws(function() { map.render(im, null, function(err, im) {}); } );
assert.throws(function() { map.render(im, {buffer_size:null}, function(err, im) {}); } );
assert.throws(function() { map.render(im, {scale:null}, function(err, im) {}); } );
assert.throws(function() { map.render(im, {scale_denominator:null}, function(err, im) {}); } );
assert.throws(function() { map.render(im, {offset_x:null}, function(err, im) {}); } );
assert.throws(function() { map.render(im, {offset_y:null}, function(err, im) {}); } );
assert.throws(function() { map.render(im, {variables:null}, function(err, im) {}); } );
map.render(im, function(err, im) {
assert.throws(function() { if (err) throw err; });
assert.end();
});
});
});
test('should fail to renderFile', (assert) => {
var map = new mapnik.Map(256, 256);
map.load('./test/stylesheet.xml', function(err,map) {
if (err) throw err;
map.zoomAll();
map.srs = '+init=pizza';
var im = 'test/data/tmp';
assert.throws(function() { map.renderFile(); } );
assert.throws(function() { map.renderFile(im, null); } );
assert.throws(function() { map.renderFile(null, function(err, im) {}); } );
assert.throws(function() { map.renderFile({}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, null, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {buffer_size:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {scale:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {scale_denominator:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {format:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {format:''}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {variables:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {palette:null}, function(err, im) {}); } );
assert.throws(function() { map.renderFile(im, {palette:{}}, function(err, im) {}); } );
map.renderFile(im, function(err, im) {
assert.throws(function() { if (err) throw err; });
assert.end();
});
});
});
test('should render to an image', (assert) => {
var map = new mapnik.Map(256, 256);
map.load('./test/stylesheet.xml', function(err,map) {
if (err) throw err;
map.zoomAll();
var im = new mapnik.Image(map.width, map.height);
map.render(im, {variables: {pizza:'pie'}}, function(err, im) {
im.encode('png', {variables: {pizza:'pie'}}, function(err,buffer) {
assert.ok(buffer);
var string = im.toString();
assert.ok(string);
assert.end();
});
});
});
});
test('should render to an image', (assert) => {
var map = new mapnik.Map(256, 256);
map.load('./test/stylesheet.xml', function(err,map) {
if (err) throw err;
map.zoomAll();
var im = new mapnik.Image(map.width, map.height);
map.render(im, {variables: {pizza:'pie'}}, function(err, im) {
im.encode('png', {variables: {pizza:'pie'}}, function(err,buffer) {
assert.ok(buffer);
var string = im.toString();
assert.ok(string);
assert.end();
});
});
});
});
test('should render to an image - raster', (assert) => {
var map = new mapnik.Map(100, 100);
map.load('./test/raster.xml', function(err,map) {
if (err) throw err;
map.zoomAll();
var im = new mapnik.Image(map.width, map.height);
var im2 = new mapnik.Image.open('./test/data/images/sat_image-expected-100x100-near.png');
map.render(im, {variables: {pizza:'pie'}}, function(err, im) {
assert.equal(0, im.compare(im2));
im.encode('png', {variables: {pizza:'pie'}}, function(err,buffer) {
assert.ok(buffer);
var string = im.toString();
assert.ok(string);
assert.end();
});
});
});
});