From 06353941e6ef6200e7130e2ccf0389b10c098996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 24 Apr 2017 18:56:15 +0200 Subject: [PATCH] Implement test to exercise buffer-size configuration by format --- test/acceptance/buffer-size-format.js | 124 ++++++++++++++++++ .../tile-7.64.48-buffer-size-1.png | Bin 0 -> 1379 bytes .../tile-7.64.48-buffer-size-128.png | Bin 0 -> 2458 bytes 3 files changed, 124 insertions(+) create mode 100644 test/acceptance/buffer-size-format.js create mode 100644 test/fixtures/buffer-size/tile-7.64.48-buffer-size-1.png create mode 100644 test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.png diff --git a/test/acceptance/buffer-size-format.js b/test/acceptance/buffer-size-format.js new file mode 100644 index 00000000..bbf643bc --- /dev/null +++ b/test/acceptance/buffer-size-format.js @@ -0,0 +1,124 @@ +require('../support/test_helper'); + +var assert = require('../support/assert'); +var TestClient = require('../support/test-client'); +var IMAGE_TOLERANCE_PER_MIL = 20; +var mapnik = require('windshaft').mapnik; + +function createMapConfig (bufferSize) { + return { + version: '1.6.0', + buffersize: bufferSize, + layers: [{ + type: "cartodb", + options: { + sql: [ + 'select', + ' *', + 'from', + ' populated_places_simple_reduced', + ].join('\n'), + cartocss: [ + '#layer {', + ' polygon-fill: #374C70;', + ' polygon-opacity: 0.9;', + ' line-width: 1;', + ' line-color: #FFF;', + ' line-opacity: 0.5;', + '}', + '#layer::labels {', + ' text-name: [name];', + ' text-face-name: \'DejaVu Sans Book\';', + ' text-size: 20;', + ' text-fill: #FFFFFF;', + ' text-label-position-tolerance: 0;', + ' text-halo-radius: 1;', + ' text-halo-fill: #6F808D;', + ' text-dy: -10;', + ' text-allow-overlap: true;', + ' text-placement: point;', + ' text-placement-type: dummy;', + '}' + ].join('\n'), + cartocss_version: '2.3.0', + interactivity: 'cartodb_id' + } + }] + }; +} + +describe.only('buffer size per format', function () { + var testCases = [ + { + desc: 'should get png tile using buffer-size 1', + coords: { z: 7, x: 64, y: 48 }, + format: 'png', + fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-1.png', + mapConfig: createMapConfig({ png: 1, 'grid.json': 1 }), + assert: function (tile, callback) { + assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback); + } + }, + { + desc: 'should get png tile using buffer-size 128', + coords: { z: 7, x: 64, y: 48 }, + format: 'png', + fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.png', + mapConfig: createMapConfig({ png: 128, 'grid.json': 128 }), + assert: function (tile, callback) { + assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback); + } + }, + { + desc: 'should get mvt tile using buffer-size 1', + coords: { z: 7, x: 64, y: 48 }, + format: 'mvt', + fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-1.png', + mapConfig: createMapConfig({ mvt: 1 }), + assert: function (tile, callback) { + var tileJSON = tile.toJSON(); + var features = tileJSON[0].features; + assert.equal(features.length, 1); + + var map = new mapnik.Map(256, 256); + tile.render(map, new mapnik.Image(256, 256), function (err, image) { + assert.ifError(err); + assert.imageIsSimilarToFile(image, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback); + }.bind(this)); + } + }, + { + desc: 'should get mvt tile using buffer-size 128', + coords: { z: 7, x: 64, y: 48 }, + format: 'mvt', + fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.png', + mapConfig: createMapConfig({ mvt: 128 }), + assert: function (tile, callback) { + var tileJSON = tile.toJSON(); + var features = tileJSON[0].features + assert.equal(features.length, 9); + + var map = new mapnik.Map(256, 256); + tile.render(map, new mapnik.Image(256, 256), function (err, image) { + assert.ifError(err); + assert.imageIsSimilarToFile(image, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback); + }.bind(this)); + } + } + ]; + + testCases.forEach(function (test) { + it(test.desc, function (done) { + var testClient = new TestClient(test.mapConfig, 1234); + var coords = test.coords; + testClient.getTile(coords.z, coords.x, coords.y, { format: test.format }, function (err, res, tile) { + assert.ifError(err); + // To generate images use: + // tile.save(test.fixturePath); + test.assert(tile, function () { + testClient.drain(done); + }); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/fixtures/buffer-size/tile-7.64.48-buffer-size-1.png b/test/fixtures/buffer-size/tile-7.64.48-buffer-size-1.png new file mode 100644 index 0000000000000000000000000000000000000000..798f7ccaf80dc1cf5c2ba2a79ee1827b85156b96 GIT binary patch literal 1379 zcmd7S|2xwO00;2TN1rCz(rtA(GM;187v?B(>hWbd?NQAQHRRLovbj57c3C1~#pBEF zC{Km3_Sq#5GK509jUHEIeK~}*4fhyp8%E_@u6@q^5%)az{^kAt?e*JR5OORCXa0pb z0021J;Xnoefa?&Y*;;+(>%%uP*qS#!;vxjvSyTLYRlhKMmoq0IzIe!18&mxUz-INEbI+{!ZdEO=kB z*fn*P9q~tWgos==qw@C9yg2qwritT>)Nfd4|2G*HJy$H(BQrP>=}w1N1P+dx)q~$S zy7i=g@<@pfN7XTnM%FD|XJq)pk#Vl7g=bn$_g!lqmBsQs!iOja-|9_`IRY5{^;)%z z>x!mLO)tHtbndg9rg-+yFDRZ#*S;MjWrs#_I0&4mx)#ot|Mq22g^gF@-gJvhA#_*U zxngs1Z7)33ler%awY;ryedbmDQeiS#`O#O-FXe?i_DPO2OEHDUKI^>fuq@NQ_lcbHStnP*y+-(+a~` zYBrS83Z*O^4O^7`wVL%9@0Yuc=DgXgI*#@& zmSFeVl=k?2bDv2fExz~B+q0e*X@Jg@dA!x#7;AFSP>KP(k`F%|bGlqM`e06( z7 zvCJ^DkIM3;=1JURV26>AzNAEje*g96T5TE?|3WwB!aSWz@GCLC^Hvm(qwUuDL02*| zc-zGZDun*h-v4Cebi5O&R_<|`ew|JOR)wayeT(-ru#3tFT_Ay6IIfY;sWMnde(W~0 z*Q3^@vGS{|4z%og@O&FJyLupi?A*dX8xOY%D`>J;(lC?WxF)E$FX-oNU!ox*( z)s|H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