Skip to content

Commit

Permalink
add test fixture for reprojected source and test upload/export
Browse files Browse the repository at this point in the history
  • Loading branch information
gretacb committed Jun 22, 2015
1 parent c7d45d2 commit 9a82f7f
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/test/app.test.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ var datatests = {
'srs': /ellps=GRS80/
}
},
'shp/NZ_Coastline_NZMG': {
filepath: '/shp/NZ_Coastline_NZMG/NZ_Coastline_NZMG.shp',
expected: {
'Datasource-file': window.testParams.dataPath + '/shp/NZ_Coastline_NZMG/NZ_Coastline_NZMG.shp',
'Datasource-type': 'shape',
'description': '',
'id': 'NZ_Coastline_NZMG',
'properties-buffer-size': '8',
'srs': '+proj=nzmg +lat_0=-41 +lon_0=173 +x_0=2510000 +y_0=6023150 +ellps=intl +units=m +no_defs'
}
}
};

tape('Drag and drop layer ', function(t) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"retire": "0.3.x",
"tape": "2.13.x",
"phantomjs": "1.9.10",
"mapnik-test-data": "http://mapbox-npm.s3.amazonaws.com/package/mapnik-test-data-2.0.1-98e4e5f4d94979576d4fff22c8e447a3a5048302.tgz"
"mapnik-test-data": "https://mapbox-npm.s3.amazonaws.com/package/mapnik-test-data-2.0.6-ed505d5585bb53e283a94957f1bb792c47816253.tgz"
},
"scripts": {
"start": "./index.js",
Expand Down
29 changes: 29 additions & 0 deletions test/expected/source-export-reprojected-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"scheme": "tms",
"attribution": "John Doe 2013.",
"center": [
0,
0,
3
],
"format": "pbf",
"maxzoom": 6,
"minzoom": 0,
"name": "Test source",
"vector_layers": [
{
"id": "NZ_Coastline_NZMG",
"description": "",
"fields": {
"featurecla": "String",
"scalerank": "Number"
}
}
],
"bounds": [
-180,
-85.05112877980659,
180,
85.0511287798066
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["NZGD49_New_Zealand_Map_Grid",GEOGCS["GCS_New_Zealand_1949",DATUM["D_New_Zealand_1949",SPHEROID["International_1924",6378388,297]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["New_Zealand_Map_Grid"],PARAMETER["latitude_of_origin",-41],PARAMETER["Longitude_Of_Origin",173],PARAMETER["false_easting",2510000],PARAMETER["false_northing",6023150],UNIT["Meter",1]]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["NZGD49 / New Zealand Map Grid",GEOGCS["NZGD49",DATUM["New_Zealand_Geodetic_Datum_1949",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993],AUTHORITY["EPSG","6272"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4272"]],PROJECTION["New_Zealand_Map_Grid"],PARAMETER["latitude_of_origin",-41],PARAMETER["central_meridian",173],PARAMETER["false_easting",2510000],PARAMETER["false_northing",6023150],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","27200"]]
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions test/fixtures-local-reprojected source/data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test source
attribution: "John Doe 2013."
minzoom: 0
maxzoom: 6
Layer:
- Datasource:
file: "NZ_Coastline_NZMG.shp"
type: shape
description: ""
id: NZ_Coastline_NZMG
name: NZ_Coastline_NZMG
properties:
"buffer-size": 0
srs: "+proj=nzmg +lat_0=-41 +lon_0=173 +x_0=2510000 +y_0=6023150 +ellps=intl +units=m +no_defs"
20 changes: 20 additions & 0 deletions test/fixtures-local-reprojected source/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
styles:
source: mapbox:///mapbox.mapbox-streets-v5
name: Test style
mtime: 1364498787322
center:
- 0
- 0
- 3
minzoom: 0
maxzoom: 19
_prefs:
saveCenter: false
attribution: ""
description: ""
bounds:
- -180
- -85
- 180
- 85
scale: 1
125 changes: 125 additions & 0 deletions test/source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var server;

var defaultsource = 'tmsource://' + tm.join(path.dirname(require.resolve('mapbox-studio-default-source')));
var localsource = 'tmsource://' + path.join(__dirname,'fixtures-local source');
var localreprojectedsource = 'tmsource://' + path.join(__dirname,'fixtures-local-reprojected source');
var tmppath = tm.join(tmp, 'Source ШЖФ - ' + +new Date);

test('setup: config', function(t) {
Expand Down Expand Up @@ -74,6 +75,30 @@ test('source.normalize', function(t) {
source.normalize({ Layer: [{ Datasource: { type: 'shape' } }] });
}, /Missing required field/);

// Test a non-mercator local source
var n = source.normalize({
id: 'tmsource://' + __dirname + '/fixtures-local-reprojected source',
Layer: [{
id: 'NZ_Coastline',
fields: {
Id: 'Valid helptext for a field',
missing: 'Invalid helptext no field named missing'
},
Datasource: {
type: 'shape',
file: __dirname + '/fixtures-local-reprojected source/NZ_Coastline_NZMG',
bogus: 'true'
}
}]
});
t.deepEqual(n.Layer.length, 1);
t.deepEqual(n.vector_layers.length, 1);
t.deepEqual(n.vector_layers[0].fields, {'Id':'Valid helptext for a field'},
'Populates field help');
t.deepEqual(Object.keys(tm.sortkeys(n.Layer[0])), ['id','Datasource','description','fields','properties','srs'],
'Populates deep defaults in Layer objects');
t.deepEqual(Object.keys(tm.sortkeys(n.Layer[0].Datasource)), ['file','type'],
'Strips invalid datasource properties based on type');

// Test a raster source with multiple layers
n = source.normalize({
Expand Down Expand Up @@ -423,6 +448,13 @@ test('source export: setup', function(t) {
});
});

test('source export: setup reprojected', function(t) {
testutil.createTmpProject('source-export-reprojected', localreprojectedsource, function(err, tmpid) {
t.ifError(err);
t.end();
});
});

test('source.mbtilesExport: exports mbtiles file', function(t) {
testutil.createTmpProject('source-export', localsource, function(err, id) {
t.ifError(err);
Expand All @@ -445,6 +477,28 @@ test('source.mbtilesExport: exports mbtiles file', function(t) {
});
});

test('source.mbtilesExport: exports reprojected mbtiles file', function(t) {
testutil.createTmpProject('source-export-reprojected', localreprojectedsource, function(err, id) {
t.ifError(err);

source.toHash(id, function(err, hash) {
t.ifError(err);
t.equal(false, fs.existsSync(hash), 'export does not exist yet');
var task = source.mbtilesExport(id);
t.strictEqual(task.id, id, 'sets task.id');
t.ok(task.progress instanceof stream.Duplex, 'sets task.progress');
task.progress.once('finished', function() {
t.equal(task.progress.progress().percentage, 100, 'progress.percentage');
t.equal(task.progress.progress().transferred, 16, 'progress.transferred');
t.equal(task.progress.progress().eta, 0, 'progress.eta');
t.equal(true, fs.existsSync(hash), 'export moved into place');
t.end();
});
});

});
});

test('source.mbtilesExport: verify export', function(t) {
testutil.createTmpProject('source-export', localsource, function(err, id) {
t.ifError(err);
Expand Down Expand Up @@ -494,6 +548,53 @@ test('source.mbtilesExport: verify export', function(t) {
});
});

test('source.mbtilesExport: verify reprojected export', function(t) {
testutil.createTmpProject('source-export-reprojected', localreprojectedsource, function(err, id) {
t.ifError(err);

var MBTiles = require('mbtiles');
source.toHash(id, function(err, hash) {
t.ifError(err);
new MBTiles({ pathname: hash }, function(err, src) {
t.ifError(err);
src._db.get('select count(1) as count, sum(length(tile_data)) as size from tiles;', function(err, row) {
t.ifError(err);
t.equal(row.count, 19);
t.equal(row.size, 3624);
check([
[0,0,0],
[1,1,0],
[2,3,1],
[3,7,2]
]);
});
function check(queue) {
if (!queue.length) return src.getInfo(function(err, info) {
t.ifError(err);

// Omit id, basename, filesize from fixture check.
delete info.id;
delete info.basename;
delete info.filesize;

if (UPDATE) {
fs.writeFileSync(__dirname + '/expected/source-export-reprojected-info.json', JSON.stringify(info, null, 2));
}
t.deepEqual(info, JSON.parse(fs.readFileSync(__dirname + '/expected/source-export-reprojected-info.json')));
t.end();
});
var zxy = queue.shift();
src.getTile(zxy[0],zxy[1],zxy[2], function(err, buffer) {
t.ifError(err);
t.ok(!!buffer);
check(queue);
});
}
});
});
});
});

test('source.mbtilesUpload: uploads map', function(t) {
testutil.createTmpProject('source-export', localsource, function(err, id) {
t.ifError(err);
Expand All @@ -518,6 +619,30 @@ test('source.mbtilesUpload: uploads map', function(t) {
});
});

test('source.mbtilesUpload: uploads reprojected map', function(t) {
testutil.createTmpProject('source-export-reprojected', localreprojectedsource, function(err, id) {
t.ifError(err);

source.upload(id, false, function(err, task) {
t.ifError(err);
t.strictEqual(task.id, id, 'sets task.id');
t.ok(task.progress instanceof stream.Duplex, 'sets task.progress');
// returns a task object with active progress
task.progress.on('error', function(err){
t.ifError(err);
t.end();
});
task.progress.on('finished', function(p){
t.equal(task.progress.progress().percentage, 100, 'progress.percentage');
t.equal(task.progress.progress().eta, 0, 'progress.eta');
t.end()
});

});

});
});

test('source.mbtilesUpload: does not allow redundant upload', function(t) {
testutil.createTmpProject('source-export', localsource, function(err, id) {
t.ifError(err);
Expand Down

0 comments on commit 9a82f7f

Please sign in to comment.