@@ -0,0 +1,73 @@
|
||||
Given /^the speedprofile "([^"]*)"$/ do |profile|
|
||||
read_speedprofile profile
|
||||
end
|
||||
|
||||
Given /^the speedprofile settings$/ do |table|
|
||||
table.raw.each do |row|
|
||||
speedprofile[ row[0] ] = row[1]
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the nodes$/ do |table|
|
||||
table.raw.each_with_index do |row,ri|
|
||||
row.each_with_index do |name,ci|
|
||||
unless name.empty?
|
||||
raise "*** node invalid name '#{name}', must be single characters" unless name.size == 1
|
||||
raise "*** invalid node name '#{name}', must me alphanumeric" unless name.match /[a-z0-9]/
|
||||
raise "*** duplicate node '#{name}'" if name_node_hash[name]
|
||||
node = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+ci*ZOOM, ORIGIN[1]-ri*ZOOM
|
||||
node << { :name => name }
|
||||
node.uid = OSM_UID
|
||||
osm_db << node
|
||||
name_node_hash[name] = node
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the ways$/ do |table|
|
||||
table.hashes.each do |row|
|
||||
name = row.delete 'nodes'
|
||||
raise "*** duplicate way '#{name}'" if name_way_hash[name]
|
||||
way = OSM::Way.new make_osm_id, OSM_USER, OSM_TIMESTAMP
|
||||
defaults = { 'highway' => 'primary' }
|
||||
way << defaults.merge( 'name' => name ).merge(row)
|
||||
way.uid = OSM_UID
|
||||
name.each_char do |c|
|
||||
raise "*** node invalid name '#{c}', must be single characters" unless c.size == 1
|
||||
raise "*** ways cannot use numbered nodes, '#{name}'" unless c.match /[a-z]/
|
||||
node = find_node_by_name(c)
|
||||
raise "*** unknown node '#{c}'" unless node
|
||||
way << node
|
||||
end
|
||||
osm_db << way
|
||||
name_way_hash[name] = way
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the relations$/ do |table|
|
||||
table.hashes.each do |row|
|
||||
relation = OSM::Relation.new make_osm_id, OSM_USER, OSM_TIMESTAMP
|
||||
relation << { :type => :restriction, :restriction => 'no_left_turn' }
|
||||
from_way = find_way_by_name(row['from'])
|
||||
raise "*** unknown way '#{row['from']}'" unless from_way
|
||||
to_way = find_way_by_name(row['to'])
|
||||
raise "*** unknown way '#{row['to']}'" unless to_way
|
||||
relation << OSM::Member.new( 'way', from_way.id, 'from' )
|
||||
relation << OSM::Member.new( 'way', to_way.id, 'to' )
|
||||
c = row['via']
|
||||
unless c.empty?
|
||||
raise "*** node invalid name '#{c}', must be single characters" unless c.size == 1
|
||||
raise "*** via node cannot use numbered nodes, '#{c}'" unless c.match /[a-z]/
|
||||
via_node = find_node_by_name(c)
|
||||
raise "*** unknown node '#{row['via']}'" unless via_node
|
||||
relation << OSM::Member.new( 'node', via_node.id, 'via' )
|
||||
end
|
||||
relation.uid = OSM_UID
|
||||
osm_db << relation
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the defaults$/ do
|
||||
end
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
require 'OSM/StreamParser'
|
||||
|
||||
class OSMTestParserCallbacks < OSM::Callbacks
|
||||
@@locations = nil
|
||||
|
||||
def self.locations
|
||||
if @@locations
|
||||
@@locations
|
||||
else
|
||||
#parse the test file, so we can later reference nodes and ways by name in tests
|
||||
@@locations = {}
|
||||
file = 'test/data/test.osm'
|
||||
callbacks = OSMTestParserCallbacks.new
|
||||
parser = OSM::StreamParser.new(:filename => file, :callbacks => callbacks)
|
||||
parser.parse
|
||||
puts @@locations
|
||||
end
|
||||
end
|
||||
|
||||
def node(node)
|
||||
@@locations[node.name] = [node.lat,node.lon]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Given /^the OSM file contains$/ do |string|
|
||||
file = 'data/test.osm'
|
||||
File.open( file, 'w') {|f| f.write(string) }
|
||||
|
||||
#convert from .osm to .osm.pbf, which is the format osrm reads
|
||||
system "osmosis --read-xml data/test.osm --write-pbf data/test.osm.pbf omitmetadata=true"
|
||||
end
|
||||
|
||||
Given /^the speedprofile contains$/ do |string|
|
||||
File.open( 'speedprofile.ini', 'w') {|f| f.write(string) }
|
||||
end
|
||||
|
||||
|
||||
|
||||
Given /^the data file "([^"]*)" is present$/ do |file|
|
||||
File.exists?(file).should == true
|
||||
end
|
||||
|
||||
When /^I run the extractor with "([^"]*)"$/ do |cmd|
|
||||
@response = `#{cmd}`
|
||||
#Dir.chdir @test_folder do
|
||||
# @response = IO.popen([cmd, :err=>[:child, :out]]) { |ls_io| ls_result_with_error = ls_io.read }
|
||||
#end
|
||||
end
|
||||
|
||||
When /^I run the preprocessor with "([^"]*)"$/ do |cmd|
|
||||
@response = `#{cmd}`
|
||||
end
|
||||
|
||||
Given /^the preprocessed files for "([^"]*)" are present and up to date$/ do |area|
|
||||
File.exists?("#{area}.osrm").should == true
|
||||
File.exists?("#{area}.osrm.names").should == true
|
||||
File.exists?("#{area}.osrm.restrictions").should == true
|
||||
File.exists?("#{area}.osrm.hsgr").should == true
|
||||
File.exists?("#{area}.osrm.nodes").should == true
|
||||
File.exists?("#{area}.osrm.ramIndex").should == true
|
||||
File.exists?("#{area}.osrm.fileIndex").should == true
|
||||
end
|
||||
|
||||
Then /^I should see the file "([^"]*)"$/ do |file|
|
||||
File.exists?(file).should == true
|
||||
end
|
||||
|
||||
When /^preprocessed files for "([^"]*)" has been removed$/ do |file|
|
||||
FileUtils.rm_r Dir["#{file}.*"], :secure => true
|
||||
end
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
When /^I request a route from ([^"]+) to ([^"]+)$/ do |a,b|
|
||||
@response = request_route a,b
|
||||
#puts @response.body
|
||||
#@response
|
||||
end
|
||||
|
||||
When /^I request a route from "([^"]*)" to "([^"]*)"$/ do |a,b|
|
||||
locations = OSMTestParserCallbacks.locations
|
||||
raise "Locations hash is empty. To reference nodes by name, please preprocess the test file earlier in the test." unless locations
|
||||
raise "Unknown node: #{a}" unless locations[a]
|
||||
raise "Unknown node: #{b}" unless locations[b]
|
||||
@response = request_route "#{locations[a][0]},#{locations[a][1]}", "#{locations[b][0]},#{locations[b][1]}"
|
||||
end
|
||||
|
||||
Then /^I should get a response/ do
|
||||
@response.code.should == "200"
|
||||
@response.body.should_not == nil
|
||||
@response.body.should_not == ''
|
||||
end
|
||||
|
||||
Then /^response should be valid JSON$/ do
|
||||
@json = JSON.parse @response.body
|
||||
end
|
||||
|
||||
Then /^response should be well-formed$/ do
|
||||
@json['version'].class.should == Float
|
||||
@json['status'].class.should == Fixnum
|
||||
@json['status_message'].class.should == String
|
||||
@json['route_summary'].class.should == Hash
|
||||
@json['route_geometry'].class.should == String
|
||||
@json['route_instructions'].class.should == Array
|
||||
@json['via_points'].class.should == Array
|
||||
@json['transactionId'].class.should == String
|
||||
end
|
||||
|
||||
Then /^a route should be found$/ do
|
||||
@json['status'].should == 0
|
||||
@json['status_message'].should == "Found route between points"
|
||||
end
|
||||
|
||||
Then /^no route should be found$/ do
|
||||
@json['status'].should == 207
|
||||
@json['status_message'].should == "Cannot find route between points"
|
||||
end
|
||||
|
||||
Then /^I should get a valid response$/ do
|
||||
step "I should get a response"
|
||||
step "response should be valid JSON"
|
||||
step "response should be well-formed"
|
||||
#step "no error should be reported in terminal"
|
||||
end
|
||||
|
||||
Then /^I should get a route$/ do
|
||||
step "I should get a valid response"
|
||||
step "a route should be found"
|
||||
#puts @response.body
|
||||
end
|
||||
|
||||
Then /^I should not get a route$/ do
|
||||
step "I should get a valid response"
|
||||
step "no route should be found"
|
||||
end
|
||||
|
||||
Then /^the route should start at "([^']*)"$/ do |name|
|
||||
@json['route_summary']['start_point'].should == name
|
||||
end
|
||||
|
||||
Then /^the route should end at "([^']*)"$/ do |name|
|
||||
@json['route_summary']['end_point'].should == name
|
||||
end
|
||||
|
||||
Then /^distance should be between (\d+) and (\d+)$/ do |min,max|
|
||||
@json['route_summary']['total_distance'].to_i.should >= min.to_i
|
||||
@json['route_summary']['total_distance'].to_i.should <= max.to_i
|
||||
end
|
||||
|
||||
Then /^the distance should be close to (\d+)m$/ do |d|
|
||||
@json['route_summary']['total_distance'].to_i.should >= d.to_i*0.95
|
||||
@json['route_summary']['total_distance'].to_i.should <= d.to_i/0.95
|
||||
end
|
||||
|
||||
Then /^number of instructions should be (\d+)$/ do |n|
|
||||
@json['route_instructions'].size.should == n
|
||||
end
|
||||
|
||||
Then /^there should be 1 turn$/ do
|
||||
step 'there should be 1 turns'
|
||||
end
|
||||
|
||||
Then /^there should be (\d+) turns$/ do |n|
|
||||
@json['route_instructions'].map {|t| t.first}.select {|t| t =~ /^Turn/ }.size.should == n.to_i
|
||||
end
|
||||
|
||||
Then /^there should be more than (\d+) turn$/ do |n|
|
||||
@json['route_instructions'].map {|t| t.first}.select {|t| t =~ /^Turn/ }.size.should > n.to_i
|
||||
end
|
||||
|
||||
Then /^there should not be any turns$/ do
|
||||
(@json['route_instructions'].size-1).should == 0
|
||||
end
|
||||
|
||||
def sanitize_route route
|
||||
route.split(',').map{|w| w.strip}.reject(&:empty?).join(', ')
|
||||
end
|
||||
|
||||
def computed_route
|
||||
@json['route_instructions'].map { |r| r[1] }.reject(&:empty?).join(', ')
|
||||
end
|
||||
|
||||
Then /^the route should follow "([^"]*)"$/ do |route|
|
||||
sanitize_route(route).should == computed_route
|
||||
end
|
||||
|
||||
Then /^the route should not follow "([^"]*)"$/ do |route|
|
||||
sanitize_route(route).should_not == computed_route
|
||||
end
|
||||
|
||||
Then /^the route should include "([^"]*)"$/ do |route|
|
||||
sanitize_route(route).should =~ /#{computed_route}/
|
||||
end
|
||||
|
||||
Then /^the route should not include "([^"]*)"$/ do |route|
|
||||
sanitize_route(route).should_not =~ /#{computed_route}/
|
||||
end
|
||||
|
||||
Then /^the route should stay on "([^"]*)"$/ do |way|
|
||||
step "the route should start at \"#{way}\""
|
||||
step "the route should end at \"#{way}\""
|
||||
step "the route should follow \"#{way}\""
|
||||
step "there should not be any turns"
|
||||
end
|
||||
|
||||
When /^I route between "([^"]*)" and "([^"]*)"$/ do |from,to|
|
||||
reprocess
|
||||
Dir.chdir 'test' do
|
||||
from_node = name_node_hash[from]
|
||||
to_node = name_node_hash[to]
|
||||
a = "#{from_node.lon},#{from_node.lat}"
|
||||
b = "#{to_node.lon},#{to_node.lat}"
|
||||
@route = parse_response( request_route(a,b) )
|
||||
end
|
||||
end
|
||||
|
||||
Then /^"([^"]*)" should be returned$/ do |route|
|
||||
@route.should == route.split(',').join(',')
|
||||
end
|
||||
|
||||
Then /^routability should be$/ do |table|
|
||||
osrm_kill
|
||||
build_ways_from_table table
|
||||
reprocess
|
||||
actual = []
|
||||
if table.headers&["forw","backw"] == []
|
||||
raise "*** routability tabel must contain either 'forw' or 'backw' column"
|
||||
end
|
||||
OSRMLauncher.new do
|
||||
table.hashes.each_with_index do |row,i|
|
||||
got = row.dup
|
||||
attempts = []
|
||||
if table.headers.include? 'forw'
|
||||
response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*ZOOM}","#{ORIGIN[1]},#{ORIGIN[0]+(2+WAY_SPACING*i)*ZOOM}")
|
||||
got['forw'] = route_status response
|
||||
if got['forw'] != row['forw']
|
||||
json = JSON.parse(response.body)
|
||||
attempts << { :attempt => 'Forward', :query => @query, :response => response }
|
||||
end
|
||||
end
|
||||
if table.headers.include? 'backw'
|
||||
response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(2+WAY_SPACING*i)*ZOOM}","#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*ZOOM}")
|
||||
got['backw'] = route_status response
|
||||
if got['backw'] != row['backw']
|
||||
attempts << { :attempt => 'Backward', :query => @query, :response => response }
|
||||
end
|
||||
end
|
||||
if got != row
|
||||
log_fail row,got,attempts
|
||||
end
|
||||
actual << got
|
||||
end
|
||||
end
|
||||
table.diff! actual
|
||||
end
|
||||
|
||||
When /^I route I should get$/ do |table|
|
||||
osrm_kill
|
||||
reprocess
|
||||
actual = []
|
||||
OSRMLauncher.new do
|
||||
table.hashes.each_with_index do |row,ri|
|
||||
from_node = @name_node_hash[ row['from'] ]
|
||||
raise "*** unknown from-node '#{row['from']}" unless from_node
|
||||
to_node = @name_node_hash[ row['to'] ]
|
||||
raise "*** unknown to-node '#{row['to']}" unless to_node
|
||||
response = request_route("#{from_node.lat},#{from_node.lon}", "#{to_node.lat},#{to_node.lon}")
|
||||
if response.code == "200" && response.body.empty? == false
|
||||
json = JSON.parse response.body
|
||||
if json['status'] == 0
|
||||
instructions = way_list json['route_instructions']
|
||||
end
|
||||
end
|
||||
|
||||
got = {'from' => row['from'], 'to' => row['to'] }
|
||||
if table.headers.include? 'start'
|
||||
got['start'] = instructions ? json['route_summary']['start_point'] : nil
|
||||
end
|
||||
if table.headers.include? 'end'
|
||||
got['end'] = instructions ? json['route_summary']['end_point'] : nil
|
||||
end
|
||||
if table.headers.include? 'route'
|
||||
got['route'] = (instructions || '').strip
|
||||
end
|
||||
|
||||
if got['route'] != row['route'] || got['start'] != row['start'] || got['end'] != row['end']
|
||||
failed = { :attempt => 'Backward', :query => @query, :response => response }
|
||||
log_fail row,got,[failed]
|
||||
end
|
||||
actual << got
|
||||
end
|
||||
end
|
||||
table.diff! actual
|
||||
end
|
||||
Reference in New Issue
Block a user