From ac0c5c27e7af62b530a3eb18ebbd2be82706253a Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Fri, 17 Mar 2017 15:19:56 +0000 Subject: [PATCH] First steps towards integrating MLD in node bindings --- include/nodejs/node_osrm_support.hpp | 28 ++++++++++++++++++++++++++++ test/nodejs/index.js | 12 ++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index 2ddde9a36..6d905d93e 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -138,6 +138,34 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo return engine_config_ptr(); } + auto algorithm = params->Get(Nan::New("algorithm").ToLocalChecked()); + if (algorithm->IsString()) + { + auto algorithm_str = *v8::String::Utf8Value(Nan::To(algorithm).ToLocalChecked()); + if (name == "CH") + { + engine_config->algorithm = EngineConfig::Algorithm::CH; + } + else if (name == "CoreCH") + { + engine_config->algorithm = EngineConfig::Algorithm::CoreCH; + } + else if (name == "MLD") + { + engine_config->algorithm = EngineConfig::Algorithm::MLD; + } + else + { + Nan::ThrowError("algorithm option must be one of 'CH', 'CoreCH', or 'MLD'."); + return engine_config_ptr(); + } + } + else if (!algorithm->IsUndefined()) + { + Nan::ThrowError("algorithm option must be a string and one of 'CH', 'CoreCH', or 'MLD'."); + return engine_config_ptr(); + } + return engine_config; } diff --git a/test/nodejs/index.js b/test/nodejs/index.js index 7cca6f93c..1b01d02c4 100644 --- a/test/nodejs/index.js +++ b/test/nodejs/index.js @@ -50,6 +50,18 @@ test('constructor: throws if given a non-string/obj argument', function(assert) /Parameter must be a path or options object/); }); +test('constructor: throws if given an unkown algorithm', function(assert) { + assert.plan(1); + assert.throws(function() { var osrm = new OSRM({algorithm: "Foo", shared_memory: true}); }, + /algorithm option needs to be one of 'CH', 'CoreCH', or 'MLD'/); +}); + +test('constructor: throws if given an invalid algorithm', function(assert) { + assert.plan(1); + assert.throws(function() { var osrm = new OSRM({algorithm: 3, shared_memory: true}); }, + /algorithm option needs to be a string and one of 'CH', 'CoreCH', or 'MLD'/); +}); + require('./route.js'); require('./trip.js'); require('./match.js');