[osmium-tool] 16/44: Add tests for time-filter and clean up implementation.
Sebastiaan Couwenberg
sebastic at moszumanska.debian.org
Tue Jul 21 20:15:54 UTC 2015
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to tag v1.1.0
in repository osmium-tool.
commit a0c1c7c21d4341f92f52c4070e3ccc52135def0f
Author: Jochen Topf <jochen at topf.org>
Date: Thu Jun 25 22:38:34 2015 +0200
Add tests for time-filter and clean up implementation.
---
CMakeLists.txt | 26 ++++++++++++++++++++++++++
src/command_time_filter.cpp | 27 ++++++++++++++++++---------
test/time-filter/input.osh | 15 +++++++++++++++
test/time-filter/output-last.osm | 5 +++++
test/time-filter/output-range-0-5.osh | 13 +++++++++++++
test/time-filter/output-range-1-2.osh | 6 ++++++
test/time-filter/output-range-1a-2a.osh | 10 ++++++++++
test/time-filter/output-range-2-3.osh | 7 +++++++
test/time-filter/output-range-2-3a.osh | 9 +++++++++
test/time-filter/output-range-2-4.osh | 9 +++++++++
test/time-filter/output-ts1.osm | 6 ++++++
test/time-filter/output-ts2.osm | 6 ++++++
test/time-filter/output-ts3.osm | 6 ++++++
13 files changed, 136 insertions(+), 9 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a66a585..84a0bc3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -242,6 +242,32 @@ if(PANDOC)
do_test(help_cat "osmium help cat" "^OSMIUM-CAT\\(1\\)")
endif()
+#-----------------------------------------------------------------------------
+
+function(check_output _name _command _output)
+ add_test(NAME ${_name} COMMAND sh -c "${_command} | cmp --quiet - ${_output}")
+endfunction()
+
+function(check_time_filter _name _type _from _to _output)
+ set(_tdir "${PROJECT_SOURCE_DIR}/test/time-filter")
+ check_output(time-filter-${_name} "osmium time-filter --generator=test -f ${_type} ${_tdir}/input.osh ${_from} ${_to}" "${_tdir}/output-${_output}.${_type}")
+endfunction()
+
+check_time_filter(last osm "" "" last)
+check_time_filter(ts1 osm 2015-01-01T01:00:00Z "" ts1)
+check_time_filter(ts1a osm 2015-01-01T01:01:00Z "" ts1)
+check_time_filter(ts2 osm 2015-01-01T02:00:00Z "" ts2)
+check_time_filter(ts2a osm 2015-01-01T02:01:00Z "" ts2)
+check_time_filter(ts3 osm 2015-01-01T03:00:00Z "" ts3)
+check_time_filter(ts3a osm 2015-01-01T03:01:00Z "" ts3)
+
+check_time_filter(range-0-5 osh 2015-01-01T00:00:00Z 2015-01-01T05:00:00Z range-0-5)
+check_time_filter(range-1-2 osh 2015-01-01T01:00:00Z 2015-01-01T02:00:00Z range-1-2)
+check_time_filter(range-1a-2a osh 2015-01-01T01:01:00Z 2015-01-01T02:01:00Z range-1a-2a)
+check_time_filter(range-2-3 osh 2015-01-01T02:00:00Z 2015-01-01T03:00:00Z range-2-3)
+check_time_filter(range-2-3a osh 2015-01-01T02:00:00Z 2015-01-01T03:01:00Z range-2-3a)
+check_time_filter(range-2-4 osh 2015-01-01T02:00:00Z 2015-01-01T04:00:00Z range-2-4)
+
#-----------------------------------------------------------------------------
diff --git a/src/command_time_filter.cpp b/src/command_time_filter.cpp
index 5e5bff7..c7fa105 100644
--- a/src/command_time_filter.cpp
+++ b/src/command_time_filter.cpp
@@ -161,15 +161,24 @@ bool CommandTimeFilter::run() {
typedef osmium::DiffIterator<object_iterator> diff_iterator;
m_vout << "Filtering data...\n";
- std::copy_if(
- diff_iterator(object_it, object_end),
- diff_iterator(object_end, object_end),
- out,
- [this](const osmium::DiffObject& d){
- return ((d.end_time() == 0 || d.end_time() > m_from) &&
- d.start_time() <= m_to) &&
- (m_from != m_to || d.curr().visible());
- });
+
+ if (m_from == m_to) {
+ std::copy_if(
+ diff_iterator(object_it, object_end),
+ diff_iterator(object_end, object_end),
+ out,
+ [this](const osmium::DiffObject& d){
+ return d.is_visible_at(m_from);
+ });
+ } else {
+ std::copy_if(
+ diff_iterator(object_it, object_end),
+ diff_iterator(object_end, object_end),
+ out,
+ [this](const osmium::DiffObject& d){
+ return d.is_between(m_from, m_to);
+ });
+ }
out.flush();
writer.close();
diff --git a/test/time-filter/input.osh b/test/time-filter/input.osh
new file mode 100644
index 0000000..6bad359
--- /dev/null
+++ b/test/time-filter/input.osh
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="testdata" upload="false">
+ <node id="1" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="1" lon="1"/>
+ <node id="1" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="1" lon="2"/>
+ <node id="1" version="3" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="1" lon="3"/>
+ <node id="1" version="4" timestamp="2015-01-01T04:00:00Z" uid="1" user="test" changeset="4" visible="false"/>
+
+ <node id="2" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="2" lon="1"/>
+ <node id="2" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="2" lon="2"/>
+ <node id="2" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="2" lon="3"/> <!-- same timestamp as version 2 -->
+
+ <node id="3" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="3" lon="1"/>
+ <node id="3" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="3" lon="2"/>
+ <node id="3" version="4" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="3" lon="3"/>
+</osm>
diff --git a/test/time-filter/output-last.osm b/test/time-filter/output-last.osm
new file mode 100644
index 0000000..5b38046
--- /dev/null
+++ b/test/time-filter/output-last.osm
@@ -0,0 +1,5 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="test">
+ <node id="2" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="3" lat="2" lon="3"/>
+ <node id="3" version="4" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" lat="3" lon="3"/>
+</osm>
diff --git a/test/time-filter/output-range-0-5.osh b/test/time-filter/output-range-0-5.osh
new file mode 100644
index 0000000..e52fa79
--- /dev/null
+++ b/test/time-filter/output-range-0-5.osh
@@ -0,0 +1,13 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="test">
+ <node id="1" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="1" lon="1"/>
+ <node id="1" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="1" lon="2"/>
+ <node id="1" version="3" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="1" lon="3"/>
+ <node id="1" version="4" timestamp="2015-01-01T04:00:00Z" uid="1" user="test" changeset="4" visible="false"/>
+ <node id="2" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="2" lon="1"/>
+ <node id="2" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="2" lon="2"/>
+ <node id="2" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="2" lon="3"/>
+ <node id="3" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="3" lon="1"/>
+ <node id="3" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="3" lon="2"/>
+ <node id="3" version="4" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="3" lon="3"/>
+</osm>
diff --git a/test/time-filter/output-range-1-2.osh b/test/time-filter/output-range-1-2.osh
new file mode 100644
index 0000000..6974275
--- /dev/null
+++ b/test/time-filter/output-range-1-2.osh
@@ -0,0 +1,6 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="test">
+ <node id="1" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="1" lon="1"/>
+ <node id="2" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="2" lon="1"/>
+ <node id="3" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="3" lon="1"/>
+</osm>
diff --git a/test/time-filter/output-range-1a-2a.osh b/test/time-filter/output-range-1a-2a.osh
new file mode 100644
index 0000000..a0b737d
--- /dev/null
+++ b/test/time-filter/output-range-1a-2a.osh
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="test">
+ <node id="1" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="1" lon="1"/>
+ <node id="1" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="1" lon="2"/>
+ <node id="2" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="2" lon="1"/>
+ <node id="2" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="2" lon="2"/>
+ <node id="2" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="2" lon="3"/>
+ <node id="3" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" visible="true" lat="3" lon="1"/>
+ <node id="3" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="3" lon="2"/>
+</osm>
diff --git a/test/time-filter/output-range-2-3.osh b/test/time-filter/output-range-2-3.osh
new file mode 100644
index 0000000..94d7755
--- /dev/null
+++ b/test/time-filter/output-range-2-3.osh
@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="test">
+ <node id="1" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="1" lon="2"/>
+ <node id="2" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="2" lon="2"/>
+ <node id="2" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="2" lon="3"/>
+ <node id="3" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="3" lon="2"/>
+</osm>
diff --git a/test/time-filter/output-range-2-3a.osh b/test/time-filter/output-range-2-3a.osh
new file mode 100644
index 0000000..d9c9ec4
--- /dev/null
+++ b/test/time-filter/output-range-2-3a.osh
@@ -0,0 +1,9 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="test">
+ <node id="1" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="1" lon="2"/>
+ <node id="1" version="3" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="1" lon="3"/>
+ <node id="2" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="2" lon="2"/>
+ <node id="2" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="2" lon="3"/>
+ <node id="3" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="3" lon="2"/>
+ <node id="3" version="4" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="3" lon="3"/>
+</osm>
diff --git a/test/time-filter/output-range-2-4.osh b/test/time-filter/output-range-2-4.osh
new file mode 100644
index 0000000..d9c9ec4
--- /dev/null
+++ b/test/time-filter/output-range-2-4.osh
@@ -0,0 +1,9 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="test">
+ <node id="1" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="1" lon="2"/>
+ <node id="1" version="3" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="1" lon="3"/>
+ <node id="2" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="2" lon="2"/>
+ <node id="2" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="2" lon="3"/>
+ <node id="3" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" visible="true" lat="3" lon="2"/>
+ <node id="3" version="4" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" visible="true" lat="3" lon="3"/>
+</osm>
diff --git a/test/time-filter/output-ts1.osm b/test/time-filter/output-ts1.osm
new file mode 100644
index 0000000..1f60ee3
--- /dev/null
+++ b/test/time-filter/output-ts1.osm
@@ -0,0 +1,6 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="test">
+ <node id="1" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" lat="1" lon="1"/>
+ <node id="2" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" lat="2" lon="1"/>
+ <node id="3" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" lat="3" lon="1"/>
+</osm>
diff --git a/test/time-filter/output-ts2.osm b/test/time-filter/output-ts2.osm
new file mode 100644
index 0000000..41220cb
--- /dev/null
+++ b/test/time-filter/output-ts2.osm
@@ -0,0 +1,6 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="test">
+ <node id="1" version="2" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" lat="1" lon="2"/>
+ <node id="2" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="3" lat="2" lon="3"/>
+ <node id="3" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="2" lat="3" lon="2"/>
+</osm>
diff --git a/test/time-filter/output-ts3.osm b/test/time-filter/output-ts3.osm
new file mode 100644
index 0000000..c90c8c4
--- /dev/null
+++ b/test/time-filter/output-ts3.osm
@@ -0,0 +1,6 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version="0.6" generator="test">
+ <node id="1" version="3" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" lat="1" lon="3"/>
+ <node id="2" version="3" timestamp="2015-01-01T02:00:00Z" uid="1" user="test" changeset="3" lat="2" lon="3"/>
+ <node id="3" version="4" timestamp="2015-01-01T03:00:00Z" uid="1" user="test" changeset="3" lat="3" lon="3"/>
+</osm>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/osmium-tool.git
More information about the Pkg-grass-devel
mailing list