Skip to content

Commit

Permalink
add line, fill, circle, symbol query tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Mar 9, 2016
1 parent f8b40ea commit 61fe35a
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 123 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"eslint": "^1.5.0",
"eslint-config-mourner": "^1.0.0",
"istanbul": "^0.4.1",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#9dc62a59e0471196a605db265eaaa14fc7bcdf65",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#f875c1f35a7b2264220226af1f5327ae79b03339",
"prova": "^2.1.2",
"sinon": "^1.15.4",
"st": "^1.0.0",
Expand Down
73 changes: 3 additions & 70 deletions test/query.test.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,12 @@
'use strict';

var Map = require('../js/ui/map');
var browser = require('../js/util/browser');
var suite = require('mapbox-gl-test-suite').query;
var querySuite = require('mapbox-gl-test-suite').query;
var suiteImplementation = require('./suite_implementation');

var tests;

if (process.argv[1] === __filename && process.argv.length > 2) {
tests = process.argv.slice(2);
}

suite.run('js', {tests: tests}, function(style, options, callback) {
browser.devicePixelRatio = options.pixelRatio;

var map = new Map({
container: {
offsetWidth: options.width,
offsetHeight: options.height,
classList: {
add: function() {}
}
},
style: style,
classes: options.classes,
interactive: false,
attributionControl: false
});

map.painter.prepareBuffers = function() {
var gl = this.gl;

if (!gl.renderbuffer) {
// Create default renderbuffer
gl.renderbuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, gl.renderbuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA, gl.drawingBufferWidth, gl.drawingBufferHeight);
}

if (!gl.stencilbuffer) {
// Create default stencilbuffer
gl.stencilbuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, gl.stencilbuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, gl.drawingBufferWidth, gl.drawingBufferHeight);
}

if (!gl.framebuffer) {
// Create frame buffer
gl.framebuffer = gl.createFramebuffer();
}

gl.bindFramebuffer(gl.FRAMEBUFFER, gl.framebuffer);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, gl.renderbuffer);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, gl.stencilbuffer);

this.clearColor();
};

map.painter.bindDefaultFramebuffer = function() {
var gl = this.gl;
gl.bindFramebuffer(gl.FRAMEBUFFER, gl.framebuffer);
};

map.once('load', function() {
function done(err, results) {
if (err) return callback(err);
callback(null, results.map(function (r) {
delete r.layer;
return r;
}));
}

if (options.at) {
map.featuresAt(options.at, options, done);
} else {
map.featuresIn(options.in, options, done);
}
});
});
querySuite.run('js', {tests: tests}, suiteImplementation);
55 changes: 3 additions & 52 deletions test/render.test.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,12 @@
'use strict';

var Map = require('../js/ui/map');
var browser = require('../js/util/browser');
var suite = require('mapbox-gl-test-suite').render;
var renderSuite = require('mapbox-gl-test-suite').render;
var suiteImplementation = require('./suite_implementation');

var tests;

if (process.argv[1] === __filename && process.argv.length > 2) {
tests = process.argv.slice(2);
}

suite.run('js', {tests: tests}, function(style, options, callback) {
browser.devicePixelRatio = options.pixelRatio;

var map = new Map({
container: {
offsetWidth: options.width,
offsetHeight: options.height,
classList: {
add: function() {},
remove: function() {}
}
},
style: style,
classes: options.classes,
interactive: false,
attributionControl: false
});

if (options.debug) map.debug = true;
if (options.collisionDebug) map.collisionDebug = true;

var gl = map.painter.gl;

map.once('load', function() {
var w = options.width * browser.devicePixelRatio,
h = options.height * browser.devicePixelRatio;

var pixels = new Uint8Array(w * h * 4);
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels);

var data = new Buffer(pixels);

map.remove();
gl.destroy();

// Flip the scanlines.
var stride = w * 4;
var tmp = new Buffer(stride);
for (var i = 0, j = h - 1; i < j; i++, j--) {
var start = i * stride;
var end = j * stride;
data.copy(tmp, 0, start, start + stride);
data.copy(data, start, end, end + stride);
tmp.copy(data, end);
}

callback(null, data);
});
});
renderSuite.run('js', {tests: tests}, suiteImplementation);
73 changes: 73 additions & 0 deletions test/suite_implementation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';

var Map = require('../js/ui/map');
var browser = require('../js/util/browser');


module.exports = function(style, options, callback) {
browser.devicePixelRatio = options.pixelRatio;

var map = new Map({
container: {
offsetWidth: options.width,
offsetHeight: options.height,
classList: {
add: function() {},
remove: function() {}
}
},
style: style,
classes: options.classes,
interactive: false,
attributionControl: false
});

if (options.debug) map.debug = true;
if (options.collisionDebug) map.collisionDebug = true;

var gl = map.painter.gl;

map.once('load', function() {
var w = options.width * browser.devicePixelRatio,
h = options.height * browser.devicePixelRatio;

var pixels = new Uint8Array(w * h * 4);
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels);

var data = new Buffer(pixels);

// Flip the scanlines.
var stride = w * 4;
var tmp = new Buffer(stride);
for (var i = 0, j = h - 1; i < j; i++, j--) {
var start = i * stride;
var end = j * stride;
data.copy(tmp, 0, start, start + stride);
data.copy(data, start, end, end + stride);
tmp.copy(data, end);
}

if (options.at) {
map.featuresAt(options.at, options, done);
} else if (options.in) {
map.featuresIn(options.in, options, done);
} else {
done(null, []);
}

function done(err, results) {
map.remove();
gl.destroy();

if (err) return callback(err);

results = results.map(function (r) {
delete r.layer;
return r;
});

callback(null, data, results);
}

});
};

0 comments on commit 61fe35a

Please sign in to comment.